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