Bug 1429174 - Introducing ConsoleUtils for logging messages to console - tests, r=bkelly
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 10 Jan 2018 22:06:37 +0100
changeset 452962 75a5873327a61af0923c83720a1f677d832e2b9c
parent 452961 8c42fc215b1be8456a1c4bb0a1491d9c2bee0ff4
child 452963 6e74b98b535425ea96ecbf65a391e9b6f3f51bc4
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1429174
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1429174 - Introducing ConsoleUtils for logging messages to console - tests, r=bkelly
dom/console/ConsoleInstance.cpp
dom/console/ConsoleInstance.h
dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js
dom/console/tests/xpcshell/xpcshell.ini
dom/webidl/Console.webidl
--- a/dom/console/ConsoleInstance.cpp
+++ b/dom/console/ConsoleInstance.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "mozilla/dom/ConsoleInstance.h"
 #include "mozilla/dom/ConsoleBinding.h"
 #include "ConsoleCommon.h"
+#include "ConsoleUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ConsoleInstance, mConsole)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(ConsoleInstance)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(ConsoleInstance)
@@ -180,10 +181,23 @@ ConsoleInstance::Count(JSContext* aCx, c
 void
 ConsoleInstance::Clear(JSContext* aCx)
 {
   const Sequence<JS::Value> data;
   mConsole->MethodInternal(aCx, Console::MethodClear,
                            NS_LITERAL_STRING("clear"), data);
 }
 
+void
+ConsoleInstance::ReportForServiceWorkerScope(const nsAString& aScope,
+                                             const nsAString& aMessage,
+                                             const nsAString& aFilename,
+                                             uint32_t aLineNumber,
+                                             uint32_t aColumnNumber)
+{
+  if (NS_IsMainThread()) {
+    ConsoleUtils::ReportForServiceWorkerScope(aScope, aMessage, aFilename,
+                                              aLineNumber, aColumnNumber);
+  }
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/console/ConsoleInstance.h
+++ b/dom/console/ConsoleInstance.h
@@ -89,16 +89,23 @@ public:
   Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData);
 
   void
   Count(JSContext* aCx, const nsAString& aLabel);
 
   void
   Clear(JSContext* aCx);
 
+  // For testing only.
+  void ReportForServiceWorkerScope(const nsAString& aScope,
+                                   const nsAString& aMessage,
+                                   const nsAString& aFilename,
+                                   uint32_t aLineNumber,
+                                   uint32_t aColumnNumber);
+
 private:
   ~ConsoleInstance();
 
   RefPtr<Console> mConsole;
 };
 
 } // dom namespace
 } // mozilla namespace
new file mode 100644
--- /dev/null
+++ b/dom/console/tests/xpcshell/test_reportForServiceWorkerScope.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+add_task(async function() {
+  let p = new Promise(resolve => {
+    function consoleListener() {
+      Services.obs.addObserver(this, "console-api-log-event");
+    }
+
+    consoleListener.prototype  = {
+      observe: function(aSubject, aTopic, aData) {
+        let obj = aSubject.wrappedJSObject;
+        Assert.ok(obj.arguments[0] === "Hello world!", "Message received!");
+        Assert.ok(obj.ID === "scope", "The ID is the scope");
+        Assert.ok(obj.innerID === "ServiceWorker", "The innerID is ServiceWorker");
+        Assert.ok(obj.filename === "filename", "The filename matches");
+        Assert.ok(obj.lineNumber === 42, "The lineNumber matches");
+        Assert.ok(obj.columnNumber === 24, "The columnNumber matches");
+
+        Services.obs.removeObserver(this, "console-api-log-event");
+        resolve();
+      }
+    };
+
+    new consoleListener();
+  });
+
+  let ci = console.createInstance();
+  ci.reportForServiceWorkerScope("scope", "Hello world!", "filename", 42, 24);
+  await p;
+});
--- a/dom/console/tests/xpcshell/xpcshell.ini
+++ b/dom/console/tests/xpcshell/xpcshell.ini
@@ -1,5 +1,6 @@
 [DEFAULT]
 head =
 support-files =
 
 [test_basic.js]
+[test_reportForServiceWorkerScope.js]
--- a/dom/webidl/Console.webidl
+++ b/dom/webidl/Console.webidl
@@ -181,8 +181,16 @@ dictionary ConsoleInstanceOptions {
   ConsoleLogLevel maxLogLevel;
 
   // String pref name which contains the level to use for maxLogLevel. If the
   // pref doesn't exist, gets removed or it is used in workers, the maxLogLevel
   // will default to the value passed to this constructor (or "all" if it wasn't
   // specified).
   DOMString maxLogLevelPref = "";
 };
+
+// this interface is just for testing
+partial interface ConsoleInstance {
+  [ChromeOnly]
+  void reportForServiceWorkerScope(DOMString scope, DOMString message,
+                                   DOMString filename, unsigned long lineNumber,
+                                   unsigned long columnNumber);
+};