|
| 1 | +<!-- webkit-test-runner [ SiteIsolationEnabled=true ] --> |
| 2 | +<script src="../../../inspector/resources/inspector-test.js"></script> |
| 3 | +<script src="../debugger/resources/site-isolation-debugger-test-utilities.js"></script> |
| 4 | +<script src="resources/frame-document-splicing-test-utilities.js"></script> |
| 5 | +<script> |
| 6 | +function test() { |
| 7 | + let suite = InspectorTest.createAsyncSuite("SiteIsolation.DOM.FrameDocumentSplicing.RemoteTransition"); |
| 8 | + |
| 9 | + let pageDocument = null; |
| 10 | + let targetNames = new Map; |
| 11 | + |
| 12 | + async function flushPageDOMAgent() { |
| 13 | + let pageTarget = WI.assumingMainTarget(); |
| 14 | + await pageTarget.DOMAgent.getSupportedEventNames(); |
| 15 | + await pageTarget.DOMAgent.getSupportedEventNames(); |
| 16 | + } |
| 17 | + |
| 18 | + function pageBodyChildWithId(id) { |
| 19 | + return pageDocument.body.children?.find((node) => node.getAttribute("id") === id) ?? null; |
| 20 | + } |
| 21 | + |
| 22 | + function lateFrameElement() { |
| 23 | + return pageBodyChildWithId("late-frame"); |
| 24 | + } |
| 25 | + |
| 26 | + async function waitUntil(predicate, maxAttempts = 50) { |
| 27 | + for (let attempt = 0; attempt < maxAttempts; ++attempt) { |
| 28 | + if (predicate()) |
| 29 | + return true; |
| 30 | + await new Promise((resolve) => setTimeout(resolve, 100)); |
| 31 | + } |
| 32 | + return false; |
| 33 | + } |
| 34 | + |
| 35 | + function expectSplicedIntoLateFrame(frameDocument, label) { |
| 36 | + let iframeElement = lateFrameElement(); |
| 37 | + InspectorTest.expectNotNull(iframeElement, "Should still find #late-frame."); |
| 38 | + InspectorTest.expectEqual(frameDocument.parentNode, iframeElement, `The ${label} frame's document should be spliced into #late-frame.`); |
| 39 | + InspectorTest.expectEqual(iframeElement?.children?.length, 1, "#late-frame should have exactly one child."); |
| 40 | + InspectorTest.expectEqual(iframeElement?.children?.[0], frameDocument, `#late-frame's only child should be the ${label} frame's document.`); |
| 41 | + InspectorTest.expectEqual(treeContainingNode(frameDocument, targetNames), "page", `The ${label} frame's document should be in the page tree.`); |
| 42 | + } |
| 43 | + |
| 44 | + suite.addTestCase({ |
| 45 | + name: "Setup", |
| 46 | + description: "Load the <iframe> while its about:blank document is still in the page's process.", |
| 47 | + async test() { |
| 48 | + pageDocument = await WI.domManager.requestDocument(); |
| 49 | + |
| 50 | + let iframeElement = await descendFromPageBody(pageDocument, (node) => node.getAttribute("id") === "late-frame"); |
| 51 | + InspectorTest.expectNotNull(iframeElement, "Should find #late-frame."); |
| 52 | + |
| 53 | + let blankDocument = iframeElement.children?.[0] ?? null; |
| 54 | + InspectorTest.expectNotNull(blankDocument, "#late-frame should have a content document."); |
| 55 | + InspectorTest.expectEqual(blankDocument?.nodeType(), Node.DOCUMENT_NODE, "#late-frame's child should be a document."); |
| 56 | + InspectorTest.expectEqual(blankDocument?.owningTarget ?? null, null, "#late-frame's document should come from the page agent."); |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + suite.addTestCase({ |
| 61 | + name: "SiteIsolation.DOM.FrameDocumentSplicing.RemoteTransition.NavigateCrossOrigin", |
| 62 | + description: "After the <iframe> navigates cross-origin, its frame target's document should be spliced under it.", |
| 63 | + async test() { |
| 64 | + await InspectorTest.evaluateInPage(`document.getElementById("late-frame").src = "http://localhost:8000/site-isolation/inspector/dom/resources/dom-frame.html?late=http"`); |
| 65 | + |
| 66 | + let frameTarget = await frameTargetForURLContainingWhenReady("late=http"); |
| 67 | + InspectorTest.expectNotNull(frameTarget, "Should find the cross-origin frame target."); |
| 68 | + targetNames.set(frameTarget, "cross-origin frame target"); |
| 69 | + |
| 70 | + await flushPageDOMAgent(); |
| 71 | + |
| 72 | + expectSplicedIntoLateFrame(WI.domManager.frameTargetDocumentForTarget(frameTarget), "cross-origin"); |
| 73 | + } |
| 74 | + }); |
| 75 | + |
| 76 | + suite.addTestCase({ |
| 77 | + name: "SiteIsolation.DOM.FrameDocumentSplicing.RemoteTransition.NavigateToAnotherRemoteProcess", |
| 78 | + description: "After the remote frame moves to a third process, the page's process is not told, so only the frame's identity can splice its new document.", |
| 79 | + async test() { |
| 80 | + await InspectorTest.evaluateInPage(`document.getElementById("late-frame").src = "https://localhost:8443/site-isolation/inspector/dom/resources/dom-frame.html?late=https"`); |
| 81 | + |
| 82 | + let frameTarget = await frameTargetForURLContainingWhenReady("late=https"); |
| 83 | + InspectorTest.expectNotNull(frameTarget, "Should find the frame target in the third process."); |
| 84 | + targetNames.set(frameTarget, "third-process frame target"); |
| 85 | + |
| 86 | + let frameDocument = WI.domManager.frameTargetDocumentForTarget(frameTarget); |
| 87 | + await waitUntil(() => frameDocument.parentNode); |
| 88 | + await flushPageDOMAgent(); |
| 89 | + |
| 90 | + expectSplicedIntoLateFrame(frameDocument, "third-process"); |
| 91 | + } |
| 92 | + }); |
| 93 | + |
| 94 | + suite.addTestCase({ |
| 95 | + name: "SiteIsolation.DOM.FrameDocumentSplicing.RemoteTransition.RemoveOwnerElement", |
| 96 | + description: "Removing an <iframe> whose frame target's document is spliced under it should unsplice that document.", |
| 97 | + async test() { |
| 98 | + let frameTarget = await frameTargetForURLContainingWhenReady("removed=1"); |
| 99 | + InspectorTest.expectNotNull(frameTarget, "Should find #removed-frame's frame target."); |
| 100 | + targetNames.set(frameTarget, "removed frame target"); |
| 101 | + |
| 102 | + let frameDocument = WI.domManager.frameTargetDocumentForTarget(frameTarget); |
| 103 | + InspectorTest.expectEqual(frameDocument.parentNode, pageBodyChildWithId("removed-frame"), "#removed-frame's document should be spliced into it."); |
| 104 | + |
| 105 | + await InspectorTest.evaluateInPage(`document.getElementById("removed-frame").remove()`); |
| 106 | + await waitUntil(() => !pageBodyChildWithId("removed-frame") && !frameDocument.parentNode); |
| 107 | + await flushPageDOMAgent(); |
| 108 | + |
| 109 | + InspectorTest.expectNull(pageBodyChildWithId("removed-frame"), "#removed-frame should be gone from the page tree."); |
| 110 | + InspectorTest.expectNull(frameDocument.parentNode, "#removed-frame's document should no longer be spliced."); |
| 111 | + } |
| 112 | + }); |
| 113 | + |
| 114 | + suite.runTestCasesAndFinish(); |
| 115 | +} |
| 116 | +</script> |
| 117 | + |
| 118 | +<body onload="runTest()"> |
| 119 | +<p>Test that an <iframe> in the page tree holds its frame's current document as the frame moves between processes, and that removing an <iframe> unsplices its frame target's document.</p> |
| 120 | +<iframe id="late-frame"></iframe> |
| 121 | +<iframe id="removed-frame" src="http://localhost:8000/site-isolation/inspector/dom/resources/dom-frame.html?removed=1"></iframe> |
| 122 | +</body> |
0 commit comments