Commit 42c56288 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1617948 - Make some inspector methods deal with adopted stylesheets....

Bug 1617948 - Make some inspector methods deal with adopted stylesheets. r=nchevobbe,firefox-style-system-reviewers,boris

And simplify the tests while at it.

Differential Revision: https://phabricator.services.mozilla.com/D144566
parent 0c2cae7d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ void DocumentOrShadowRoot::ClearAdoptedStyleSheets() {

void DocumentOrShadowRoot::CloneAdoptedSheetsFrom(
    const DocumentOrShadowRoot& aSource) {
  if (!aSource.AdoptedSheetCount()) {
  if (aSource.mAdoptedStyleSheets.IsEmpty()) {
    return;
  }

+3 −1
Original line number Diff line number Diff line
@@ -76,7 +76,9 @@ class DocumentOrShadowRoot : public RadioGroupManager {

  size_t SheetCount() const { return mStyleSheets.Length(); }

  size_t AdoptedSheetCount() const { return mAdoptedStyleSheets.Length(); }
  const nsTArray<RefPtr<StyleSheet>>& AdoptedStyleSheets() const {
    return mAdoptedStyleSheets;
  }

  /**
   * Returns an index for the sheet in relative style order.
+8 −5
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
                                       nsTArray<RefPtr<StyleSheet>>& aResult) {
  // Get the agent, then user and finally xbl sheets in the style set.
  PresShell* presShell = aDocument.GetPresShell();
  nsTHashSet<StyleSheet*> sheetSet;

  if (presShell) {
    ServoStyleSet* styleSet = presShell->StyleSet();
@@ -101,8 +102,8 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
    AutoTArray<StyleSheet*, 32> nonDocumentSheets;
    styleSet->AppendAllNonDocumentAuthorSheets(nonDocumentSheets);

    // The non-document stylesheet array can't have duplicates right now, but it
    // could once we include adopted stylesheets.
    // The non-document stylesheet array can have duplicates due to adopted
    // stylesheets.
    nsTHashSet<StyleSheet*> sheetSet;
    for (StyleSheet* sheet : nonDocumentSheets) {
      if (sheetSet.EnsureInserted(sheet)) {
@@ -116,9 +117,11 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
    aResult.AppendElement(aDocument.SheetAt(i));
  }

  // FIXME(emilio, bug 1617948): This doesn't deal with adopted stylesheets, and
  // it should. It should also handle duplicates correctly when it does, see
  // above.
  for (auto& sheet : aDocument.AdoptedStyleSheets()) {
    if (sheetSet.EnsureInserted(sheet)) {
      aResult.AppendElement(sheet);
    }
  }
}

bool InspectorUtils::IsIgnorableWhitespace(CharacterData& aDataNode) {
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ void ServoStyleRuleMap::EnsureTable(ShadowRoot& aShadowRoot) {
  for (auto index : IntegerRange(aShadowRoot.SheetCount())) {
    FillTableFromStyleSheet(*aShadowRoot.SheetAt(index));
  }
  for (auto& sheet : aShadowRoot.AdoptedStyleSheets()) {
    FillTableFromStyleSheet(*sheet);
  }
}

void ServoStyleRuleMap::SheetAdded(StyleSheet& aStyleSheet) {
+14 −7
Original line number Diff line number Diff line
@@ -171,9 +171,20 @@ const tests = [
         "declaration from UA stylesheet html.css");
    },
  },
  {
    title: "Check adopted sheets",
    async run(doc, win) {
      checkRules(doc, [1]);
      let sheet = new win.CSSStyleSheet();
      sheet.replaceSync(`unknowntagname { z-index: 5 }`);
      doc.adoptedStyleSheets.push(sheet);
      checkRules(doc, [1, 5]);
    },
  },
];

async function runTests() {
add_task(async function runTests() {
  await SpecialPowers.pushPrefEnv({ set: [["layout.css.constructable-stylesheets.enabled", true]] });
  for (let i = 0; i < tests.length; i++) {
    let test = tests[i];
    info(`Test ${i}: ${test.title}`);
@@ -184,16 +195,12 @@ async function runTests() {
    iframe.src = `file_getCSSStyleRules-${test.base}.html`;
    await new Promise(resolve => { iframe.onload = resolve; });
    try {
      await test.run(iframe.contentDocument);
      await test.run(iframe.contentDocument, iframe.contentWindow);
    } catch (e) {
      ok(false, "JavaScript error: " + e);
    }
  }
  SimpleTest.finish();
}

runTests();

});
</script>
</pre>
</body>
Loading