|
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 |
|
5 // https rather than chrome to improve coverage |
|
6 const TESTCASE_URI = TEST_BASE_HTTPS + "sourcemaps.html"; |
|
7 const PREF = "devtools.styleeditor.source-maps-enabled"; |
|
8 |
|
9 |
|
10 const contents = { |
|
11 "sourcemaps.scss": [ |
|
12 "", |
|
13 "$paulrougetpink: #f06;", |
|
14 "", |
|
15 "div {", |
|
16 " color: $paulrougetpink;", |
|
17 "}", |
|
18 "", |
|
19 "span {", |
|
20 " background-color: #EEE;", |
|
21 "}" |
|
22 ].join("\n"), |
|
23 "contained.scss": [ |
|
24 "$pink: #f06;", |
|
25 "", |
|
26 "#header {", |
|
27 " color: $pink;", |
|
28 "}" |
|
29 ].join("\n"), |
|
30 "sourcemaps.css": [ |
|
31 "div {", |
|
32 " color: #ff0066; }", |
|
33 "", |
|
34 "span {", |
|
35 " background-color: #EEE; }", |
|
36 "", |
|
37 "/*# sourceMappingURL=sourcemaps.css.map */" |
|
38 ].join("\n"), |
|
39 "contained.css": [ |
|
40 "#header {", |
|
41 " color: #f06; }", |
|
42 "", |
|
43 "/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJzYXNzL2NvbnRhaW5lZC5zY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBO0VBQ0UsT0FISyIsInNvdXJjZXNDb250ZW50IjpbIiRwaW5rOiAjZjA2O1xuXG4jaGVhZGVyIHtcbiAgY29sb3I6ICRwaW5rO1xufSJdfQ==*/" |
|
44 ].join("\n") |
|
45 } |
|
46 |
|
47 const cssNames = ["sourcemaps.css", "contained.css"]; |
|
48 const scssNames = ["sourcemaps.scss", "contained.scss"]; |
|
49 |
|
50 waitForExplicitFinish(); |
|
51 |
|
52 let test = asyncTest(function*() { |
|
53 Services.prefs.setBoolPref(PREF, true); |
|
54 |
|
55 let {UI} = yield addTabAndOpenStyleEditors(5, null, TESTCASE_URI); |
|
56 |
|
57 is(UI.editors.length, 3, |
|
58 "correct number of editors with source maps enabled"); |
|
59 |
|
60 // Test first plain css editor |
|
61 testFirstEditor(UI.editors[0]); |
|
62 |
|
63 // Test Scss editors |
|
64 yield testEditor(UI.editors[1], scssNames); |
|
65 yield testEditor(UI.editors[2], scssNames); |
|
66 |
|
67 // Test disabling original sources |
|
68 yield togglePref(UI); |
|
69 |
|
70 is(UI.editors.length, 3, "correct number of editors after pref toggled"); |
|
71 |
|
72 // Test CSS editors |
|
73 yield testEditor(UI.editors[1], cssNames); |
|
74 yield testEditor(UI.editors[2], cssNames); |
|
75 |
|
76 Services.prefs.clearUserPref(PREF); |
|
77 }); |
|
78 |
|
79 function testFirstEditor(editor) { |
|
80 let name = getStylesheetNameFor(editor); |
|
81 is(name, "simple.css", "First style sheet display name is correct"); |
|
82 } |
|
83 |
|
84 function testEditor(editor, possibleNames) { |
|
85 let name = getStylesheetNameFor(editor); |
|
86 ok(possibleNames.indexOf(name) >= 0, name + " editor name is correct"); |
|
87 |
|
88 return openEditor(editor).then(() => { |
|
89 let expectedText = contents[name]; |
|
90 |
|
91 let text = editor.sourceEditor.getText(); |
|
92 is(text, expectedText, name + " editor contains expected text"); |
|
93 }); |
|
94 } |
|
95 |
|
96 /* Helpers */ |
|
97 |
|
98 function togglePref(UI) { |
|
99 let deferred = promise.defer(); |
|
100 let count = 0; |
|
101 |
|
102 UI.on("editor-added", (event, editor) => { |
|
103 if (++count == 3) { |
|
104 deferred.resolve(); |
|
105 } |
|
106 }) |
|
107 |
|
108 Services.prefs.setBoolPref(PREF, false); |
|
109 return deferred.promise; |
|
110 } |
|
111 |
|
112 function openEditor(editor) { |
|
113 getLinkFor(editor).click(); |
|
114 |
|
115 return editor.getSourceEditor(); |
|
116 } |
|
117 |
|
118 function getLinkFor(editor) { |
|
119 return editor.summary.querySelector(".stylesheet-name"); |
|
120 } |
|
121 |
|
122 function getStylesheetNameFor(editor) { |
|
123 return editor.summary.querySelector(".stylesheet-name > label") |
|
124 .getAttribute("value") |
|
125 } |