diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/server/tests/chrome/test_css-logic-specificity.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/chrome/test_css-logic-specificity.html')
-rw-r--r-- | devtools/server/tests/chrome/test_css-logic-specificity.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/devtools/server/tests/chrome/test_css-logic-specificity.html b/devtools/server/tests/chrome/test_css-logic-specificity.html new file mode 100644 index 0000000000..3d927728e8 --- /dev/null +++ b/devtools/server/tests/chrome/test_css-logic-specificity.html @@ -0,0 +1,82 @@ +<!DOCTYPE HTML> +<html> +<!-- +Test that css-logic calculates CSS specificity properly +--> +<head> + <meta charset="utf-8"> + <title>Test css-logic specificity</title> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +</head> +<body style="background:blue;"> + <script type="application/javascript"> + "use strict"; + + window.onload = function() { + const {require} = ChromeUtils.importESModule("resource://devtools/shared/loader/Loader.sys.mjs"); + const {CssLogic, CssSelector} = require("devtools/server/actors/inspector/css-logic"); + const InspectorUtils = SpecialPowers.InspectorUtils; + + const TEST_DATA = [ + {text: "*", expected: 0}, + {text: "LI", expected: 1}, + {text: "UL LI", expected: 2}, + {text: "UL OL + LI", expected: 3}, + {text: "H1 + [REL=\"up\"]", expected: 1025}, + {text: "UL OL LI.red", expected: 1027}, + {text: "LI.red.level", expected: 2049}, + {text: ".red .level", expected: 2048}, + {text: "#x34y", expected: 1048576}, + {text: "#s12:not(FOO)", expected: 1048577}, + {text: "body#home div#warning p.message", expected: 2098179}, + {text: "* body#home div#warning p.message", expected: 2098179}, + {text: "#footer :not(nav) li", expected: 1048578}, + {text: "bar:nth-child(n)", expected: 1025}, + {text: "li::marker", expected: 2}, + {text: "a:hover", expected: 1025}, + ]; + + function createDocument() { + let text = TEST_DATA.map(i=>i.text).join(","); + text = '<style type="text/css">' + text + " {color:red;}</style>"; + // eslint-disable-next-line no-unsanitized/property + document.body.innerHTML = text; + } + + function getExpectedSpecificity(selectorText) { + return TEST_DATA.filter(i => i.text === selectorText)[0].expected; + } + + SimpleTest.waitForExplicitFinish(); + + createDocument(); + const cssLogic = new CssLogic(); + + cssLogic.highlight(document.body); + const cssSheet = cssLogic.sheets[0]; + const cssRule = cssSheet.domSheet.cssRules[0]; + const selectors = CssLogic.getSelectors(cssRule); + + info("Iterating over the test selectors"); + for (let i = 0; i < selectors.length; i++) { + const selectorText = selectors[i]; + info("Testing selector " + selectorText); + + const selector = new CssSelector(cssRule, selectorText, i); + const expected = getExpectedSpecificity(selectorText); + const specificity = InspectorUtils.getSpecificity(selector.cssRule, + selector.selectorIndex); + is(specificity, expected, + 'Selector "' + selectorText + '" has a specificity of ' + expected); + } + + info("Testing specificity of element.style"); + const colorProp = cssLogic.getPropertyInfo("background"); + is(colorProp.matchedSelectors[0].specificity, 0x40000000, + "Element styles have specificity of 0x40000000 (1073741824)."); + + SimpleTest.finish(); + }; + </script> +</body> +</html> |