Bug 659625 - part1: implement Console::clear in dom/base/Console.cpp;r=baku
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 13 Apr 2016 16:33:43 +0200
changeset 330948 a56ae641acdc74ba0e3ee25e3eea97cec5d174da
parent 330947 c07f4c92f8a60d99d1f2fa14704ce33ce347c4f8
child 330949 ff3f8e8e89dce96d03ca9e31015825aa6444cb4b
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs659625
milestone48.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 659625 - part1: implement Console::clear in dom/base/Console.cpp;r=baku Remove the noop implementation of console.clear and actually clear the console storage. mozReview-Commit-ID: B9NGhRARKoR MozReview-Commit-ID: 2sMEGB2BsAs
dom/base/Console.cpp
dom/base/Console.h
dom/base/test/mochitest.ini
dom/base/test/test_bug659625.html
dom/webidl/Console.webidl
toolkit/modules/Console.jsm
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -1037,16 +1037,17 @@ Console::WrapObject(JSContext* aCx, JS::
 
 METHOD(Log, "log")
 METHOD(Info, "info")
 METHOD(Warn, "warn")
 METHOD(Error, "error")
 METHOD(Exception, "exception")
 METHOD(Debug, "debug")
 METHOD(Table, "table")
+METHOD(Clear, "clear")
 
 void
 Console::Trace(JSContext* aCx)
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mStatus == eInitialized);
 
   const Sequence<JS::Value> data;
@@ -1532,16 +1533,21 @@ Console::ProcessCallData(JSContext* aCx,
     outerID = aData->mOuterIDString;
     innerID = aData->mInnerIDString;
   } else {
     MOZ_ASSERT(aData->mIDType == ConsoleCallData::eNumber);
     outerID.AppendInt(aData->mOuterIDNumber);
     innerID.AppendInt(aData->mInnerIDNumber);
   }
 
+  if (aData->mMethodName == MethodClear) {
+    nsresult rv = mStorage->ClearEvents(innerID);
+    NS_WARN_IF(NS_FAILED(rv));
+  }
+
   if (NS_FAILED(mStorage->RecordEvent(innerID, outerID, eventValue))) {
     NS_WARNING("Failed to record a console event.");
   }
 }
 
 bool
 Console::PopulateConsoleNotificationInTheTargetScope(JSContext* aCx,
                                                      const Sequence<JS::Value>& aArguments,
--- a/dom/base/Console.h
+++ b/dom/base/Console.h
@@ -111,16 +111,19 @@ public:
 
   void
   Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData);
 
   void
   Count(JSContext* aCx, const Sequence<JS::Value>& aData);
 
   void
+  Clear(JSContext* aCx, const Sequence<JS::Value>& aData);
+
+  void
   NoopMethod();
 
   void
   ClearStorage();
 
   void
   RetrieveConsoleEvents(JSContext* aCx, nsTArray<JS::Value>& aEvents,
                         ErrorResult& aRv);
@@ -151,17 +154,18 @@ private:
     MethodDirxml,
     MethodGroup,
     MethodGroupCollapsed,
     MethodGroupEnd,
     MethodTime,
     MethodTimeEnd,
     MethodTimeStamp,
     MethodAssert,
-    MethodCount
+    MethodCount,
+    MethodClear
   };
 
   void
   Method(JSContext* aCx, MethodName aName, const nsAString& aString,
          const Sequence<JS::Value>& aData);
 
   // This method must receive aCx and aArguments in the same JSCompartment.
   void
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -644,16 +644,17 @@ skip-if = toolkit == 'android' #bug 6870
 [test_bug628938.html]
 [test_bug631615.html]
 [test_bug638112.html]
 [test_bug647518.html]
 [test_bug650001.html]
 [test_bug650776.html]
 [test_bug650784.html]
 [test_bug656283.html]
+[test_bug659625.html]
 [test_bug664916.html]
 [test_bug666604.html]
 skip-if = buildapp == 'b2g' # b2g(dom.disable_open_during_load not implemented in b2g) b2g-debug(dom.disable_open_during_load not implemented in b2g) b2g-desktop(dom.disable_open_during_load not implemented in b2g)
 [test_bug675121.html]
 skip-if = buildapp == 'b2g' # b2g(bug 901378) b2g-debug(bug 901378) b2g-desktop(bug 901378)
 [test_bug675166.html]
 [test_bug682463.html]
 [test_bug682554.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_bug659625.html
@@ -0,0 +1,92 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=659625
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 659625</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=659625">Mozilla Bug 659625</a>
+<script type="application/javascript">
+  const { Cc, Ci } = SpecialPowers;
+  let consoleStorage = Cc["@mozilla.org/consoleAPI-storage;1"];
+  let storage = consoleStorage.getService(Ci.nsIConsoleAPIStorage);
+
+  let clearAndCheckStorage = () => {
+    console.clear();
+    ok(storage.getEvents().length === 1,
+      "Only one event remains in consoleAPIStorage");
+    ok(storage.getEvents()[0].level === "clear",
+      "Remaining event has level 'clear'");
+  }
+
+  storage.clearEvents();
+  ok(storage.getEvents().length === 0,
+    "Console is empty when test is starting");
+  clearAndCheckStorage();
+
+  console.log("log");
+  console.debug("debug");
+  console.warn("warn");
+  console.error("error");
+  console.exception("exception");
+  ok(storage.getEvents().length === 6,
+    "5 new console events have been registered for logging variants");
+  clearAndCheckStorage();
+
+  console.trace();
+  ok(storage.getEvents().length === 2,
+    "1 new console event registered for trace");
+  clearAndCheckStorage();
+
+  console.dir({});
+  ok(storage.getEvents().length === 2,
+    "1 new console event registered for dir");
+  clearAndCheckStorage();
+
+  console.count("count-label");
+  console.count("count-label");
+  ok(storage.getEvents().length === 3,
+    "2 new console events registered for 2 count calls");
+  clearAndCheckStorage();
+
+  console.group("group-label")
+  console.log("group-log");
+  ok(storage.getEvents().length === 3,
+    "2 new console events registered for group + log");
+  clearAndCheckStorage();
+
+  console.groupCollapsed("group-collapsed")
+  console.log("group-collapsed-log");
+  ok(storage.getEvents().length === 3,
+    "2 new console events registered for groupCollapsed + log");
+  clearAndCheckStorage();
+
+  console.group("closed-group-label")
+  console.log("group-log");
+  console.groupEnd()
+  ok(storage.getEvents().length === 4,
+    "3 new console events registered for group/groupEnd");
+  clearAndCheckStorage();
+
+  console.time("time-label");
+  console.timeEnd();
+  ok(storage.getEvents().length === 3,
+    "2 new console events registered for time/timeEnd");
+  clearAndCheckStorage();
+
+  console.timeStamp("timestamp-label");
+  ok(storage.getEvents().length === 2,
+    "1 new console event registered for timeStamp");
+  clearAndCheckStorage();
+
+  // Check that console.clear() clears previous clear messages
+  clearAndCheckStorage();
+
+</script>
+</body>
+</html>
--- a/dom/webidl/Console.webidl
+++ b/dom/webidl/Console.webidl
@@ -18,27 +18,26 @@ interface Console {
   void dir(any... data);
   void dirxml(any... data);
   void group(any... data);
   void groupCollapsed(any... data);
   void groupEnd(any... data);
   void time(optional any time);
   void timeEnd(optional any time);
   void timeStamp(optional any data);
+  void clear(any... data);
 
   void profile(any... data);
   void profileEnd(any... data);
 
   void assert(boolean condition, any... data);
   void count(any... data);
 
   // No-op methods for compatibility with other browsers.
   [BinaryName="noopMethod"]
-  void clear();
-  [BinaryName="noopMethod"]
   void markTimeline();
   [BinaryName="noopMethod"]
   void timeline();
   [BinaryName="noopMethod"]
   void timelineEnd();
 };
 
 // This is used to propagate console events to the observers.
--- a/toolkit/modules/Console.jsm
+++ b/toolkit/modules/Console.jsm
@@ -278,16 +278,17 @@ function logProperty(aProp, aValue) {
   return reply;
 }
 
 const LOG_LEVELS = {
   "all": Number.MIN_VALUE,
   "debug": 2,
   "log": 3,
   "info": 3,
+  "clear": 3,
   "trace": 3,
   "timeEnd": 3,
   "time": 3,
   "group": 3,
   "groupEnd": 3,
   "dir": 3,
   "dirxml": 3,
   "warn": 4,