browser/devtools/styleinspector/test/browser_ruleview_original-source-link.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial