Bug 1419350 - Update tests; r=ochameau draft
authorJan Odvarko <odvarko@gmail.com>
Thu, 01 Mar 2018 10:48:41 +0100
changeset 761743 b8ccd200f913ffcd93d3b9bb44b77c9555654572
parent 761742 4e2c4d9cc66e2ae4e8c03f5419922903d717f858
push id100983
push userjodvarko@mozilla.com
push dateThu, 01 Mar 2018 09:49:17 +0000
reviewersochameau
bugs1419350
milestone60.0a1
Bug 1419350 - Update tests; r=ochameau MozReview-Commit-ID: ArLb7ItI9hT
testing/talos/talos/tests/devtools/addon/content/damp.js
testing/talos/talos/tests/devtools/addon/content/pages/custom/panels-in-background/panels-in-background.html
testing/talos/talos/tests/devtools/addon/content/pages/custom/panels-in-background/sjs_simple-test-server.sjs
--- a/testing/talos/talos/tests/devtools/addon/content/damp.js
+++ b/testing/talos/talos/tests/devtools/addon/content/damp.js
@@ -18,19 +18,22 @@ XPCOMUtils.defineLazyGetter(this, "EVENT
 });
 XPCOMUtils.defineLazyGetter(this, "TargetFactory", function() {
   let { TargetFactory } = require("devtools/client/framework/target");
   return TargetFactory;
 });
 
 const webserver = Services.prefs.getCharPref("addon.test.damp.webserver");
 
-const SIMPLE_URL = webserver + "/tests/devtools/addon/content/pages/simple.html";
+const PAGES_BASE_URL = webserver + "/tests/devtools/addon/content/pages/";
+const SIMPLE_URL = PAGES_BASE_URL + "simple.html";
 const COMPLICATED_URL = webserver + "/tests/tp5n/bild.de/www.bild.de/index.html";
-const CUSTOM_URL = webserver + "/tests/devtools/addon/content/pages/custom/$TOOL/index.html";
+const CUSTOM_URL = PAGES_BASE_URL + "custom/$TOOL/index.html";
+const PANELS_IN_BACKGROUND = PAGES_BASE_URL +
+  "custom/panels-in-background/panels-in-background.html";
 
 // Record allocation count in new subtests if DEBUG_DEVTOOLS_ALLOCATIONS is set to
 // "normal". Print allocation sites to stdout if DEBUG_DEVTOOLS_ALLOCATIONS is set to
 // "verbose".
 const DEBUG_ALLOCATIONS = env.get("DEBUG_DEVTOOLS_ALLOCATIONS");
 
 function getMostRecentBrowserWindow() {
   return Services.wm.getMostRecentWindow("navigator:browser");
@@ -706,37 +709,58 @@ async _consoleOpenWithCachedMessagesTest
   async _coldInspectorOpen() {
     await this.testSetup(SIMPLE_URL);
     await this.openToolboxAndLog("cold.inspector", "inspector");
     await this.closeToolbox();
     await this.testTeardown();
   },
 
   async _panelsInBackgroundReload() {
-    let url = "data:text/html;charset=UTF-8," + encodeURIComponent(`
-      <script>
-      // Log a significant amount of messages
-      for(let i = 0; i < 2000; i++) {
-        console.log("log in background", i);
-      }
-      </script>
-    `);
-    await this.testSetup(url);
+    await this.testSetup(PANELS_IN_BACKGROUND);
+
+    // Make sure the Console and Network panels are initialized
     let toolbox = await this.openToolbox("webconsole");
+    let monitor = await toolbox.selectTool("netmonitor");
 
-    // Select the options panel to make the console be in background.
+    // Select the options panel to make both the Console and Network
+    // panel be in background.
     // Options panel should not do anything on page reload.
     await toolbox.selectTool("options");
 
+    // Reload the page and wait for all HTTP requests
+    // to finish (1 doc + 600 XHRs).
+    let payloadReady = this.waitForPayload(601, monitor.panelWin);
     await this.reloadPageAndLog("panelsInBackground", toolbox);
+    await payloadReady;
 
+    // Clean up
     await this.closeToolbox();
     await this.testTeardown();
   },
 
+  waitForPayload(count, panelWin) {
+    return new Promise(resolve => {
+      let payloadReady = 0;
+
+      function onPayloadReady(_, id) {
+        payloadReady++;
+        maybeResolve();
+      }
+
+      function maybeResolve() {
+        if (payloadReady >= count) {
+          panelWin.off(EVENTS.PAYLOAD_READY, onPayloadReady);
+          resolve();
+        }
+      }
+
+      panelWin.on(EVENTS.PAYLOAD_READY, onPayloadReady);
+    });
+  },
+
   async reloadInspectorAndLog(label, toolbox) {
     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");
     };
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/devtools/addon/content/pages/custom/panels-in-background/panels-in-background.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this file,
+   - You can obtain one at http://mozilla.org/MPL/2.0/.  -->
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Custom page for panels running in background</title>
+</head>
+<body>
+<script type="application/x-javascript">
+  function peformLogs(count) {
+    for (let i = 0; i < count; i++) {
+      console.log("log in background", i);
+    }
+  }
+
+  function performRequests(count) {
+    for (let i = 0; i < count; i++) {
+      let xhr = new XMLHttpRequest();
+      xhr.open("GET", "sjs_simple-test-server.sjs", true);
+      xhr.send(null);
+    }
+  }
+
+  peformLogs(2000);
+  performRequests(600);
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/devtools/addon/content/pages/custom/panels-in-background/sjs_simple-test-server.sjs
@@ -0,0 +1,7 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function handleRequest(request, response) {
+  response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
+  response.write("Hello world!");
+}