Bug 1487649 - Don't do a name check when cloning a shadow root for print preview. r=smaug

Otherwise the ShadowRoot for <use> or other internal ones may not get cloned
properly.

Differential Revision: https://phabricator.services.mozilla.com/D4756

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2018-09-03 14:10:58 +00:00
Родитель 766fce11a1
Коммит 541e942cb1
2 изменённых файлов: 39 добавлений и 6 удалений

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

@ -610,13 +610,8 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
if (clone->OwnerDoc()->IsStaticDocument()) {
ShadowRoot* originalShadowRoot = aNode->AsElement()->GetShadowRoot();
if (originalShadowRoot) {
ShadowRootInit init;
init.mMode = originalShadowRoot->Mode();
RefPtr<ShadowRoot> newShadowRoot =
clone->AsElement()->AttachShadow(init, aError);
if (NS_WARN_IF(aError.Failed())) {
return nullptr;
}
clone->AsElement()->AttachShadowWithoutNameChecks(originalShadowRoot->Mode());
newShadowRoot->CloneInternalDataFrom(originalShadowRoot);
for (nsIContent* origChild = originalShadowRoot->GetFirstChild();

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

@ -306,6 +306,44 @@ async function runTest8() {
exitprintpreview();
ok(compareCanvases(), "Printing pages with fonts loaded from CSS and JS should be the same.");
requestAnimationFrame(function() { setTimeout(runTest9); } );
}
// Test for bug 1487649
async function runTest9() {
window.frames[0].document.body.innerHTML = `
<svg width="100" height="100">
<rect width='100' height='100' fill='lime'/>
</svg>
`;
printpreview();
ctx1.drawWindow(window.frames[1], 0, 0, 400, 400, "rgb(255,255,255)");
exitprintpreview();
window.frames[0].document.body.innerHTML = `
<svg width="100" height="100">
<defs>
<g id="useme">
<rect width='100' height='100' fill='lime'/>
</g>
</defs>
<use />
</svg>
`;
// Set the attribute explicitly because this is a chrome document, and the
// href attribute would get sanitized.
window.frames[0].document.querySelector("use").setAttribute("href", "#useme");
// Ensure the <use> shadow tree is created so we test what we want to test.
window.frames[0].document.body.offsetTop;
printpreview();
ctx2.drawWindow(window.frames[1], 0, 0, 400, 400, "rgb(255,255,255)");
exitprintpreview();
ok(compareCanvases(), "Printing <use> subtrees should create same output");
finish();
}