test_getRelativeRuleLine.html (2714B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test InspectorUtils::getRelativeRuleLine</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 8 <style> 9 @supports (not (whatever: 72 zq)) { 10 #test { 11 background-color: #f0c; 12 } 13 } 14 15 #test { 16 color: #f0c; 17 } 18 </style> 19 <style>#test { color: red; }</style> 20 <style> 21 @invalidatkeyword { 22 } 23 24 #test { 25 color: blue; 26 } 27 </style> 28 <style>#test { color: red; }</style><!-- This tests stylesheet caching --> 29 <style> 30 #test { 31 color: tomato; 32 33 &:where(*) { 34 color: gold; 35 36 &:not(.foo) { 37 color: plum; 38 } 39 40 color: salmon; 41 } 42 43 color: blanchedalmond; 44 color: snow; 45 46 & > span { 47 color: cornflowerblue; 48 } 49 50 color: seagreen; 51 } 52 </style><!-- This tests nesting --> 53 <script> 54 const InspectorUtils = SpecialPowers.InspectorUtils; 55 56 let tests = [ 57 { sheetNo: 0, ruleNo: 0, lineNo: 1, columnNo: 1 }, 58 { sheetNo: 1, ruleNo: 0, lineNo: 2, columnNo: 5 }, 59 { sheetNo: 1, ruleNo: 1, lineNo: 8, columnNo: 5 }, 60 { sheetNo: 2, ruleNo: 0, lineNo: 1, columnNo: 1 }, 61 { sheetNo: 3, ruleNo: 0, lineNo: 5, columnNo: 6 }, 62 { sheetNo: 4, ruleNo: 0, lineNo: 1, columnNo: 1 }, 63 { sheetNo: 5, ruleNo: 0, lineNo: 2, columnNo: 5 }, 64 { sheetNo: 5, ruleNo: [0, 0], lineNo: 5, columnNo: 7 }, 65 { sheetNo: 5, ruleNo: [0, 0, 0], lineNo: 8, columnNo: 9 }, 66 { sheetNo: 5, ruleNo: [0, 0, 1], lineNo: 12, columnNo: 9 }, 67 { sheetNo: 5, ruleNo: [0, 1], lineNo: 15, columnNo: 7 }, 68 { sheetNo: 5, ruleNo: [0, 2], lineNo: 18, columnNo: 7 }, 69 { sheetNo: 5, ruleNo: [0, 3], lineNo: 22, columnNo: 7 }, 70 ]; 71 72 function doTest() { 73 for (let test of tests) { 74 let sheet = document.styleSheets[test.sheetNo]; 75 let rule; 76 if (Array.isArray(test.ruleNo)) { 77 for(const index of test.ruleNo) { 78 rule = (rule ? rule : sheet).cssRules[index]; 79 } 80 } else { 81 rule = sheet.cssRules[test.ruleNo]; 82 } 83 let line = InspectorUtils.getRelativeRuleLine(rule); 84 let column = InspectorUtils.getRuleColumn(rule); 85 info("testing sheet " + test.sheetNo + ", rule " + test.ruleNo); 86 is(line, test.lineNo, "line number is correct"); 87 is(column, test.columnNo, "column number is correct"); 88 } 89 90 SimpleTest.finish(); 91 } 92 93 SimpleTest.waitForExplicitFinish(); 94 addLoadEvent(doTest); 95 </script> 96 </head> 97 <body> 98 <h1>Test InspectorUtils::getRelativeRuleLine</h1> 99 <p id="display"></p> 100 <div id="content" style="display: none"> 101 102 </div> 103 <pre id="test"> 104 </pre> 105 </body> 106 </html>