From 7cb67eb95751c4f4274c8aff5f63f92ceb2944b2 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Fri, 4 Sep 2026 05:27:17 +0800 Subject: [PATCH] fix(window): keep retired iframe relations discarded --- .../extracted/frame_navigation_and_history.rs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_navigation_and_history.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_navigation_and_history.rs index c101d8e1d6a..4088fe521d4 100644 --- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_navigation_and_history.rs +++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_navigation_and_history.rs @@ -4164,3 +4164,69 @@ fn iframe_src_navigation_uses_owner_document_encoding_for_query() { "iframe navigation must use the same owner-document encoding as its reflected src: {attribute_bootstrap:?}" ); } + +#[test] +fn reattaching_iframe_does_not_resurrect_retired_window_relations() { + let mut vm = new_storage_test_vm("https://loaded-iframe-discard-relations.test/"); + + vm.eval( + r#" +(() => { + const child = document.createElement("iframe"); + (document.body || document.documentElement || document).appendChild(child); + const grandchild = child.contentDocument.createElement("iframe"); + grandchild.srcdoc = "

loaded grandchild

"; + child.contentDocument.body.appendChild(grandchild); + globalThis.__loadedDiscardChild = child; + globalThis.__loadedDiscardGrandchild = grandchild; + return "scheduled"; +})() +"#, + ) + .expect("loaded descendant frame setup should evaluate"); + vm.drain_pending_child_frame_work_for_test(); + + let result = vm + .eval( + r#" +(() => { + const child = globalThis.__loadedDiscardChild; + const grandchild = globalThis.__loadedDiscardGrandchild; + const childWindow = child.contentWindow; + const grandchildWindow = grandchild.contentWindow; + const before = { + grandchildLoaded: grandchildWindow.document.body.textContent === "loaded grandchild", + childParentIsTop: childWindow.parent === window, + childTopIsTop: childWindow.top === window, + grandchildParentIsChild: grandchildWindow.parent === childWindow, + grandchildTopIsTop: grandchildWindow.top === window + }; + + child.remove(); + const detached = { + childParentIsNull: childWindow.parent === null, + childTopIsNull: childWindow.top === null, + grandchildParentIsNull: grandchildWindow.parent === null, + grandchildTopIsNull: grandchildWindow.top === null + }; + + (document.body || document.documentElement || document).appendChild(child); + const reattached = { + newChildWindow: child.contentWindow !== childWindow, + oldChildParentIsNull: childWindow.parent === null, + oldChildTopIsNull: childWindow.top === null, + oldGrandchildParentIsNull: grandchildWindow.parent === null, + oldGrandchildTopIsNull: grandchildWindow.top === null, + oldGrandchildRemoved: child.contentDocument.querySelector("iframe") === null + }; + return JSON.stringify({ before, detached, reattached }); +})() +"#, + ) + .expect("loaded descendant frame discard probe should evaluate"); + + assert_eq!( + result, + r#"{"before":{"grandchildLoaded":true,"childParentIsTop":true,"childTopIsTop":true,"grandchildParentIsChild":true,"grandchildTopIsTop":true},"detached":{"childParentIsNull":true,"childTopIsNull":true,"grandchildParentIsNull":true,"grandchildTopIsNull":true},"reattached":{"newChildWindow":true,"oldChildParentIsNull":true,"oldChildTopIsNull":true,"oldGrandchildParentIsNull":true,"oldGrandchildTopIsNull":true,"oldGrandchildRemoved":true}}"# + ); +}