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
120
|
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
///////////////////
//
// Whitelisting this test.
// As part of bug 1077403, the leaking uncaught rejection should be fixed.
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
const TESTCASE_URI = TEST_BASE + "simple.html";
let TESTCASE_CSS_SOURCE = "body{background-color:red;";
let gOriginalHref;
let gUI;
waitForExplicitFinish();
add_task(function*() {
let panel = yield addTabAndOpenStyleEditors(2, null, TESTCASE_URI);
gUI = panel.UI;
let editor = yield createNew();
testInitialState(editor);
let waitForPropertyChange = onPropertyChange(editor);
yield typeInEditor(editor);
yield waitForPropertyChange;
testUpdated(editor);
gUI = null;
});
function createNew() {
info("Creating a new stylesheet now");
let deferred = promise.defer();
gUI.once("editor-added", (ev, editor) => {
editor.getSourceEditor().then(deferred.resolve);
});
waitForFocus(function () {// create a new style sheet
let newButton = gPanelWindow.document.querySelector(".style-editor-newButton");
ok(newButton, "'new' button exists");
EventUtils.synthesizeMouseAtCenter(newButton, {}, gPanelWindow);
}, gPanelWindow);
return deferred.promise;
}
function onPropertyChange(aEditor) {
let deferred = promise.defer();
aEditor.styleSheet.on("property-change", function onProp(property, value) {
// wait for text to be entered fully
let text = aEditor.sourceEditor.getText();
if (property == "ruleCount" && text == TESTCASE_CSS_SOURCE + "}") {
aEditor.styleSheet.off("property-change", onProp);
deferred.resolve();
}
});
return deferred.promise;
}
function testInitialState(aEditor) {
info("Testing the initial state of the new editor");
gOriginalHref = aEditor.styleSheet.href;
let summary = aEditor.summary;
ok(aEditor.sourceLoaded, "new editor is loaded when attached");
ok(aEditor.isNew, "new editor has isNew flag");
ok(aEditor.sourceEditor.hasFocus(), "new editor has focus");
summary = aEditor.summary;
let ruleCount = summary.querySelector(".stylesheet-rule-count").textContent;
is(parseInt(ruleCount), 0,
"new editor initially shows 0 rules");
let computedStyle = content.getComputedStyle(content.document.body, null);
is(computedStyle.backgroundColor, "rgb(255, 255, 255)",
"content's background color is initially white");
}
function typeInEditor(aEditor) {
let deferred = promise.defer();
waitForFocus(function () {
for each (let c in TESTCASE_CSS_SOURCE) {
EventUtils.synthesizeKey(c, {}, gPanelWindow);
}
ok(aEditor.unsaved, "new editor has unsaved flag");
deferred.resolve();
}, gPanelWindow);
return deferred.promise;
}
function testUpdated(aEditor) {
info("Testing the state of the new editor after editing it");
is(aEditor.sourceEditor.getText(), TESTCASE_CSS_SOURCE + "}",
"rule bracket has been auto-closed");
let ruleCount = aEditor.summary.querySelector(".stylesheet-rule-count").textContent;
is(parseInt(ruleCount), 1,
"new editor shows 1 rule after modification");
is(aEditor.styleSheet.href, gOriginalHref,
"style sheet href did not change");
}
|