|
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 /* Bug 660560 */ |
|
5 |
|
6 function test() |
|
7 { |
|
8 waitForExplicitFinish(); |
|
9 |
|
10 gBrowser.selectedTab = gBrowser.addTab(); |
|
11 gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() { |
|
12 gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true); |
|
13 |
|
14 ok(window.Scratchpad, "Scratchpad variable exists"); |
|
15 |
|
16 Services.prefs.setIntPref("devtools.editor.tabsize", 5); |
|
17 |
|
18 openScratchpad(runTests); |
|
19 }, true); |
|
20 |
|
21 content.location = "data:text/html,Scratchpad test for the Tab key, bug 660560"; |
|
22 } |
|
23 |
|
24 function runTests() |
|
25 { |
|
26 let sp = gScratchpadWindow.Scratchpad; |
|
27 ok(sp, "Scratchpad object exists in new window"); |
|
28 |
|
29 ok(sp.editor.hasFocus(), "the editor has focus"); |
|
30 |
|
31 sp.setText("window.foo;"); |
|
32 sp.editor.setCursor({ line: 0, ch: 0 }); |
|
33 |
|
34 EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow); |
|
35 |
|
36 is(sp.getText(), " window.foo;", "Tab key added 5 spaces"); |
|
37 |
|
38 is(sp.editor.getCursor().line, 0, "line is correct"); |
|
39 is(sp.editor.getCursor().ch, 5, "character is correct"); |
|
40 |
|
41 sp.editor.setCursor({ line: 0, ch: 6 }); |
|
42 |
|
43 EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow); |
|
44 |
|
45 is(sp.getText(), " w indow.foo;", |
|
46 "Tab key added 4 spaces"); |
|
47 |
|
48 is(sp.editor.getCursor().line, 0, "line is correct"); |
|
49 is(sp.editor.getCursor().ch, 10, "character is correct"); |
|
50 |
|
51 gScratchpadWindow.close(); |
|
52 |
|
53 Services.prefs.setIntPref("devtools.editor.tabsize", 6); |
|
54 Services.prefs.setBoolPref("devtools.editor.expandtab", false); |
|
55 |
|
56 openScratchpad(runTests2); |
|
57 } |
|
58 |
|
59 function runTests2() |
|
60 { |
|
61 let sp = gScratchpadWindow.Scratchpad; |
|
62 |
|
63 sp.setText("window.foo;"); |
|
64 sp.editor.setCursor({ line: 0, ch: 0 }); |
|
65 |
|
66 EventUtils.synthesizeKey("VK_TAB", {}, gScratchpadWindow); |
|
67 |
|
68 is(sp.getText(), "\twindow.foo;", "Tab key added the tab character"); |
|
69 |
|
70 is(sp.editor.getCursor().line, 0, "line is correct"); |
|
71 is(sp.editor.getCursor().ch, 1, "character is correct"); |
|
72 |
|
73 Services.prefs.clearUserPref("devtools.editor.tabsize"); |
|
74 Services.prefs.clearUserPref("devtools.editor.expandtab"); |
|
75 |
|
76 finish(); |
|
77 } |