test_non_content_accessible_pseudos.html (2122B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <style id="sheet"></style> 5 <script> 6 // Even though some of these no longer exist, we still do want to test that 7 // they aren't exposed to the web. 8 const NON_CONTENT_ACCESIBLE_PSEUDOS = [ 9 "::-moz-complex-control-wrapper", 10 "::-moz-number-wrapper", 11 "::-moz-number-text", 12 "::-moz-number-spin-up", 13 "::-moz-number-spin-down", 14 "::-moz-number-spin-box", 15 "::-moz-search-clear-button", 16 17 ":-moz-native-anonymous", 18 ":-moz-table-border-nonzero", 19 ":-moz-browser-frame", 20 ":-moz-devtools-highlighted", 21 ":-moz-styleeditor-transitioning", 22 ":-moz-handler-clicktoplay", 23 ":-moz-handler-vulnerable-updatable", 24 ":-moz-handler-vulnerable-no-update", 25 ":-moz-handler-disabled", 26 ":-moz-handler-blocked", 27 ":-moz-handler-chrased", 28 ":-moz-has-dir-attr", 29 ":-moz-dir-attr-ltr", 30 ":-moz-dir-attr-rtl", 31 ":-moz-dir-attr-like-auto", 32 ":-moz-autofill-preview", 33 ":-moz-is-html", 34 ":-moz-locale-dir(rtl)", 35 ":-moz-locale-dir(ltr)", 36 37 "::-moz-tree-row", 38 "::-moz-tree-row(foo)", 39 ]; 40 41 test(function() { 42 sheet.textContent = `div { color: initial }`; 43 assert_equals(sheet.sheet.cssRules.length, 1); 44 }, "sanity"); 45 46 for (const pseudo of NON_CONTENT_ACCESIBLE_PSEUDOS) { 47 test(function() { 48 sheet.textContent = `${pseudo} { color: blue; }`; 49 assert_equals(sheet.sheet.cssRules.length, 0, 50 pseudo + " shouldn't be accessible to content"); 51 if (pseudo.indexOf("::") === 0) { 52 let pseudoStyle; 53 try { 54 pseudoStyle = getComputedStyle(document.documentElement, pseudo); 55 } catch (ex) { 56 // We can hit this when layout.css.computed-style.throw-on-invalid-pseudo is true 57 assert_true(true, `${pseudo} shouldn't be visible to content`); 58 return; 59 } 60 let elementStyle = getComputedStyle(document.documentElement); 61 for (prop of pseudoStyle) { 62 assert_equals(pseudoStyle[prop], elementStyle[prop], 63 pseudo + " styles shouldn't be visible from getComputedStyle"); 64 } 65 } 66 }, pseudo); 67 } 68 </script>