browser_repeated_messages_accuracy.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Test that makes sure messages are not considered repeated when coming from
  5. // different lines of code, or from different severities, etc.
  6. // See bugs 720180 and 800510.
  7. "use strict";
  8. const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
  9. "test/test-repeated-messages.html";
  10. const PREF = "devtools.webconsole.persistlog";
  11. add_task(function* () {
  12. Services.prefs.setBoolPref(PREF, true);
  13. let { browser } = yield loadTab(TEST_URI);
  14. let hud = yield openConsole();
  15. yield consoleOpened(hud);
  16. let loaded = loadBrowser(browser);
  17. BrowserReload();
  18. yield loaded;
  19. yield testCSSRepeats(hud);
  20. yield testCSSRepeatsAfterReload(hud);
  21. yield testConsoleRepeats(hud);
  22. yield testConsoleFalsyValues(hud);
  23. Services.prefs.clearUserPref(PREF);
  24. });
  25. function consoleOpened(hud) {
  26. // Check that css warnings are not coalesced if they come from different
  27. // lines.
  28. info("waiting for 2 css warnings");
  29. return waitForMessages({
  30. webconsole: hud,
  31. messages: [{
  32. name: "two css warnings",
  33. category: CATEGORY_CSS,
  34. count: 2,
  35. repeats: 1,
  36. }],
  37. });
  38. }
  39. function testCSSRepeats(hud) {
  40. info("wait for repeats after page reload");
  41. return waitForMessages({
  42. webconsole: hud,
  43. messages: [{
  44. name: "two css warnings, repeated twice",
  45. category: CATEGORY_CSS,
  46. repeats: 2,
  47. count: 2,
  48. }],
  49. });
  50. }
  51. function testCSSRepeatsAfterReload(hud) {
  52. hud.jsterm.clearOutput(true);
  53. hud.jsterm.execute("testConsole()");
  54. info("wait for repeats with the console API");
  55. return waitForMessages({
  56. webconsole: hud,
  57. messages: [
  58. {
  59. name: "console.log 'foo repeat' repeated twice",
  60. category: CATEGORY_WEBDEV,
  61. severity: SEVERITY_LOG,
  62. repeats: 2,
  63. },
  64. {
  65. name: "console.log 'foo repeat' repeated once",
  66. category: CATEGORY_WEBDEV,
  67. severity: SEVERITY_LOG,
  68. repeats: 1,
  69. },
  70. {
  71. name: "console.error 'foo repeat' repeated once",
  72. category: CATEGORY_WEBDEV,
  73. severity: SEVERITY_ERROR,
  74. repeats: 1,
  75. },
  76. ],
  77. });
  78. }
  79. function testConsoleRepeats(hud) {
  80. hud.jsterm.clearOutput(true);
  81. hud.jsterm.execute("undefined");
  82. ContentTask.spawn(gBrowser.selectedBrowser, {}, function* () {
  83. content.console.log("undefined");
  84. });
  85. info("make sure console API messages are not coalesced with jsterm output");
  86. return waitForMessages({
  87. webconsole: hud,
  88. messages: [
  89. {
  90. name: "'undefined' jsterm input message",
  91. text: "undefined",
  92. category: CATEGORY_INPUT,
  93. },
  94. {
  95. name: "'undefined' jsterm output message",
  96. text: "undefined",
  97. category: CATEGORY_OUTPUT,
  98. },
  99. {
  100. name: "'undefined' console.log message",
  101. text: "undefined",
  102. category: CATEGORY_WEBDEV,
  103. repeats: 1,
  104. },
  105. ],
  106. });
  107. }
  108. function testConsoleFalsyValues(hud) {
  109. hud.jsterm.clearOutput(true);
  110. hud.jsterm.execute("testConsoleFalsyValues()");
  111. info("wait for repeats of falsy values with the console API");
  112. return waitForMessages({
  113. webconsole: hud,
  114. messages: [
  115. {
  116. name: "console.log 'NaN' repeated once",
  117. category: CATEGORY_WEBDEV,
  118. severity: SEVERITY_LOG,
  119. repeats: 1,
  120. },
  121. {
  122. name: "console.log 'undefined' repeated once",
  123. category: CATEGORY_WEBDEV,
  124. severity: SEVERITY_LOG,
  125. repeats: 1,
  126. },
  127. {
  128. name: "console.log 'null' repeated once",
  129. category: CATEGORY_WEBDEV,
  130. severity: SEVERITY_LOG,
  131. repeats: 1,
  132. },
  133. {
  134. name: "console.log 'NaN' repeated twice",
  135. category: CATEGORY_WEBDEV,
  136. severity: SEVERITY_LOG,
  137. repeats: 2,
  138. },
  139. {
  140. name: "console.log 'undefined' repeated twice",
  141. category: CATEGORY_WEBDEV,
  142. severity: SEVERITY_LOG,
  143. repeats: 2,
  144. },
  145. {
  146. name: "console.log 'null' repeated twice",
  147. category: CATEGORY_WEBDEV,
  148. severity: SEVERITY_LOG,
  149. repeats: 2,
  150. },
  151. ],
  152. });
  153. }