browser/devtools/scratchpad/test/browser_scratchpad_eval_func.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* vim: set ts=2 et sw=2 tw=80: */
     2 /* Any copyright is dedicated to the Public Domain.
     3    http://creativecommons.org/publicdomain/zero/1.0/ */
     5 function test()
     6 {
     7   waitForExplicitFinish();
     9   gBrowser.selectedTab = gBrowser.addTab();
    10   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    11     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    12     openScratchpad(runTests);
    13   }, true);
    15   content.location = "data:text/html;charset=utf8,test Scratchpad eval function.";
    16 }
    18 function reportErrorAndQuit(error) {
    19   DevToolsUtils.reportException("browser_scratchpad_eval_func.js", error);
    20   ok(false);
    21   finish();
    22 }
    24 function runTests(sw)
    25 {
    26   const sp = sw.Scratchpad;
    28   let foo = "" + function main() { console.log(1); };
    29   let bar = "var bar = " + (() => { console.log(2); });
    31   const fullText =
    32     foo + "\n" +
    33     "\n" +
    34     bar + "\n"
    36   sp.setText(fullText);
    38   // On the function declaration.
    39   sp.editor.setCursor({ line: 0, ch: 18 });
    40   sp.evalTopLevelFunction()
    41     .then(([text, error, result]) => {
    42       is(text, foo, "Should re-eval foo.");
    43       ok(!error, "Should not have got an error.");
    44       ok(result, "Should have got a result.");
    45     })
    47     // On the arrow function.
    48     .then(() => {
    49       sp.editor.setCursor({ line: 2, ch: 18 });
    50       return sp.evalTopLevelFunction();
    51     })
    52     .then(([text, error, result]) => {
    53       is(text, bar.replace("var ", ""), "Should re-eval bar.");
    54       ok(!error, "Should not have got an error.");
    55       ok(result, "Should have got a result.");
    56     })
    58     // On the empty line.
    59     .then(() => {
    60       sp.editor.setCursor({ line: 1, ch: 0 });
    61       return sp.evalTopLevelFunction();
    62     })
    63     .then(([text, error, result]) => {
    64       is(text, fullText,
    65          "Should get full text back since we didn't find a specific function.");
    66       ok(!error, "Should not have got an error.");
    67       ok(!result, "Should not have got a result.");
    68     })
    70     // Syntax error.
    71     .then(() => {
    72       sp.setText("function {}");
    73       sp.editor.setCursor({ line: 0, ch: 9 });
    74       return sp.evalTopLevelFunction();
    75     })
    76     .then(([text, error, result]) => {
    77       is(text, "function {}",
    78          "Should get the full text back since there was a parse error.");
    79       ok(!error, "Should not have got an error");
    80       ok(!result, "Should not have got a result");
    81       ok(sp.getText().contains("SyntaxError"),
    82          "We should have written the syntax error to the scratchpad.");
    83     })
    85     .then(finish, reportErrorAndQuit);
    86 }

mercurial