michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Test that the stylesheet links in the rule view are correct when source maps michael@0: // are involved michael@0: michael@0: const TESTCASE_URI = TEST_URL_ROOT + "doc_sourcemaps.html"; michael@0: const PREF = "devtools.styleeditor.source-maps-enabled"; michael@0: const SCSS_LOC = "doc_sourcemaps.scss:4"; michael@0: const CSS_LOC = "doc_sourcemaps.css:1"; michael@0: michael@0: let test = asyncTest(function*() { michael@0: info("Setting the " + PREF + " pref to true"); michael@0: Services.prefs.setBoolPref(PREF, true); michael@0: michael@0: info("Opening the test page and opening the inspector"); michael@0: yield addTab(TESTCASE_URI); michael@0: let {toolbox, inspector, view} = yield openRuleView(); michael@0: michael@0: info("Selecting the test node"); michael@0: yield selectNode("div", inspector); michael@0: michael@0: yield verifyLinkText(SCSS_LOC, view); michael@0: michael@0: info("Setting the " + PREF + " pref to false"); michael@0: Services.prefs.setBoolPref(PREF, false); michael@0: yield verifyLinkText(CSS_LOC, view); michael@0: michael@0: info("Setting the " + PREF + " pref to true again"); michael@0: Services.prefs.setBoolPref(PREF, true); michael@0: michael@0: yield testClickingLink(toolbox, view); michael@0: yield checkDisplayedStylesheet(toolbox); michael@0: michael@0: info("Clearing the " + PREF + " pref"); michael@0: Services.prefs.clearUserPref(PREF); michael@0: }); michael@0: michael@0: function* testClickingLink(toolbox, view) { michael@0: info("Listening for switch to the style editor"); michael@0: let onStyleEditorReady = toolbox.once("styleeditor-ready"); michael@0: michael@0: info("Finding the stylesheet link and clicking it"); michael@0: let link = getRuleViewLinkByIndex(view, 1); michael@0: link.scrollIntoView(); michael@0: link.click(); michael@0: yield onStyleEditorReady; michael@0: } michael@0: michael@0: function checkDisplayedStylesheet(toolbox) { michael@0: let def = promise.defer(); michael@0: michael@0: let panel = toolbox.getCurrentPanel(); michael@0: panel.UI.on("editor-selected", (event, editor) => { michael@0: // The style editor selects the first sheet at first load before michael@0: // selecting the desired sheet. michael@0: if (editor.styleSheet.href.endsWith("scss")) { michael@0: info("Original source editor selected"); michael@0: editor.getSourceEditor().then(editorSelected).then(def.resolve, def.reject); michael@0: } michael@0: }); michael@0: michael@0: return def.promise; michael@0: } michael@0: michael@0: function editorSelected(editor) { michael@0: let href = editor.styleSheet.href; michael@0: ok(href.endsWith("doc_sourcemaps.scss"), "selected stylesheet is correct one"); michael@0: michael@0: let {line, col} = editor.sourceEditor.getCursor(); michael@0: is(line, 3, "cursor is at correct line number in original source"); michael@0: } michael@0: michael@0: function verifyLinkText(text, view) { michael@0: info("Verifying that the rule-view stylesheet link is " + text); michael@0: let label = getRuleViewLinkByIndex(view, 1).querySelector("label"); michael@0: return waitForSuccess( michael@0: () => label.getAttribute("value") == text, michael@0: "Link text changed to display correct location: " + text michael@0: ); michael@0: }