Bug 1427419 - Part 3: Move inIDOMUtils.getCSSStyleRules to InspectorUtils. r=bz draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 06 Jan 2018 15:08:13 +0800
changeset 716748 e1292dcaf5c989f1add079614221167ce785434b
parent 716747 27c2c20a1c5b9825871532da9027910fdb3e7a17
child 716749 144ea7133caa029df905df6caf1003963a5336d1
push id94496
push userbmo:cam@mcc.id.au
push dateSat, 06 Jan 2018 07:08:40 +0000
reviewersbz
bugs1427419
milestone59.0a1
Bug 1427419 - Part 3: Move inIDOMUtils.getCSSStyleRules to InspectorUtils. r=bz MozReview-Commit-ID: 3pcxsYhguOk
devtools/client/shared/test/test-actor.js
devtools/server/actors/highlighters/geometry-editor.js
devtools/server/actors/highlighters/shapes.js
devtools/server/actors/styles.js
devtools/server/css-logic.js
devtools/shared/inspector/css-logic.js
dom/webidl/InspectorUtils.webidl
layout/base/tests/test_bug416896.html
layout/inspector/InspectorUtils.h
layout/inspector/inDOMUtils.cpp
layout/inspector/inDOMUtils.h
layout/inspector/inIDOMUtils.idl
layout/inspector/tests/test_bug462787.html
layout/inspector/tests/test_bug462789.html
layout/inspector/tests/test_bug536379-2.html
layout/inspector/tests/test_bug536379.html
layout/inspector/tests/test_bug557726.html
layout/inspector/tests/test_getCSSStyleRules.html
layout/inspector/tests/test_selectormatcheselement.html
--- a/devtools/client/shared/test/test-actor.js
+++ b/devtools/client/shared/test/test-actor.js
@@ -779,18 +779,18 @@ var TestActor = exports.TestActor = prot
    * - {Boolean} isContentSheet.
    */
   getStyleSheetsInfoForNode: function (selector) {
     let node = this._querySelector(selector);
     let domRules = getCSSStyleRules(node);
 
     let sheets = [];
 
-    for (let i = 0, n = domRules.Count(); i < n; i++) {
-      let sheet = domRules.GetElementAt(i).parentStyleSheet;
+    for (let i = 0, n = domRules.length; i < n; i++) {
+      let sheet = domRules[i].parentStyleSheet;
       sheets.push({
         href: sheet.href,
         isContentSheet: isContentStylesheet(sheet)
       });
     }
 
     return sheets;
   },
--- a/devtools/server/actors/highlighters/geometry-editor.js
+++ b/devtools/server/actors/highlighters/geometry-editor.js
@@ -126,18 +126,18 @@ function getOffsetParent(node) {
 function getDefinedGeometryProperties(node) {
   let props = new Map();
   if (!node) {
     return props;
   }
 
   // Get the list of css rules applying to the current node.
   let cssRules = getCSSStyleRules(node);
-  for (let i = 0; i < cssRules.Count(); i++) {
-    let rule = cssRules.GetElementAt(i);
+  for (let i = 0; i < cssRules.length; i++) {
+    let rule = cssRules[i];
     for (let name of GeoProp.allProps()) {
       let value = rule.style.getPropertyValue(name);
       if (value && value !== "auto") {
         // getCSSStyleRules returns rules ordered from least to most specific
         // so just override any previous properties we have set.
         props.set(name, {
           cssRule: rule
         });
--- a/devtools/server/actors/highlighters/shapes.js
+++ b/devtools/server/actors/highlighters/shapes.js
@@ -2512,18 +2512,18 @@ class ShapesHighlighter extends AutoRefr
  */
 function getDefinedShapeProperties(node, property) {
   let prop = "";
   if (!node) {
     return prop;
   }
 
   let cssRules = getCSSStyleRules(node);
-  for (let i = 0; i < cssRules.Count(); i++) {
-    let rule = cssRules.GetElementAt(i);
+  for (let i = 0; i < cssRules.length; i++) {
+    let rule = cssRules[i];
     let value = rule.style.getPropertyValue(property);
     if (value && value !== "auto") {
       prop = value;
     }
   }
 
   if (node.style) {
     let value = node.style.getPropertyValue(property);
--- a/devtools/server/actors/styles.js
+++ b/devtools/server/actors/styles.js
@@ -4,16 +4,17 @@
 
 "use strict";
 
 const {Ci} = require("chrome");
 const promise = require("promise");
 const protocol = require("devtools/shared/protocol");
 const {LongStringActor} = require("devtools/server/actors/string");
 const {Task} = require("devtools/shared/task");
+const InspectorUtils = require("InspectorUtils");
 
 // This will also add the "stylesheet" actor type for protocol.js to recognize
 
 const {pageStyleSpec, styleRuleSpec, ELEMENT_STYLE} = require("devtools/shared/specs/styles");
 
 loader.lazyRequireGetter(this, "CssLogic", "devtools/server/css-logic", true);
 loader.lazyRequireGetter(this, "SharedCssLogic", "devtools/shared/inspector/css-logic");
 loader.lazyRequireGetter(this, "getDefinedGeometryProperties",
@@ -563,27 +564,27 @@ var PageStyleActor = protocol.ActorClass
    * @param DOMNode node
    * @param string pseudo
    * @param DOMNode inherited
    * @param object options
    *
    * @returns Array
    */
   _getElementRules: function (node, pseudo, inherited, options) {
-    let domRules = DOMUtils.getCSSStyleRules(node, pseudo);
+    let domRules = InspectorUtils.getCSSStyleRules(node, pseudo);
     if (!domRules) {
       return [];
     }
 
     let rules = [];
 
     // getCSSStyleRules returns ordered from least-specific to
     // most-specific.
-    for (let i = domRules.Count() - 1; i >= 0; i--) {
-      let domRule = domRules.GetElementAt(i);
+    for (let i = domRules.length - 1; i >= 0; i--) {
+      let domRule = domRules[i];
 
       let isSystem = !SharedCssLogic.isContentStylesheet(domRule.parentStyleSheet);
 
       if (isSystem && options.filter != SharedCssLogic.FILTER.UA) {
         continue;
       }
 
       if (inherited) {
--- a/devtools/server/css-logic.js
+++ b/devtools/server/css-logic.js
@@ -547,19 +547,19 @@ CssLogic.prototype = {
       try {
         domRules = getCSSStyleRules(element);
       } catch (ex) {
         console.log("CL__buildMatchedRules error: " + ex);
         continue;
       }
 
       // getCSSStyleRules can return null with a shadow DOM element.
-      let numDomRules = domRules ? domRules.Count() : 0;
+      let numDomRules = domRules ? domRules.length : 0;
       for (let i = 0; i < numDomRules; i++) {
-        let domRule = domRules.GetElementAt(i);
+        let domRule = domRules[i];
         if (domRule.type !== CSSRule.STYLE_RULE) {
           continue;
         }
 
         let sheet = this.getSheet(domRule.parentStyleSheet, -1);
         if (sheet._passId !== this._passId) {
           sheet.index = sheetIndex++;
           sheet._passId = this._passId;
--- a/devtools/shared/inspector/css-logic.js
+++ b/devtools/shared/inspector/css-logic.js
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { getRootBindingParent } = require("devtools/shared/layout/utils");
 const { getTabPrefs } = require("devtools/shared/indentation");
-const { Ci, Cc } = require("chrome");
+const InspectorUtils = require("InspectorUtils");
 
 const MAX_DATA_URL_LENGTH = 40;
 
 /*
  * About the objects defined in this file:
  * - CssLogic contains style information about a view context. It provides
  *   access to 2 sets of objects: Css[Sheet|Rule|Selector] provide access to
  *   information that does not change when the selected element changes while
@@ -33,19 +33,19 @@ const MAX_DATA_URL_LENGTH = 40;
  * - CssPropertyInfo contains style information for a single property for the
  *   highlighted element.
  * - CssSelectorInfo is a wrapper around CssSelector, which adds sorting with
  *   reference to the selected element.
  */
 
 /**
  * Provide access to the style information in a page.
- * CssLogic uses the standard DOM API, and the Gecko inIDOMUtils API to access
- * styling information in the page, and present this to the user in a way that
- * helps them understand:
+ * CssLogic uses the standard DOM API, and the Gecko InspectorUtils API to
+ * access styling information in the page, and present this to the user in a way
+ * that helps them understand:
  * - why their expectations may not have been fulfilled
  * - how browsers process CSS
  * @constructor
  */
 
 const Services = require("Services");
 
 loader.lazyImporter(this, "findCssSelector", "resource://gre/modules/css-selector.js");
@@ -506,14 +506,12 @@ function getBindingElementAndPseudo(node
 exports.getBindingElementAndPseudo = getBindingElementAndPseudo;
 
 /**
  * Returns css style rules for a given a node.
  * This function can handle ::before or ::after pseudo element as well as
  * normal element.
  */
 function getCSSStyleRules(node) {
-  const DOMUtils =
-    Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
   let { bindingElement, pseudo } = getBindingElementAndPseudo(node);
-  return DOMUtils.getCSSStyleRules(bindingElement, pseudo);
+  return InspectorUtils.getCSSStyleRules(bindingElement, pseudo);
 }
 exports.getCSSStyleRules = getCSSStyleRules;
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -5,16 +5,19 @@
  */
 
 /**
  * A collection of utility methods for use by devtools.
  */
 [ChromeOnly]
 namespace InspectorUtils {
   sequence<StyleSheet> getAllStyleSheets(Document document);
+  sequence<CSSRule> getCSSStyleRules(
+    Element element,
+    [TreatNullAs=EmptyString] optional DOMString pseudo = "");
 };
 
 dictionary InspectorRGBTriple {
   /*
    * NOTE: Using octet for RGB components is not generally OK, because
    * they can be outside the 0-255 range, but for backwards-compatible
    * named colors (which is what we use this dictionary for) the 0-255
    * assumption is fine.
--- a/layout/base/tests/test_bug416896.html
+++ b/layout/base/tests/test_bug416896.html
@@ -17,41 +17,40 @@ https://bugzilla.mozilla.org/show_bug.cg
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 416896 **/
+
+ const InspectorUtils = SpecialPowers.InspectorUtils;
+
  var inlineSheet = $("i").sheet;
  isnot(inlineSheet, null, "Should have sheet here");
 
  var linkedSheet = $("l").sheet;
  isnot(linkedSheet, null, "Should have sheet here");
 
- var domUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
-                             .getService(SpecialPowers.Ci.inIDOMUtils);
- const nsIDOMCSSStyleRule = SpecialPowers.Ci["nsIDOMCSSStyleRule"];
- var inspectedRules = domUtils.getCSSStyleRules(document.links[0]);
+ var inspectedRules = InspectorUtils.getCSSStyleRules(document.links[0]);
 
  var seenInline = false;
  var seenLinked = false;
  
- for (var i = 0; i < inspectedRules.Count(); ++i)
+ for (var i = 0; i < inspectedRules.length; ++i)
  {
-   var rule =
-     SpecialPowers.unwrap(inspectedRules.GetElementAt(i).QueryInterface(nsIDOMCSSStyleRule));
+   var rule = SpecialPowers.unwrap(inspectedRules[i]);
    var sheet = rule.parentStyleSheet;
    if (sheet == inlineSheet) {
      is(sheet.href, null, "It's an inline sheet");
      is(seenInline, false, "Only one inline rule matches");
      seenInline = true;
    } else {
-     isnot(sheet.href, null, "Shouldn't have null href here");
+     isnot(sheet.href, null, "Shouldn't have null href here " + i);
      if (sheet == linkedSheet) {
        is(seenLinked, false, "Only one linked rule matches");
        seenLinked = true;
      }
    }
  }
 
  is(seenLinked, true, "Didn't find the linked rule?");
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -5,32 +5,48 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 #ifndef mozilla_dom_InspectorUtils_h
 #define mozilla_dom_InspectorUtils_h
 
 #include "mozilla/dom/BindingDeclarations.h"
 
+class nsAtom;
 class nsIDocument;
+class nsStyleContext;
 
 namespace mozilla {
 class StyleSheet;
+namespace css {
+class Rule;
+} // namespace css
+namespace dom {
+class Element;
+} // namespace dom
 } // namespace mozilla
 
 namespace mozilla {
 namespace dom {
 
 /**
  * A collection of utility methods for use by devtools.
  */
 class InspectorUtils
 {
 public:
   static void GetAllStyleSheets(GlobalObject& aGlobal,
                                 nsIDocument& aDocument,
                                 nsTArray<RefPtr<StyleSheet>>& aResult);
+  static void GetCSSStyleRules(GlobalObject& aGlobal,
+                               Element& aElement,
+                               const nsAString& aPseudo,
+                               nsTArray<RefPtr<css::Rule>>& aResult);
+
+private:
+  static already_AddRefed<nsStyleContext>
+    GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_InspectorUtils_h
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -201,84 +201,81 @@ inDOMUtils::GetChildrenForNode(nsIDOMNod
   if (!kids) {
     aNode->GetChildNodes(getter_AddRefs(kids));
   }
 
   kids.forget(aChildren);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement,
-                             const nsAString& aPseudo,
-                             nsIArrayExtensions **_retval)
+namespace mozilla {
+namespace dom {
+
+/* static */ void
+InspectorUtils::GetCSSStyleRules(GlobalObject& aGlobalObject,
+                                 Element& aElement,
+                                 const nsAString& aPseudo,
+                                 nsTArray<RefPtr<css::Rule>>& aResult)
 {
-  NS_ENSURE_ARG_POINTER(aElement);
-
-  *_retval = nullptr;
-
   RefPtr<nsAtom> pseudoElt;
   if (!aPseudo.IsEmpty()) {
     pseudoElt = NS_Atomize(aPseudo);
   }
 
-  nsCOMPtr<Element> element = do_QueryInterface(aElement);
-  NS_ENSURE_STATE(element);
   RefPtr<nsStyleContext> styleContext =
-    GetCleanStyleContextForElement(element, pseudoElt);
+    GetCleanStyleContextForElement(&aElement, pseudoElt);
   if (!styleContext) {
     // This can fail for elements that are not in the document or
     // if the document they're in doesn't have a presshell.  Bail out.
-    return NS_OK;
+    return;
   }
 
 
-  nsCOMPtr<nsIMutableArray> rules = nsArray::Create();
   if (auto gecko = styleContext->GetAsGecko()) {
     nsRuleNode* ruleNode = gecko->RuleNode();
     if (!ruleNode) {
-      return NS_OK;
+      return;
     }
 
     AutoTArray<nsRuleNode*, 16> ruleNodes;
     while (!ruleNode->IsRoot()) {
       ruleNodes.AppendElement(ruleNode);
       ruleNode = ruleNode->GetParent();
     }
 
     for (nsRuleNode* ruleNode : Reversed(ruleNodes)) {
       RefPtr<Declaration> decl = do_QueryObject(ruleNode->GetRule());
       if (decl) {
         css::Rule* owningRule = decl->GetOwningRule();
         if (owningRule) {
-          rules->AppendElement(owningRule);
+          aResult.AppendElement(owningRule);
         }
       }
     }
   } else {
-    nsIDocument* doc = element->GetOwnerDocument();
+    nsIDocument* doc = aElement.OwnerDoc();
     nsIPresShell* shell = doc->GetShell();
     if (!shell) {
-      return NS_OK;
+      return;
     }
 
     ServoStyleContext* servo = styleContext->AsServo();
     nsTArray<const RawServoStyleRule*> rawRuleList;
     Servo_ComputedValues_GetStyleRuleList(servo, &rawRuleList);
 
     AutoTArray<ServoStyleRuleMap*, 1> maps;
     {
       ServoStyleSet* styleSet = shell->StyleSet()->AsServo();
       ServoStyleRuleMap* map = styleSet->StyleRuleMap();
       map->EnsureTable();
       maps.AppendElement(map);
     }
 
     // Collect style rule maps for bindings.
-    for (nsIContent* bindingContent = element; bindingContent;
+    for (nsIContent* bindingContent = &aElement; bindingContent;
          bindingContent = bindingContent->GetBindingParent()) {
       for (nsXBLBinding* binding = bindingContent->GetXBLBinding();
            binding; binding = binding->GetBaseBinding()) {
         if (ServoStyleSet* styleSet = binding->GetServoStyleSet()) {
           ServoStyleRuleMap* map = styleSet->StyleRuleMap();
           map->EnsureTable();
           maps.AppendElement(map);
         }
@@ -295,27 +292,26 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
       ServoStyleRule* rule = nullptr;
       for (ServoStyleRuleMap* map : maps) {
         rule = map->Lookup(rawRule);
         if (rule) {
           break;
         }
       }
       if (rule) {
-        rules->AppendElement(static_cast<css::Rule*>(rule));
+        aResult.AppendElement(rule);
       } else {
         MOZ_ASSERT_UNREACHABLE("We should be able to map a raw rule to a rule");
       }
     }
   }
-
-  rules.forget(_retval);
+}
 
-  return NS_OK;
-}
+} // namespace dom
+} // namespace mozilla
 
 static already_AddRefed<BindingStyleRule>
 GetRuleFromDOMRule(nsIDOMCSSStyleRule *aRule, ErrorResult& rv)
 {
   nsCOMPtr<nsICSSStyleRuleDOMWrapper> rule = do_QueryInterface(aRule);
   if (!rule) {
     rv.Throw(NS_ERROR_INVALID_POINTER);
     return nullptr;
@@ -1124,19 +1120,22 @@ inDOMUtils::GetContentState(nsIDOMElemen
   NS_ENSURE_ARG_POINTER(content);
 
   // NOTE: if this method is removed,
   // please remove GetInternalValue from EventStates
   *aState = content->AsElement()->State().GetInternalValue();
   return NS_OK;
 }
 
+namespace mozilla {
+namespace dom {
+
 /* static */ already_AddRefed<nsStyleContext>
-inDOMUtils::GetCleanStyleContextForElement(dom::Element* aElement,
-                                           nsAtom* aPseudo)
+InspectorUtils::GetCleanStyleContextForElement(dom::Element* aElement,
+                                               nsAtom* aPseudo)
 {
   MOZ_ASSERT(aElement);
 
   nsIDocument* doc = aElement->GetComposedDoc();
   if (!doc) {
     return nullptr;
   }
 
@@ -1152,16 +1151,19 @@ inDOMUtils::GetCleanStyleContextForEleme
 
   presContext->EnsureSafeToHandOutCSSRules();
 
   RefPtr<nsStyleContext> styleContext =
     nsComputedDOMStyle::GetStyleContext(aElement, aPseudo, presShell);
   return styleContext.forget();
 }
 
+} // namespace dom
+} // namespace mozilla
+
 NS_IMETHODIMP
 inDOMUtils::GetUsedFontFaces(nsIDOMRange* aRange,
                              nsIDOMFontFaceList** aFontFaceList)
 {
   return static_cast<nsRange*>(aRange)->GetUsedFontFaces(aFontFaceList);
 }
 
 static EventStates
--- a/layout/inspector/inDOMUtils.h
+++ b/layout/inspector/inDOMUtils.h
@@ -24,19 +24,15 @@ class inDOMUtils final : public inIDOMUt
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_INIDOMUTILS
 
   inDOMUtils();
 
 private:
   virtual ~inDOMUtils();
-
-  static already_AddRefed<nsStyleContext>
-    GetCleanStyleContextForElement(mozilla::dom::Element* aElement,
-                                   nsAtom* aPseudo);
 };
 
 // {0a499822-a287-4089-ad3f-9ffcd4f40263}
 #define IN_DOMUTILS_CID \
   {0x0a499822, 0xa287, 0x4089, {0xad, 0x3f, 0x9f, 0xfc, 0xd4, 0xf4, 0x02, 0x63}}
 
 #endif // __inDOMUtils_h__
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,18 +15,16 @@ interface nsIDOMNode;
 interface nsIDOMNodeList;
 interface nsIDOMFontFaceList;
 interface nsIDOMRange;
 interface nsIDOMCSSStyleSheet;
 
 [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
-  nsIArrayExtensions getCSSStyleRules(in nsIDOMElement aElement, [optional] in DOMString aPseudo);
-
   /**
    * Get the line number of a rule.
    *
    * @param nsIDOMCSSRule aRule The rule.
    * @return The rule's line number.  Line numbers are 1-based.
    */
   unsigned long getRuleLine(in nsIDOMCSSRule aRule);
 
--- a/layout/inspector/tests/test_bug462787.html
+++ b/layout/inspector/tests/test_bug462787.html
@@ -14,28 +14,29 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 462787 **/
 
+const InspectorUtils = SpecialPowers.InspectorUtils;
+
 function do_test() {
   const INVALID_POINTER = SpecialPowers.Cr.NS_ERROR_INVALID_POINTER;
 
   var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
                              .getService(SpecialPowers.Ci.inIDOMUtils);
   try {
-    utils.getCSSStyleRules(null); 
+    InspectorUtils.getCSSStyleRules(null);
     ok(false, "expected an exception"); 
   }
   catch(e) {
-    e = SpecialPowers.wrap(e);
-    is(e.result, INVALID_POINTER, "got the expected exception");
+    is(e.name, "TypeError", "got the expected exception");
   }
 
   try {
     utils.getRuleLine(null); 
     ok(false, "expected an exception"); 
   }
   catch(e) {
     e = SpecialPowers.wrap(e);
--- a/layout/inspector/tests/test_bug462789.html
+++ b/layout/inspector/tests/test_bug462789.html
@@ -14,34 +14,36 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 462789 **/
 
+const InspectorUtils = SpecialPowers.InspectorUtils;
+
 function do_test() {
   const ERROR_INVALID_ARG = 0x80070057;
   const DOCUMENT_NODE_TYPE = 9;
 
   var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
                              .getService(SpecialPowers.Ci.inIDOMUtils);
 
   var iframe = document.getElementById("bug462789_iframe");
   var docElement = iframe.contentDocument.documentElement;
   var body = docElement.children[1];
   var rule = iframe.contentDocument.styleSheets[0].cssRules[0];
   var text = body.firstChild;
 
   try {
-    var res = utils.getCSSStyleRules(docElement);
-    is(res, null, "getCSSStyleRules");
-    res = utils.getCSSStyleRules(body);
-    is(res, null, "getCSSStyleRules");
+    var res = InspectorUtils.getCSSStyleRules(docElement);
+    is(res.length, 0, "getCSSStyleRules");
+    res = InspectorUtils.getCSSStyleRules(body);
+    is(res.length, 0, "getCSSStyleRules");
   }
   catch(e) { ok(false, "got an unexpected exception:" + e); }
 
   try {
     var res = utils.getRuleLine(rule);
     is(res, 1, "getRuleLine");
   }
   catch(e) { ok(false, "got an unexpected exception:" + e); }
--- a/layout/inspector/tests/test_bug536379-2.html
+++ b/layout/inspector/tests/test_bug536379-2.html
@@ -15,21 +15,19 @@ https://bugzilla.mozilla.org/show_bug.cg
 <p id="display"></p>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 536379 **/
 
 const CI = SpecialPowers.Ci;
 const CC = SpecialPowers.Cc;
+const InspectorUtils = SpecialPowers.InspectorUtils;
 
-var domUtils =
-  CC["@mozilla.org/inspector/dom-utils;1"].getService(CI.inIDOMUtils);
-var rules = domUtils.getCSSStyleRules(document.getElementById("display"));
-var firstPRule =
-  rules.GetElementAt(rules.Count() - 2).QueryInterface(CI.nsIDOMCSSStyleRule);
+var rules = InspectorUtils.getCSSStyleRules(document.getElementById("display"));
+var firstPRule = rules[rules.length - 2];
 firstPRule.style.removeProperty("color");
 ok(true, "should not crash");
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/inspector/tests/test_bug536379.html
+++ b/layout/inspector/tests/test_bug536379.html
@@ -15,30 +15,27 @@ https://bugzilla.mozilla.org/show_bug.cg
 <p id="display"></p>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 536379 **/
 
 const CI = SpecialPowers.Ci;
 const CC = SpecialPowers.Cc;
+const InspectorUtils = SpecialPowers.InspectorUtils;
 
-var domUtils =
-  CC["@mozilla.org/inspector/dom-utils;1"].getService(CI.inIDOMUtils);
-var rules = domUtils.getCSSStyleRules(document.getElementById("display"));
-var firstPRule =
-  rules.GetElementAt(rules.Count() - 2).QueryInterface(CI.nsIDOMCSSStyleRule);
+var rules = InspectorUtils.getCSSStyleRules(document.getElementById("display"));
+var firstPRule = rules[rules.length - 2];
 firstPRule.style.removeProperty("color");
 ok(true, "should not crash");
 
 var links = document.getElementsByTagName("link");
 is(links.length, 3, "links.length");
 is(SpecialPowers.unwrap(firstPRule.parentStyleSheet), links[1].sheet, "sheet match for first P rule");
-var secondPRule =
-  rules.GetElementAt(rules.Count() - 1).QueryInterface(CI.nsIDOMCSSStyleRule);
+var secondPRule = rules[rules.length - 1];
 is(SpecialPowers.unwrap(secondPRule.parentStyleSheet), links[2].sheet, "sheet match for second P rule");
 is(links[1].href, links[2].href, "links should have same href");
 isnot(links[1].sheet, links[2].sheet, "links should have different sheets");
 isnot(firstPRule, secondPRule, "rules should be different");
 isnot(firstPRule.cssText, secondPRule.cssText, "text should be different since property was removed from one");
 
 </script>
 </pre>
--- a/layout/inspector/tests/test_bug557726.html
+++ b/layout/inspector/tests/test_bug557726.html
@@ -36,60 +36,55 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="div1">
   text with ::before, ::after, and ::first-letter pseudo-elements
 </div>
 
 <script type="application/javascript">
 
 /** Test for Bug 557726 **/
 
+const InspectorUtils = SpecialPowers.InspectorUtils;
+
 function getSelectors (rules) {
   var styleElement = document.getElementById("pseudo-style");
   var selectors = [];
-  for (var i = 0; i < rules.Count(); i++) {
-    var rule = rules.GetElementAt(i).QueryInterface(SpecialPowers.Ci.nsIDOMCSSStyleRule);
+  for (var i = 0; i < rules.length; i++) {
+    var rule = rules[i];
     if (SpecialPowers.unwrap(rule.parentStyleSheet.ownerNode) == styleElement) // no user agent rules
       selectors.push(rule.selectorText);
   }
   return selectors;
 }
 
-var domUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
-               .getService(SpecialPowers.Ci.inIDOMUtils);
-
 var div = document.getElementById("div1");
 
 /* empty or missing pseudo-element argument */
-var selectors = getSelectors(domUtils.getCSSStyleRules(div));
+var selectors = getSelectors(InspectorUtils.getCSSStyleRules(div));
 is(selectors.length, 1, "psuedo-element argument should be optional");
 is(selectors[0], "#div1", "should only have the non-pseudo element rule");
 
-selectors = getSelectors(domUtils.getCSSStyleRules(div, null));
-is(selectors.length, 1, "pseudo-element argument can be null");
-is(selectors[0], "#div1", "should only have the non pseudo-element rule");
-
-selectors = getSelectors(domUtils.getCSSStyleRules(div, ""));
+selectors = getSelectors(InspectorUtils.getCSSStyleRules(div, ""));
 is(selectors.length, 1, "pseudo-element argument can be empty string");
 is(selectors[0], "#div1", "should only have the non pseudo-element rule");
 
 
 /* invalid pseudo-element argument */
-var rules = domUtils.getCSSStyleRules(div, "not a valid pseudo element");
-is(rules, null, "invalid pseudo-element returns no rules list");
+var rules = InspectorUtils.getCSSStyleRules(div, "not a valid pseudo element");
+is(rules.length, 0, "invalid pseudo-element returns no rules");
 
 
 /* valid pseudo-element argument */
-selectors = getSelectors(domUtils.getCSSStyleRules(div, ":first-letter"));
+selectors = getSelectors(InspectorUtils.getCSSStyleRules(div, ":first-letter"));
 is(selectors.length, 1, "pseudo-element argument can be used");
 is(selectors[0], "#div1::first-letter", "should only have the ::first-letter rule");
 
-selectors = getSelectors(domUtils.getCSSStyleRules(div, ":before"));
+selectors = getSelectors(InspectorUtils.getCSSStyleRules(div, ":before"));
 is(selectors.length, 2, "::before pseudo-element has two matching rules");
 isnot(selectors.indexOf("#div1::after, #div1::before"), -1, "fetched rule for ::before")
 isnot(selectors.indexOf("#div1::before"), -1, "fetched rule for ::before")
 
-selectors = getSelectors(domUtils.getCSSStyleRules(div, ":first-line"));
+selectors = getSelectors(InspectorUtils.getCSSStyleRules(div, ":first-line"));
 is(selectors.length, 0, "valid pseudo-element but no matching rules");
 
 </script>
 </pre>
 </body>
 </html>
--- a/layout/inspector/tests/test_getCSSStyleRules.html
+++ b/layout/inspector/tests/test_getCSSStyleRules.html
@@ -10,28 +10,26 @@
 <pre id="log">
 <script>
 /**
  * This test checks that getCSSStyleRules returns correct style set in
  * various cases. To avoid effects from UA sheets, most of the tests use
  * an element with "unknowntagname".
  */
 
+const InspectorUtils = SpecialPowers.InspectorUtils;
+
 let iframe = document.getElementById("test");
-let domUtils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
-                            .getService(SpecialPowers.Ci.inIDOMUtils);
-const nsIDOMCSSStyleRule = SpecialPowers.Ci["nsIDOMCSSStyleRule"];
 
 SimpleTest.waitForExplicitFinish();
 
 function* getStyleRules(elem) {
-  let rules = domUtils.getCSSStyleRules(elem);
+  let rules = InspectorUtils.getCSSStyleRules(elem);
   for (let i = 0; i < rules.length; i++) {
-    yield SpecialPowers.unwrap(rules.GetElementAt(i)
-                               .QueryInterface(nsIDOMCSSStyleRule));
+    yield SpecialPowers.unwrap(rules[i]);
   }
 }
 
 // This will check that value of z-index property declarations in the
 // rules from getCSSStyleRules matches the given content.
 function checkRules(doc, rulesContent, queryStr = "unknowntagname") {
   let elem = doc.querySelector(queryStr);
   let rules = [...getStyleRules(elem)];
--- a/layout/inspector/tests/test_selectormatcheselement.html
+++ b/layout/inspector/tests/test_selectormatcheselement.html
@@ -33,24 +33,26 @@ https://bugzilla.mozilla.org/show_bug.cg
     }
   </style>
 </head>
 <body>
 <div id="foo">foo content</div>
 <pre id="test">
 <script type="application/javascript">
 
+const InspectorUtils = SpecialPowers.InspectorUtils;
+
 function do_test() {
   var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
     .getService(SpecialPowers.Ci.inIDOMUtils);
 
   var element = document.querySelector("#foo");
 
-  var elementRules = utils.getCSSStyleRules(element);
-  var elementRule = elementRules.GetElementAt(elementRules.Count() - 1);
+  var elementRules = InspectorUtils.getCSSStyleRules(element);
+  var elementRule = elementRules[elementRules.length - 1];
 
   is (utils.selectorMatchesElement(element, elementRule, 0), true,
     "Matches #foo");
   is (utils.selectorMatchesElement(element, elementRule, 1), false,
     "Doesn't match #bar");
   is (utils.selectorMatchesElement(element, elementRule, 0, ":bogus"), false,
     "Doesn't match #foo with a bogus pseudo");
   is (utils.selectorMatchesElement(element, elementRule, 2, ":bogus"), false,
@@ -61,18 +63,18 @@ function do_test() {
   checkPseudo(":before");
   checkPseudo(":after");
   checkPseudo(":first-letter");
   checkPseudo(":first-line");
 
   SimpleTest.finish();
 
   function checkPseudo(pseudo) {
-    var rules = utils.getCSSStyleRules(element, pseudo);
-    var rule = rules.GetElementAt(rules.Count() - 1);
+    var rules = InspectorUtils.getCSSStyleRules(element, pseudo);
+    var rule = rules[rules.length - 1];
 
     is (utils.selectorMatchesElement(element, rule, 0), false,
       "Doesn't match without " + pseudo);
     is (utils.selectorMatchesElement(element, rule, 1), false,
       "Doesn't match without " + pseudo);
 
     is (utils.selectorMatchesElement(element, rule, 0, pseudo), true,
       "Matches on #foo" + pseudo);