Truly independent web browser
Tests/LibWeb: Add tests for WindowProxies in realms of dead documents
Andreas Kling145dd3503c5e
diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/window-proxy-of-iframe-leaving-for-another-process-leaves-its-realm.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/window-proxy-of-iframe-leaving-for-another-process-leaves-its-realm.txtnew file mode 100644index 00000000000..a275871cc4d--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/window-proxy-of-iframe-leaving-for-another-process-leaves-its-realm.txt@@ -0,0 +1,3 @@+in the realm of a destroyed document here: false+document here destroyed: true+in the realm of a destroyed document when remote: truediff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.txtnew file mode 100644index 00000000000..cae95f427ac--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.txt@@ -0,0 +1,5 @@+WebContent#0+ iframe#0: remote WebContent#1+ iframe#0: remote WebContent#0+first grandchild's document destroyed: true+in the realm of a destroyed document: truediff --git a/Tests/LibWeb/Text/expected/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.txt b/Tests/LibWeb/Text/expected/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.txtnew file mode 100644index 00000000000..4b1a9958b30--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.txt@@ -0,0 +1,5 @@+message: same origin+in the realm of a destroyed document here: false+message: cross-site+document here destroyed: true+in the realm of a destroyed document when remote: truediff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-of-iframe-leaving-for-another-process-leaves-its-realm.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-of-iframe-leaving-for-another-process-leaves-its-realm.htmlnew file mode 100644index 00000000000..238d26102f5--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-of-iframe-leaving-for-another-process-leaves-its-realm.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script>+ // An iframe whose next document another process hosts keeps the WindowProxy scripts hold for it. That WindowProxy+ // must not stay in the realm of the document the iframe displayed here, as it would keep that document alive.+ promiseTest(async () => {+ const httpServer = httpTestServer();++ const remoteUrl = new URL(+ await httpServer.createEcho("GET", "/window-proxy-of-iframe-leaving", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: "<!DOCTYPE html>remote",+ })+ );+ remoteUrl.hostname = uniqueLocalhostHostname("window-proxy-of-iframe-leaving");++ const iframe = document.createElement("iframe");+ document.body.appendChild(iframe);+ const windowProxy = iframe.contentWindow;+ const documentHere = iframe.contentDocument;+ println(`in the realm of a destroyed document here: ${internals.isInRealmOfDestroyedDocument(windowProxy)}`);++ iframe.src = remoteUrl;+ if (!(await waitForCondition(() => remoteFrameCount() === 1))) {+ println("iframe did not become remote");+ return;+ }+ println(`document here destroyed: ${await waitForCondition(() => internals.isInRealmOfDestroyedDocument(documentHere))}`);+ println(`in the realm of a destroyed document when remote: ${internals.isInRealmOfDestroyedDocument(windowProxy)}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.htmlnew file mode 100644index 00000000000..bc6614360dd--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.html@@ -0,0 +1,51 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script>+ // A grandchild same origin with the top document, under an isolated iframe, is hosted in the top document's+ // process. The WindowProxy of the isolated iframe that the grandchild reaches through parent must not stay in the+ // grandchild's realm once the grandchild navigates to another document, as it would keep that document alive.+ // This page is served over HTTP so that the grandchild can be same origin with it.+ promiseTest(async () => {+ const httpServer = httpTestServer();+ const childHostname = uniqueLocalhostHostname("window-proxy-reached-by-grandchild");++ const secondGrandchildUrl = await httpServer.createEcho("GET", "/window-proxy-reached-by-grandchild-second", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><script>top.postMessage("second grandchild", "*");<\/script>`,+ });++ const firstGrandchildUrl = await httpServer.createEcho("GET", "/window-proxy-reached-by-grandchild-first", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><script>+ top.firstGrandchildDocument = document;+ parent.postMessage("first grandchild", "*");+ location.replace(${JSON.stringify(secondGrandchildUrl)});+ <\/script>`,+ });++ const childUrl = new URL(+ await httpServer.createEcho("GET", "/window-proxy-reached-by-grandchild-child", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><iframe src="${firstGrandchildUrl}"></iframe>`,+ })+ );+ childUrl.hostname = childHostname;++ const secondGrandchildLoaded = new Promise(resolve => {+ addEventListener("message", event => {+ if (event.data === "second grandchild") resolve();+ });+ });+ const iframe = document.createElement("iframe");+ iframe.src = childUrl;+ document.body.appendChild(iframe);+ await secondGrandchildLoaded;++ println(internals.dumpSiteIsolationProcessTree().trimEnd());+ println(`first grandchild's document destroyed: ${await waitForCondition(() => internals.isInRealmOfDestroyedDocument(firstGrandchildDocument))}`);+ println(`in the realm of a destroyed document: ${internals.isInRealmOfDestroyedDocument(iframe.contentWindow)}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.html.headers b/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.html.headersnew file mode 100644index 00000000000..156209f9c81--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/window-proxy-reached-by-same-site-grandchild-leaves-its-realm.html.headers@@ -0,0 +1 @@+Content-Type: text/htmldiff --git a/Tests/LibWeb/Text/input/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.html b/Tests/LibWeb/Text/input/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.htmlnew file mode 100644index 00000000000..f8538d9679f--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.html@@ -0,0 +1,40 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ // A popup that navigates cross-site leaves its opener's process. The WindowProxy the opener holds for it must not+ // stay in the realm of the document the popup displayed here, as it would keep that document alive.+ // This page is served over HTTP so that the popup's first document can be same origin with it.+ promiseTest(async () => {+ const httpServer = httpTestServer();++ const crossSiteUrl = new URL(+ await httpServer.createEcho("GET", "/window-proxy-of-popup-leaving-cross-site", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><script>opener.postMessage("cross-site", "*");<\/script>`,+ })+ );+ crossSiteUrl.hostname = uniqueLocalhostHostname("window-proxy-of-popup-leaving");++ const sameOriginUrl = await httpServer.createEcho("GET", "/window-proxy-of-popup-leaving-same-origin", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><script>opener.postMessage("same origin", "*");<\/script>`,+ });++ const nextMessage = () => new Promise(resolve => addEventListener("message", event => resolve(event.data), { once: true }));++ let message = nextMessage();+ const popup = window.open(sameOriginUrl);+ println(`message: ${await message}`);+ const documentHere = popup.document;+ println(`in the realm of a destroyed document here: ${internals.isInRealmOfDestroyedDocument(popup)}`);++ message = nextMessage();+ popup.location = crossSiteUrl.href;+ println(`message: ${await message}`);+ println(`document here destroyed: ${await waitForCondition(() => internals.isInRealmOfDestroyedDocument(documentHere))}`);+ println(`in the realm of a destroyed document when remote: ${internals.isInRealmOfDestroyedDocument(popup)}`);+ popup.close();+ });+</script>diff --git a/Tests/LibWeb/Text/input/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.html.headers b/Tests/LibWeb/Text/input/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.html.headersnew file mode 100644index 00000000000..156209f9c81--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/window-proxy-of-popup-leaving-for-another-process-leaves-its-realm.html.headers@@ -0,0 +1 @@+Content-Type: text/html