Bug 1396539 - Wait correctly for inspector load before resolving toolbox-ready. r=pbro draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 05 Sep 2017 11:31:01 +0200
changeset 660185 5db74483cdbd02c26e8c46c4346544902feef8fe
parent 659384 f64e2b4dcf5eec0b4ad456c149680a67b7c26dc4
child 730149 8e537a76901f7fb62531bc4425c6c766d22ebe92
push id78307
push userbmo:poirot.alex@gmail.com
push dateWed, 06 Sep 2017 17:13:25 +0000
reviewerspbro
bugs1396539
milestone57.0a1
Bug 1396539 - Wait correctly for inspector load before resolving toolbox-ready. r=pbro MozReview-Commit-ID: GP3O1NZqVEE
devtools/client/debugger/test/mochitest/browser_dbg_pause-warning.js
devtools/client/inspector/inspector.js
devtools/client/inspector/markup/markup.js
devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js
--- a/devtools/client/debugger/test/mochitest/browser_dbg_pause-warning.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg_pause-warning.js
@@ -28,19 +28,17 @@ function test() {
   });
 }
 
 function testPause() {
   gDebugger.gThreadClient.addOneTimeListener("paused", () => {
     ok(gDebugger.gThreadClient.paused,
       "threadClient.paused has been updated to true.");
 
-    gToolbox.once("inspector-selected").then(inspector => {
-      inspector.once("inspector-updated").then(testNotificationIsUp1);
-    });
+    gToolbox.once("inspector-selected").then(testNotificationIsUp1);
     gToolbox.selectTool("inspector");
   });
 
   EventUtils.sendMouseEvent({ type: "mousedown" },
     gDebugger.document.getElementById("resume"),
     gDebugger);
 
   // Evaluate a script to fully pause the debugger
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -230,17 +230,17 @@ Inspector.prototype = {
         }).catch(console.error),
         this._target.actorHasMethod("inspector", "resolveRelativeURL").then(value => {
           this._supportsResolveRelativeURL = value;
         }).catch(console.error),
       ]);
     });
   },
 
-  _deferredOpen: function (defaultSelection) {
+  _deferredOpen: async function (defaultSelection) {
     this.breadcrumbs = new HTMLBreadcrumbs(this);
 
     this.walker.on("new-root", this.onNewRoot);
 
     this.selection.on("new-node-front", this.onNewSelection);
     this.selection.on("detached-front", this.onDetached);
 
     if (this.target.isLocalTab) {
@@ -270,37 +270,35 @@ Inspector.prototype = {
       this.target.on("thread-resumed", this.updateDebuggerPausedWarning);
       this._toolbox.on("select", this.updateDebuggerPausedWarning);
       this.updateDebuggerPausedWarning();
     }
 
     this._initMarkup();
     this.isReady = false;
 
-    return new Promise(resolve => {
-      this.once("markuploaded", () => {
-        this.isReady = true;
+    this.setupSearchBox();
+    this.setupSidebar();
+    this.setupExtensionSidebars();
 
-        // All the components are initialized. Let's select a node.
-        if (defaultSelection) {
-          this.selection.setNodeFront(defaultSelection, "inspector-open");
-          this.markup.expandNode(this.selection.nodeFront);
-        }
+    await this.once("markuploaded");
+    this.isReady = true;
 
-        // And setup the toolbar only now because it may depend on the document.
-        this.setupToolbar();
+    // All the components are initialized. Let's select a node.
+    if (defaultSelection) {
+      let onAllPanelsUpdated = this.once("inspector-updated");
+      this.selection.setNodeFront(defaultSelection, "inspector-open");
+      await onAllPanelsUpdated;
+      await this.markup.expandNode(this.selection.nodeFront);
+    }
 
-        this.emit("ready");
-        resolve(this);
-      });
-
-      this.setupSearchBox();
-      this.setupSidebar();
-      this.setupExtensionSidebars();
-    });
+    // And setup the toolbar only now because it may depend on the document.
+    await this.setupToolbar();
+    this.emit("ready");
+    return this;
   },
 
   _onBeforeNavigate: function () {
     this._defaultNode = null;
     this.selection.setNodeFront(null);
     this._destroyMarkup();
     this.isDirty = false;
     this._pendingSelection = null;
--- a/devtools/client/inspector/markup/markup.js
+++ b/devtools/client/inspector/markup/markup.js
@@ -1150,17 +1150,17 @@ MarkupView.prototype = {
     });
   },
 
   /**
    * Expand the node's children.
    */
   expandNode: function (node) {
     let container = this.getContainer(node);
-    this._expandContainer(container);
+    return this._expandContainer(container);
   },
 
   /**
    * Expand the entire tree beneath a container.
    *
    * @param  {MarkupContainer} container
    *         The container to expand.
    */
@@ -1643,17 +1643,17 @@ MarkupView.prototype = {
         if (!this._containers) {
           return promise.reject("markup view destroyed");
         }
         this._queuedChildUpdates.delete(container);
 
         // If children are dirty, we got a change notification for this node
         // while the request was in progress, we need to do it again.
         if (container.childrenDirty) {
-          return this._updateChildren(container, {expand: centered});
+          return this._updateChildren(container, {expand: centered || expand});
         }
 
         let fragment = this.doc.createDocumentFragment();
 
         for (let child of children.nodes) {
           let childContainer = this.importNode(child, flash);
           fragment.appendChild(childContainer.elt);
         }
--- a/devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js
+++ b/devtools/client/inspector/test/browser_inspector_switch-to-inspector-on-pick.js
@@ -28,12 +28,9 @@ function openToolbox(tab) {
 function* startPickerAndAssertSwitchToInspector(toolbox) {
   info("Clicking element picker button.");
   let pickButton = toolbox.doc.querySelector("#command-button-pick");
   pickButton.click();
 
   info("Waiting for inspector to be selected.");
   yield toolbox.once("inspector-selected");
   is(toolbox.currentToolId, "inspector", "Switched to the inspector");
-
-  info("Waiting for inspector to update.");
-  yield toolbox.getCurrentPanel().once("inspector-updated");
 }