Bug 1401187 - Consider tool reload when reloading web page in DAMP. r=bgrins
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 20 Sep 2017 00:20:33 +0200
changeset 435476 ae2699e5b050cc2e607bbca597060dc300cac65e
parent 435475 9bb338b4b503e30c7511d65f9ecd7dfc035b4bc9
child 435477 97a7cd935f22129be5d75fdc68ff9239ef229373
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1401187
milestone58.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 1401187 - Consider tool reload when reloading web page in DAMP. r=bgrins MozReview-Commit-ID: JMAqIuMf6mr
testing/talos/talos/tests/devtools/addon/content/damp.js
testing/talos/talos/tests/devtools/addon/content/pages/simple.html
--- a/testing/talos/talos/tests/devtools/addon/content/damp.js
+++ b/testing/talos/talos/tests/devtools/addon/content/damp.js
@@ -60,27 +60,37 @@ Damp.prototype = {
     });
   },
 
   closeCurrentTab() {
     this._win.BrowserCloseTabOrWindow();
     return this._win.gBrowser.selectedTab;
   },
 
-  reloadPage() {
+  reloadPage(onReload) {
     let startReloadTimestamp = performance.now();
     return new Promise((resolve, reject) => {
       let browser = gBrowser.selectedBrowser;
-      browser.addEventListener("load", function onload() {
-        let stopReloadTimestamp = performance.now();
-        resolve({
-          time: stopReloadTimestamp - startReloadTimestamp
+      if (typeof (onReload) == "function") {
+        onReload().then(function() {
+          let stopReloadTimestamp = performance.now();
+          resolve({
+            time: stopReloadTimestamp - startReloadTimestamp
+          });
         });
-      }, {capture: true, once: true});
+      } else {
+        browser.addEventListener("load", function onload() {
+          let stopReloadTimestamp = performance.now();
+          resolve({
+            time: stopReloadTimestamp - startReloadTimestamp
+          });
+        }, {capture: true, once: true});
+      }
       browser.reload();
+
     });
   },
 
   openToolbox(tool = "webconsole") {
     let tab = getActiveTab(getMostRecentBrowserWindow());
     let target = TargetFactory.forTab(tab);
     let startRecordTimestamp = performance.now();
     let showPromise = gDevTools.showToolbox(target, tool);
@@ -285,50 +295,85 @@ Damp.prototype = {
     return toolbox;
   },
 
   async closeToolboxAndLog(name) {
     let {time} = await this.closeToolbox();
     this._results.push({name: name + ".close.DAMP", value: time });
   },
 
-  async reloadPageAndLog(name) {
-    let {time} = await this.reloadPage();
+  async reloadPageAndLog(name, onReload) {
+    let {time} = await this.reloadPage(onReload);
     this._results.push({name: name + ".reload.DAMP", value: time });
   },
 
   async _coldInspectorOpen(url) {
     await this.testSetup(url);
     await this.openToolboxAndLog("cold.inspector", "inspector");
     await this.closeToolbox();
     await this.testTeardown();
   },
 
-  _getToolLoadingTests(url, label) {
+  _getToolLoadingTests(url, label, { expectedMessages, expectedSources }) {
     let subtests = {
       inspectorOpen: Task.async(function* () {
         yield this.testSetup(url);
-        yield this.openToolboxAndLog(label + ".inspector", "inspector");
-        yield this.reloadPageAndLog(label + ".inspector");
+        let toolbox = yield this.openToolboxAndLog(label + ".inspector", "inspector");
+        let onReload = async function() {
+          let inspector = toolbox.getPanel("inspector");
+          // First wait for markup view to be loaded against the new root node
+          await inspector.once("new-root");
+          // Then wait for inspector to be updated
+          await inspector.once("inspector-updated");
+        };
+        yield this.reloadPageAndLog(label + ".inspector", onReload);
         yield this.closeToolboxAndLog(label + ".inspector");
         yield this.testTeardown();
       }),
 
       webconsoleOpen: Task.async(function* () {
         yield this.testSetup(url);
-        yield this.openToolboxAndLog(label + ".webconsole", "webconsole");
-        yield this.reloadPageAndLog(label + ".webconsole");
+        let toolbox = yield this.openToolboxAndLog(label + ".webconsole", "webconsole");
+        let onReload = async function() {
+          let webconsole = toolbox.getPanel("webconsole");
+          await new Promise(done => {
+            let messages = 0;
+            let receiveMessages = () => {
+              if (++messages == expectedMessages) {
+                webconsole.hud.ui.off("new-messages", receiveMessages);
+                done();
+              }
+            };
+            webconsole.hud.ui.on("new-messages", receiveMessages);
+          });
+        };
+        yield this.reloadPageAndLog(label + ".webconsole", onReload);
         yield this.closeToolboxAndLog(label + ".webconsole");
         yield this.testTeardown();
       }),
 
       debuggerOpen: Task.async(function* () {
         yield this.testSetup(url);
-        yield this.openToolboxAndLog(label + ".jsdebugger", "jsdebugger");
-        yield this.reloadPageAndLog(label + ".jsdebugger");
+        let toolbox = yield this.openToolboxAndLog(label + ".jsdebugger", "jsdebugger");
+        let onReload = async function() {
+          let dbg = toolbox.getPanel("jsdebugger");
+          await new Promise(done => {
+            let { selectors, store } = dbg.panelWin.getGlobalsForTesting();
+            let unsubscribe;
+            function countSources() {
+              const sources = selectors.getSources(store.getState());
+              if (sources.size == expectedSources) {
+                unsubscribe();
+                done();
+              }
+            }
+            unsubscribe = store.subscribe(countSources);
+          });
+        };
+        yield this.reloadPageAndLog(label + ".jsdebugger", onReload);
         yield this.closeToolboxAndLog(label + ".jsdebugger");
         yield this.testTeardown();
       }),
 
       styleEditorOpen: Task.async(function* () {
         yield this.testSetup(url);
         yield this.openToolboxAndLog(label + ".styleeditor", "styleeditor");
         yield this.reloadPageAndLog(label + ".styleeditor");
@@ -542,18 +587,19 @@ Damp.prototype = {
       // Run cold test only once
       let topWindow = getMostRecentBrowserWindow();
       if (!topWindow.coldRunDAMP) {
         topWindow.coldRunDAMP = true;
         tests = tests.concat(this._coldInspectorOpen);
       }
     }
 
-    tests = tests.concat(this._getToolLoadingTests(SIMPLE_URL, "simple"));
-    tests = tests.concat(this._getToolLoadingTests(COMPLICATED_URL, "complicated"));
+    tests = tests.concat(this._getToolLoadingTests(SIMPLE_URL, "simple", { expectedMessages: 1, expectedSources: 1 }));
+
+    tests = tests.concat(this._getToolLoadingTests(COMPLICATED_URL, "complicated", { expectedMessages: 7, expectedSources: 32 }));
 
     if (config.subtests.indexOf("consoleBulkLogging") > -1) {
       tests = tests.concat(this._consoleBulkLoggingTest);
     }
     if (config.subtests.indexOf("consoleStreamLogging") > -1) {
       tests = tests.concat(this._consoleStreamLoggingTest);
     }
     this._doSequence(tests, this._doneInternal);
--- a/testing/talos/talos/tests/devtools/addon/content/pages/simple.html
+++ b/testing/talos/talos/tests/devtools/addon/content/pages/simple.html
@@ -1,9 +1,14 @@
 <html>
 <head>
 <meta charset="UTF-8"/>
 <title>Simple Page for DAMP Test</title>
+<script>
+  window.addEventListener("load", function() {
+    console.log("loaded");
+  });
+</script>
 </head>
 <body>
 	<h1>This is a simple page</h1>
 </body>
 </html>