Bug 1463525 - Add frontend to countReset;r=nchevobbe
authorBrian Grinstead <bgrinstead@mozilla.com>
Tue, 22 May 2018 11:49:47 -0700
changeset 476435 f3f6bb6829a5184f9c0acb6bb88375743004ce0a
parent 476434 8579efe6135a275fe5c29b2c7970cb0cec4f88fd
child 476436 73d696f9e675f144e6284f0f6517f04f88612ba5
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1463525
milestone62.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 1463525 - Add frontend to countReset;r=nchevobbe MozReview-Commit-ID: DuZLisDdTeG
devtools/client/locales/en-US/webconsole.properties
devtools/client/webconsole/test/components/console-api-call.test.js
devtools/client/webconsole/test/fixtures/stub-generators/stub-snippets.js
devtools/client/webconsole/test/fixtures/stubs/consoleApi.js
devtools/client/webconsole/utils/messages.js
--- a/devtools/client/locales/en-US/webconsole.properties
+++ b/devtools/client/locales/en-US/webconsole.properties
@@ -49,16 +49,20 @@ timeEnd=%1$S: %2$Sms
 # call to console.clear() to let the user know the previous messages of the
 # console have been removed programmatically.
 consoleCleared=Console was cleared.
 
 # LOCALIZATION NOTE (noCounterLabel): this string is used to display
 # count-messages with no label provided.
 noCounterLabel=<no label>
 
+# LOCALIZATION NOTE (counterDoesntExist): this string is displayed when
+# console.countReset() is called with a counter that doesn't exist.
+counterDoesntExist=Counter “%S” doesn’t exist.
+
 # LOCALIZATION NOTE (noGroupLabel): this string is used to display
 # console.group messages with no label provided.
 noGroupLabel=<no group label>
 
 # LOCALIZATION NOTE (Autocomplete.blank): this string is used when inputnode
 # string containing anchor doesn't matches to any property in the content.
 Autocomplete.blank=  <- no result
 
--- a/devtools/client/webconsole/test/components/console-api-call.test.js
+++ b/devtools/client/webconsole/test/components/console-api-call.test.js
@@ -197,16 +197,22 @@ describe("ConsoleAPICall component:", ()
         key: "console.count | default: 3",
         expectedBodyText: "default: 3",
       }, {
         key: "console.count | default: 4",
         expectedBodyText: "default: 4",
       }, {
         key: "console.count | test counter: 3",
         expectedBodyText: "test counter: 3",
+      }, {
+        key: "console.countReset | test counter: 0",
+        expectedBodyText: "test counter: 0",
+      }, {
+        key: "console.countReset | counterDoesntExist",
+        expectedBodyText: "Counter “test counter” doesn’t exist.",
       }];
 
       for (const {key, expectedBodyText} of messages) {
         const message = stubPreparedMessages.get(key);
         const wrapper = render(ConsoleApiCall({ message, serviceContainer }));
 
         expect(wrapper.find(".message-body").text()).toBe(expectedBodyText);
       }
--- a/devtools/client/webconsole/test/fixtures/stub-generators/stub-snippets.js
+++ b/devtools/client/webconsole/test/fixtures/stub-generators/stub-snippets.js
@@ -162,26 +162,30 @@ consoleApi.set("console.count", {
     "console.count | default: 1",
     "console.count | default: 2",
     "console.count | test counter: 1",
     "console.count | test counter: 2",
     "console.count | default: 3",
     "console.count | clear",
     "console.count | default: 4",
     "console.count | test counter: 3",
+    "console.countReset | test counter: 0",
+    "console.countReset | counterDoesntExist",
   ],
   code: `
     console.count();
     console.count();
     console.count("test counter");
     console.count("test counter");
     console.count();
     console.clear();
     console.count();
     console.count("test counter");
+    console.countReset("test counter");
+    console.countReset("test counter");
 `});
 
 // CSS messages
 const cssMessage = new Map();
 
 cssMessage.set("Unknown property", `
 p {
   such-unknown-property: wow;
--- a/devtools/client/webconsole/test/fixtures/stubs/consoleApi.js
+++ b/devtools/client/webconsole/test/fixtures/stubs/consoleApi.js
@@ -1723,16 +1723,68 @@ stubPreparedMessages.set(`console.count 
   "exceptionDocURL": null,
   "userProvidedStyles": [],
   "notes": null,
   "indent": 0,
   "prefix": "",
   "private": false
 }));
 
+stubPreparedMessages.set(`console.countReset | test counter: 0`, new ConsoleMessage({
+  "id": "1",
+  "allowRepeating": true,
+  "source": "console-api",
+  "timeStamp": 1526920412190,
+  "type": "log",
+  "helperType": null,
+  "level": "log",
+  "messageText": "test counter: 0",
+  "parameters": null,
+  "repeatId": "{\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"line\":10,\"column\":5},\"groupId\":null,\"indent\":0,\"level\":\"log\",\"messageText\":\"test counter: 0\",\"parameters\":null,\"source\":\"console-api\",\"type\":\"log\",\"userProvidedStyles\":[],\"private\":false}",
+  "stacktrace": null,
+  "frame": {
+    "source": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
+    "line": 10,
+    "column": 5
+  },
+  "groupId": null,
+  "exceptionDocURL": null,
+  "userProvidedStyles": [],
+  "notes": null,
+  "indent": 0,
+  "prefix": "",
+  "private": false
+}));
+
+stubPreparedMessages.set(`console.countReset | counterDoesntExist`, new ConsoleMessage({
+  "id": "1",
+  "allowRepeating": true,
+  "source": "console-api",
+  "timeStamp": 1526920412191,
+  "type": "log",
+  "helperType": null,
+  "level": "warn",
+  "messageText": "Counter “test counter” doesn’t exist.",
+  "parameters": null,
+  "repeatId": "{\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"line\":11,\"column\":5},\"groupId\":null,\"indent\":0,\"level\":\"warn\",\"messageText\":\"Counter “test counter” doesn’t exist.\",\"parameters\":null,\"source\":\"console-api\",\"type\":\"log\",\"userProvidedStyles\":[],\"private\":false}",
+  "stacktrace": null,
+  "frame": {
+    "source": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
+    "line": 11,
+    "column": 5
+  },
+  "groupId": null,
+  "exceptionDocURL": null,
+  "userProvidedStyles": [],
+  "notes": null,
+  "indent": 0,
+  "prefix": "",
+  "private": false
+}));
+
 stubPackets.set(`console.log('foobar', 'test')`, {
   "from": "server1.conn0.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
     "addonId": "",
     "arguments": [
       "foobar",
       "test"
@@ -3349,12 +3401,68 @@ stubPackets.set(`console.count | test co
     "timeStamp": 1511365913335,
     "timer": null,
     "workerType": "none",
     "styles": [],
     "category": "webdev"
   }
 });
 
+stubPackets.set(`console.countReset | test counter: 0`, {
+  "from": "server1.conn0.child1/consoleActor2",
+  "type": "consoleAPICall",
+  "message": {
+    "addonId": "",
+    "arguments": [
+      "test counter"
+    ],
+    "columnNumber": 5,
+    "counter": {
+      "count": 0,
+      "label": "test counter"
+    },
+    "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
+    "functionName": "triggerPacket",
+    "groupName": "",
+    "level": "countReset",
+    "lineNumber": 10,
+    "prefix": "",
+    "private": false,
+    "timeStamp": 1526920412190,
+    "timer": null,
+    "workerType": "none",
+    "styles": [],
+    "category": "webdev"
+  }
+});
+
+stubPackets.set(`console.countReset | counterDoesntExist`, {
+  "from": "server1.conn0.child1/consoleActor2",
+  "type": "consoleAPICall",
+  "message": {
+    "addonId": "",
+    "arguments": [
+      "test counter"
+    ],
+    "columnNumber": 5,
+    "counter": {
+      "error": "counterDoesntExist",
+      "label": "test counter"
+    },
+    "filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
+    "functionName": "triggerPacket",
+    "groupName": "",
+    "level": "countReset",
+    "lineNumber": 11,
+    "prefix": "",
+    "private": false,
+    "timeStamp": 1526920412191,
+    "timer": null,
+    "workerType": "none",
+    "styles": [],
+    "category": "webdev"
+  }
+});
+
 module.exports = {
   stubPreparedMessages,
   stubPackets,
 };
--- a/devtools/client/webconsole/utils/messages.js
+++ b/devtools/client/webconsole/utils/messages.js
@@ -78,23 +78,28 @@ function transformConsoleAPICallPacket(p
 
   // Special per-type conversion.
   switch (type) {
     case "clear":
       // We show a message to users when calls console.clear() is called.
       parameters = [l10n.getStr("consoleCleared")];
       break;
     case "count":
+    case "countReset":
       // Chrome RDP doesn't have a special type for count.
       type = MESSAGE_TYPE.LOG;
       let {counter} = message;
 
       if (!counter) {
         // We don't show anything if we don't have counter data.
         type = MESSAGE_TYPE.NULL_MESSAGE;
+      } else if (counter.error) {
+        messageText = l10n.getFormatStr(counter.error, [counter.label]);
+        level = MESSAGE_LEVEL.WARN;
+        parameters = null;
       } else {
         let label = counter.label ? counter.label : l10n.getStr("noCounterLabel");
         messageText = `${label}: ${counter.count}`;
         parameters = null;
       }
       break;
     case "time":
       parameters = null;