summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/speculation-rules/prerender/resources/cross-origin-iframe.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/speculation-rules/prerender/resources/cross-origin-iframe.html')
-rw-r--r--testing/web-platform/tests/speculation-rules/prerender/resources/cross-origin-iframe.html57
1 files changed, 57 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/resources/cross-origin-iframe.html b/testing/web-platform/tests/speculation-rules/prerender/resources/cross-origin-iframe.html
new file mode 100644
index 0000000000..10a3b62f0e
--- /dev/null
+++ b/testing/web-platform/tests/speculation-rules/prerender/resources/cross-origin-iframe.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<script src="/common/utils.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="/speculation-rules/prerender/resources/utils.js"></script>
+<script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script>
+<body>
+<script>
+
+async function main() {
+ const crossOriginUrl =
+ new URL('cross-origin-iframe-src.html',
+ get_host_info()['HTTPS_REMOTE_ORIGIN'] +
+ window.location.pathname);
+
+ // Start loading a cross-origin iframe. The iframe messages us with the
+ // value of its document.prerendering, which should be false since load
+ // is delayed until after activation.
+ const crossOriginIframe = document.createElement('iframe');
+
+ const gotMessage = new Promise((resolve, reject) => {
+ window.addEventListener('message', (e) => {
+ if (e.data == 'document.prerendering: false')
+ resolve();
+ else
+ reject('bad message: ' + e.data);
+ });
+ });
+
+ crossOriginIframe.src = crossOriginUrl.href;
+ document.body.appendChild(crossOriginIframe);
+
+ // To give the test a chance to fail by giving enough time if it loads the
+ // cross-origin iframe instead of deferring, wait for a same-origin iframe to
+ // load before proceeding with the test.
+ await createFrame('empty.html');
+
+ // Start the event collector to trigger activation.
+ const prerenderEventCollector = new PrerenderEventCollector();
+ prerenderEventCollector.start(gotMessage,
+ 'iframe loaded');
+
+}
+
+// The main test page (cross-origin-iframe.https.html) loads the initiator
+// page, then the initiator page will prerender itself with the
+// `prerendering` parameter.
+const params = new URLSearchParams(location.search);
+if (!params.has('prerendering')) {
+ const rule_extras = {'target_hint': getTargetHint()};
+ loadInitiatorPage(rule_extras);
+} else {
+ main();
+}
+</script>
+</body>