browser_styleeditor_media_sidebar_sourcemaps.js (1739B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // https rather than chrome to improve coverage 7 const TESTCASE_URI = TEST_BASE_HTTPS + "media-rules-sourcemaps.html"; 8 const MAP_PREF = "devtools.source-map.client-service.enabled"; 9 10 const LABELS = [ 11 "screen and (max-width: 320px)", 12 "screen and (min-width: 1200px)", 13 ]; 14 const LINE_NOS = [5, 8]; 15 16 waitForExplicitFinish(); 17 18 add_task(async function () { 19 Services.prefs.setBoolPref(MAP_PREF, true); 20 21 const { ui } = await openStyleEditorForURL(TESTCASE_URI); 22 23 is(ui.editors.length, 1, "correct number of editors"); 24 25 // Test editor with @media rules 26 const mediaEditor = ui.editors[0]; 27 await openEditor(mediaEditor); 28 testAtRulesEditor(mediaEditor); 29 30 Services.prefs.clearUserPref(MAP_PREF); 31 }); 32 33 function testAtRulesEditor(editor) { 34 const sidebar = editor.details.querySelector(".stylesheet-sidebar"); 35 is(sidebar.hidden, false, "sidebar is showing on editor with @media"); 36 37 const entries = [...sidebar.querySelectorAll(".at-rule-label")]; 38 is(entries.length, 2, "two @media rules displayed in sidebar"); 39 40 testRule(entries[0], LABELS[0], LINE_NOS[0]); 41 testRule(entries[1], LABELS[1], LINE_NOS[1]); 42 } 43 44 function testRule(rule, text, lineno) { 45 const cond = rule.querySelector(".at-rule-condition"); 46 is(cond.textContent, text, "media label is correct for " + text); 47 48 const line = rule.querySelector(".at-rule-line"); 49 is(line.textContent, ":" + lineno, "correct line number shown"); 50 } 51 52 /* Helpers */ 53 54 function openEditor(editor) { 55 getLinkFor(editor).click(); 56 57 return editor.getSourceEditor(); 58 } 59 60 function getLinkFor(editor) { 61 return editor.summary.querySelector(".stylesheet-name"); 62 }