Bug 1006027 - ConsoleAPI uses timestamps in msecs. r=bz, a=lsblakk
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 12 May 2014 18:03:55 +0100
changeset 192325 5608c1796eee
parent 192324 fd3adb4a2d16
child 192326 ddae11a4c731
push id3568
push userryanvm@gmail.com
push date2014-05-20 16:00 +0000
treeherdermozilla-beta@26ba0b7f24ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, lsblakk
bugs1006027
milestone30.0
Bug 1006027 - ConsoleAPI uses timestamps in msecs. r=bz, a=lsblakk
browser/devtools/webconsole/test/browser.ini
browser/devtools/webconsole/test/browser_webconsole_bug_1006027_message_timestamps_incorrect.js
dom/base/Console.cpp
old mode 100644
new mode 100755
--- a/browser/devtools/webconsole/test/browser.ini
+++ b/browser/devtools/webconsole/test/browser.ini
@@ -227,16 +227,17 @@ run-if = os == "win"
 [browser_webconsole_bug_782653_CSS_links_in_Style_Editor.js]
 [browser_webconsole_bug_804845_ctrl_key_nav.js]
 run-if = os == "mac"
 [browser_webconsole_bug_817834_add_edited_input_to_history.js]
 [browser_webconsole_bug_821877_csp_errors.js]
 [browser_webconsole_bug_837351_securityerrors.js]
 [browser_webconsole_bug_846918_hsts_invalid-headers.js]
 [browser_webconsole_bug_915141_toggle_response_logging_with_keyboard.js]
+[browser_webconsole_bug_1006027_message_timestamps_incorrect.js]
 [browser_webconsole_cached_autocomplete.js]
 [browser_webconsole_change_font_size.js]
 [browser_webconsole_chrome.js]
 [browser_webconsole_closure_inspection.js]
 [browser_webconsole_completion.js]
 [browser_webconsole_console_extras.js]
 [browser_webconsole_console_logging_api.js]
 [browser_webconsole_count.js]
new file mode 100755
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_webconsole_bug_1006027_message_timestamps_incorrect.js
@@ -0,0 +1,40 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+function test() {
+  Task.spawn(runner).then(finishTest);
+
+  function* runner() {
+    const {tab} = yield loadTab("data:text/html;charset=utf8,<title>Test for Bug 1006027");
+
+    const target = TargetFactory.forTab(tab);
+    const hud = yield openConsole(tab);
+
+    hud.jsterm.execute("console.log('bug1006027')");
+
+    yield waitForMessages({
+      webconsole: hud,
+      messages: [{
+        name: "console.log",
+        text: "bug1006027",
+        category: CATEGORY_WEBDEV,
+        severity: SEVERITY_LOG,
+      }],
+    });
+
+    info('hud.outputNode.textContent:\n'+hud.outputNode.textContent);
+    let timestampNodes = hud.outputNode.querySelectorAll('span.timestamp');
+    let aTimestampMilliseconds = Array.prototype.map.call(timestampNodes,
+      function (value) {
+         // We are parsing timestamps as local time, relative to the begin of the epoch.
+         // This is not the correct value of the timestamp, but good enough for comparison.
+         return Date.parse('T'+String.trim(value.textContent));
+      });
+
+    let minTimestamp = Math.min.apply(null, aTimestampMilliseconds);
+    let maxTimestamp = Math.max.apply(null, aTimestampMilliseconds);
+    ok(Math.abs(maxTimestamp - minTimestamp) < 1000, "console.log message timestamp spread < 1000ms confirmed");
+  }
+}
+
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -133,17 +133,17 @@ JSStructuredCloneCallbacks gConsoleCallb
 };
 
 class ConsoleCallData MOZ_FINAL : public LinkedListElement<ConsoleCallData>
 {
 public:
   ConsoleCallData()
     : mMethodName(Console::MethodLog)
     , mPrivate(false)
-    , mTimeStamp(JS_Now())
+    , mTimeStamp(JS_Now() / PR_USEC_PER_MSEC)
     , mMonotonicTimer(0)
   {
     MOZ_COUNT_CTOR(ConsoleCallData);
   }
 
   ~ConsoleCallData()
   {
     MOZ_COUNT_DTOR(ConsoleCallData);