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