From d4aeb28fd26494b3e0a380d0cec46333fdb6d28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 31 Aug 2018 12:08:04 +0000 Subject: [PATCH] Bug 1487649 - Don't do a name check when cloning a shadow root for print preview. r=smaug Otherwise the ShadowRoot for or other internal ones may not get cloned properly. Differential Revision: https://phabricator.services.mozilla.com/D4756 --HG-- extra : moz-landing-system : lando --- dom/base/nsNodeUtils.cpp | 7 +--- .../base/tests/chrome/printpreview_helper.xul | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) 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..85b767752c0c 100644 --- a/layout/base/tests/chrome/printpreview_helper.xul +++ b/layout/base/tests/chrome/printpreview_helper.xul @@ -306,6 +306,41 @@ 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 = ` + + + + + + + + + `; + + // Ensure the shadow tree is created so we test what we want to test. + await new Promise(resolve => requestAnimationFrame(resolve)); + await new Promise(resolve => requestAnimationFrame(resolve)); + + printpreview(); + ctx2.drawWindow(window.frames[1], 0, 0, 400, 400, "rgb(255,255,255)"); + exitprintpreview(); + ok(compareCanvases(), "Printing subtrees should create same output"); + finish(); }