browser_console.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 the basic features of the Browser Console, bug 587757.
  5. "use strict";
  6. const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
  7. "test/test-console.html?" + Date.now();
  8. const TEST_FILE = "chrome://mochitests/content/browser/devtools/client/" +
  9. "webconsole/test/test-cu-reporterror.js";
  10. const TEST_XHR_ERROR_URI = `http://example.com/404.html?${Date.now()}`;
  11. const TEST_IMAGE = "http://example.com/browser/devtools/client/webconsole/" +
  12. "test/test-image.png";
  13. "use strict";
  14. add_task(function* () {
  15. yield loadTab(TEST_URI);
  16. let opened = waitForBrowserConsole();
  17. let hud = HUDService.getBrowserConsole();
  18. ok(!hud, "browser console is not open");
  19. info("wait for the browser console to open with ctrl-shift-j");
  20. EventUtils.synthesizeKey("j", { accelKey: true, shiftKey: true }, window);
  21. hud = yield opened;
  22. ok(hud, "browser console opened");
  23. yield consoleOpened(hud);
  24. });
  25. function consoleOpened(hud) {
  26. hud.jsterm.clearOutput(true);
  27. expectUncaughtException();
  28. executeSoon(() => {
  29. foobarExceptionBug587757();
  30. });
  31. // Add a message from a chrome window.
  32. hud.iframeWindow.console.log("bug587757a");
  33. // Check Cu.reportError stack.
  34. // Use another js script to not depend on the test file line numbers.
  35. Services.scriptloader.loadSubScript(TEST_FILE, hud.iframeWindow);
  36. // Add a message from a content window.
  37. content.console.log("bug587757b");
  38. // Test eval.
  39. hud.jsterm.execute("document.location.href");
  40. // Check for network requests.
  41. let xhr = new XMLHttpRequest();
  42. xhr.onload = () => console.log("xhr loaded, status is: " + xhr.status);
  43. xhr.open("get", TEST_URI, true);
  44. xhr.send();
  45. // Check for xhr error.
  46. let xhrErr = new XMLHttpRequest();
  47. xhrErr.onload = () => {
  48. console.log("xhr error loaded, status is: " + xhrErr.status);
  49. };
  50. xhrErr.open("get", TEST_XHR_ERROR_URI, true);
  51. xhrErr.send();
  52. // Check that Fetch requests are categorized as "XHR".
  53. fetch(TEST_IMAGE).then(() => { console.log("fetch loaded"); });
  54. return waitForMessages({
  55. webconsole: hud,
  56. messages: [
  57. {
  58. name: "chrome window console.log() is displayed",
  59. text: "bug587757a",
  60. category: CATEGORY_WEBDEV,
  61. severity: SEVERITY_LOG,
  62. },
  63. {
  64. name: "Cu.reportError is displayed",
  65. text: "bug1141222",
  66. category: CATEGORY_JS,
  67. severity: SEVERITY_ERROR,
  68. stacktrace: [{
  69. file: TEST_FILE,
  70. line: 2,
  71. }, {
  72. file: TEST_FILE,
  73. line: 4,
  74. },
  75. // Ignore the rest of the stack,
  76. // just assert Cu.reportError call site
  77. // and consoleOpened call
  78. ]
  79. },
  80. {
  81. name: "content window console.log() is displayed",
  82. text: "bug587757b",
  83. category: CATEGORY_WEBDEV,
  84. severity: SEVERITY_LOG,
  85. },
  86. {
  87. name: "jsterm eval result",
  88. text: "browser.xul",
  89. category: CATEGORY_OUTPUT,
  90. severity: SEVERITY_LOG,
  91. },
  92. {
  93. name: "exception message",
  94. text: "foobarExceptionBug587757",
  95. category: CATEGORY_JS,
  96. severity: SEVERITY_ERROR,
  97. },
  98. {
  99. name: "network message",
  100. text: "test-console.html",
  101. category: CATEGORY_NETWORK,
  102. severity: SEVERITY_INFO,
  103. isXhr: true,
  104. },
  105. {
  106. name: "xhr error message",
  107. text: "404.html",
  108. category: CATEGORY_NETWORK,
  109. severity: SEVERITY_ERROR,
  110. isXhr: true,
  111. },
  112. {
  113. name: "network message",
  114. text: "test-image.png",
  115. category: CATEGORY_NETWORK,
  116. severity: SEVERITY_INFO,
  117. isXhr: true,
  118. },
  119. ],
  120. });
  121. }