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(
const DocumentOrShadowRoot& aSource) {
if (aSource.mAdoptedStyleSheets.IsEmpty()) {
if (!aSource.AdoptedSheetCount()) {
return;
}

View file

@ -76,9 +76,7 @@ class DocumentOrShadowRoot : public RadioGroupManager {
size_t SheetCount() const { return mStyleSheets.Length(); }
const nsTArray<RefPtr<StyleSheet>>& AdoptedStyleSheets() const {
return mAdoptedStyleSheets;
}
size_t AdoptedSheetCount() const { return mAdoptedStyleSheets.Length(); }
/**
* 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) {
// 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();
@ -102,8 +101,8 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
AutoTArray<StyleSheet*, 32> nonDocumentSheets;
styleSet->AppendAllNonDocumentAuthorSheets(nonDocumentSheets);
// The non-document stylesheet array can have duplicates due to adopted
// stylesheets.
// The non-document stylesheet array can't have duplicates right now, but it
// could once we include adopted stylesheets.
nsTHashSet<StyleSheet*> sheetSet;
for (StyleSheet* sheet : nonDocumentSheets) {
if (sheetSet.EnsureInserted(sheet)) {
@ -117,11 +116,9 @@ void InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
aResult.AppendElement(aDocument.SheetAt(i));
}
for (auto& sheet : aDocument.AdoptedStyleSheets()) {
if (sheetSet.EnsureInserted(sheet)) {
aResult.AppendElement(sheet);
}
}
// 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.
}
bool InspectorUtils::IsIgnorableWhitespace(CharacterData& aDataNode) {

View file

@ -37,9 +37,6 @@ 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) {

View file

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

View file

@ -1,40 +1,44 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=734861
-->
<meta charset="utf-8">
<title>Test for Bug 734861</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=734861">Mozilla Bug 734861</a>
<div id="host"></div>
<script>
/** Test for Bug 734861 **/
const InspectorUtils = SpecialPowers.InspectorUtils;
<head>
<meta charset="utf-8">
<title>Test for Bug 734861</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
add_task(async function() {
await SpecialPowers.pushPrefEnv({ set: [["layout.css.constructable-stylesheets.enabled", true]] });
let sheet = new CSSStyleSheet();
await sheet.replace(`* { color: blue }`);
/** Test for Bug 734861 **/
let host = document.querySelector("#host");
host.adoptedStyleSheets = [sheet, sheet];
document.adoptedStyleSheets.push(sheet);
const InspectorUtils = SpecialPowers.InspectorUtils;
let res = InspectorUtils.getAllStyleSheets(document);
SimpleTest.waitForExplicitFinish();
let foundUA = false;
let adoptedCount = 0;
for (let s of InspectorUtils.getAllStyleSheets(document)) {
if (SpecialPowers.unwrap(s) == sheet) {
adoptedCount++;
}
if (s.href === "resource://gre-resources/ua.css") {
foundUA = true;
function runTest() {
var res = InspectorUtils.getAllStyleSheets(document);
var foundUA = false;
for (var i = 0; i < res.length; i++) {
if (res[i].href === "resource://gre-resources/ua.css") {
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.");
is(adoptedCount, 1, "Adopted stylesheet should show up once");
});
</script>
</script>
</head>
<body onload="runTest();">
<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())) {
aArray.AppendElement(aShadowRoot.SheetAt(index));
}
aArray.AppendElements(aShadowRoot.AdoptedStyleSheets());
});
}
@ -1072,22 +1071,11 @@ bool ServoStyleSet::EnsureUniqueInnerOnCSSSheets() {
queue.AppendElement(
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()) {
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
// incomplete sheets, we'll cause problems when the sheet is actually
// loaded. We don't care about incomplete sheets here anyway, because this