Bug 1405243 - Migrate browser_webconsole_bug_1006027_message_timestamps_incorrect.js to a server test; r=bgrins. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Mon, 19 Mar 2018 16:42:09 +0100
changeset 769468 beeec437f12592b2229c89a5ab9125cc66d1971e
parent 769198 0b997836c7cf258a2b821eaa1c1ee66b9289ab17
child 769469 33a6acde41f1d33af4b127a2b9ad00a48721f9d2
child 769473 61fa671d0f6c31b68d9b94a388454d39446a12bf
push id103136
push userbmo:nchevobbe@mozilla.com
push dateMon, 19 Mar 2018 17:15:22 +0000
reviewersbgrins
bugs1405243
milestone61.0a1
Bug 1405243 - Migrate browser_webconsole_bug_1006027_message_timestamps_incorrect.js to a server test; r=bgrins. The test was testing that the 3 messages we display when evaluating a console.log (text of the input, evaluation result, consoleAPI message) all had a timestamp in a 2000ms range. This wasn't really what it should have been about, since the original bugfix (for Bug 1405243), was only in Console.cpp (and the fix is still up there). So here we only assert that the timestamp in the ConsoleAPI packet is between the moment the log was requested and the time we receive the packet. MozReview-Commit-ID: HikGCJGHXMy
devtools/shared/webconsole/test/chrome.ini
devtools/shared/webconsole/test/test_console_timestamp.html
--- a/devtools/shared/webconsole/test/chrome.ini
+++ b/devtools/shared/webconsole/test/chrome.ini
@@ -18,16 +18,17 @@ support-files =
 [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_timestamp.html]
 [test_console_worker.html]
 [test_file_uri.html]
 [test_reflow.html]
 [test_jsterm.html]
 [test_jsterm_autocomplete.html]
 [test_jsterm_cd_iframe.html]
 [test_jsterm_last_result.html]
 [test_jsterm_queryselector.html]
new file mode 100644
--- /dev/null
+++ b/devtools/shared/webconsole/test/test_console_timestamp.html
@@ -0,0 +1,61 @@
+<!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";
+
+const TEST_URL = "data:text/html,<html>Test ConsoleAPI timestamp correctness";
+
+window.onload = async function () {
+  SimpleTest.waitForExplicitFinish();
+  let state;
+  try {
+    const onAttachConsole = new Promise(resolve => attachConsole(
+      ["ConsoleAPI"],
+      (consoleState, response) => resolve(consoleState)
+    ));
+    state = await onAttachConsole;
+    const debuggerClient = state.dbgClient;
+
+    info("Testing console.log packet timestamp correctness");
+    const clientLogTimestamp = Date.now();
+    const packet = await consoleAPICall(debuggerClient,
+      () => top.console.log("test"));
+    const packetReceivedTimestamp = Date.now();
+
+    const {timeStamp} = packet.message;
+    ok(clientLogTimestamp <= timeStamp && timeStamp <= packetReceivedTimestamp,
+      "console.log message timestamp is between the expected time range " +
+      `(${clientLogTimestamp} <= ${timeStamp} <= ${packetReceivedTimestamp})`
+    );
+  } catch (e) {
+    ok(false, `Error thrown: ${e.message}`);
+  }
+
+  await closeDebugger(state);
+  SimpleTest.finish();
+};
+
+
+function consoleAPICall(debuggerClient, consoleCall) {
+  const onConsoleAPICall = debuggerClient.addOneTimeListener("consoleAPICall");
+  consoleCall();
+  return onConsoleAPICall;
+}
+
+  </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