Bug 1451820 - Part 2: Updates mochitest for Part 1. r=Honza
authorZhang Junzhi <zjz@zjz.name>
Sat, 14 Apr 2018 17:47:23 +0800
changeset 467540 294df035b797b3959f072e3fcc8433c055baebb3
parent 467539 82f8237f91df33fa7a73645257da2dfe5ad94a97
child 467541 9a93ea4f7c11676cf9541671f4af7bbf15d7c2d1
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1451820
milestone61.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 1451820 - Part 2: Updates mochitest for Part 1. r=Honza MozReview-Commit-ID: 5E4zR3b0X4J
devtools/client/netmonitor/test/browser_net_filter-01.js
devtools/client/netmonitor/test/head.js
--- a/devtools/client/netmonitor/test/browser_net_filter-01.js
+++ b/devtools/client/netmonitor/test/browser_net_filter-01.js
@@ -1,24 +1,35 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+// Used to test filtering a unicode URI component
+const UNICODE_IN_URI_COMPONENT = "\u6e2c";
+const ENCODED_CHARS_IN_URI_COMP = encodeURIComponent(UNICODE_IN_URI_COMPONENT);
+
+// Used to test filtering an international domain name with Unicode
+const IDN = "xn--hxajbheg2az3al.xn--jxalpdlp";
+const UNICODE_IN_IDN = "\u03c0\u03b1";
+
 /**
  * Test if filtering items in the network table works correctly.
  */
 const BASIC_REQUESTS = [
-  { url: "sjs_content-type-test-server.sjs?fmt=html&res=undefined&text=Sample" },
+  { url: getSjsURLInUnicodeIdn() + "?fmt=html&res=undefined&text=Sample" },
   { url: "sjs_content-type-test-server.sjs?fmt=css&text=sample" },
   { url: "sjs_content-type-test-server.sjs?fmt=js&text=sample" },
+  { url: `sjs_content-type-test-server.sjs?fmt=html&text=${ENCODED_CHARS_IN_URI_COMP}` },
+  { url: `sjs_content-type-test-server.sjs?fmt=css&text=${ENCODED_CHARS_IN_URI_COMP}` },
+  { url: `sjs_content-type-test-server.sjs?fmt=js&text=${ENCODED_CHARS_IN_URI_COMP}` },
 ];
 
 const REQUESTS_WITH_MEDIA = BASIC_REQUESTS.concat([
-  { url: "sjs_content-type-test-server.sjs?fmt=font" },
+  { url: getSjsURLInUnicodeIdn() + "?fmt=font" },
   { url: "sjs_content-type-test-server.sjs?fmt=image" },
   { url: "sjs_content-type-test-server.sjs?fmt=audio" },
   { url: "sjs_content-type-test-server.sjs?fmt=video" },
 ]);
 
 const REQUESTS_WITH_MEDIA_AND_FLASH = REQUESTS_WITH_MEDIA.concat([
   { url: "sjs_content-type-test-server.sjs?fmt=flash" },
 ]);
@@ -26,16 +37,49 @@ const REQUESTS_WITH_MEDIA_AND_FLASH = RE
 const REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS = REQUESTS_WITH_MEDIA_AND_FLASH.concat([
   /* "Upgrade" is a reserved header and can not be set on XMLHttpRequest */
   { url: "sjs_content-type-test-server.sjs?fmt=ws" },
 ]);
 
 const EXPECTED_REQUESTS = [
   {
     method: "GET",
+    url: getSjsURLInUnicodeIdn() + "?fmt=html",
+    data: {
+      fuzzyUrl: true,
+      status: 200,
+      statusText: "OK",
+      type: "html",
+      fullMimeType: "text/html; charset=utf-8"
+    }
+  },
+  {
+    method: "GET",
+    url: CONTENT_TYPE_SJS + "?fmt=css",
+    data: {
+      fuzzyUrl: true,
+      status: 200,
+      statusText: "OK",
+      type: "css",
+      fullMimeType: "text/css; charset=utf-8"
+    }
+  },
+  {
+    method: "GET",
+    url: CONTENT_TYPE_SJS + "?fmt=js",
+    data: {
+      fuzzyUrl: true,
+      status: 200,
+      statusText: "OK",
+      type: "js",
+      fullMimeType: "application/javascript; charset=utf-8"
+    }
+  },
+  {
+    method: "GET",
     url: CONTENT_TYPE_SJS + "?fmt=html",
     data: {
       fuzzyUrl: true,
       status: 200,
       statusText: "OK",
       type: "html",
       fullMimeType: "text/html; charset=utf-8"
     }
@@ -59,17 +103,17 @@ const EXPECTED_REQUESTS = [
       status: 200,
       statusText: "OK",
       type: "js",
       fullMimeType: "application/javascript; charset=utf-8"
     }
   },
   {
     method: "GET",
-    url: CONTENT_TYPE_SJS + "?fmt=font",
+    url: getSjsURLInUnicodeIdn() + "?fmt=font",
     data: {
       fuzzyUrl: true,
       status: 200,
       statusText: "OK",
       type: "woff",
       fullMimeType: "font/woff"
     }
   },
@@ -141,163 +185,192 @@ add_task(async function() {
   store.dispatch(Actions.batchEnable(false));
 
   function setFreetextFilter(value) {
     store.dispatch(Actions.setRequestFilterText(value));
   }
 
   info("Starting test... ");
 
-  let wait = waitForNetworkEvents(monitor, 9);
+  let wait = waitForNetworkEvents(monitor,
+                                  REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS.length);
   loadFrameScriptUtils();
   await performRequestsInContent(REQUESTS_WITH_MEDIA_AND_FLASH_AND_WS);
   await wait;
 
   EventUtils.sendMouseEvent({ type: "mousedown" },
     document.querySelectorAll(".request-list-item")[0]);
 
   isnot(getSelectedRequest(store.getState()), null,
     "There should be a selected item in the requests menu.");
   is(getSelectedIndex(store.getState()), 0,
     "The first item should be selected in the requests menu.");
   is(!!document.querySelector(".network-details-panel"), true,
     "The network details panel should render correctly.");
 
   // First test with single filters...
   testFilterButtons(monitor, "all");
-  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
+  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-html-button"));
   testFilterButtons(monitor, "html");
-  await testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
+  await testContents([1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Reset filters
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-css-button"));
   testFilterButtons(monitor, "css");
-  await testContents([0, 1, 0, 0, 0, 0, 0, 0, 0]);
+  await testContents([0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-js-button"));
   testFilterButtons(monitor, "js");
-  await testContents([0, 0, 1, 0, 0, 0, 0, 0, 0]);
+  await testContents([0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-xhr-button"));
   testFilterButtons(monitor, "xhr");
-  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 0]);
+  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   EventUtils.sendMouseEvent({ type: "click" },
      document.querySelector(".requests-list-filter-fonts-button"));
   testFilterButtons(monitor, "fonts");
-  await testContents([0, 0, 0, 1, 0, 0, 0, 0, 0]);
+  await testContents([0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-images-button"));
   testFilterButtons(monitor, "images");
-  await testContents([0, 0, 0, 0, 1, 0, 0, 0, 0]);
+  await testContents([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-media-button"));
   testFilterButtons(monitor, "media");
-  await testContents([0, 0, 0, 0, 0, 1, 1, 0, 0]);
+  await testContents([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-ws-button"));
   testFilterButtons(monitor, "ws");
-  await testContents([0, 0, 0, 0, 0, 0, 0, 0, 1]);
+  await testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
 
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
 
   testFilterButtons(monitor, "all");
-  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
+  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   // Text in filter box that matches nothing should hide all.
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   setFreetextFilter("foobar");
-  await testContents([0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  await testContents([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
-  // Text in filter box that matches should filter out everything else.
+  // ASCII text in filter box that matches should filter out everything else.
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   setFreetextFilter("sample");
-  await testContents([1, 1, 1, 0, 0, 0, 0, 0, 0]);
+  await testContents([1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
-  // Text in filter box that matches should filter out everything else.
+  // ASCII text in filter box that matches should filter out everything else.
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   setFreetextFilter("SAMPLE");
-  await testContents([1, 1, 1, 0, 0, 0, 0, 0, 0]);
+  await testContents([1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
-  // Test negative filtering (only show unmatched items)
+  // Test negative filtering ASCII text(only show unmatched items)
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   setFreetextFilter("-sample");
-  await testContents([0, 0, 0, 1, 1, 1, 1, 1, 1]);
+  await testContents([0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
+
+  // Unicode text in filter box that matches should filter out everything else.
+  EventUtils.sendMouseEvent({ type: "click" },
+    document.querySelector(".requests-list-filter-all-button"));
+  setFreetextFilter(UNICODE_IN_URI_COMPONENT);
+  await testContents([0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0]);
+
+  // Ditto, except the above is for a Unicode URI component, and this one is for
+  // a Unicode domain name.
+  EventUtils.sendMouseEvent({ type: "click" },
+    document.querySelector(".requests-list-filter-all-button"));
+  setFreetextFilter(UNICODE_IN_IDN);
+  await testContents([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]);
+
+  // Test negative filtering Unicode text(only show unmatched items)
+  EventUtils.sendMouseEvent({ type: "click" },
+    document.querySelector(".requests-list-filter-all-button"));
+  setFreetextFilter(`-${UNICODE_IN_URI_COMPONENT}`);
+  await testContents([1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1]);
+
+  // Ditto, except the above is for a Unicode URI component, and this one is for
+  // a Unicode domain name.
+  EventUtils.sendMouseEvent({ type: "click" },
+    document.querySelector(".requests-list-filter-all-button"));
+  setFreetextFilter(`-${UNICODE_IN_IDN}`);
+  await testContents([0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1]);
 
   // ...then combine multiple filters together.
 
   // Enable filtering for html and css; should show request of both type.
   setFreetextFilter("");
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-html-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-css-button"));
   testFilterButtonsCustom(monitor, [0, 1, 1, 0, 0, 0, 0, 0, 0, 0]);
-  await testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
+  await testContents([1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0]);
 
   // Html and css filter enabled and text filter should show just the html and css match.
   // Should not show both the items matching the button plus the items matching the text.
   setFreetextFilter("sample");
-  await testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
+  await testContents([1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
+  setFreetextFilter(UNICODE_IN_URI_COMPONENT);
+  await testContents([0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0]);
   setFreetextFilter("");
   testFilterButtonsCustom(monitor, [0, 1, 1, 0, 0, 0, 0, 0, 0, 0]);
-  await testContents([1, 1, 0, 0, 0, 0, 0, 0, 0]);
+  await testContents([1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0]);
 
   // Disable some filters. Only one left active.
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-css-button"));
   testFilterButtons(monitor, "html");
-  await testContents([1, 0, 0, 0, 0, 0, 0, 0, 0]);
+  await testContents([1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
   // Disable last active filter. Should toggle to all.
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-html-button"));
   testFilterButtons(monitor, "all");
-  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
+  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   // Enable few filters and click on all. Only "all" should be checked.
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-html-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-css-button"));
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-ws-button"));
   testFilterButtonsCustom(monitor, [0, 1, 1, 0, 0, 0, 0, 0, 1, 0]);
   EventUtils.sendMouseEvent({ type: "click" },
     document.querySelector(".requests-list-filter-all-button"));
   testFilterButtons(monitor, "all");
-  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1]);
+  await testContents([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
 
   await teardown(monitor);
 
   function getSelectedIndex(state) {
     if (!state.requests.selectedId) {
       return -1;
     }
     return getSortedRequests(state).findIndex(r => r.id === state.requests.selectedId);
@@ -344,8 +417,13 @@ add_task(async function() {
           method,
           url,
           data
         );
       }
     }
   }
 });
+
+function getSjsURLInUnicodeIdn() {
+  const { hostname } = new URL(CONTENT_TYPE_SJS);
+  return CONTENT_TYPE_SJS.replace(hostname, IDN);
+}
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -13,17 +13,20 @@
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
   this);
 
 const {
   getFormattedIPAndPort,
   getFormattedTime,
 } = require("devtools/client/netmonitor/src/utils/format-utils");
-const { getUnicodeUrl } = require("devtools/client/shared/unicode-url");
+const {
+  getUnicodeUrl,
+  getUnicodeHostname,
+} = require("devtools/client/shared/unicode-url");
 const {
   getFormattedProtocol,
   getUrlBaseName,
   getUrlHost,
   getUrlQuery,
   getUrlScheme,
 } = require("devtools/client/netmonitor/src/utils/request-utils");
 const { EVENTS } = require("devtools/client/netmonitor/src/constants");
@@ -408,17 +411,17 @@ function verifyRequestItemTarget(documen
   let { fuzzyUrl, status, statusText, cause, type, fullMimeType,
         transferred, size, time, displayedStatus } = data;
 
   let target = document.querySelectorAll(".request-list-item")[visibleIndex];
   // Bug 1414981 - Request URL should not show #hash
   let unicodeUrl = getUnicodeUrl(url.split("#")[0]);
   let name = getUrlBaseName(url);
   let query = getUrlQuery(url);
-  let host = getUrlHost(url);
+  let host = getUnicodeHostname(getUrlHost(url));
   let scheme = getUrlScheme(url);
   let {
     remoteAddress,
     remotePort,
     totalTime,
     eventTimings = { timings: {} },
   } = requestItem;
   let formattedIPPort = getFormattedIPAndPort(remoteAddress, remotePort);