Bug 1277348 - Use a common navigateTo helper in inspector tests. r=pbro
MozReview-Commit-ID: Ev8ifjObIiD
--- a/devtools/client/inspector/test/browser_inspector_destroy-after-navigation.js
+++ b/devtools/client/inspector/test/browser_inspector_destroy-after-navigation.js
@@ -4,24 +4,19 @@
"use strict";
// Testing that closing the inspector after navigating to a page doesn't fail.
const URL_1 = "data:text/plain;charset=UTF-8,abcde";
const URL_2 = "data:text/plain;charset=UTF-8,12345";
add_task(function* () {
- let { toolbox } = yield openInspectorForURL(URL_1);
+ let { inspector, toolbox } = yield openInspectorForURL(URL_1);
- info("Navigating to different URL.");
- let navigated = toolbox.target.once("navigate");
- navigateTo(toolbox, URL_2);
-
- info("Waiting for 'navigate' event from toolbox target.");
- yield navigated;
+ yield navigateTo(inspector, URL_2);
info("Destroying toolbox");
try {
yield toolbox.destroy();
ok(true, "Toolbox destroyed");
} catch (e) {
ok(false, "An exception occured while destroying toolbox");
console.error(e);
--- a/devtools/client/inspector/test/browser_inspector_navigation.js
+++ b/devtools/client/inspector/test/browser_inspector_navigation.js
@@ -9,35 +9,35 @@
const TEST_URL_FILE = "browser/devtools/client/inspector/test/" +
"doc_inspector_breadcrumbs.html";
const TEST_URL_1 = "http://test1.example.org/" + TEST_URL_FILE;
const TEST_URL_2 = "http://test2.example.org/" + TEST_URL_FILE;
add_task(function* () {
- let { inspector, toolbox, testActor } = yield openInspectorForURL(TEST_URL_1);
- let markuploaded = inspector.once("markuploaded");
+ let { inspector, testActor } = yield openInspectorForURL(TEST_URL_1);
yield selectNode("#i1", inspector);
info("Navigating to a different page.");
- yield navigateTo(toolbox, TEST_URL_2);
-
- info("Waiting for markup view to load after navigation.");
- yield markuploaded;
+ yield navigateTo(inspector, TEST_URL_2);
ok(true, "New page loaded");
yield selectNode("#i1", inspector);
- markuploaded = inspector.once("markuploaded");
+ let markuploaded = inspector.once("markuploaded");
+ let onUpdated = inspector.once("inspector-updated");
info("Going back in history");
yield testActor.eval("history.go(-1)");
info("Waiting for markup view to load after going back in history.");
yield markuploaded;
+ info("Check that the inspector updates");
+ yield onUpdated;
+
ok(true, "Old page loaded");
is((yield testActor.eval("location.href;")), TEST_URL_1, "URL is correct.");
yield selectNode("#i1", inspector);
});
--- a/devtools/client/inspector/test/browser_inspector_select-last-selected.js
+++ b/devtools/client/inspector/test/browser_inspector_select-last-selected.js
@@ -59,43 +59,37 @@ add_task(function* () {
let { inspector, toolbox, testActor } = yield openInspectorForURL(PAGE_1);
for (let { url, nodeToSelect, selectedNode } of TEST_DATA) {
if (nodeToSelect) {
info("Selecting node " + nodeToSelect + " before navigation.");
yield selectNode(nodeToSelect, inspector);
}
- let onNewRoot = inspector.once("new-root");
yield navigateToAndWaitForNewRoot(url);
- info("Waiting for new root.");
- yield onNewRoot;
-
- info("Waiting for inspector to update after new-root event.");
- yield inspector.once("inspector-updated");
-
let nodeFront = yield getNodeFront(selectedNode, inspector);
ok(nodeFront, "Got expected node front");
is(inspector.selection.nodeFront, nodeFront,
selectedNode + " is selected after navigation.");
}
- function navigateToAndWaitForNewRoot(url) {
+ function* navigateToAndWaitForNewRoot(url) {
info("Navigating and waiting for new-root event after navigation.");
- let newRoot = inspector.once("new-root");
+ let current = yield testActor.eval("location.href");
+ if (url == current) {
+ info("Reloading page.");
+ let markuploaded = inspector.once("markuploaded");
+ let onNewRoot = inspector.once("new-root");
+ let onUpdated = inspector.once("inspector-updated");
- return testActor.eval("location.href")
- .then(current => {
- if (url == current) {
- info("Reloading page.");
- let activeTab = toolbox.target.activeTab;
- return activeTab.reload();
- }
-
- info("Navigating to " + url);
- navigateTo(toolbox, url);
-
- return newRoot;
- });
+ let activeTab = toolbox.target.activeTab;
+ yield activeTab.reload();
+ info("Waiting for inspector to be ready.");
+ yield markuploaded;
+ yield onNewRoot;
+ yield onUpdated;
+ } else {
+ yield navigateTo(inspector, url);
+ }
}
});
--- a/devtools/client/inspector/test/head.js
+++ b/devtools/client/inspector/test/head.js
@@ -49,20 +49,34 @@ registerCleanupFunction(() => {
registerCleanupFunction(function* () {
// Move the mouse outside inspector. If the test happened fake a mouse event
// somewhere over inspector the pointer is considered to be there when the
// next test begins. This might cause unexpected events to be emitted when
// another test moves the mouse.
EventUtils.synthesizeMouseAtPoint(1, 1, {type: "mousemove"}, window);
});
-var navigateTo = function (toolbox, url) {
- let activeTab = toolbox.target.activeTab;
- return activeTab.navigateTo(url);
-};
+function* navigateTo(inspector, url) {
+ let markuploaded = inspector.once("markuploaded");
+ let onNewRoot = inspector.once("new-root");
+ let onUpdated = inspector.once("inspector-updated");
+
+ info("Navigating to: " + url);
+ let activeTab = inspector.toolbox.target.activeTab;
+ yield activeTab.navigateTo(url);
+
+ info("Waiting for markup view to load after navigation.");
+ yield markuploaded;
+
+ info("Waiting for new root.");
+ yield onNewRoot;
+
+ info("Waiting for inspector to update after new-root event.");
+ yield onUpdated;
+}
/**
* Start the element picker and focus the content window.
* @param {Toolbox} toolbox
* @param {Boolean} skipFocus - Allow tests to bypass the focus event.
*/
var startPicker = Task.async(function* (toolbox, skipFocus) {
info("Start the element picker");