browser_rules_original-source-link2.js (2799B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that the stylesheet links in the rule view are correct when source maps 7 // are involved. 8 9 const TESTCASE_URI = URL_ROOT + "doc_sourcemaps2.html"; 10 const PREF = "devtools.source-map.client-service.enabled"; 11 const SCSS_LOC = "doc_sourcemaps.scss:4"; 12 const CSS_LOC = "doc_sourcemaps2.css:1"; 13 14 add_task(async function () { 15 info("Setting the " + PREF + " pref to true"); 16 Services.prefs.setBoolPref(PREF, true); 17 18 await addTab(TESTCASE_URI); 19 const { toolbox, inspector, view } = await openRuleView(); 20 21 info("Selecting the test node"); 22 await selectNode("div", inspector); 23 24 await verifyLinkText(SCSS_LOC, view); 25 26 info("Setting the " + PREF + " pref to false"); 27 Services.prefs.setBoolPref(PREF, false); 28 await verifyLinkText(CSS_LOC, view); 29 30 info("Setting the " + PREF + " pref to true again"); 31 Services.prefs.setBoolPref(PREF, true); 32 33 await testClickingLink(toolbox, view); 34 const selectedEditor = 35 await waitForOriginalStyleSheetEditorSelection(toolbox); 36 const href = selectedEditor.styleSheet.href; 37 ok( 38 href.endsWith("doc_sourcemaps.scss"), 39 "selected stylesheet is correct one" 40 ); 41 await selectedEditor.getSourceEditor(); 42 43 const { line } = selectedEditor.sourceEditor.getCursor(); 44 is(line, 3, "cursor is at correct line number in original source"); 45 46 info("Clearing the " + PREF + " pref"); 47 Services.prefs.clearUserPref(PREF); 48 }); 49 50 async function testClickingLink(toolbox, view) { 51 info("Listening for switch to the style editor"); 52 const onStyleEditorReady = toolbox.once("styleeditor-selected"); 53 54 info("Finding the stylesheet link and clicking it"); 55 const link = getRuleViewLinkByIndex(view, 1); 56 link.scrollIntoView(); 57 link.click(); 58 await onStyleEditorReady; 59 } 60 61 function waitForOriginalStyleSheetEditorSelection(toolbox) { 62 const panel = toolbox.getCurrentPanel(); 63 return new Promise(resolve => { 64 const maybeContinue = editor => { 65 // The style editor selects the first sheet at first load before 66 // selecting the desired sheet. 67 if (editor.styleSheet.href.endsWith("scss")) { 68 info("Original source editor selected"); 69 off(); 70 resolve(editor); 71 } 72 }; 73 const off = panel.UI.on("editor-selected", maybeContinue); 74 if (panel.UI.selectedEditor) { 75 maybeContinue(panel.UI.selectedEditor); 76 } 77 }); 78 } 79 80 function verifyLinkText(text, view) { 81 info("Verifying that the rule-view stylesheet link is " + text); 82 const label = getRuleViewLinkByIndex(view, 1).querySelector( 83 ".ruleview-rule-source-label" 84 ); 85 return waitForSuccess(function () { 86 return label.textContent == text; 87 }, "Link text changed to display correct location: " + text); 88 }