Bug 1797957 - Fix HTMLSummaryElement::GetDetails() for XML pretty print. r=smaug

That's the only place where we have a non-anonymous summary in an UA
widget, which the code didn't handle correctly (it assumed that if we
were in an UA widget we were in a details shadow tree).

I could try to write a test for this if you think it's worth it but we
don't have many existing tests (non-reftest) for the XML prettyprinter
that I can see...

Differential Revision: https://phabricator.services.mozilla.com/D160662
This commit is contained in:
Emilio Cobos Álvarez 2022-10-31 10:37:33 +00:00
Родитель d2a137781a
Коммит f4455175cf
3 изменённых файлов: 28 добавлений и 3 удалений

Просмотреть файл

@ -102,3 +102,4 @@ support-files =
file_browser_refresh_image.sjs
file_browser_refresh_iframe.sjs
[browser_page_load_event_telemetry.js]
[browser_xml_toggle.js]

Просмотреть файл

@ -0,0 +1,21 @@
const URL = `data:text/xml,
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
`;
add_task(async function xml_pretty_print_toggle() {
await BrowserTestUtils.withNewTab(URL, async function(browser) {
await SpecialPowers.spawn(browser, [], () => {
let summary = content.document.documentElement.openOrClosedShadowRoot.querySelector("summary");
let details = summary.parentNode;
ok(details.open, "Should be open");
summary.click();
ok(!details.open, "Should be closed");
});
});
});

Просмотреть файл

@ -101,10 +101,13 @@ bool HTMLSummaryElement::IsMainSummary() const {
}
HTMLDetailsElement* HTMLSummaryElement::GetDetails() const {
if (HasBeenInUAWidget()) {
return HTMLDetailsElement::FromNodeOrNull(GetContainingShadowHost());
if (auto* details = HTMLDetailsElement::FromNodeOrNull(GetParent())) {
return details;
}
return HTMLDetailsElement::FromNodeOrNull(GetParent());
if (!HasBeenInUAWidget()) {
return nullptr;
}
return HTMLDetailsElement::FromNodeOrNull(GetContainingShadowHost());
}
JSObject* HTMLSummaryElement::WrapNode(JSContext* aCx,