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