Bug 1260403 - followup: Fix brotli test. r=jsnajdr, a=test-only
authorTooru Fujisawa <arai_a@mac.com>
Thu, 17 Nov 2016 08:17:47 +0900
changeset 352560 5468cd9ed8e4a4cc32d37135842c04a7df8a58ee
parent 352559 c684ebca8623a319e2ebd93a8140de680bf88456
child 352561 7fd470321b2aad560c74ca585ecd0cb67e6eff56
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsnajdr, test-only
bugs1260403
milestone52.0a2
Bug 1260403 - followup: Fix brotli test. r=jsnajdr, a=test-only
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_brotli.js
devtools/client/netmonitor/test/browser_net_content-type.js
devtools/client/netmonitor/test/head.js
devtools/client/netmonitor/test/html_brotli-test-page.html
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -2,16 +2,17 @@
 tags = devtools
 subsuite = devtools
 support-files =
   dropmarker.svg
   head.js
   html_cause-test-page.html
   html_content-type-test-page.html
   html_content-type-without-cache-test-page.html
+  html_brotli-test-page.html
   html_image-tooltip-test-page.html
   html_cors-test-page.html
   html_custom-get-page.html
   html_cyrillic-test-page.html
   html_frame-test-page.html
   html_frame-subdocument.html
   html_filter-test-page.html
   html_infinite-get-page.html
@@ -63,16 +64,17 @@ skip-if = true # Bug 1309191 - replace w
 [browser_net_charts-03.js]
 [browser_net_charts-04.js]
 [browser_net_charts-05.js]
 [browser_net_charts-06.js]
 [browser_net_charts-07.js]
 [browser_net_clear.js]
 [browser_net_complex-params.js]
 [browser_net_content-type.js]
+[browser_net_brotli.js]
 [browser_net_curl-utils.js]
 [browser_net_copy_image_as_data_uri.js]
 subsuite = clipboard
 [browser_net_copy_svg_image_as_data_uri.js]
 subsuite = clipboard
 [browser_net_copy_url.js]
 subsuite = clipboard
 [browser_net_copy_params.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_brotli.js
@@ -0,0 +1,91 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const BROTLI_URL = HTTPS_EXAMPLE_URL + "html_brotli-test-page.html";
+const BROTLI_REQUESTS = 1;
+
+/**
+ * Test brotli encoded response is handled correctly on HTTPS.
+ */
+
+add_task(function* () {
+  let { L10N } = require("devtools/client/netmonitor/l10n");
+
+  let { tab, monitor } = yield initNetMonitor(BROTLI_URL);
+  info("Starting test... ");
+
+  let { document, Editor, NetMonitorView } = monitor.panelWin;
+  let { RequestsMenu } = NetMonitorView;
+
+  RequestsMenu.lazyUpdate = false;
+
+  let wait = waitForNetworkEvents(monitor, BROTLI_REQUESTS);
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+    content.wrappedJSObject.performRequests();
+  });
+  yield wait;
+
+  verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
+    "GET", HTTPS_CONTENT_TYPE_SJS + "?fmt=br", {
+      status: 200,
+      statusText: "Connected",
+      type: "plain",
+      fullMimeType: "text/plain",
+      transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 10),
+      size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 64),
+      time: true
+    });
+
+  let onEvent = waitForResponseBodyDisplayed();
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    document.getElementById("details-pane-toggle"));
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    document.querySelectorAll("#details-pane tab")[3]);
+  yield onEvent;
+  yield testResponseTab("br");
+
+  yield teardown(monitor);
+
+  function* testResponseTab(type) {
+    let tabEl = document.querySelectorAll("#details-pane tab")[3];
+    let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
+
+    is(tabEl.getAttribute("selected"), "true",
+      "The response tab in the network details pane should be selected.");
+
+    function checkVisibility(box) {
+      is(tabpanel.querySelector("#response-content-info-header")
+        .hasAttribute("hidden"), true,
+        "The response info header doesn't have the intended visibility.");
+      is(tabpanel.querySelector("#response-content-json-box")
+        .hasAttribute("hidden"), box != "json",
+        "The response content json box doesn't have the intended visibility.");
+      is(tabpanel.querySelector("#response-content-textarea-box")
+        .hasAttribute("hidden"), box != "textarea",
+        "The response content textarea box doesn't have the intended visibility.");
+      is(tabpanel.querySelector("#response-content-image-box")
+        .hasAttribute("hidden"), box != "image",
+        "The response content image box doesn't have the intended visibility.");
+    }
+
+    switch (type) {
+      case "br": {
+        checkVisibility("textarea");
+
+        let expected = "X".repeat(64);
+        let editor = yield NetMonitorView.editor("#response-content-textarea");
+        is(editor.getText(), expected,
+          "The text shown in the source editor is incorrect for the brotli request.");
+        is(editor.getMode(), Editor.modes.text,
+          "The mode active in the source editor is incorrect for the brotli request.");
+        break;
+      }
+    }
+  }
+
+  function waitForResponseBodyDisplayed() {
+    return monitor.panelWin.once(monitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
+  }
+});
--- a/devtools/client/netmonitor/test/browser_net_content-type.js
+++ b/devtools/client/netmonitor/test/browser_net_content-type.js
@@ -2,122 +2,98 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 /**
  * Tests if different response content types are handled correctly.
  */
 
-function* content_type_test(isHTTPS) {
+add_task(function* () {
   let { L10N } = require("devtools/client/netmonitor/l10n");
 
-  let pageURL = isHTTPS ? HTTPS_CONTENT_TYPE_WITHOUT_CACHE_URL
-                        : CONTENT_TYPE_WITHOUT_CACHE_URL;
-  let imageURL = isHTTPS ? HTTPS_TEST_IMAGE
-                         : TEST_IMAGE;
-  let sjsURL = isHTTPS ? HTTPS_CONTENT_TYPE_SJS
-                       : CONTENT_TYPE_SJS;
-  let { tab, monitor } = yield initNetMonitor(pageURL);
+  let { tab, monitor } = yield initNetMonitor(CONTENT_TYPE_WITHOUT_CACHE_URL);
   info("Starting test... ");
 
   let { document, Editor, NetMonitorView } = monitor.panelWin;
   let { RequestsMenu } = NetMonitorView;
 
   RequestsMenu.lazyUpdate = false;
 
   let wait = waitForNetworkEvents(monitor, CONTENT_TYPE_WITHOUT_CACHE_REQUESTS);
   yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
     content.wrappedJSObject.performRequests();
   });
   yield wait;
 
-  let okStatus = isHTTPS ? "Connected" : "OK";
-
   verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
-    "GET", sjsURL + "?fmt=xml", {
+    "GET", CONTENT_TYPE_SJS + "?fmt=xml", {
       status: 200,
-      statusText: okStatus,
+      statusText: "OK",
       type: "xml",
       fullMimeType: "text/xml; charset=utf-8",
       size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 42),
       time: true
     });
   verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1),
-    "GET", sjsURL + "?fmt=css", {
+    "GET", CONTENT_TYPE_SJS + "?fmt=css", {
       status: 200,
-      statusText: okStatus,
+      statusText: "OK",
       type: "css",
       fullMimeType: "text/css; charset=utf-8",
       size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 34),
       time: true
     });
   verifyRequestItemTarget(RequestsMenu.getItemAtIndex(2),
-    "GET", sjsURL + "?fmt=js", {
+    "GET", CONTENT_TYPE_SJS + "?fmt=js", {
       status: 200,
-      statusText: okStatus,
+      statusText: "OK",
       type: "js",
       fullMimeType: "application/javascript; charset=utf-8",
       size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 34),
       time: true
     });
   verifyRequestItemTarget(RequestsMenu.getItemAtIndex(3),
-    "GET", sjsURL + "?fmt=json", {
+    "GET", CONTENT_TYPE_SJS + "?fmt=json", {
       status: 200,
-      statusText: okStatus,
+      statusText: "OK",
       type: "json",
       fullMimeType: "application/json; charset=utf-8",
       size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 29),
       time: true
     });
-  if (!isHTTPS) {
-    // 404 doesn't work on HTTPS test harness.
-    verifyRequestItemTarget(RequestsMenu.getItemAtIndex(4),
-      "GET", sjsURL + "?fmt=bogus", {
-        status: 404,
-        statusText: "Not Found",
-        type: "html",
-        fullMimeType: "text/html; charset=utf-8",
-        size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 24),
-        time: true
-      });
-  }
+  verifyRequestItemTarget(RequestsMenu.getItemAtIndex(4),
+    "GET", CONTENT_TYPE_SJS + "?fmt=bogus", {
+      status: 404,
+      statusText: "Not Found",
+      type: "html",
+      fullMimeType: "text/html; charset=utf-8",
+      size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 24),
+      time: true
+    });
   verifyRequestItemTarget(RequestsMenu.getItemAtIndex(5),
-    "GET", imageURL, {
+    "GET", TEST_IMAGE, {
       fuzzyUrl: true,
       status: 200,
-      statusText: okStatus,
+      statusText: "OK",
       type: "png",
       fullMimeType: "image/png",
       size: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 580),
       time: true
     });
   verifyRequestItemTarget(RequestsMenu.getItemAtIndex(6),
-    "GET", sjsURL + "?fmt=gzip", {
+    "GET", CONTENT_TYPE_SJS + "?fmt=gzip", {
       status: 200,
-      statusText: okStatus,
+      statusText: "OK",
       type: "plain",
       fullMimeType: "text/plain",
       transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 73),
       size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 10.73),
       time: true
     });
-  if (isHTTPS) {
-    // Brotli is enabled only on HTTPS.
-    verifyRequestItemTarget(RequestsMenu.getItemAtIndex(6),
-      "GET", sjsURL + "?fmt=gzip", {
-        status: 200,
-        statusText: okStatus,
-        type: "plain",
-        fullMimeType: "text/plain",
-        transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeB", 73),
-        size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 10.73),
-        time: true
-      });
-  }
 
   let onEvent = waitForResponseBodyDisplayed();
   EventUtils.sendMouseEvent({ type: "mousedown" },
     document.getElementById("details-pane-toggle"));
   EventUtils.sendMouseEvent({ type: "mousedown" },
     document.querySelectorAll("#details-pane tab")[3]);
   yield onEvent;
   yield testResponseTab("xml");
@@ -135,21 +111,16 @@ function* content_type_test(isHTTPS) {
   yield testResponseTab("html");
 
   yield selectIndexAndWaitForTabUpdated(5);
   yield testResponseTab("png");
 
   yield selectIndexAndWaitForTabUpdated(6);
   yield testResponseTab("gzip");
 
-  if (isHTTPS) {
-    yield selectIndexAndWaitForTabUpdated(7);
-    yield testResponseTab("br");
-  }
-
   yield teardown(monitor);
 
   function* testResponseTab(type) {
     let tabEl = document.querySelectorAll("#details-pane tab")[3];
     let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
 
     is(tabEl.getAttribute("selected"), "true",
       "The response tab in the network details pane should be selected.");
@@ -264,40 +235,21 @@ function* content_type_test(isHTTPS) {
         let expected = new Array(1000).join("Hello gzip!");
         let editor = yield NetMonitorView.editor("#response-content-textarea");
         is(editor.getText(), expected,
           "The text shown in the source editor is incorrect for the gzip request.");
         is(editor.getMode(), Editor.modes.text,
           "The mode active in the source editor is incorrect for the gzip request.");
         break;
       }
-      case "br": {
-        checkVisibility("textarea");
-
-        let expected = "X".repeat(64);
-        let editor = yield NetMonitorView.editor("#response-content-textarea");
-        is(editor.getText(), expected,
-          "The text shown in the source editor is incorrect for the brotli request.");
-        is(editor.getMode(), Editor.modes.text,
-          "The mode active in the source editor is incorrect for the brotli request.");
-        break;
-      }
     }
   }
 
   function selectIndexAndWaitForTabUpdated(index) {
     let onTabUpdated = monitor.panelWin.once(monitor.panelWin.EVENTS.TAB_UPDATED);
     RequestsMenu.selectedIndex = index;
     return onTabUpdated;
   }
 
   function waitForResponseBodyDisplayed() {
     return monitor.panelWin.once(monitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
   }
-}
-
-add_task(function* () {
-    yield* content_type_test(false);
 });
-
-add_task(function* () {
-    yield* content_type_test(true);
-});
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -15,17 +15,16 @@ var { Toolbox } = require("devtools/clie
 const EXAMPLE_URL = "http://example.com/browser/devtools/client/netmonitor/test/";
 const HTTPS_EXAMPLE_URL = "https://example.com/browser/devtools/client/netmonitor/test/";
 
 const API_CALLS_URL = EXAMPLE_URL + "html_api-calls-test-page.html";
 const SIMPLE_URL = EXAMPLE_URL + "html_simple-test-page.html";
 const NAVIGATE_URL = EXAMPLE_URL + "html_navigate-test-page.html";
 const CONTENT_TYPE_URL = EXAMPLE_URL + "html_content-type-test-page.html";
 const CONTENT_TYPE_WITHOUT_CACHE_URL = EXAMPLE_URL + "html_content-type-without-cache-test-page.html";
-const HTTPS_CONTENT_TYPE_WITHOUT_CACHE_URL = HTTPS_EXAMPLE_URL + "html_content-type-without-cache-test-page.html";
 const CONTENT_TYPE_WITHOUT_CACHE_REQUESTS = 8;
 const CYRILLIC_URL = EXAMPLE_URL + "html_cyrillic-test-page.html";
 const STATUS_CODES_URL = EXAMPLE_URL + "html_status-codes-test-page.html";
 const POST_DATA_URL = EXAMPLE_URL + "html_post-data-test-page.html";
 const POST_JSON_URL = EXAMPLE_URL + "html_post-json-test-page.html";
 const POST_RAW_URL = EXAMPLE_URL + "html_post-raw-test-page.html";
 const POST_RAW_WITH_HEADERS_URL = EXAMPLE_URL + "html_post-raw-with-headers-test-page.html";
 const PARAMS_URL = EXAMPLE_URL + "html_params-test-page.html";
@@ -53,17 +52,16 @@ const SORTING_SJS = EXAMPLE_URL + "sjs_s
 const HTTPS_REDIRECT_SJS = EXAMPLE_URL + "sjs_https-redirect-test-server.sjs";
 const CORS_SJS_PATH = "/browser/devtools/client/netmonitor/test/sjs_cors-test-server.sjs";
 const HSTS_SJS = EXAMPLE_URL + "sjs_hsts-test-server.sjs";
 
 const HSTS_BASE_URL = EXAMPLE_URL;
 const HSTS_PAGE_URL = CUSTOM_GET_URL;
 
 const TEST_IMAGE = EXAMPLE_URL + "test-image.png";
-const HTTPS_TEST_IMAGE = HTTPS_EXAMPLE_URL + "test-image.png";
 const TEST_IMAGE_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==";
 
 const FRAME_SCRIPT_UTILS_URL = "chrome://devtools/content/shared/frame-script-utils.js";
 
 // All tests are asynchronous.
 waitForExplicitFinish();
 
 const gEnableLogging = Services.prefs.getBoolPref("devtools.debugger.log");
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/html_brotli-test-page.html
@@ -0,0 +1,38 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!doctype html>
+
+<html>
+  <head>
+    <meta charset="utf-8"/>
+    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
+    <meta http-equiv="Pragma" content="no-cache" />
+    <meta http-equiv="Expires" content="0" />
+    <title>Network Monitor test page</title>
+  </head>
+
+  <body>
+    <p>Brotli test</p>
+
+    <script type="text/javascript">
+      function get(aAddress, aCallback) {
+        var xhr = new XMLHttpRequest();
+        xhr.open("GET", aAddress, true);
+
+        xhr.onreadystatechange = function() {
+          if (this.readyState == this.DONE) {
+            aCallback();
+          }
+        };
+        xhr.send(null);
+      }
+
+      function performRequests() {
+        get("sjs_content-type-test-server.sjs?fmt=br", function() {
+          // Done.
+        });
+      }
+    </script>
+  </body>
+
+</html>