Bug 913641 - Execute test steps off the main reload event loop. r=miker
authorPatrick Brosset <pbrosset@mozilla.com>
Wed, 11 Sep 2013 09:50:44 -0400
changeset 146674 169a0df8cdb4c0616ce2f9a1813be9b1e8083bff
parent 146673 947a298ea5bb90af2c2d7ba4e2630ff61ae97052
child 146675 7fa0fd335e9f78d21d2b7c22d30884e26e9b695a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmiker
bugs913641
milestone26.0a1
Bug 913641 - Execute test steps off the main reload event loop. r=miker
browser/devtools/inspector/test/browser_inspector_select_last_selected.html
browser/devtools/inspector/test/browser_inspector_select_last_selected.js
browser/devtools/inspector/test/browser_inspector_select_last_selected2.html
--- a/browser/devtools/inspector/test/browser_inspector_select_last_selected.html
+++ b/browser/devtools/inspector/test/browser_inspector_select_last_selected.html
@@ -1,14 +1,21 @@
 <!DOCTYPE html>
-
-<div id="id1"></div>
-<div id="id2"></div>
-<div id="id3">
-	<ul class="aList">
-		<li class="item"></li>
-		<li class="item"></li>
-		<li class="item"></li>
-		<li class="item">
-			<span id="id4"></span>
-		</li>
-	</ul>
-</div>
\ No newline at end of file
+<html lang="en">
+	<head>
+		<meta charset="UTF-8">
+		<title>select last selected test</title>
+	</head>
+	<body>
+		<div id="id1"></div>
+		<div id="id2"></div>
+		<div id="id3">
+			<ul class="aList">
+				<li class="item"></li>
+				<li class="item"></li>
+				<li class="item"></li>
+				<li class="item">
+					<span id="id4"></span>
+				</li>
+			</ul>
+		</div>
+	</body>
+</html>
\ No newline at end of file
--- a/browser/devtools/inspector/test/browser_inspector_select_last_selected.js
+++ b/browser/devtools/inspector/test/browser_inspector_select_last_selected.js
@@ -25,79 +25,102 @@ function test() {
   }, true);
   content.location = page1;
 
   function startTests() {
     testSameNodeSelectedOnPageReload();
   }
 
   function endTests() {
-    toolbox.destroy();
-    toolbox = inspector = page1 = page2 = null;
-    gBrowser.removeCurrentTab();
-    finish();
+    executeSoon(() => {
+      toolbox.destroy();
+      toolbox = inspector = page1 = page2 = null;
+      gBrowser.removeCurrentTab();
+      finish();
+    });
   }
 
-  function testReSelectingAnElement(id, callback) {
+  function loadPageAnd(page, callback) {
+    inspector.once("markuploaded", () => {
+      executeSoon(callback);
+    });
+
+    if (page) {
+      content.location = page;
+    } else {
+      content.location.reload();
+    }
+  }
+
+  function reloadAndReselect(id, callback) {
     let div = content.document.getElementById(id);
-    inspector.selection.setNode(div);
+
     inspector.once("inspector-updated", () => {
       is(inspector.selection.node, div);
-      inspector.once("markuploaded", () => {
+
+      loadPageAnd(false, () => {
         is(inspector.selection.node.id, id, "Node re-selected after reload");
-        callback();
+        executeSoon(callback);
       });
-      content.location.reload();
     });
+
+    inspector.selection.setNode(div);
   }
 
   // Test that nodes selected on the test page remain selected after reload
   function testSameNodeSelectedOnPageReload()
   {
     // Select a few nodes and check they are re-selected after reload of the same
     // page
-    testReSelectingAnElement("id1", () => {
-      testReSelectingAnElement("id2", () => {
-        testReSelectingAnElement("id3", () => {
-          testReSelectingAnElement("id4", testBodySelectedOnNavigate);
+    reloadAndReselect("id1", () => {
+      reloadAndReselect("id2", () => {
+        reloadAndReselect("id3", () => {
+          reloadAndReselect("id4", testBodySelectedOnNavigate);
         });
       });
     });
   }
 
   // Test that since the previously selected node doesn't exist on the new page
   // the body is selected
   function testBodySelectedOnNavigate() {
     // Last node selected was id4, go to a different page and check body is
     // selected
-    inspector.once("markuploaded", () => {
-      is(
-        inspector.selection.node.tagName.toLowerCase(),
-        "body",
-        "Node not found, selecting body"
-      );
-      testSameNodeSelectedOnNavigateAwayAndBack();
+    loadPageAnd(page2, () => {
+      executeSoon(() => {
+        is(
+          inspector.selection.node.tagName.toLowerCase(),
+          "body",
+          "Node not found, body selected"
+        );
+        executeSoon(testSameNodeSelectedOnNavigateAwayAndBack);
+      });
     });
-    content.location = page2;
   }
 
   // Test that the node selected on page 1 gets selected again after a navigation
   // is made to another page and back again
   function testSameNodeSelectedOnNavigateAwayAndBack() {
     // On page2, select id5
     let id = "id5";
     let div = content.document.getElementById(id);
-    inspector.selection.setNode(div);
+
     inspector.once("inspector-updated", () => {
       is(inspector.selection.node.id, id);
-      // go to page1 but do not select anything
-      inspector.once("markuploaded", () => {
-        // go back to page2 and check id5 is still the current selection
-        inspector.once("markuploaded", () => {
-          is(inspector.selection.node.id, id, "Node re-selected after navigation");
-          endTests();
+
+      executeSoon(() => {
+        // go to page1 but do not select anything
+        loadPageAnd(page1, () => {
+
+          executeSoon(() => {
+            // go back to page2 and check id5 is still the current selection
+            loadPageAnd(page2, () => {
+              is(inspector.selection.node.id, id, "Node re-selected after navigation");
+              executeSoon(endTests);
+            });
+          });
         });
-        content.location = page2;
       });
-      content.location = page1;
     });
+
+    inspector.selection.setNode(div);
   }
 }
--- a/browser/devtools/inspector/test/browser_inspector_select_last_selected2.html
+++ b/browser/devtools/inspector/test/browser_inspector_select_last_selected2.html
@@ -1,3 +1,10 @@
 <!DOCTYPE html>
-
-<div id="id5"></div>
\ No newline at end of file
+<html lang="en">
+	<head>
+		<meta charset="UTF-8">
+		<title>select last selected test</title>
+	</head>
+	<body>
+		<div id="id5"></div>
+	</body>
+</html>
\ No newline at end of file