browser_scratchpad_throw_output.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. function test()
  4. {
  5. waitForExplicitFinish();
  6. gBrowser.selectedTab = gBrowser.addTab();
  7. gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
  8. gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
  9. openScratchpad(testThrowOutput);
  10. }, true);
  11. content.location = "data:text/html;charset=utf8,<p>Test throw outputs in Scratchpad</p>";
  12. }
  13. function testThrowOutput()
  14. {
  15. let scratchpad = gScratchpadWindow.Scratchpad, tests = [];
  16. let falsyValues = ["false", "0", "-0", "null", "undefined", "Infinity",
  17. "-Infinity", "NaN"];
  18. falsyValues.forEach(function (value) {
  19. tests.push({
  20. method: "display",
  21. code: "throw " + value + ";",
  22. result: "throw " + value + ";\n/*\nException: " + value + "\n*/",
  23. label: "Correct exception message for '" + value + "' is shown"
  24. });
  25. });
  26. let { DebuggerServer } = require("devtools/server/main");
  27. let longLength = DebuggerServer.LONG_STRING_LENGTH + 1;
  28. let longString = new Array(longLength).join("a");
  29. let shortedString = longString.substring(0,
  30. DebuggerServer.LONG_STRING_INITIAL_LENGTH) + "\u2026";
  31. tests.push({
  32. method: "display",
  33. code: "throw (new Array(" + longLength + ").join('a'));",
  34. result: "throw (new Array(" + longLength + ").join('a'));\n" +
  35. "/*\nException: " + shortedString + "\n*/",
  36. label: "Correct exception message for a longString is shown"
  37. });
  38. runAsyncTests(scratchpad, tests).then(function () {
  39. finish();
  40. });
  41. }