diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/server/tests/mochitest/test_css-logic-specificity.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/server/tests/mochitest/test_css-logic-specificity.html')
-rw-r--r-- | devtools/server/tests/mochitest/test_css-logic-specificity.html | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/devtools/server/tests/mochitest/test_css-logic-specificity.html b/devtools/server/tests/mochitest/test_css-logic-specificity.html new file mode 100644 index 000000000..45169c1fd --- /dev/null +++ b/devtools/server/tests/mochitest/test_css-logic-specificity.html @@ -0,0 +1,84 @@ +<!DOCTYPE HTML> +<html> +<!-- +Test that css-logic calculates CSS specificity properly +--> +<head> + <meta charset="utf-8"> + <title>Test css-logic specificity</title> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +</head> +<body style="background:blue;"> + <script type="application/javascript;version=1.8"> + + window.onload = function() { + var {utils: Cu, classes: Cc, interfaces: Ci} = Components; + + const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); + const {CssLogic, CssSelector} = require("devtools/server/css-logic"); + const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"] + .getService(Ci.inIDOMUtils); + + 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: 257}, + {text: "UL OL LI.red", expected: 259}, + {text: "LI.red.level", expected: 513}, + {text: ".red .level", expected: 512}, + {text: "#x34y", expected: 65536}, + {text: "#s12:not(FOO)", expected: 65537}, + {text: "body#home div#warning p.message", expected: 131331}, + {text: "* body#home div#warning p.message", expected: 131331}, + {text: "#footer :not(nav) li", expected: 65538}, + {text: "bar:nth-child(n)", expected: 257}, + {text: "li::-moz-list-number", expected: 1}, + {text: "a:hover", expected: 257} + ]; + + function createDocument() { + let text = TEST_DATA.map(i=>i.text).join(","); + text = '<style type="text/css">' + text + " {color:red;}</style>"; + document.body.innerHTML = text; + } + + function getExpectedSpecificity(selectorText) { + return TEST_DATA.filter(i => i.text === selectorText)[0].expected; + } + + SimpleTest.waitForExplicitFinish(); + + createDocument(); + let cssLogic = new CssLogic(DOMUtils.isInheritedProperty); + + cssLogic.highlight(document.body); + let cssSheet = cssLogic.sheets[0]; + let cssRule = cssSheet.domSheet.cssRules[0]; + let selectors = CssLogic.getSelectors(cssRule); + + info("Iterating over the test selectors") + for (let i = 0; i < selectors.length; i++) { + let selectorText = selectors[i]; + info("Testing selector " + selectorText); + + let selector = new CssSelector(cssRule, selectorText, i); + let expected = getExpectedSpecificity(selectorText); + let specificity = DOMUtils.getSpecificity(selector.cssRule, + selector.selectorIndex) + is(specificity, expected, + 'Selector "' + selectorText + '" has a specificity of ' + expected); + } + + info("Testing specificity of element.style"); + let colorProp = cssLogic.getPropertyInfo("background"); + is(colorProp.matchedSelectors[0].specificity, 0x01000000, + "Element styles have specificity of 0x01000000 (16777216)."); + + SimpleTest.finish(); + } + + </script> +</body> +</html> |