diff --git a/devtools/client/inspector/boxmodel/box-model.js b/devtools/client/inspector/boxmodel/box-model.js index 839b608f5ca2..0290d69af88a 100644 --- a/devtools/client/inspector/boxmodel/box-model.js +++ b/devtools/client/inspector/boxmodel/box-model.js @@ -126,8 +126,16 @@ BoxModel.prototype = { /** * Updates the box model panel by dispatching the new layout data. + * + * @param {String} reason + * Optional string describing the reason why the boxmodel is updated. */ - updateBoxModel() { + updateBoxModel(reason) { + this._updateReasons = this._updateReasons || []; + if (reason) { + this._updateReasons.push(reason); + } + let lastRequest = Task.spawn((function* () { if (!(this.isPanelVisible() && this.inspector.selection.isConnected() && @@ -151,9 +159,11 @@ BoxModel.prototype = { return this._lastRequest; } - this._lastRequest = null; + this.inspector.emit("boxmodel-view-updated", this._updateReasons); + + this._lastRequest = null; + this._updateReasons = []; - this.inspector.emit("boxmodel-view-updated"); return null; }).bind(this)).catch(console.error); @@ -173,7 +183,7 @@ BoxModel.prototype = { this.trackReflows(); } - this.updateBoxModel(); + this.updateBoxModel("new-selection"); }, /** diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js index 1638b4791415..dfcf8ceefe5a 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-navigation.js @@ -17,14 +17,16 @@ add_task(function* () { yield testFirstPage(inspector, view, testActor); info("Navigate to the second page"); + let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval(`content.location.href="${IFRAME2}"`); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; yield testSecondPage(inspector, view, testActor); info("Go back to the first page"); + onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.eval("content.history.back();"); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; yield testBackToFirstPage(inspector, view, testActor); }); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js index f589a82632e8..f1ed222949a4 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-after-reload.js @@ -14,8 +14,9 @@ add_task(function* () { yield assertBoxModelView(inspector, view, testActor); info("Reload the page"); + let onMarkupLoaded = waitForMarkupLoaded(inspector); yield testActor.reload(); - yield inspector.once("markuploaded"); + yield onMarkupLoaded; info("Test that the box model view works on the reloaded page"); yield assertBoxModelView(inspector, view, testActor); diff --git a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js index 3e7b82e46b10..6aa10e441ae9 100644 --- a/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js +++ b/devtools/client/inspector/boxmodel/test/browser_boxmodel_update-in-iframes.js @@ -40,8 +40,9 @@ function* testReflowsAfterIframeDeletion(inspector, view, testActor) { "iframe"); info("Deleting the iframe2"); + let onInspectorUpdated = inspector.once("inspector-updated"); yield removeIframe2(testActor); - yield inspector.once("inspector-updated"); + yield onInspectorUpdated; info("Selecting the test node in iframe1"); yield selectNodeInIframe1("p", inspector); diff --git a/devtools/client/inspector/boxmodel/test/head.js b/devtools/client/inspector/boxmodel/test/head.js index 6074a45ec8ec..de25fe893077 100644 --- a/devtools/client/inspector/boxmodel/test/head.js +++ b/devtools/client/inspector/boxmodel/test/head.js @@ -66,10 +66,37 @@ function openBoxModelView() { /** * Wait for the boxmodel-view-updated event. - * @return a promise + * + * @param {InspectorPanel} inspector + * The instance of InspectorPanel currently loaded in the toolbox. + * @param {Boolean} waitForSelectionUpdate + * Should the boxmodel-view-updated event come from a new selection. + * @return {Promise} a promise */ -function waitForUpdate(inspector) { - return inspector.once("boxmodel-view-updated"); +function waitForUpdate(inspector, waitForSelectionUpdate) { + return new Promise(resolve => { + inspector.on("boxmodel-view-updated", function onUpdate(e, reasons) { + // Wait for another update event if we are waiting for a selection related event. + if (waitForSelectionUpdate && !reasons.includes("new-selection")) { + return; + } + + inspector.off("boxmodel-view-updated", onUpdate); + resolve(); + }); + }); +} + +/** + * Wait for both boxmode-view-updated and markuploaded events. + * + * @return {Promise} a promise that resolves when both events have been received. + */ +function waitForMarkupLoaded(inspector) { + return Promise.all([ + waitForUpdate(inspector), + inspector.once("markuploaded"), + ]); } function getStyle(testActor, selector, propertyName) { @@ -93,6 +120,7 @@ function setStyle(testActor, selector, propertyName, value) { */ var _selectNode = selectNode; selectNode = function* (node, inspector, reason) { + let onUpdate = waitForUpdate(inspector, true); yield _selectNode(node, inspector, reason); - yield waitForUpdate(inspector); + yield onUpdate; }; diff --git a/devtools/client/inspector/test/shared-head.js b/devtools/client/inspector/test/shared-head.js index a953d547e7f5..c42690a2813e 100644 --- a/devtools/client/inspector/test/shared-head.js +++ b/devtools/client/inspector/test/shared-head.js @@ -52,7 +52,15 @@ var openInspectorSidebarTab = Task.async(function* (id) { let {toolbox, inspector, testActor} = yield openInspector(); info("Selecting the " + id + " sidebar"); - inspector.sidebar.select(id); + + if (id === "computedview" || id === "layoutview") { + // The layout and computed views should wait until the box-model widget is ready. + let onBoxModelViewReady = inspector.once("boxmodel-view-updated"); + inspector.sidebar.select(id); + yield onBoxModelViewReady; + } else { + inspector.sidebar.select(id); + } return { toolbox,