|
1 /* vim: set ft=javascript 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 "use strict"; |
|
6 |
|
7 // Test that the stylesheet links in the rule view are correct when source maps |
|
8 // are involved |
|
9 |
|
10 const TESTCASE_URI = TEST_URL_ROOT + "doc_sourcemaps.html"; |
|
11 const PREF = "devtools.styleeditor.source-maps-enabled"; |
|
12 const SCSS_LOC = "doc_sourcemaps.scss:4"; |
|
13 const CSS_LOC = "doc_sourcemaps.css:1"; |
|
14 |
|
15 let test = asyncTest(function*() { |
|
16 info("Setting the " + PREF + " pref to true"); |
|
17 Services.prefs.setBoolPref(PREF, true); |
|
18 |
|
19 info("Opening the test page and opening the inspector"); |
|
20 yield addTab(TESTCASE_URI); |
|
21 let {toolbox, inspector, view} = yield openRuleView(); |
|
22 |
|
23 info("Selecting the test node"); |
|
24 yield selectNode("div", inspector); |
|
25 |
|
26 yield verifyLinkText(SCSS_LOC, view); |
|
27 |
|
28 info("Setting the " + PREF + " pref to false"); |
|
29 Services.prefs.setBoolPref(PREF, false); |
|
30 yield verifyLinkText(CSS_LOC, view); |
|
31 |
|
32 info("Setting the " + PREF + " pref to true again"); |
|
33 Services.prefs.setBoolPref(PREF, true); |
|
34 |
|
35 yield testClickingLink(toolbox, view); |
|
36 yield checkDisplayedStylesheet(toolbox); |
|
37 |
|
38 info("Clearing the " + PREF + " pref"); |
|
39 Services.prefs.clearUserPref(PREF); |
|
40 }); |
|
41 |
|
42 function* testClickingLink(toolbox, view) { |
|
43 info("Listening for switch to the style editor"); |
|
44 let onStyleEditorReady = toolbox.once("styleeditor-ready"); |
|
45 |
|
46 info("Finding the stylesheet link and clicking it"); |
|
47 let link = getRuleViewLinkByIndex(view, 1); |
|
48 link.scrollIntoView(); |
|
49 link.click(); |
|
50 yield onStyleEditorReady; |
|
51 } |
|
52 |
|
53 function checkDisplayedStylesheet(toolbox) { |
|
54 let def = promise.defer(); |
|
55 |
|
56 let panel = toolbox.getCurrentPanel(); |
|
57 panel.UI.on("editor-selected", (event, editor) => { |
|
58 // The style editor selects the first sheet at first load before |
|
59 // selecting the desired sheet. |
|
60 if (editor.styleSheet.href.endsWith("scss")) { |
|
61 info("Original source editor selected"); |
|
62 editor.getSourceEditor().then(editorSelected).then(def.resolve, def.reject); |
|
63 } |
|
64 }); |
|
65 |
|
66 return def.promise; |
|
67 } |
|
68 |
|
69 function editorSelected(editor) { |
|
70 let href = editor.styleSheet.href; |
|
71 ok(href.endsWith("doc_sourcemaps.scss"), "selected stylesheet is correct one"); |
|
72 |
|
73 let {line, col} = editor.sourceEditor.getCursor(); |
|
74 is(line, 3, "cursor is at correct line number in original source"); |
|
75 } |
|
76 |
|
77 function verifyLinkText(text, view) { |
|
78 info("Verifying that the rule-view stylesheet link is " + text); |
|
79 let label = getRuleViewLinkByIndex(view, 1).querySelector("label"); |
|
80 return waitForSuccess( |
|
81 () => label.getAttribute("value") == text, |
|
82 "Link text changed to display correct location: " + text |
|
83 ); |
|
84 } |