Backed out changeset 3855f8235011 (bug 1617948) for causing mochitest plain failures in test_get_all_style_sheets. CLOSED TREE

This commit is contained in:
Molnar Sandor 2022-04-27 01:03:10 +03:00
parent 3bb8f57dd5
commit deabbe0548
7 changed files with 47 additions and 70 deletions

View file

@ -203,7 +203,7 @@ void DocumentOrShadowRoot::ClearAdoptedStyleSheets() {
void DocumentOrShadowRoot::CloneAdoptedSheetsFrom( void DocumentOrShadowRoot::CloneAdoptedSheetsFrom(
const DocumentOrShadowRoot& aSource) { const DocumentOrShadowRoot& aSource) {
if (aSource.mAdoptedStyleSheets.IsEmpty()) { if (!aSource.AdoptedSheetCount()) {
return; return;
} }

View file

@ -76,9 +76,7 @@ class DocumentOrShadowRoot : public RadioGroupManager {
size_t SheetCount() const { return mStyleSheets.Length(); } size_t SheetCount() const { return mStyleSheets.Length(); }
const nsTArray<RefPtr<StyleSheet>>& AdoptedStyleSheets() const { size_t AdoptedSheetCount() const { return mAdoptedStyleSheets.Length(); }
return mAdoptedStyleSheets;
}
/** /**
* Returns an index for the sheet in relative style order. * Returns an index for the sheet in relative style order.

View file

@ -83,7 +83,6 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
nsTArray<RefPtr<StyleSheet>>& aResult) { nsTArray<RefPtr<StyleSheet>>& aResult) {
// Get the agent, then user and finally xbl sheets in the style set. // Get the agent, then user and finally xbl sheets in the style set.
PresShell* presShell = aDocument.GetPresShell(); PresShell* presShell = aDocument.GetPresShell();
nsTHashSet<StyleSheet*> sheetSet;
if (presShell) { if (presShell) {
ServoStyleSet* styleSet = presShell->StyleSet(); ServoStyleSet* styleSet = presShell->StyleSet();
@ -102,8 +101,8 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
AutoTArray<StyleSheet*, 32> nonDocumentSheets; AutoTArray<StyleSheet*, 32> nonDocumentSheets;
styleSet->AppendAllNonDocumentAuthorSheets(nonDocumentSheets); styleSet->AppendAllNonDocumentAuthorSheets(nonDocumentSheets);
// The non-document stylesheet array can have duplicates due to adopted // The non-document stylesheet array can't have duplicates right now, but it
// stylesheets. // could once we include adopted stylesheets.
nsTHashSet<StyleSheet*> sheetSet; nsTHashSet<StyleSheet*> sheetSet;
for (StyleSheet* sheet : nonDocumentSheets) { for (StyleSheet* sheet : nonDocumentSheets) {
if (sheetSet.EnsureInserted(sheet)) { if (sheetSet.EnsureInserted(sheet)) {
@ -117,11 +116,9 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
aResult.AppendElement(aDocument.SheetAt(i)); aResult.AppendElement(aDocument.SheetAt(i));
} }
for (auto& sheet : aDocument.AdoptedStyleSheets()) { // FIXME(emilio, bug 1617948): This doesn't deal with adopted stylesheets, and
if (sheetSet.EnsureInserted(sheet)) { // it should. It should also handle duplicates correctly when it does, see
aResult.AppendElement(sheet); // above.
}
}
} }
bool InspectorUtils::IsIgnorableWhitespace(CharacterData& aDataNode) { bool InspectorUtils::IsIgnorableWhitespace(CharacterData& aDataNode) {

View file

@ -37,9 +37,6 @@ void ServoStyleRuleMap::EnsureTable(ShadowRoot& aShadowRoot) {
for (auto index : IntegerRange(aShadowRoot.SheetCount())) { for (auto index : IntegerRange(aShadowRoot.SheetCount())) {
FillTableFromStyleSheet(*aShadowRoot.SheetAt(index)); FillTableFromStyleSheet(*aShadowRoot.SheetAt(index));
} }
for (auto& sheet : aShadowRoot.AdoptedStyleSheets()) {
FillTableFromStyleSheet(*sheet);
}
} }
void ServoStyleRuleMap::SheetAdded(StyleSheet& aStyleSheet) { void ServoStyleRuleMap::SheetAdded(StyleSheet& aStyleSheet) {

View file

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

View file

@ -1,40 +1,44 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html>
<!-- <!--
https://bugzilla.mozilla.org/show_bug.cgi?id=734861 https://bugzilla.mozilla.org/show_bug.cgi?id=734861
--> -->
<meta charset="utf-8"> <head>
<title>Test for Bug 734861</title> <meta charset="utf-8">
<script src="/tests/SimpleTest/SimpleTest.js"></script> <title>Test for Bug 734861</title>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/> <script src="/tests/SimpleTest/SimpleTest.js"></script>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=734861">Mozilla Bug 734861</a> <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<div id="host"></div> <script type="application/javascript">
<script>
/** Test for Bug 734861 **/
const InspectorUtils = SpecialPowers.InspectorUtils;
add_task(async function() { /** Test for Bug 734861 **/
await SpecialPowers.pushPrefEnv({ set: [["layout.css.constructable-stylesheets.enabled", true]] });
let sheet = new CSSStyleSheet();
await sheet.replace(`* { color: blue }`);
let host = document.querySelector("#host"); const InspectorUtils = SpecialPowers.InspectorUtils;
host.adoptedStyleSheets = [sheet, sheet];
document.adoptedStyleSheets.push(sheet);
let res = InspectorUtils.getAllStyleSheets(document); SimpleTest.waitForExplicitFinish();
let foundUA = false; function runTest() {
let adoptedCount = 0; var res = InspectorUtils.getAllStyleSheets(document);
for (let s of InspectorUtils.getAllStyleSheets(document)) {
if (SpecialPowers.unwrap(s) == sheet) { var foundUA = false;
adoptedCount++; for (var i = 0; i < res.length; i++) {
} if (res[i].href === "resource://gre-resources/ua.css") {
if (s.href === "resource://gre-resources/ua.css") { foundUA = true;
foundUA = true; break;
}
} }
ok(foundUA, "UA sheet should be returned with all the other sheets.");
SimpleTest.finish();
} }
ok(foundUA, "UA sheet should be returned with all the other sheets."); </script>
is(adoptedCount, 1, "Adopted stylesheet should show up once"); </head>
}); <body onload="runTest();">
</script> <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=734861">Mozilla Bug 734861</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View file

@ -662,7 +662,6 @@ void ServoStyleSet::AppendAllNonDocumentAuthorSheets(
for (auto index : IntegerRange(aShadowRoot.SheetCount())) { for (auto index : IntegerRange(aShadowRoot.SheetCount())) {
aArray.AppendElement(aShadowRoot.SheetAt(index)); aArray.AppendElement(aShadowRoot.SheetAt(index));
} }
aArray.AppendElements(aShadowRoot.AdoptedStyleSheets());
}); });
} }
@ -1072,22 +1071,11 @@ bool ServoStyleSet::EnsureUniqueInnerOnCSSSheets() {
queue.AppendElement( queue.AppendElement(
std::make_pair(aShadowRoot.SheetAt(index), SheetOwner{&aShadowRoot})); std::make_pair(aShadowRoot.SheetAt(index), SheetOwner{&aShadowRoot}));
} }
for (auto& adopted : aShadowRoot.AdoptedStyleSheets()) {
queue.AppendElement(
std::make_pair(adopted.get(), SheetOwner{&aShadowRoot}));
}
}); });
while (!queue.IsEmpty()) { while (!queue.IsEmpty()) {
auto [sheet, owner] = queue.PopLastElement(); auto [sheet, owner] = queue.PopLastElement();
if (sheet->HasForcedUniqueInner()) {
// We already processed this sheet and its children.
// Normally we don't hit this but adopted stylesheets can have dupes so we
// can save some work here.
continue;
}
// Only call EnsureUniqueInner for complete sheets. If we do call it on // Only call EnsureUniqueInner for complete sheets. If we do call it on
// incomplete sheets, we'll cause problems when the sheet is actually // incomplete sheets, we'll cause problems when the sheet is actually
// loaded. We don't care about incomplete sheets here anyway, because this // loaded. We don't care about incomplete sheets here anyway, because this