Bug 1448553 - Part 7: Adds mochitests to test the feature of filtering Unicode strings and Unicode filenames in the Web Console. r?nchevobbe draft
authorZhang Junzhi <zjz@zjz.name>
Wed, 11 Apr 2018 03:08:28 +0800
changeset 779885 77def8adbea7242c782b4958eb3540e10eadd716
parent 778659 c87918cadf252af8cc0301a208fb2c6aa7368144
push id105902
push userbmo:zjz@zjz.name
push dateTue, 10 Apr 2018 19:09:01 +0000
reviewersnchevobbe
bugs1448553
milestone61.0a1
Bug 1448553 - Part 7: Adds mochitests to test the feature of filtering Unicode strings and Unicode filenames in the Web Console. r?nchevobbe This patch makes sure the feature of filtering Unicode strings and Unicode filenames works correctly by adding mochitests so that we don't regress for fixing this bug. MozReview-Commit-ID: Htozi18dXns
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filter_by_input.js
devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_console_log_filter.html
devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_test1.js
devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_test2.js
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -15,19 +15,16 @@ support-files =
   test_bug_770099_violation.html
   test_bug_770099_violation.html^headers^
   test_console_csp_ignore_reflected_xss_message.html
   test_console_csp_ignore_reflected_xss_message.html^headers^
   test_hpkp-invalid-headers.sjs
   test_hsts-invalid-headers.sjs
   test-autocomplete-in-stackframe.html
   test-batching.html
-  test-bug_923281_console_log_filter.html
-  test-bug_923281_test1.js
-  test-bug_923281_test2.js
   test-console-trace-duplicates.html
   test-bug-585956-console-trace.html
   test-bug-599725-response-headers.sjs
   test-bug-601177-log-levels.html
   test-bug-601177-log-levels.js
   test-bug-630733-response-redirect-headers.sjs
   test-bug-632275-getters.html
   test-bug-646025-console-file-location.html
@@ -270,16 +267,17 @@ skip-if = (e10s && debug) || (e10s && os
 [browser_webconsole_duplicate_errors.js]
 [browser_webconsole_errors_after_page_reload.js]
 [browser_webconsole_eval_in_debugger_stackframe.js]
 [browser_webconsole_eval_in_debugger_stackframe2.js]
 [browser_webconsole_execution_scope.js]
 [browser_webconsole_external_script_errors.js]
 [browser_webconsole_file_uri.js]
 skip-if = true #	Bug 1404382
+[browser_webconsole_filter_by_input.js]
 [browser_webconsole_filter_scroll.js]
 [browser_webconsole_filters.js]
 [browser_webconsole_filters_persist.js]
 [browser_webconsole_highlighter_console_helper.js]
 [browser_webconsole_history_arrow_keys.js]
 [browser_webconsole_hpkp_invalid-headers.js]
 [browser_webconsole_hsts_invalid-headers.js]
 [browser_webconsole_iframe_wrong_hud.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filter_by_input.js
@@ -0,0 +1,193 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests that the text filter box works to filter based on filenames
+// where the logs were generated.
+
+"use strict";
+
+// In this test, we are trying to test the filtering functionality of the filter
+// input. We test filtering not only for the contents of logs themseleves but
+// also for the filenames.
+//
+// We simulate an HTML file which executes two Javascript files, one with an
+// ASCII filename outputs some ASCII logs and the other one with a Unicode
+// filename outputs some Unicode logs.
+
+// seasons
+const SEASON = {
+  english: "season",
+  chinese: "\u5b63",
+};
+const SEASONS = [
+  {
+    english: "spring",
+    chinese: "\u6625",
+    escapedChinese: "\\u6625",
+  },
+  {
+    english: "summer",
+    chinese: "\u590f",
+    escapedChinese: "\\u590f",
+  },
+  {
+    english: "autumn",
+    chinese: "\u79cb",
+    escapedChinese: "\\u79cb",
+  },
+  {
+    english: "winter",
+    chinese: "\u51ac",
+    escapedChinese: "\\u51ac",
+  },
+];
+
+// filenames
+const FILENAME_OF_HTML = `test.html`;
+const FILENAME_OF_ASCII_JS = `${SEASON.english}.js`;
+const FILENAME_OF_UNICODE_JS = `${SEASON.chinese}.js`;
+const URI_ENCODED_FILENAME_OF_UNICODE_JS =
+        encodeURIComponent(FILENAME_OF_UNICODE_JS);
+
+// file contents
+const CONTENT_OF_HTML = `<!DOCTYPE html
+><meta charset="utf-8"
+><title>Test filtering logs by filling keywords in the filter input.</title
+><script>
+console.log("Test filtering ${SEASON.english} names.");
+</script
+><script src="/${FILENAME_OF_ASCII_JS}"></script
+><script src="/${URI_ENCODED_FILENAME_OF_UNICODE_JS}"></script>`;
+let CONTENT_OF_ASCII_JS = '';
+let CONTENT_OF_UNICODE_JS = '';
+for (let curSeason of SEASONS) {
+  CONTENT_OF_ASCII_JS += `console.log("${curSeason.english}");`;
+  CONTENT_OF_UNICODE_JS += `console.log("${curSeason.escapedChinese}");`;
+}
+
+let hud;
+
+add_task(async function() {
+  const testUrl = createServerAndGetTestUrl();
+  hud = await openNewTabAndConsole(testUrl);
+  testFilteringLogs();
+});
+
+// Create an HTTP server to simulate a response for the a URL request and return
+// the URL.
+function createServerAndGetTestUrl() {
+  const httpServer = createTestHTTPServer();
+
+  httpServer.registerContentType("html", "text/html");
+  httpServer.registerContentType("js", "application/javascript");
+
+  httpServer.registerPathHandler("/" + FILENAME_OF_HTML,
+    function(request, response) {
+      response.setStatusLine(request.httpVersion, 200, "OK");
+      response.write(CONTENT_OF_HTML);
+    }
+  );
+  httpServer.registerPathHandler("/" + FILENAME_OF_ASCII_JS,
+    function(request, response) {
+      response.setStatusLine(request.httpVersion, 200, "OK");
+      response.write(CONTENT_OF_ASCII_JS);
+    }
+  );
+  httpServer.registerPathHandler("/" + URI_ENCODED_FILENAME_OF_UNICODE_JS,
+    function(request, response) {
+      response.setStatusLine(request.httpVersion, 200, "OK");
+      response.write(CONTENT_OF_UNICODE_JS);
+    }
+  );
+  const port = httpServer.identity.primaryPort;
+  return `http://localhost:${port}/${FILENAME_OF_HTML}`;
+}
+
+function testFilteringLogs() {
+  // One external Javascript file outputs every season name in English, and the
+  // other Javascript file outputs every season name in Chinese.
+  // The HTML file outputs one line on its own.
+  // So the total number of all the logs is the doubled number of seasons plus
+  // one.
+  is(countVisibleLogs(), SEASONS.length * 2 + 1,
+       "the total number of all the logs before starting filtering");
+
+  // All the logs outputted by the ASCII Javascript file are visible, the others
+  // are hidden.
+  fillInFilterInputBox(FILENAME_OF_ASCII_JS);
+  is(countVisibleLogs(), SEASONS.length,
+       `the number of all the logs containing ${FILENAME_OF_ASCII_JS}`);
+
+  // Every season name in English is outputted once.
+  for (let curSeason of SEASONS) {
+    fillInFilterInputBox(curSeason.english);
+    is(countVisibleLogs(), 1,
+         `the number of all the logs containing ${curSeason.english}`);
+
+  }
+  // All the logs outputted by the ASCII Javascript file are visible, the others
+  // are hidden.
+  fillInFilterInputBox(FILENAME_OF_UNICODE_JS);
+  is(countVisibleLogs(), SEASONS.length,
+       `the number of all the logs containing ${FILENAME_OF_UNICODE_JS}`);
+
+  // Every season name in Chinese is outputted once.
+  for (let curSeason of SEASONS) {
+    fillInFilterInputBox(curSeason.chinese);
+    is(countVisibleLogs(), 1,
+         `the number of all the logs containing ${curSeason.chinese}`);
+
+  }
+  // The filename of the ASCII Javascript file contains the English word season,
+  // so all the logs outputted by the file are visible, besides, the HTML
+  // outputs one line containing the English word season, so it is also visible.
+  // The other logs are hidden. So the number of all the visible logs is the
+  // season number plus one.
+  fillInFilterInputBox(SEASON.english);
+  is(countVisibleLogs(), SEASONS.length + 1,
+       `the number of all the logs containing ${SEASON.english}`);
+
+  // The filename of the Unicode Javascript file contains the Chinese word
+  // season, so all the logs outputted by the file are visible. The other logs
+  // are hidden. So the number of all the visible logs is the season number.
+  fillInFilterInputBox(SEASON.chinese);
+  is(countVisibleLogs(), SEASONS.length,
+       `the number of all the logs containing ${SEASON.chinese}`);
+
+  // After clearing the text in the filter input box, all the logs are visible
+  // again.
+  fillInFilterInputBox(null);
+  is(countVisibleLogs(), SEASONS.length * 2 + 1,
+       "the total number of all the logs after clearing filtering");
+}
+
+async function fillInFilterInputBox(value) {
+  hud.ui.filterBox.focus();
+  hud.ui.filterBox.select();
+  if (value) {
+    EventUtils.sendString(value);
+  } else {
+    EventUtils.synthesizeKey("KEY_Delete");
+  }
+  await new Promise(resolve => {
+    setTimeout(() => {
+      resolve();
+    }, 1000);
+  });
+}
+
+function countVisibleLogs() {
+  let outputNode = hud.outputNode;
+  let messageNodes = outputNode.querySelectorAll(".message");
+  let displayedMessageNodes = 0;
+  let view = hud.iframeWindow;
+  for (let i = 0; i < messageNodes.length; i++) {
+    let computedStyle = view.getComputedStyle(messageNodes[i]);
+    if (computedStyle.display !== "none") {
+      displayedMessageNodes++;
+    }
+  }
+  return displayedMessageNodes;
+}
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_console_log_filter.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<!DOCTYPE HTML>
-<html dir="ltr" xml:lang="en-US" lang="en-US">
-  <head>
-    <meta charset="utf-8">
-    <title>Console test</title>
-    <!-- Any copyright is dedicated to the Public Domain.
-       - http://creativecommons.org/publicdomain/zero/1.0/ -->
-    <script type="text/javascript" src="test-bug_923281_test1.js"></script>
-    <script type="text/javascript" src="test-bug_923281_test2.js"></script>
-  </head>
-  <body></body>
-</html>
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_test1.js
+++ /dev/null
@@ -1,9 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-console.log("Sample log.");
-console.log("This log should be filtered when filtered for test2.js.");
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_test2.js
+++ /dev/null
@@ -1,8 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-console.log("This is a random text.");