browser_console_nsiconsolemessage.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // Check that nsIConsoleMessages are displayed in the Browser Console.
  5. // See bug 859756.
  6. "use strict";
  7. const TEST_URI = "data:text/html;charset=utf8,<title>bug859756</title>\n" +
  8. "<p>hello world\n<p>nsIConsoleMessages ftw!";
  9. function test() {
  10. const FILTER_PREF = "devtools.browserconsole.filter.jslog";
  11. Services.prefs.setBoolPref(FILTER_PREF, true);
  12. registerCleanupFunction(() => {
  13. Services.prefs.clearUserPref(FILTER_PREF);
  14. });
  15. Task.spawn(function* () {
  16. const {tab} = yield loadTab(TEST_URI);
  17. // Test for cached nsIConsoleMessages.
  18. Services.console.logStringMessage("test1 for bug859756");
  19. info("open web console");
  20. let hud = yield openConsole(tab);
  21. ok(hud, "web console opened");
  22. Services.console.logStringMessage("do-not-show-me");
  23. ContentTask.spawn(gBrowser.selectedBrowser, null, function* () {
  24. content.console.log("foobarz");
  25. });
  26. yield waitForMessages({
  27. webconsole: hud,
  28. messages: [{
  29. text: "foobarz",
  30. category: CATEGORY_WEBDEV,
  31. severity: SEVERITY_LOG,
  32. }],
  33. });
  34. let text = hud.outputNode.textContent;
  35. is(text.indexOf("do-not-show-me"), -1,
  36. "nsIConsoleMessages are not displayed");
  37. is(text.indexOf("test1 for bug859756"), -1,
  38. "nsIConsoleMessages are not displayed (confirmed)");
  39. yield closeConsole(tab);
  40. info("web console closed");
  41. hud = yield HUDService.toggleBrowserConsole();
  42. ok(hud, "browser console opened");
  43. Services.console.logStringMessage("test2 for bug859756");
  44. let results = yield waitForMessages({
  45. webconsole: hud,
  46. messages: [{
  47. text: "test1 for bug859756",
  48. category: CATEGORY_JS,
  49. }, {
  50. text: "test2 for bug859756",
  51. category: CATEGORY_JS,
  52. }, {
  53. text: "do-not-show-me",
  54. category: CATEGORY_JS,
  55. }],
  56. });
  57. let msg = [...results[2].matched][0];
  58. ok(msg, "message element for do-not-show-me (nsIConsoleMessage)");
  59. isnot(msg.textContent.indexOf("do-not-show"), -1,
  60. "element content is correct");
  61. ok(!msg.classList.contains("filtered-by-type"), "element is not filtered");
  62. hud.setFilterState("jslog", false);
  63. ok(msg.classList.contains("filtered-by-type"), "element is filtered");
  64. }).then(finishTest);
  65. }