bug 926325 - Refactored test to avoid js errors in test run; r=mikeratcliffe
authorPatrick Brosset <pbrosset@mozilla.com>
Tue, 15 Oct 2013 17:32:00 +0200
changeset 166303 82184578e17c9352a7b4b5ea2d56d3e8911e28cf
parent 166252 858e3e2130c9dc1de3950704a85185b4189059e4
child 166304 dd9a6a9181bdee7b9af5ef07fdf736e08a952f2b
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikeratcliffe
bugs926325
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 926325 - Refactored test to avoid js errors in test run; r=mikeratcliffe
browser/devtools/inspector/inspector-panel.js
browser/devtools/inspector/test/browser_inspector_bug_922125_destroy_on_navigate.js
--- a/browser/devtools/inspector/inspector-panel.js
+++ b/browser/devtools/inspector/inspector-panel.js
@@ -21,16 +21,43 @@ loader.lazyGetter(this, "SelectorSearch"
 
 const LAYOUT_CHANGE_TIMER = 250;
 
 /**
  * Represents an open instance of the Inspector for a tab.
  * The inspector controls the highlighter, the breadcrumbs,
  * the markup view, and the sidebar (computed view, rule view
  * and layout view).
+ *
+ * Events:
+ * - ready
+ *      Fired when the inspector panel is opened for the first time and ready to
+ *      use
+ * - new-root
+ *      Fired after a new root (navigation to a new page) event was fired by
+ *      the walker, and taken into account by the inspector (after the markup
+ *      view has been reloaded)
+ * - markuploaded
+ *      Fired when the markup-view frame has loaded
+ * - layout-change
+ *      Fired when the layout of the inspector changes
+ * - breadcrumbs-updated
+ *      Fired when the breadcrumb widget updates to a new node
+ * - layoutview-updated
+ *      Fired when the layoutview (box model) updates to a new node
+ * - markupmutation
+ *      Fired after markup mutations have been processed by the markup-view
+ * - computed-view-refreshed
+ *      Fired when the computed rules view updates to a new node
+ * - computed-view-property-expanded
+ *      Fired when a property is expanded in the computed rules view
+ * - computed-view-property-collapsed
+ *      Fired when a property is collapsed in the computed rules view
+ * - rule-view-refreshed
+ *      Fired when the rule view updates to a new node
  */
 function InspectorPanel(iframeWindow, toolbox) {
   this._toolbox = toolbox;
   this._target = toolbox._target;
   this.panelDoc = iframeWindow.document;
   this.panelWin = iframeWindow;
   this.panelWin.inspector = this;
 
@@ -315,16 +342,17 @@ InspectorPanel.prototype = {
         return;
       }
       this.selection.setNodeFront(defaultNode, "navigateaway");
 
       this._initMarkup();
       this.once("markuploaded", () => {
         this.markup.expandNode(this.selection.nodeFront);
         this.setupSearchBox();
+        this.emit("new-root");
       });
     });
   },
 
   _selectionCssSelector: null,
 
   /**
    * Set the currently selected node unique css selector.
--- a/browser/devtools/inspector/test/browser_inspector_bug_922125_destroy_on_navigate.js
+++ b/browser/devtools/inspector/test/browser_inspector_bug_922125_destroy_on_navigate.js
@@ -5,62 +5,81 @@ let Toolbox = devtools.Toolbox;
 let TargetFactory = devtools.TargetFactory;
 
 function test() {
   waitForExplicitFinish();
 
   const URL_1 = "data:text/html;charset=UTF-8,<div id='one' style='color:red;'>ONE</div>";
   const URL_2 = "data:text/html;charset=UTF-8,<div id='two' style='color:green;'>TWO</div>";
 
-  let inspector;
+  let toolbox, inspector;
 
   // open tab, load URL_1, and wait for load to finish
   let tab = gBrowser.selectedTab = gBrowser.addTab();
   let target = TargetFactory.forTab(gBrowser.selectedTab);
+  let deferred = promise.defer();
   let browser = gBrowser.getBrowserForTab(tab);
 
-  function onPageOneLoad() {
-    browser.removeEventListener("load", onPageOneLoad, true);
+  function onTabLoad() {
+    browser.removeEventListener("load", onTabLoad, true);
+    deferred.resolve(null);
+  }
+  browser.addEventListener("load", onTabLoad, true);
+  browser.loadURI(URL_1);
 
-    gDevTools.showToolbox(target).then(aToolbox => {
-      return aToolbox.selectTool("inspector");
-    }).then(i => {
+  // open devtools panel
+  deferred.promise.then(() => {
+    return gDevTools.showToolbox(target, null, Toolbox.HostType.BOTTOM);
+  }).then(aToolbox => {
+    toolbox = aToolbox;
+  }).then(() => {
+    // select the inspector
+    return toolbox.selectTool("inspector").then(i => {
       inspector = i;
 
       // Verify we are on page one
       let testNode = content.document.querySelector("#one");
       ok(testNode, "We have the test node on page 1");
 
       assertMarkupViewIsLoaded();
+    });
+  }).then(() => {
+    // navigate to URL_2
+    let deferred = promise.defer();
 
-      // Listen to will-navigate to check if the view is empty
-      target.on("will-navigate", () => {
-        info("Navigation to page 2 has started, the inspector should be empty");
-        assertMarkupViewIsEmpty();
-      });
-      inspector.once("markuploaded", () => {
-        info("Navigation to page 2 was done, the inspector should be back up");
+    // Listen to will-navigate to check if the view is empty
+    target.on("will-navigate", () => {
+      info("Navigation to page 2 has started, the inspector should be empty");
+      assertMarkupViewIsEmpty();
+    });
+    inspector.once("new-root", () => {
+      info("Navigation to page 2 was done, the inspector should be back up");
 
-        // Verify we are on page one
-        let testNode = content.document.querySelector("#two");
-        ok(testNode, "We have the test node on page 2");
+      // Verify we are on page one
+      let testNode = content.document.querySelector("#two");
+      ok(testNode, "We have the test node on page 2");
+
+      // On page 2 load, verify we have the right content
+      assertMarkupViewIsLoaded();
 
-        // On page 2 load, verify we have the right content
-        assertMarkupViewIsLoaded();
-        endTests();
+      inspector.selection.setNode(content.document.querySelector("#two"));
+      inspector.once("inspector-updated", () => {
+        deferred.resolve();
       });
+    });
 
-      // Navigate to page 2
+    inspector.selection.setNode(content.document.querySelector("#one"));
+    inspector.once("inspector-updated", () => {
       browser.loadURI(URL_2);
     });
-  }
 
-  // Navigate to page 1
-  browser.addEventListener("load", onPageOneLoad, true);
-  browser.loadURI(URL_1);
+    return deferred.promise;
+  }).then(() => {
+    endTests();
+  });
 
   function assertMarkupViewIsLoaded() {
     let markupViewBox = inspector.panelDoc.getElementById("markup-box");
     is(markupViewBox.childNodes.length, 1, "The markup-view is loaded");
   }
 
   function assertMarkupViewIsEmpty() {
     let markupViewBox = inspector.panelDoc.getElementById("markup-box");