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>
Fri, 06 Apr 2018 00:46:07 +0800
changeset 778915 92bf25771924c8d2b9e569cb006a94797032384b
parent 778659 c87918cadf252af8cc0301a208fb2c6aa7368144
push id105617
push userbmo:zjz@zjz.name
push dateSat, 07 Apr 2018 06:49:13 +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: 3I2aU9Fj35t
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filename_filters.js
devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_console_filename_filter.html
devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_console_log_filter.html
devtools/client/webconsole/test/browser.ini
devtools/client/webconsole/test/browser_webconsole_log_file_filter.js
devtools/client/webconsole/test/test-bug_923281_console_log_filter.html
devtools/client/webconsole/test/test-bug_923281_test1.js
devtools/client/webconsole/test/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,17 +15,17 @@ 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_console_filename_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
@@ -270,16 +270,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_filename_filters.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]
rename from devtools/client/webconsole/test/browser_webconsole_log_file_filter.js
rename to devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filename_filters.js
--- a/devtools/client/webconsole/test/browser_webconsole_log_file_filter.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_filename_filters.js
@@ -1,83 +1,117 @@
 /* -*- 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.
+// Tests that the text filter box works to filter based on filenames where the
+// logs were generated. These tests are for bug 923281 and bug 1448553.
 
 "use strict";
 
-const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
-                 "test/test-bug_923281_console_log_filter.html";
-
 var hud;
 
-add_task(function* () {
-  yield loadTab(TEST_URI);
+// Testcase 1: Test filtering outputs with an ASCII filename when searching a
+// keyword.
+
+const TEST_ASCII_URI = "http://example.com/browser/devtools/client/" +
+                         "webconsole/new-console-output/test/mochitest/" +
+                         "test-bug_923281_console_filename_filter.html";
+
+function testFilteringOutputsWithAsciiFilename() {
+  const numLogs = findMessages(hud, "").length;
+
+  is(numLogs, 3, "There are 3 logs in total.");
+
+  is(findMessages(hud, "random").length, 1,
+     "the log not containing string \"random\" are hidden");
+
+  is(findMessages(hud, "test2.js").length, 2,
+     "show only logs containing string " +
+       "\"test2.js\" or log nodes created from files with filename " +
+       "containing \"test2.js\" as substring.");
+
+  is(findMessages(hud, "test1").length, 2,
+     "show only logs containing string " +
+       "\"test1\" or log nodes created from files with filename " +
+       "containing \"test1\" as substring.");
+}
+
+// Testcase 2: Test filtering outputs in a Unicode filename when searching a
+// keyword.
+
+// There are three hanzi:
+// The `HANZI_1` is used both as a Unicode filename and a console log.
+// The `HANZI_2` is used only as a console log.
+
+// The value of the `uri` property is used as a URI-encoded form in a URL.
+// The value of the `js` is used as a Javascript string form.
+const HANZI_1 = {
+  uriEncoded: "%E6%B8%AC",
+  js: "\u6e2c",
+  escapedJs: "\\u6e2c",
+};
+
+// A hanzi in two forms.
+// The value of the `js` is used to in Javascript string.
+const HANZI_2 = {
+  js: "\u8a66",
+  escapedJs: "\\u8a66",
+};
 
-  hud = yield openConsole();
-  yield consoleOpened();
+const RESPONSE_DATA = `<!DOCTYPE html
+><meta charset="utf-8"
+><title>Test for filtering a Unicode filename</title
+><script>
+console.log("This log has no Unicode character.");
+console.log("This log has unicode: ${HANZI_1.escapedJs}");
+console.log("This log has unicode: ${HANZI_2.escapedJs}");
+</script>`;
+
+// Create an HTTP server to simulate a response for the a URL request
+// containing a Unicode filename.
+const httpServer = createTestHTTPServer();
+httpServer.registerContentType("html", "text/html");
+httpServer.registerPathHandler(`/${HANZI_1.uriEncoded}.html`,
+  function(request, response) {
+    response.setStatusLine(request.httpVersion, 200, "OK");
+    response.write(RESPONSE_DATA);
+  }
+);
+
+// The file suffix and the URL path used to simulate a URL request containing a
+// Unicode filename.
+const TEST_URI_ENCODED_URL = "http://localhost:" +
+                                httpServer.identity.primaryPort + "/" +
+                                HANZI_1.uriEncoded + ".html";
 
-  testLiveFilteringOnSearchStrings();
+function testFilteringOutputsWithUnicodeFilename() {
+  const numLogs = findMessages(hud, "").length;
+
+  is(numLogs, 3, "There are 3 logs in total.");
+
+  is(findMessages(hud, HANZI_1.js).length, numLogs,
+       "No log should be hidden, " +
+         "because the searched hanzi is included in the filename of " +
+         "all the logs");
+
+  is(findMessages(hud, HANZI_2.js).length, 1,
+       "Only one log should be shown, " +
+          "because all the other logs don't include the searched hanzi.");
+
+  is(findMessages(hud, HANZI_1.uriEncoded).length, 0,
+       "The filename is displayed as Unicode, " +
+          "and shouldn't be searched with a URI-encoded string.");
+}
+
+add_task(async function() {
+  // Testcase 1: Test filtering logs with an ASCII filename.
+  hud = await openNewTabAndConsole(TEST_ASCII_URI);
+  testFilteringOutputsWithAsciiFilename();
+
+  // Testcase 2: Test filtering logs with a URI-encoded filename.
+  hud = await openNewTabAndConsole(TEST_URI_ENCODED_URL);
+  testFilteringOutputsWithUnicodeFilename();
 
   hud = null;
 });
 
-async function consoleOpened() {
-  await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
-    content.console.log("sentinel log");
-  });
-  return waitForMessages({
-    webconsole: hud,
-    messages: [{
-      text: "sentinel log",
-      category: CATEGORY_WEBDEV,
-      severity: SEVERITY_LOG
-    }],
-  });
-}
-
-function testLiveFilteringOnSearchStrings() {
-  is(hud.outputNode.children.length, 4, "number of messages");
-
-  setStringFilter("random");
-  is(countMessageNodes(), 1, "the log nodes not containing string " +
-      "\"random\" are hidden");
-
-  setStringFilter("test2.js");
-  is(countMessageNodes(), 2, "show only log nodes containing string " +
-      "\"test2.js\" or log nodes created from files with filename " +
-      "containing \"test2.js\" as substring.");
-
-  setStringFilter("test1");
-  is(countMessageNodes(), 2, "show only log nodes containing string " +
-      "\"test1\" or log nodes created from files with filename " +
-      "containing \"test1\" as substring.");
-
-  setStringFilter("");
-  is(countMessageNodes(), 4, "show all log nodes on setting filter string " +
-      "as \"\".");
-}
-
-function countMessageNodes() {
-  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;
-}
-
-function setStringFilter(value) {
-  hud.ui.filterBox.value = value;
-  hud.ui.adjustVisibilityOnSearchStringChange();
-}
-
rename from devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_console_log_filter.html
rename to devtools/client/webconsole/new-console-output/test/mochitest/test-bug_923281_console_filename_filter.html
--- a/devtools/client/webconsole/test/browser.ini
+++ b/devtools/client/webconsole/test/browser.ini
@@ -117,19 +117,16 @@ support-files =
   test-repeated-messages.html
   test-result-format-as-string.html
   test-trackingprotection-securityerrors.html
   test-webconsole-error-observer.html
   test_bug_770099_violation.html
   test_bug_770099_violation.html^headers^
   test-autocomplete-in-stackframe.html
   testscript.js
-  test-bug_923281_console_log_filter.html
-  test-bug_923281_test1.js
-  test-bug_923281_test2.js
   test-bug_939783_console_trace_duplicates.html
   test-bug-952277-highlight-nodes-in-vview.html
   test-bug-609872-cd-iframe-parent.html
   test-bug-609872-cd-iframe-child.html
   test-bug-989025-iframe-parent.html
   test-bug_1050691_click_function_to_source.html
   test-bug_1050691_click_function_to_source.js
   test-console-api-stackframe.html
@@ -360,17 +357,16 @@ skip-if = (os == 'linux' && bits == 32 &
 [browser_webconsole_split_focus.js]
 [browser_webconsole_split_persist.js]
 [browser_webconsole_trackingprotection_errors.js]
 tags = trackingprotection
 skip-if = (os == 'win' && bits == 64) # Bug 1390001
 [browser_webconsole_view_source.js]
 skip-if = (os == 'win' && bits == 64) # Bug 1390001
 [browser_webconsole_reflow.js]
-[browser_webconsole_log_file_filter.js]
 [browser_webconsole_expandable_timestamps.js]
 [browser_webconsole_autocomplete_accessibility.js]
 [browser_webconsole_autocomplete_in_debugger_stackframe.js]
 [browser_webconsole_autocomplete_popup_close_on_tab_switch.js]
 [browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js]
 [browser_console_hide_jsterm_when_devtools_chrome_enabled_false.js]
 [browser_console_history_persist.js]
 [browser_webconsole_output_01.js]
deleted file mode 100644
--- a/devtools/client/webconsole/test/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/test/test-bug_923281_test1.js
+++ /dev/null
@@ -1,7 +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/ */
-
-console.log("Sample log.");
-console.log("This log should be filtered when filtered for test2.js.");
deleted file mode 100644
--- a/devtools/client/webconsole/test/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.");