summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/speculation-rules/prerender/windowclient-navigate.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/speculation-rules/prerender/windowclient-navigate.https.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/speculation-rules/prerender/windowclient-navigate.https.html')
-rw-r--r--testing/web-platform/tests/speculation-rules/prerender/windowclient-navigate.https.html72
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/web-platform/tests/speculation-rules/prerender/windowclient-navigate.https.html b/testing/web-platform/tests/speculation-rules/prerender/windowclient-navigate.https.html
new file mode 100644
index 0000000000..608584636a
--- /dev/null
+++ b/testing/web-platform/tests/speculation-rules/prerender/windowclient-navigate.https.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<title>WindowClient.navigate() for prerendered main page</title>
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="/common/utils.js"></script>
+<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
+<script src="../resources/utils.js"></script>
+<script src="resources/utils.js"></script>
+
+<body>
+<script>
+setup(() => assertSpeculationRulesIsSupported());
+
+const uid = token();
+
+const PAGE_URL = `resources/prerendered-page.html?uid=${uid}`;
+const WORKER_URL = `resources/windowclient-navigate-worker.js?uid=${uid}`;
+const SAME_ORIGIN_DESTINATION =
+ get_host_info()['HTTPS_ORIGIN'] + base_path() + 'resources/empty.html';
+
+promise_test(async t => {
+ const registration =
+ await service_worker_unregister_and_register(t, WORKER_URL, PAGE_URL);
+ t.add_cleanup(() => registration.unregister());
+ await wait_for_state(t, get_newest_worker(registration), 'activated');
+
+ const readyChannel = new PrerenderChannel('prerender-channel', uid);
+ t.add_cleanup(_ => readyChannel.close());
+
+ const readyPromise = new Promise(resolve => {
+ readyChannel.addEventListener('message', e => {
+ resolve(e.data);
+ }, {
+ once: true
+ });
+ });
+
+ startPrerendering(PAGE_URL);
+
+ const prerenderResult = await readyPromise;
+ assert_equals(prerenderResult, 'prerender success',
+ 'should succeed to prerender a page');
+
+ const resultChannel = new PrerenderChannel('test-channel', uid);
+ t.add_cleanup(_ => resultChannel.close());
+
+ const navigationPromise = new Promise(resolve => {
+ resultChannel.addEventListener('message', e => {
+ resolve(e.data);
+ }, {
+ once: true
+ });
+ });
+
+ // Asks the service worker to navigate the prerendered page to `navigationUrl`
+ // via `WindowClient.navigate(url)`.
+ const bc = new PrerenderChannel('navigation-channel', uid);
+ bc.postMessage(JSON.stringify({
+ navigationUrl: SAME_ORIGIN_DESTINATION,
+ clientUrl: new URL(PAGE_URL, window.location).toString(),
+ respondTo: 'test-channel',
+ }));
+ bc.close();
+
+ const navigationResult = await navigationPromise;
+ assert_equals(navigationResult, 'navigate() failed with TypeError',
+ 'should fail the navigation with TypeError');
+}, 'WindowClient.navigate() for a prerendered main page should throw a' +
+ 'TypeError');
+</script>