haikuwebkit/LayoutTests/fast/parser/adoption-agency-unload-ifra...

39 lines
853 B
HTML
Raw Permalink Normal View History

parserRemoveChild should unload subframes https://bugs.webkit.org/show_bug.cgi?id=168151 Reviewed by Darin Adler. Source/WebCore: Fix the bug that the adoption agency algorithm does not unload subframes as it disconnects nodes. Also moved calls to nodeWillBeRemoved inside NoEventDispatchAssertion to expand on r211965. Tests: fast/parser/adoption-agency-clear-focus-range.html fast/parser/adoption-agency-unload-iframe-1.html fast/parser/adoption-agency-unload-iframe-2.html * dom/ContainerNode.cpp: (WebCore::ContainerNode::takeAllChildrenFrom): Rewritten using idioms used in removeChildren and parserAppendChild. Disconnect all subframes first since this can synchronously dispatch an unload event. Then update DOM ranges, the focused element, and other states in the document. Second, use the regular removeBetween, notifyChildNodeRemoved, childrenChanged sequence of calls to disconnect nodes instead of a single call to removeDetachedChildren to properly disconnect child nodes since those nodes may have already come live due to execution of synchronous scripts prior to the adoption agency algorithm has run, or in response to the unload event we just dispatched. Third, append these nodes using parserAppendChild to avoid dispatching mutation events. (WebCore::willRemoveChild): Removed the call to nodeWillBeRemoved. It's now called within NoEventDispatchAssertion in each call site of willRemoveChild and willRemoveChildren. (WebCore::willRemoveChildren): Ditto. (WebCore::ContainerNode::removeChild): Call nodeWillBeRemoved inside NoEventDispatchAssertion. (WebCore::ContainerNode::replaceAllChildren): Call nodeWillBeRemoved inside NoEventDispatchAssertion. (WebCore::ContainerNode::parserRemoveChild): Disconnect subframes and update document's states. * html/parser/HTMLConstructionSite.cpp: (WebCore::executeTakeAllChildrenAndReparentTask): Add a release assert that new parent does not already have a parent. LayoutTests: Add two W3C-style testharness tests for unloading iframes inside the adoption agency algorithm. Also added a test to make sure ContainerNode::takeAllChildrenFrom adjusts the focused element and DOM ranges. * fast/css/stylesheet-candidate-nodes-crash-expected.txt: Rebaselined. The difference comes from the fact iframe now is unloaded in parserRemoveChild as expected and then reloaded in parserAppendChild inside insertErrorMessageBlock as opposed to after the parser had completed as if the iframe had never been detached. * fast/parser/adoption-agency-clear-focus-range-expected.txt: Added. * fast/parser/adoption-agency-clear-focus-range.html: Added. * fast/parser/adoption-agency-unload-iframe-1-expected.txt: Added. * fast/parser/adoption-agency-unload-iframe-1.html: Added. * fast/parser/adoption-agency-unload-iframe-2-expected.txt: Added. * fast/parser/adoption-agency-unload-iframe-2.html: Added. Canonical link: https://commits.webkit.org/185255@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212218 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-13 04:21:03 +00:00
<!DOCTYPE html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<b><p><script>
let oldBody = document.body;
oldBody.remove();
let b = oldBody.querySelector('b');
document.documentElement.appendChild(b);
/* html
+ b
+ p
+ script */
let iframe = document.createElement('iframe');
b.firstChild.appendChild(iframe);
/* html
+ b
+ p
+ script
+ iframe */
let oldGlobal = iframe.contentWindow;
window.onload = () => {
document.documentElement.appendChild(document.createElement('body'));
let test = async_test('An iframe removed by the adoption agency algorithm must be unloaded');
test.step(() => {
assert_not_equals(oldGlobal, iframe.contentWindow);
});
test.done();
}
</script></b>