summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/speculation-rules/prefetch/redirect-url.sub.https.html
blob: 02bb35349ff9f72e74d0244473447b9ea89ce9a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/utils.js"></script>
<script src="../resources/utils.js"></script>
<script src="resources/utils.sub.js"></script>

<script>
  setup(() => assertSpeculationRulesIsSupported());

  promise_test(async t => {
    const agent = await spawnWindow(t);
    // Because `forceSinglePrefetch()` waits for 2 seconds, the redirect and final
    // responses are expected to be received before `navigate()` below.
    const nextUrl = new URL('/common/redirect.py', location.href);
    const finalUrl = agent.getExecutorURL({ page: 2 });
    nextUrl.searchParams.set('location', finalUrl);
    await agent.forceSinglePrefetch(nextUrl);
    await agent.navigate(nextUrl, {expectedDestinationUrl: finalUrl});

    assert_prefetched(await agent.getRequestHeaders(),
        'Prefetched response should be used by navigation.');
  }, 'Redirect and final response received before navigation start');

  promise_test(async t => {
    const agent = await spawnWindow(t);
    // Because `forceSinglePrefetch()` waits for 2 seconds, we put 2.5-second delay
    // here to make the redirect response is received after `navigate()` below.
    const nextUrl = new URL('/common/slow-redirect.py?delay=2.5', location.href);
    const finalUrl = agent.getExecutorURL({ page: 2 });
    nextUrl.searchParams.set('location', finalUrl);
    await agent.forceSinglePrefetch(nextUrl);
    await agent.navigate(nextUrl, {expectedDestinationUrl: finalUrl});

    assert_prefetched(await agent.getRequestHeaders(),
        'Prefetched response should be used by navigation.');
  }, 'Same-origin redirect response received after navigation start');

  promise_test(async t => {
    const agent = await spawnWindow(t);
    // Because `forceSinglePrefetch()` waits for 2 seconds, we put 2.5-second delay
    // here to make the redirect response is received after `navigate()` below.
    const nextUrl = new URL('/common/slow-redirect.py?delay=2.5', location.href);
    const finalUrl = agent.getExecutorURL({ page: 2, hostname: '{{hosts[alt][www]}}' });
    nextUrl.searchParams.set('location', finalUrl);
    await agent.forceSinglePrefetch(nextUrl);
    await agent.navigate(nextUrl, {expectedDestinationUrl: finalUrl});

    assert_prefetched(await agent.getRequestHeaders(),
        'Prefetched response should be used by navigation.');
  }, 'Cross-site redirect response received after navigation start');
</script>