browser/devtools/scratchpad/test/browser_scratchpad_execute_print.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.

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 onTabLoad() {
michael@0 11 gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
michael@0 12 openScratchpad(runTests);
michael@0 13 }, true);
michael@0 14
michael@0 15 content.location = "data:text/html,<p>test run() and display() in Scratchpad";
michael@0 16 }
michael@0 17
michael@0 18
michael@0 19 function runTests()
michael@0 20 {
michael@0 21 let sp = gScratchpadWindow.Scratchpad;
michael@0 22 let tests = [{
michael@0 23 method: "run",
michael@0 24 prepare: function() {
michael@0 25 content.wrappedJSObject.foobarBug636725 = 1;
michael@0 26 sp.editor.setText("++window.foobarBug636725");
michael@0 27 },
michael@0 28 then: function([code, , result]) {
michael@0 29 is(code, sp.getText(), "code is correct");
michael@0 30 is(result, content.wrappedJSObject.foobarBug636725,
michael@0 31 "result is correct");
michael@0 32
michael@0 33 is(sp.getText(), "++window.foobarBug636725",
michael@0 34 "run() does not change the editor content");
michael@0 35
michael@0 36 is(content.wrappedJSObject.foobarBug636725, 2,
michael@0 37 "run() updated window.foobarBug636725");
michael@0 38 }
michael@0 39 },
michael@0 40 {
michael@0 41 method: "display",
michael@0 42 prepare: function() {},
michael@0 43 then: function() {
michael@0 44 is(content.wrappedJSObject.foobarBug636725, 3,
michael@0 45 "display() updated window.foobarBug636725");
michael@0 46
michael@0 47 is(sp.getText(), "++window.foobarBug636725\n/*\n3\n*/",
michael@0 48 "display() shows evaluation result in the textbox");
michael@0 49
michael@0 50 is(sp.editor.getSelection(), "\n/*\n3\n*/", "getSelection is correct");
michael@0 51 }
michael@0 52 },
michael@0 53 {
michael@0 54 method: "run",
michael@0 55 prepare: function() {
michael@0 56 sp.editor.setText("window.foobarBug636725 = 'a';\n" +
michael@0 57 "window.foobarBug636725 = 'b';");
michael@0 58 sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 29 });
michael@0 59 },
michael@0 60 then: function([code, , result]) {
michael@0 61 is(code, "window.foobarBug636725 = 'a';", "code is correct");
michael@0 62 is(result, "a", "result is correct");
michael@0 63
michael@0 64 is(sp.getText(), "window.foobarBug636725 = 'a';\n" +
michael@0 65 "window.foobarBug636725 = 'b';",
michael@0 66 "run() does not change the textbox value");
michael@0 67
michael@0 68 is(content.wrappedJSObject.foobarBug636725, "a",
michael@0 69 "run() worked for the selected range");
michael@0 70 }
michael@0 71 },
michael@0 72 {
michael@0 73 method: "display",
michael@0 74 prepare: function() {
michael@0 75 sp.editor.setText("window.foobarBug636725 = 'c';\n" +
michael@0 76 "window.foobarBug636725 = 'b';");
michael@0 77 sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 22 });
michael@0 78 },
michael@0 79 then: function() {
michael@0 80 is(content.wrappedJSObject.foobarBug636725, "a",
michael@0 81 "display() worked for the selected range");
michael@0 82
michael@0 83 is(sp.getText(), "window.foobarBug636725" +
michael@0 84 "\n/*\na\n*/" +
michael@0 85 " = 'c';\n" +
michael@0 86 "window.foobarBug636725 = 'b';",
michael@0 87 "display() shows evaluation result in the textbox");
michael@0 88
michael@0 89 is(sp.editor.getSelection(), "\n/*\na\n*/", "getSelection is correct");
michael@0 90 }
michael@0 91 }];
michael@0 92
michael@0 93 runAsyncCallbackTests(sp, tests).then(function() {
michael@0 94 ok(sp.editor.somethingSelected(), "something is selected");
michael@0 95 sp.editor.dropSelection();
michael@0 96 ok(!sp.editor.somethingSelected(), "something is no longer selected");
michael@0 97 ok(!sp.editor.getSelection(), "getSelection is empty");
michael@0 98
michael@0 99 // Test undo/redo.
michael@0 100 sp.editor.setText("foo1");
michael@0 101 sp.editor.setText("foo2");
michael@0 102 is(sp.getText(), "foo2", "editor content updated");
michael@0 103 sp.undo();
michael@0 104 is(sp.getText(), "foo1", "undo() works");
michael@0 105 sp.redo();
michael@0 106 is(sp.getText(), "foo2", "redo() works");
michael@0 107
michael@0 108 finish();
michael@0 109 });
michael@0 110 }

mercurial