The issue here is that when we incrementally add the anon content container, we end up computing its insertion frame as the SVG frame. That is kind of messed up (because they'd usually be under nsCanvasFrame), but is sort of ok because they go in the top layer anyhow. We really want to avoid reframing when showing DevTools in order to avoid papering over bugs. Allow the SVG code to deal with it the way it also deals with ::backdrop (which has the same issue), and fix the frame construction code to don't even probe for <svg>::before / ::after. It took forever to come up with a reproducer because we turn on the AccessibleCaret pref on tests, which paper over this... :/ Differential Revision: https://phabricator.services.mozilla.com/D310633
87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
"use strict";
|
|
|
|
// Tests that anonymous content inserted via insertAnonymousContent gets a
|
|
// frame (and thus a non-empty layout rect) when the document is an SVG
|
|
// document. The DevTools highlighters rely on this. See bug 1850539.
|
|
|
|
const SVG_DATA_URI =
|
|
"data:image/svg+xml," +
|
|
encodeURIComponent(
|
|
`<svg xmlns='http://www.w3.org/2000/svg' width='150' height='150'>` +
|
|
`<rect x='10' y='10' width='100' height='100' fill='purple'/>` +
|
|
`</svg>`
|
|
);
|
|
|
|
async function doTest() {
|
|
function waitForFrame() {
|
|
return new Promise(r => {
|
|
content.requestAnimationFrame(() => {
|
|
content.requestAnimationFrame(r);
|
|
});
|
|
});
|
|
}
|
|
|
|
await waitForFrame();
|
|
|
|
{
|
|
let children = InspectorUtils.getChildrenForNode(
|
|
content.document,
|
|
true,
|
|
true
|
|
);
|
|
is(children.length, 1, "Shouldn't have existing anon content (document)");
|
|
}
|
|
|
|
{
|
|
let children = InspectorUtils.getChildrenForNode(
|
|
content.document.documentElement,
|
|
true,
|
|
true
|
|
).filter(n => !["scrollbar", "scrollcorner"].includes(n.tagName));
|
|
is(
|
|
children.length,
|
|
1,
|
|
"Shouldn't have existing anon content (documentElement)"
|
|
);
|
|
}
|
|
|
|
let ac = content.document.insertAnonymousContent();
|
|
ac.root.innerHTML = `<div style="position: absolute; width: 50px; height: 30px;">anonymous content</div>`;
|
|
|
|
let div = ac.root.querySelector("div");
|
|
let rect = div.getBoundingClientRect();
|
|
Assert.greater(
|
|
rect.width,
|
|
0,
|
|
"Anonymous content in an SVG document should have a non-zero width"
|
|
);
|
|
Assert.greater(
|
|
rect.height,
|
|
0,
|
|
"Anonymous content in an SVG document should have a non-zero height"
|
|
);
|
|
|
|
content.document.removeAnonymousContent(ac);
|
|
}
|
|
|
|
add_task(async function () {
|
|
// AccessibleCaret inserts anonymous content into the document too early to
|
|
// reproduce this.
|
|
await SpecialPowers.pushPrefEnv({
|
|
set: [
|
|
["layout.accessiblecaret.enabled", false],
|
|
["layout.accessiblecaret.enabled_on_touch", false],
|
|
],
|
|
});
|
|
|
|
await BrowserTestUtils.withNewTab(
|
|
{ gBrowser, url: SVG_DATA_URI },
|
|
async function (browser) {
|
|
await SpecialPowers.spawn(browser, [], doTest);
|
|
}
|
|
);
|
|
});
|