|
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 669612 */ |
|
5 |
|
6 // only finish() when correct number of tests are done |
|
7 const expected = 4; |
|
8 var count = 0; |
|
9 function done() |
|
10 { |
|
11 if (++count == expected) { |
|
12 finish(); |
|
13 } |
|
14 } |
|
15 |
|
16 var ScratchpadManager = Scratchpad.ScratchpadManager; |
|
17 |
|
18 |
|
19 function test() |
|
20 { |
|
21 waitForExplicitFinish(); |
|
22 |
|
23 testListeners(); |
|
24 testRestoreNotFromFile(); |
|
25 testRestoreFromFileSaved(); |
|
26 testRestoreFromFileUnsaved(); |
|
27 |
|
28 gBrowser.selectedTab = gBrowser.addTab(); |
|
29 content.location = "data:text/html,<p>test star* UI for unsaved file changes"; |
|
30 } |
|
31 |
|
32 function testListeners() |
|
33 { |
|
34 openScratchpad(function(aWin, aScratchpad) { |
|
35 aScratchpad.setText("new text"); |
|
36 ok(isStar(aWin), "show star if scratchpad text changes"); |
|
37 |
|
38 aScratchpad.dirty = false; |
|
39 ok(!isStar(aWin), "no star before changing text"); |
|
40 |
|
41 aScratchpad.setFilename("foo.js"); |
|
42 aScratchpad.setText("new text2"); |
|
43 ok(isStar(aWin), "shows star if scratchpad text changes"); |
|
44 |
|
45 aScratchpad.dirty = false; |
|
46 ok(!isStar(aWin), "no star if scratchpad was just saved"); |
|
47 |
|
48 aScratchpad.setText("new text3"); |
|
49 ok(isStar(aWin), "shows star if scratchpad has more changes"); |
|
50 |
|
51 aScratchpad.undo(); |
|
52 ok(!isStar(aWin), "no star if scratchpad undo to save point"); |
|
53 |
|
54 aScratchpad.undo(); |
|
55 ok(isStar(aWin), "star if scratchpad undo past save point"); |
|
56 |
|
57 aWin.close(); |
|
58 done(); |
|
59 }, {noFocus: true}); |
|
60 } |
|
61 |
|
62 function testRestoreNotFromFile() |
|
63 { |
|
64 let session = [{ |
|
65 text: "test1", |
|
66 executionContext: 1 |
|
67 }]; |
|
68 |
|
69 let [win] = ScratchpadManager.restoreSession(session); |
|
70 openScratchpad(function(aWin, aScratchpad) { |
|
71 aScratchpad.setText("new text"); |
|
72 ok(isStar(win), "show star if restored scratchpad isn't from a file"); |
|
73 |
|
74 win.close(); |
|
75 done(); |
|
76 }, {window: win, noFocus: true}); |
|
77 } |
|
78 |
|
79 function testRestoreFromFileSaved() |
|
80 { |
|
81 let session = [{ |
|
82 filename: "test.js", |
|
83 text: "test1", |
|
84 executionContext: 1, |
|
85 saved: true |
|
86 }]; |
|
87 |
|
88 let [win] = ScratchpadManager.restoreSession(session); |
|
89 openScratchpad(function(aWin, aScratchpad) { |
|
90 ok(!isStar(win), "no star before changing text in scratchpad restored from file"); |
|
91 |
|
92 aScratchpad.setText("new text"); |
|
93 ok(isStar(win), "star when text changed from scratchpad restored from file"); |
|
94 |
|
95 win.close(); |
|
96 done(); |
|
97 }, {window: win, noFocus: true}); |
|
98 } |
|
99 |
|
100 function testRestoreFromFileUnsaved() |
|
101 { |
|
102 let session = [{ |
|
103 filename: "test.js", |
|
104 text: "test1", |
|
105 executionContext: 1, |
|
106 saved: false |
|
107 }]; |
|
108 |
|
109 let [win] = ScratchpadManager.restoreSession(session); |
|
110 openScratchpad(function() { |
|
111 ok(isStar(win), "star with scratchpad restored with unsaved text"); |
|
112 |
|
113 win.close(); |
|
114 done(); |
|
115 }, {window: win, noFocus: true}); |
|
116 } |
|
117 |
|
118 function isStar(win) |
|
119 { |
|
120 return win.document.title.match(/^\*[^\*]/); |
|
121 } |