Bug 986201 - Return correct specificity for element styles instead of causing an exception. r=jwalker
--- a/browser/devtools/styleinspector/test/browser_styleinspector_csslogic-specificity.js
+++ b/browser/devtools/styleinspector/test/browser_styleinspector_csslogic-specificity.js
@@ -45,21 +45,27 @@ let test = asyncTest(function*() {
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).");
});
function createDocument() {
let doc = content.document;
doc.body.innerHTML = getStylesheetText();
+ doc.body.style.background = "blue";
doc.title = "Computed view specificity test";
}
function getStylesheetText() {
info("Creating the test stylesheet");
let text = TEST_DATA.map(i=>i.text).join(",");
return '<style type="text/css">' + text + " {color:red;}</style>";
}
--- a/toolkit/devtools/styleinspector/css-logic.js
+++ b/toolkit/devtools/styleinspector/css-logic.js
@@ -1501,16 +1501,24 @@ CssSelector.prototype = {
*
* @see http://www.w3.org/TR/css3-selectors/#specificity
* @see http://www.w3.org/TR/CSS2/selector.html
*
* @return {Number} The selector's specificity.
*/
get specificity()
{
+ if (this.elementStyle) {
+ // We can't ask specificity from DOMUtils as element styles don't provide
+ // CSSStyleRule interface DOMUtils expect. However, specificity of element
+ // style is constant, 1,0,0,0 or 0x01000000, just return the constant
+ // directly. @see http://www.w3.org/TR/CSS2/cascade.html#specificity
+ return 0x01000000;
+ }
+
if (this._specificity) {
return this._specificity;
}
this._specificity = domUtils.getSpecificity(this.cssRule.domRule,
this.selectorIndex);
return this._specificity;