diff --git a/dom/base/nsNodeUtils.cpp b/dom/base/nsNodeUtils.cpp index 9c2b3a3bd0be..7d5fb40650a4 100644 --- a/dom/base/nsNodeUtils.cpp +++ b/dom/base/nsNodeUtils.cpp @@ -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 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(); diff --git a/layout/base/tests/chrome/printpreview_helper.xul b/layout/base/tests/chrome/printpreview_helper.xul index b9f71204f1c4..aac0ed817b28 100644 --- a/layout/base/tests/chrome/printpreview_helper.xul +++ b/layout/base/tests/chrome/printpreview_helper.xul @@ -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 = ` + + + + `; + + printpreview(); + ctx1.drawWindow(window.frames[1], 0, 0, 400, 400, "rgb(255,255,255)"); + exitprintpreview(); + + window.frames[0].document.body.innerHTML = ` + + + + + + + + + `; + + // 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 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 subtrees should create same output"); + finish(); }