browser/devtools/scratchpad/test/browser_scratchpad_throw_output.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/scratchpad/test/browser_scratchpad_throw_output.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +
     1.9 +function test()
    1.10 +{
    1.11 +  waitForExplicitFinish();
    1.12 +
    1.13 +  gBrowser.selectedTab = gBrowser.addTab();
    1.14 +  gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    1.15 +    gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    1.16 +    openScratchpad(testThrowOutput);
    1.17 +  }, true);
    1.18 +
    1.19 +  content.location = "data:text/html;charset=utf8,<p>Test throw outputs in Scratchpad</p>";
    1.20 +}
    1.21 +
    1.22 +function testThrowOutput()
    1.23 +{
    1.24 +  let scratchpad = gScratchpadWindow.Scratchpad, tests = [];
    1.25 +
    1.26 +  let falsyValues = ["false", "0", "-0", "null", "undefined", "Infinity",
    1.27 +                      "-Infinity", "NaN"];
    1.28 +  falsyValues.forEach(function(value) {
    1.29 +    tests.push({
    1.30 +      method: "display",
    1.31 +      code: "throw " + value + ";",
    1.32 +      result: "throw " + value + ";\n/*\nException: " + value + "\n*/",
    1.33 +      label: "Correct exception message for '" + value + "' is shown"
    1.34 +    });
    1.35 +  });
    1.36 +
    1.37 +  let server = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {})
    1.38 +               .DebuggerServer;
    1.39 +
    1.40 +  let longLength = server.LONG_STRING_LENGTH + 1;
    1.41 +  let longString = new Array(longLength).join("a");
    1.42 +  let shortedString = longString.substring(0, server.LONG_STRING_INITIAL_LENGTH) +
    1.43 +                      "\u2026";
    1.44 +
    1.45 +  tests.push({
    1.46 +    method: "display",
    1.47 +    code: "throw (new Array(" + longLength + ").join('a'));",
    1.48 +    result: "throw (new Array(" + longLength + ").join('a'));\n" +
    1.49 +            "/*\nException: " + shortedString + "\n*/",
    1.50 +    label: "Correct exception message for a longString is shown"
    1.51 +  });
    1.52 +
    1.53 +  runAsyncTests(scratchpad, tests).then(function() {
    1.54 +    finish();
    1.55 +  });
    1.56 +}

mercurial