summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/request/request-reset-attributes.https.html
blob: 7be3608d737c34a599795621f107ae5243d2ab13 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<body>
<script>
const worker = 'resources/request-reset-attributes-worker.js';

function wait(ms) {
  return new Promise(resolve => step_timeout(resolve, ms));
}

promise_test(async (t) => {
    const scope = 'resources/hello.txt?name=isReloadNavigation';
    let frame;
    let reg;

    try {
      reg = await service_worker_unregister_and_register(t, worker, scope);
      await wait_for_state(t, reg.installing, 'activated');
      frame = await with_iframe(scope);
      assert_equals(frame.contentDocument.body.textContent,
                    'old: false, new: false');
      await new Promise((resolve) => {
        frame.onload = resolve;
        frame.contentWindow.location.reload();
      });
      assert_equals(frame.contentDocument.body.textContent,
                    'old: true, new: false');
    } finally {
      if (frame) {
        frame.remove();
      }
      if (reg) {
        await reg.unregister();
      }
    }
  }, 'Request.isReloadNavigation is reset with non-empty RequestInit');

promise_test(async (t) => {
    const scope = 'resources/hello.html?name=isHistoryNavigation';
    let frame;
    let reg;

    try {
      reg = await service_worker_unregister_and_register(t, worker, scope);
      await wait_for_state(t, reg.installing, 'activated');
      frame = await with_iframe(scope);
      assert_equals(frame.contentDocument.body.textContent,
                    'old: false, new: false');
      // Use step_timeout(0) to ensure the history entry is created for Blink
      // and WebKit. See https://bugs.webkit.org/show_bug.cgi?id=42861.
      await wait(0);
      await new Promise((resolve) => {
        frame.onload = resolve;
        frame.src = 'resources/hello.html?ignore';
      });
      await wait(0);
      await new Promise((resolve) => {
        frame.onload = resolve;
        frame.contentWindow.history.go(-1);
      });
      assert_equals(frame.contentDocument.body.textContent,
                    'old: true, new: false');
    } finally {
      if (frame) {
        frame.remove();
      }
      if (reg) {
        await reg.unregister();
      }
    }
}, 'Request.isHistoryNavigation is reset with non-empty RequestInit');

promise_test(async (t) => {
    const scope = 'resources/hello.txt?name=mode';
    let frame;
    let reg;

    try {
      reg = await service_worker_unregister_and_register(t, worker, scope);
      await wait_for_state(t, reg.installing, 'activated');
      frame = await with_iframe(scope);
      assert_equals(frame.contentDocument.body.textContent,
                    'old: navigate, new: same-origin');
    } finally {
      if (frame) {
        frame.remove();
      }
      if (reg) {
        await reg.unregister();
      }
    }
  }, 'Request.mode is reset with non-empty RequestInit when it\'s "navigate"');
</script>