Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 */
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 }
16 var ScratchpadManager = Scratchpad.ScratchpadManager;
19 function test()
20 {
21 waitForExplicitFinish();
23 testListeners();
24 testRestoreNotFromFile();
25 testRestoreFromFileSaved();
26 testRestoreFromFileUnsaved();
28 gBrowser.selectedTab = gBrowser.addTab();
29 content.location = "data:text/html,<p>test star* UI for unsaved file changes";
30 }
32 function testListeners()
33 {
34 openScratchpad(function(aWin, aScratchpad) {
35 aScratchpad.setText("new text");
36 ok(isStar(aWin), "show star if scratchpad text changes");
38 aScratchpad.dirty = false;
39 ok(!isStar(aWin), "no star before changing text");
41 aScratchpad.setFilename("foo.js");
42 aScratchpad.setText("new text2");
43 ok(isStar(aWin), "shows star if scratchpad text changes");
45 aScratchpad.dirty = false;
46 ok(!isStar(aWin), "no star if scratchpad was just saved");
48 aScratchpad.setText("new text3");
49 ok(isStar(aWin), "shows star if scratchpad has more changes");
51 aScratchpad.undo();
52 ok(!isStar(aWin), "no star if scratchpad undo to save point");
54 aScratchpad.undo();
55 ok(isStar(aWin), "star if scratchpad undo past save point");
57 aWin.close();
58 done();
59 }, {noFocus: true});
60 }
62 function testRestoreNotFromFile()
63 {
64 let session = [{
65 text: "test1",
66 executionContext: 1
67 }];
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");
74 win.close();
75 done();
76 }, {window: win, noFocus: true});
77 }
79 function testRestoreFromFileSaved()
80 {
81 let session = [{
82 filename: "test.js",
83 text: "test1",
84 executionContext: 1,
85 saved: true
86 }];
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");
92 aScratchpad.setText("new text");
93 ok(isStar(win), "star when text changed from scratchpad restored from file");
95 win.close();
96 done();
97 }, {window: win, noFocus: true});
98 }
100 function testRestoreFromFileUnsaved()
101 {
102 let session = [{
103 filename: "test.js",
104 text: "test1",
105 executionContext: 1,
106 saved: false
107 }];
109 let [win] = ScratchpadManager.restoreSession(session);
110 openScratchpad(function() {
111 ok(isStar(win), "star with scratchpad restored with unsaved text");
113 win.close();
114 done();
115 }, {window: win, noFocus: true});
116 }
118 function isStar(win)
119 {
120 return win.document.title.match(/^\*[^\*]/);
121 }