Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/ */
5 "use strict";
7 // Test that the stylesheet links in the rule view are correct when source maps
8 // are involved
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";
15 let test = asyncTest(function*() {
16 info("Setting the " + PREF + " pref to true");
17 Services.prefs.setBoolPref(PREF, true);
19 info("Opening the test page and opening the inspector");
20 yield addTab(TESTCASE_URI);
21 let {toolbox, inspector, view} = yield openRuleView();
23 info("Selecting the test node");
24 yield selectNode("div", inspector);
26 yield verifyLinkText(SCSS_LOC, view);
28 info("Setting the " + PREF + " pref to false");
29 Services.prefs.setBoolPref(PREF, false);
30 yield verifyLinkText(CSS_LOC, view);
32 info("Setting the " + PREF + " pref to true again");
33 Services.prefs.setBoolPref(PREF, true);
35 yield testClickingLink(toolbox, view);
36 yield checkDisplayedStylesheet(toolbox);
38 info("Clearing the " + PREF + " pref");
39 Services.prefs.clearUserPref(PREF);
40 });
42 function* testClickingLink(toolbox, view) {
43 info("Listening for switch to the style editor");
44 let onStyleEditorReady = toolbox.once("styleeditor-ready");
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 }
53 function checkDisplayedStylesheet(toolbox) {
54 let def = promise.defer();
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 });
66 return def.promise;
67 }
69 function editorSelected(editor) {
70 let href = editor.styleSheet.href;
71 ok(href.endsWith("doc_sourcemaps.scss"), "selected stylesheet is correct one");
73 let {line, col} = editor.sourceEditor.getCursor();
74 is(line, 3, "cursor is at correct line number in original source");
75 }
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 }