1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/styleinspector/test/browser_ruleview_original-source-link.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +// Test that the stylesheet links in the rule view are correct when source maps 1.11 +// are involved 1.12 + 1.13 +const TESTCASE_URI = TEST_URL_ROOT + "doc_sourcemaps.html"; 1.14 +const PREF = "devtools.styleeditor.source-maps-enabled"; 1.15 +const SCSS_LOC = "doc_sourcemaps.scss:4"; 1.16 +const CSS_LOC = "doc_sourcemaps.css:1"; 1.17 + 1.18 +let test = asyncTest(function*() { 1.19 + info("Setting the " + PREF + " pref to true"); 1.20 + Services.prefs.setBoolPref(PREF, true); 1.21 + 1.22 + info("Opening the test page and opening the inspector"); 1.23 + yield addTab(TESTCASE_URI); 1.24 + let {toolbox, inspector, view} = yield openRuleView(); 1.25 + 1.26 + info("Selecting the test node"); 1.27 + yield selectNode("div", inspector); 1.28 + 1.29 + yield verifyLinkText(SCSS_LOC, view); 1.30 + 1.31 + info("Setting the " + PREF + " pref to false"); 1.32 + Services.prefs.setBoolPref(PREF, false); 1.33 + yield verifyLinkText(CSS_LOC, view); 1.34 + 1.35 + info("Setting the " + PREF + " pref to true again"); 1.36 + Services.prefs.setBoolPref(PREF, true); 1.37 + 1.38 + yield testClickingLink(toolbox, view); 1.39 + yield checkDisplayedStylesheet(toolbox); 1.40 + 1.41 + info("Clearing the " + PREF + " pref"); 1.42 + Services.prefs.clearUserPref(PREF); 1.43 +}); 1.44 + 1.45 +function* testClickingLink(toolbox, view) { 1.46 + info("Listening for switch to the style editor"); 1.47 + let onStyleEditorReady = toolbox.once("styleeditor-ready"); 1.48 + 1.49 + info("Finding the stylesheet link and clicking it"); 1.50 + let link = getRuleViewLinkByIndex(view, 1); 1.51 + link.scrollIntoView(); 1.52 + link.click(); 1.53 + yield onStyleEditorReady; 1.54 +} 1.55 + 1.56 +function checkDisplayedStylesheet(toolbox) { 1.57 + let def = promise.defer(); 1.58 + 1.59 + let panel = toolbox.getCurrentPanel(); 1.60 + panel.UI.on("editor-selected", (event, editor) => { 1.61 + // The style editor selects the first sheet at first load before 1.62 + // selecting the desired sheet. 1.63 + if (editor.styleSheet.href.endsWith("scss")) { 1.64 + info("Original source editor selected"); 1.65 + editor.getSourceEditor().then(editorSelected).then(def.resolve, def.reject); 1.66 + } 1.67 + }); 1.68 + 1.69 + return def.promise; 1.70 +} 1.71 + 1.72 +function editorSelected(editor) { 1.73 + let href = editor.styleSheet.href; 1.74 + ok(href.endsWith("doc_sourcemaps.scss"), "selected stylesheet is correct one"); 1.75 + 1.76 + let {line, col} = editor.sourceEditor.getCursor(); 1.77 + is(line, 3, "cursor is at correct line number in original source"); 1.78 +} 1.79 + 1.80 +function verifyLinkText(text, view) { 1.81 + info("Verifying that the rule-view stylesheet link is " + text); 1.82 + let label = getRuleViewLinkByIndex(view, 1).querySelector("label"); 1.83 + return waitForSuccess( 1.84 + () => label.getAttribute("value") == text, 1.85 + "Link text changed to display correct location: " + text 1.86 + ); 1.87 +}