Bug 1403450 - Add test cases from browser_webconsole_repeated_messages_accuracy.js to mocha; r=jdescottes. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Tue, 13 Feb 2018 07:57:24 +0100
changeset 754839 632e10a25c724044979d2ef4a02648e95ff88bbb
parent 754838 f41fb80356a99b50cb57d71c041d938647fdafbd
push id99010
push userbmo:nchevobbe@mozilla.com
push dateWed, 14 Feb 2018 11:22:58 +0000
reviewersjdescottes
bugs1403450
milestone60.0a1
Bug 1403450 - Add test cases from browser_webconsole_repeated_messages_accuracy.js to mocha; r=jdescottes. This test had some cases that weren't covered in our mocha tests, so we add them. In order to do that, we added a stub. We remove the mochitest and its support file. Since the support file was used by another test, we modify it to add the part that was used. MozReview-Commit-ID: AL4qWcWHQiA
devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js
devtools/client/webconsole/new-console-output/test/fixtures/stubs/evaluationResult.js
devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_repeat_different_objects.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_repeated_messages_accuracy.js
devtools/client/webconsole/new-console-output/test/mochitest/test-repeated-messages.html
devtools/client/webconsole/new-console-output/test/store/messages.test.js
--- a/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js
+++ b/devtools/client/webconsole/new-console-output/test/fixtures/stub-generators/stub-snippets.js
@@ -173,17 +173,18 @@ p {
 `);
 
 // Evaluation Result
 const evaluationResultCommands = [
   "new Date(0)",
   "asdf()",
   "1 + @",
   "inspect({a: 1})",
-  "cd(document)"
+  "cd(document)",
+  "undefined"
 ];
 
 let evaluationResult = new Map(evaluationResultCommands.map(cmd => [cmd, cmd]));
 evaluationResult.set("longString message Error",
   `throw new Error("Long error ".repeat(10000))`);
 
 evaluationResult.set(`eval throw ""`, `throw ""`);
 evaluationResult.set(`eval throw "tomato"`, `throw "tomato"`);
--- a/devtools/client/webconsole/new-console-output/test/fixtures/stubs/evaluationResult.js
+++ b/devtools/client/webconsole/new-console-output/test/fixtures/stubs/evaluationResult.js
@@ -161,16 +161,38 @@ stubPreparedMessages.set(`cd(document)`,
   "stacktrace": null,
   "frame": null,
   "groupId": null,
   "userProvidedStyles": null,
   "notes": null,
   "indent": 0
 }));
 
+stubPreparedMessages.set(`undefined`, new ConsoleMessage({
+  "id": "1",
+  "allowRepeating": true,
+  "source": "javascript",
+  "timeStamp": 1518606917356,
+  "type": "result",
+  "helperType": null,
+  "level": "log",
+  "parameters": [
+    {
+      "type": "undefined"
+    }
+  ],
+  "repeatId": "{\"frame\":null,\"groupId\":null,\"indent\":0,\"level\":\"log\",\"parameters\":[{\"type\":\"undefined\"}],\"source\":\"javascript\",\"type\":\"result\",\"userProvidedStyles\":null}",
+  "stacktrace": null,
+  "frame": null,
+  "groupId": null,
+  "userProvidedStyles": null,
+  "notes": null,
+  "indent": 0
+}));
+
 stubPreparedMessages.set(`longString message Error`, new ConsoleMessage({
   "id": "1",
   "allowRepeating": true,
   "source": "javascript",
   "timeStamp": 1493108241073,
   "type": "result",
   "helperType": null,
   "level": "error",
@@ -385,16 +407,29 @@ stubPackets.set(`cd(document)`, {
   "frame": null,
   "helperResult": {
     "type": "error",
     "message": "cdFunctionInvalidArgument"
   },
   "notes": null
 });
 
+stubPackets.set(`undefined`, {
+  "from": "server1.conn0.child1/consoleActor2",
+  "input": "undefined",
+  "result": {
+    "type": "undefined"
+  },
+  "timestamp": 1518606917356,
+  "exception": null,
+  "frame": null,
+  "helperResult": null,
+  "notes": null
+});
+
 stubPackets.set(`longString message Error`, {
   "from": "server1.conn0.child1/consoleActor2",
   "input": "throw new Error(\"Long error \".repeat(10000))",
   "result": {
     "type": "undefined"
   },
   "timestamp": 1493108241073,
   "exception": {
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser.ini
@@ -139,17 +139,16 @@ support-files =
   test-mutation.html
   test-network-exceptions.html
   test-network-request.html
   test-network.html
   test-observe-http-ajax.html
   test-own-console.html
   test-property-provider.html
   test-reopen-closed-tab.html
-  test-repeated-messages.html
   test-result-format-as-string.html
   test-sourcemap-error-01.html
   test-sourcemap-error-01.js
   test-sourcemap-error-02.html
   test-sourcemap-error-02.js
   test-stacktrace-location-debugger-link.html
   test-subresource-security-error.html
   test-subresource-security-error.js
@@ -334,18 +333,16 @@ skip-if = true #	Bug 1403448
 [browser_webconsole_output_copy.js]
 subsuite = clipboard
 [browser_webconsole_output_copy_newlines.js]
 subsuite = clipboard
 [browser_webconsole_output_order.js]
 [browser_webconsole_persist.js]
 [browser_webconsole_reopen_closed_tab.js]
 [browser_webconsole_repeat_different_objects.js]
-[browser_webconsole_repeated_messages_accuracy.js]
-skip-if = true #	Bug 1403450
 [browser_webconsole_sandbox_update_after_navigation.js]
 [browser_webconsole_script_errordoc_urls.js]
 skip-if = true #	Bug 1403454
 # old console skip-if = e10s # Bug 1042253 - webconsole tests disabled with e10s
 [browser_webconsole_scroll.js]
 [browser_webconsole_select_all.js]
 [browser_webconsole_show_subresource_security_errors.js]
 [browser_webconsole_shows_reqs_in_netmonitor.js]
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_repeat_different_objects.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_repeat_different_objects.js
@@ -3,31 +3,33 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Test that makes sure messages are not considered repeated when console.log()
 // is invoked with different objects, see bug 865288.
 
 "use strict";
 
-const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
-                 "new-console-output/test/mochitest/test-repeated-messages.html";
+const TEST_URI = "data:text/html,Test repeated objects";
 
 add_task(async function () {
-  let hud = await openNewTabAndConsole(TEST_URI);
-  hud.jsterm.clearOutput();
+  const hud = await openNewTabAndConsole(TEST_URI);
 
-  let onMessages = waitForMessages({
+  const onMessages = waitForMessages({
     hud,
     messages: [
       { text: "abba" },
       { text: "abba" },
       { text: "abba" },
     ],
   });
 
-  hud.jsterm.execute("window.testConsoleObjects()");
+  ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    for (var i = 0; i < 3; i++) {
+      const o = { id: "abba" };
+      content.console.log("abba", o);
+    }
+  });
 
   info("waiting for 3 console.log objects, with the exact same text content");
   let messages = await onMessages;
-
-  is(messages.length, 3, "3 message elements");
+  is(messages.length, 3, "There are 3 messages, as expected.");
 });
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_repeated_messages_accuracy.js
+++ /dev/null
@@ -1,178 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-// Test that makes sure messages are not considered repeated when coming from
-// different lines of code, or from different severities, etc.
-// See bugs 720180 and 800510.
-
-"use strict";
-
-const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
-                 "test/test-repeated-messages.html";
-const PREF = "devtools.webconsole.persistlog";
-
-add_task(function* () {
-  Services.prefs.setBoolPref(PREF, true);
-
-  let { browser } = yield loadTab(TEST_URI);
-
-  let hud = yield openConsole();
-
-  yield consoleOpened(hud);
-
-  let loaded = loadBrowser(browser);
-  BrowserReload();
-  yield loaded;
-
-  yield testCSSRepeats(hud);
-  yield testCSSRepeatsAfterReload(hud);
-  yield testConsoleRepeats(hud);
-  yield testConsoleFalsyValues(hud);
-
-  Services.prefs.clearUserPref(PREF);
-});
-
-function consoleOpened(hud) {
-  // Check that css warnings are not coalesced if they come from different
-  // lines.
-  info("waiting for 2 css warnings");
-
-  return waitForMessages({
-    webconsole: hud,
-    messages: [{
-      name: "two css warnings",
-      category: CATEGORY_CSS,
-      count: 2,
-      repeats: 1,
-    }],
-  });
-}
-
-function testCSSRepeats(hud) {
-  info("wait for repeats after page reload");
-
-  return waitForMessages({
-    webconsole: hud,
-    messages: [{
-      name: "two css warnings, repeated twice",
-      category: CATEGORY_CSS,
-      repeats: 2,
-      count: 2,
-    }],
-  });
-}
-
-function testCSSRepeatsAfterReload(hud) {
-  hud.jsterm.clearOutput(true);
-  hud.jsterm.execute("testConsole()");
-
-  info("wait for repeats with the console API");
-
-  return waitForMessages({
-    webconsole: hud,
-    messages: [
-      {
-        name: "console.log 'foo repeat' repeated twice",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 2,
-      },
-      {
-        name: "console.log 'foo repeat' repeated once",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 1,
-      },
-      {
-        name: "console.error 'foo repeat' repeated once",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_ERROR,
-        repeats: 1,
-      },
-    ],
-  });
-}
-
-function testConsoleRepeats(hud) {
-  hud.jsterm.clearOutput(true);
-  hud.jsterm.execute("undefined");
-
-  ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
-    content.console.log("undefined");
-  });
-
-  info("make sure console API messages are not coalesced with jsterm output");
-
-  return waitForMessages({
-    webconsole: hud,
-    messages: [
-      {
-        name: "'undefined' jsterm input message",
-        text: "undefined",
-        category: CATEGORY_INPUT,
-      },
-      {
-        name: "'undefined' jsterm output message",
-        text: "undefined",
-        category: CATEGORY_OUTPUT,
-      },
-      {
-        name: "'undefined' console.log message",
-        text: "undefined",
-        category: CATEGORY_WEBDEV,
-        repeats: 1,
-      },
-    ],
-  });
-}
-
-function testConsoleFalsyValues(hud) {
-  hud.jsterm.clearOutput(true);
-  hud.jsterm.execute("testConsoleFalsyValues()");
-
-  info("wait for repeats of falsy values with the console API");
-
-  return waitForMessages({
-    webconsole: hud,
-    messages: [
-      {
-        name: "console.log 'NaN' repeated once",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 1,
-      },
-      {
-        name: "console.log 'undefined' repeated once",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 1,
-      },
-      {
-        name: "console.log 'null' repeated once",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 1,
-      },
-      {
-        name: "console.log 'NaN' repeated twice",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 2,
-      },
-      {
-        name: "console.log 'undefined' repeated twice",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 2,
-      },
-      {
-        name: "console.log 'null' repeated twice",
-        category: CATEGORY_WEBDEV,
-        severity: SEVERITY_LOG,
-        repeats: 2,
-      },
-    ],
-  });
-}
deleted file mode 100644
--- a/devtools/client/webconsole/new-console-output/test/mochitest/test-repeated-messages.html
+++ /dev/null
@@ -1,53 +0,0 @@
-<!DOCTYPE HTML>
-<html dir="ltr" xml:lang="en-US" lang="en-US">
-  <head>
-    <meta charset="utf8">
-    <title>Test for bugs 720180, 800510, 865288 and 1218089</title>
-    <script>
-      function testConsole() {
-        // same line and column number
-        for(var i = 0; i < 2; i++) {
-          console.log("foo repeat");
-        }
-        console.log("foo repeat");
-        console.error("foo repeat");
-      }
-      function testConsoleObjects() {
-        for (var i = 0; i < 3; i++) {
-          var o = { id: "abba" };
-          console.log("abba", o);
-        }
-      }
-      function testConsoleFalsyValues(){
-        [NaN, undefined, null].forEach(function(item, index){
-          console.log(item);
-        });
-        [NaN, NaN].forEach(function(item, index){
-          console.log(item);
-        });
-        [undefined, undefined].forEach(function(item, index){
-          console.log(item);
-        });
-        [null, null].forEach(function(item, index){
-          console.log(item);
-        });
-      }
-    </script>
-    <style>
-      body {
-        background-image: foobarz;
-      }
-      p {
-        background-image: foobarz;
-      }
-    </style>
-    <!--
-    - Any copyright is dedicated to the Public Domain.
-    - http://creativecommons.org/publicdomain/zero/1.0/
-    -->
-  </head>
-  <body>
-    <p>Hello world!</p>
-  </body>
-</html>
-
--- a/devtools/client/webconsole/new-console-output/test/store/messages.test.js
+++ b/devtools/client/webconsole/new-console-output/test/store/messages.test.js
@@ -59,16 +59,41 @@ describe("Message reducer:", () => {
 
       const messages = getAllMessagesById(getState());
 
       expect(messages.size).toBe(1);
       const repeat = getAllRepeatById(getState());
       expect(repeat[getFirstMessage(getState()).id]).toBe(4);
     });
 
+    it("doesn't increment repeat on same log message with different locations", () => {
+      const key1 = "console.log('foobar', 'test')";
+      const { dispatch, getState } = setupStore();
+
+      const packet = clonePacket(stubPackets.get(key1));
+
+      // Dispatch original packet.
+      dispatch(actions.messagesAdd([packet]));
+
+      // Dispatch same packet with modified column number.
+      packet.message.columnNumber = packet.message.columnNumber + 1;
+      dispatch(actions.messagesAdd([packet]));
+
+      // Dispatch same packet with modified line number.
+      packet.message.lineNumber = packet.message.lineNumber + 1;
+      dispatch(actions.messagesAdd([packet]));
+
+      const messages = getAllMessagesById(getState());
+
+      expect(messages.size).toBe(3);
+
+      const repeat = getAllRepeatById(getState());
+      expect(Object.keys(repeat).length).toBe(0);
+    });
+
     it("increments repeat on a repeating css message", () => {
       const key1 = "Unknown property ‘such-unknown-property’.  Declaration dropped.";
       const { dispatch, getState } = setupStore([key1, key1]);
 
       const packet = clonePacket(stubPackets.get(key1));
 
       // Repeat ID must be the same even if the timestamp is different.
       packet.pageError.timeStamp = 1;
@@ -79,16 +104,41 @@ describe("Message reducer:", () => {
       const messages = getAllMessagesById(getState());
 
       expect(messages.size).toBe(1);
 
       const repeat = getAllRepeatById(getState());
       expect(repeat[getFirstMessage(getState()).id]).toBe(4);
     });
 
+    it("doesn't increment repeat on same css message with different locations", () => {
+      const key1 = "Unknown property ‘such-unknown-property’.  Declaration dropped.";
+      const { dispatch, getState } = setupStore();
+
+      const packet = clonePacket(stubPackets.get(key1));
+
+      // Dispatch original packet.
+      dispatch(actions.messagesAdd([packet]));
+
+      // Dispatch same packet with modified column number.
+      packet.pageError.columnNumber = packet.pageError.columnNumber + 1;
+      dispatch(actions.messagesAdd([packet]));
+
+      // Dispatch same packet with modified line number.
+      packet.pageError.lineNumber = packet.pageError.lineNumber + 1;
+      dispatch(actions.messagesAdd([packet]));
+
+      const messages = getAllMessagesById(getState());
+
+      expect(messages.size).toBe(3);
+
+      const repeat = getAllRepeatById(getState());
+      expect(Object.keys(repeat).length).toBe(0);
+    });
+
     it("increments repeat on a repeating error message", () => {
       const key1 = "ReferenceError: asdf is not defined";
       const { dispatch, getState } = setupStore([key1, key1]);
 
       const packet = clonePacket(stubPackets.get(key1));
 
       // Repeat ID must be the same even if the timestamp is different.
       packet.pageError.timeStamp = 1;
@@ -121,16 +171,67 @@ describe("Message reducer:", () => {
 
       expect(messages.size).toBe(4);
       const repeat = getAllRepeatById(getState());
       expect(repeat[getFirstMessage(getState()).id]).toBe(2);
       expect(repeat[getMessageAt(getState(), 2).id]).toBe(3);
       expect(repeat[getLastMessage(getState()).id]).toBe(undefined);
     });
 
+    it("doesn't increment undefined messages coming from different places", () => {
+      const { getState } = setupStore([
+        "console.log(undefined)",
+        "undefined",
+      ]);
+
+      const messages = getAllMessagesById(getState());
+      expect(messages.size).toBe(2);
+
+      const repeat = getAllRepeatById(getState());
+      expect(Object.keys(repeat).length).toBe(0);
+    });
+
+    it("doesn't increment successive falsy but different messages", () => {
+      const { getState } = setupStore([
+        "console.log(NaN)",
+        "console.log(undefined)",
+        "console.log(null)",
+      ], {actions});
+
+      let messages = getAllMessagesById(getState());
+      expect(messages.size).toBe(3);
+      let repeat = getAllRepeatById(getState());
+      expect(Object.keys(repeat).length).toBe(0);
+    });
+
+    it("increment falsy messages when expected", () => {
+      const { dispatch, getState } = setupStore();
+
+      const nanPacket = stubPackets.get("console.log(NaN)");
+      dispatch(actions.messagesAdd([nanPacket, nanPacket]));
+      let messages = getAllMessagesById(getState());
+      expect(messages.size).toBe(1);
+      let repeat = getAllRepeatById(getState());
+      expect(repeat[getLastMessage(getState()).id]).toBe(2);
+
+      const undefinedPacket = stubPackets.get("console.log(undefined)");
+      dispatch(actions.messagesAdd([undefinedPacket, undefinedPacket]));
+      messages = getAllMessagesById(getState());
+      expect(messages.size).toBe(2);
+      repeat = getAllRepeatById(getState());
+      expect(repeat[getLastMessage(getState()).id]).toBe(2);
+
+      const nullPacket = stubPackets.get("console.log(null)");
+      dispatch(actions.messagesAdd([nullPacket, nullPacket]));
+      messages = getAllMessagesById(getState());
+      expect(messages.size).toBe(3);
+      repeat = getAllRepeatById(getState());
+      expect(repeat[getLastMessage(getState()).id]).toBe(2);
+    });
+
     it("does not clobber a unique message", () => {
       const key1 = "console.log('foobar', 'test')";
       const { dispatch, getState } = setupStore([key1, key1]);
 
       const packet = stubPackets.get(key1);
       dispatch(actions.messagesAdd([packet]));
 
       const packet2 = stubPackets.get("console.log(undefined)");