Bug 1403458 - Convert browser_webconsole_assert.js to a backend test; r=bgrins. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Tue, 24 Oct 2017 10:45:29 +0200
changeset 685994 10101ebd0f300e6794b37db7f19c41c936683d7d
parent 685993 4e755ebedb6360991b820a61a53544c604def4c4
child 685995 b17a3a796e94ed0dc7c1e814dc3ab418899f8a29
child 686100 e2af7cc3bda73052b14c8c6a5450b184b734860a
push id86060
push userbmo:nchevobbe@mozilla.com
push dateWed, 25 Oct 2017 08:02:33 +0000
reviewersbgrins
bugs1403458
milestone58.0a1
Bug 1403458 - Convert browser_webconsole_assert.js to a backend test; r=bgrins. The test ensures that packet are sent for falsy console.assert calls, and that no packet are sent for truthy console.assert.calls, using a timeout. Mochitest and support files are removed from the new frontend. MozReview-Commit-ID: C9QpXfBySLo
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_assert.js
devtools/client/webconsole/new-console-output/test/mochitest/test-console-assert.html
devtools/shared/webconsole/test/chrome.ini
devtools/shared/webconsole/test/test_console_assert.html
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -95,17 +95,16 @@ support-files =
   test-bug-869003-iframe.html
   test-bug-869003-top-window.html
   test-bug-952277-highlight-nodes-in-vview.html
   test-bug-989025-iframe-parent.html
   test-certificate-messages.html
   test-closure-optimized-out.html
   test-closures.html
   test-console-api-stackframe.html
-  test-console-assert.html
   test-console-clear.html
   test-console-column.html
   test-console-count-external-file.js
   test-console-count.html
   test-console-extras.html
   test-console-filters.html
   test-console-group.html
   test-console-output-02.html
@@ -209,18 +208,16 @@ subsuite = clipboard
 [browser_jsterm_no_autocompletion_on_defined_variables.js]
 [browser_jsterm_no_input_and_tab_key_pressed.js]
 [browser_jsterm_no_input_change_and_tab_key_pressed.js]
 [browser_netmonitor_shows_reqs_in_webconsole.js]
 [browser_webconsole_allow_mixedcontent_securityerrors.js]
 tags = mcb
 skip-if = true #	Bug 1403452
 # old console skip-if = (os == 'win' && bits == 64) # Bug 1390001
-[browser_webconsole_assert.js]
-skip-if = true #	Bug 1403458
 [browser_webconsole_autocomplete_and_selfxss.js]
 subsuite = clipboard
 skip-if = true #	Bug 1404850
 # old console skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32 debug devtools for timeouts
 [browser_webconsole_autocomplete_crossdomain_iframe.js]
 skip-if = true # Bug 1408919
 [browser_webconsole_autocomplete_in_debugger_stackframe.js]
 skip-if = true # Bug 1408920
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_assert.js
+++ /dev/null
@@ -1,56 +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/ */
-
-// Test that console.assert() works as expected (i.e. outputs only on falsy
-// asserts). See bug 760193.
-
-"use strict";
-
-const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
-                 "test/test-console-assert.html";
-
-add_task(function* () {
-  yield loadTab(TEST_URI);
-
-  let hud = yield openConsole();
-  yield consoleOpened(hud);
-});
-
-function consoleOpened(hud) {
-  hud.jsterm.execute("test()");
-
-  return waitForMessages({
-    webconsole: hud,
-    messages: [{
-      text: "undefined",
-      category: CATEGORY_OUTPUT,
-      severity: SEVERITY_LOG,
-    },
-    {
-      text: "start",
-      category: CATEGORY_WEBDEV,
-      severity: SEVERITY_LOG,
-    },
-    {
-      text: "false assert",
-      category: CATEGORY_WEBDEV,
-      severity: SEVERITY_ERROR,
-    },
-    {
-      text: "falsy assert",
-      category: CATEGORY_WEBDEV,
-      severity: SEVERITY_ERROR,
-    },
-    {
-      text: "end",
-      category: CATEGORY_WEBDEV,
-      severity: SEVERITY_LOG,
-    }],
-  }).then(() => {
-    let nodes = hud.outputNode.querySelectorAll(".message");
-    is(nodes.length, 6,
-       "only six messages are displayed, no output from the true assert");
-  });
-}
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-console-assert.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!DOCTYPE HTML>
-<html dir="ltr" xml:lang="en-US" lang="en-US">
-  <head>
-    <!--
-      Any copyright is dedicated to the Public Domain.
-      http://creativecommons.org/publicdomain/zero/1.0/
-    -->
-    <meta charset="utf-8">
-    <title>console.assert() test</title>
-    <script type="text/javascript">
-      function test() {
-        console.log("start");
-        console.assert(false, "false assert");
-        console.assert(0, "falsy assert");
-        console.assert(true, "true assert");
-        console.log("end");
-      }
-    </script>
-  </head>
-  <body>
-    <p>test console.assert()</p>
-  </body>
-</html>
--- a/devtools/shared/webconsole/test/chrome.ini
+++ b/devtools/shared/webconsole/test/chrome.ini
@@ -13,16 +13,17 @@ support-files =
 
 [test_basics.html]
 [test_bug819670_getter_throws.html]
 [test_cached_messages.html]
 [test_commands_other.html]
 [test_commands_registration.html]
 [test_consoleapi.html]
 [test_consoleapi_innerID.html]
+[test_console_assert.html]
 [test_console_group_styling.html]
 [test_console_serviceworker.html]
 [test_console_serviceworker_cached.html]
 [test_console_styling.html]
 [test_console_worker.html]
 [test_file_uri.html]
 [test_reflow.html]
 [test_jsterm.html]
new file mode 100644
--- /dev/null
+++ b/devtools/shared/webconsole/test/test_console_assert.html
@@ -0,0 +1,108 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test for console.group styling with %c</title>
+  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="common.js"></script>
+  <!-- Any copyright is dedicated to the Public Domain.
+     - http://creativecommons.org/publicdomain/zero/1.0/ -->
+  <script>
+"use strict";
+
+window.onload = async function () {
+  SimpleTest.waitForExplicitFinish();
+  let state;
+  try {
+    state = await new Promise(resolve =>
+      attachConsole(["ConsoleAPI"], resolve)
+    );
+    const {dbgClient} = state;
+
+    const consoleAPICall = consoleCall => {
+      const onConsoleAPICall = new Promise((resolve, reject) => {
+        dbgClient.addOneTimeListener(
+          "consoleAPICall",
+          (type, packet) => resolve({type, packet})
+        );
+      });
+      consoleCall();
+      return onConsoleAPICall;
+    };
+
+    await testFalseAssert(consoleAPICall);
+    await testFalsyAssert(consoleAPICall);
+    await testUndefinedAssert(consoleAPICall);
+    await testNullAssert(consoleAPICall);
+    await testTrueAssert(consoleAPICall);
+
+  } catch (e) {
+    ok(false, `Error thrown: ${e.message}`);
+  }
+
+  closeDebugger(state, () => SimpleTest.finish());
+};
+
+async function testFalseAssert(consoleAPICall) {
+  info(`Testing console.assert(false)`);
+  let {packet} = await consoleAPICall(() =>
+    top.console.assert(false, "assertion is false"));
+
+  checkConsoleAPICall(packet.message, {
+    arguments: ["assertion is false"]
+  });
+}
+
+async function testFalsyAssert(consoleAPICall) {
+  info(`Testing console.assert(0")`);
+  let {packet} = await consoleAPICall(() =>
+    top.console.assert(0, "assertion is false"));
+
+  checkConsoleAPICall(packet.message, {
+    arguments: ["assertion is false"]
+  });
+}
+
+async function testUndefinedAssert(consoleAPICall) {
+  info(`Testing console.assert(undefined)`);
+  let {packet} = await consoleAPICall(() =>
+    top.console.assert(undefined, "assertion is false"));
+
+  checkConsoleAPICall(packet.message, {
+    arguments: ["assertion is false"]
+  });
+}
+
+async function testNullAssert(consoleAPICall) {
+  info(`Testing console.assert(null)`);
+  let {packet} = await consoleAPICall(() =>
+    top.console.assert(null, "assertion is false"));
+
+  checkConsoleAPICall(packet.message, {
+    arguments: ["assertion is false"]
+  });
+}
+
+async function testTrueAssert(consoleAPICall) {
+  info(`Testing console.assert(true)`);
+  const onConsoleApiCall = consoleAPICall(() =>
+    top.console.assert(true, "assertion is false"));
+
+  const TIMEOUT = Symbol();
+  const onTimeout = new Promise(resolve => setTimeout(() => resolve(TIMEOUT), 1000));
+
+  const res = await Promise.race([onConsoleApiCall, onTimeout]);
+  is(res, TIMEOUT,
+    "There was no consoleAPICall event in response to a truthy console.assert");
+}
+
+  </script>
+</head>
+<body>
+  <p id="display"></p>
+  <div id="content" style="display: none">
+  </div>
+  <pre id="test">
+  </pre>
+</body>
+</html>
\ No newline at end of file