summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/background-fetch.https.html
blob: 7036f2bb5f3bb5e42b5af1b5f970141c0884b5ef (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<title>Test fenced frame does not allow call background fetch</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>

<body>

  <script>
    const background_fetch_register_key = token();

    async function test(url, expected, message) {
      attachFencedFrame(url)

      // Get the result for the top-level fenced frame.
      const fenced_frame_result = await nextValueFromServer(
          background_fetch_register_key);
      assert_equals(fenced_frame_result, expected, message);
    }

    promise_test(async () => {
      const method = "fetch";
      const fenced_frame_url = 'resources/background-fetch-inner.https.html';
      const url = generateURL(fenced_frame_url,
                              [background_fetch_register_key, method]);

      await test(
        url,
        '[backgroundFetch.fetch] Failed inside fencedframe as expected',
        'backgroundFetch.fetch is disallowed inside a same-origin fenced frame');

      const CROSS_ORIGIN_DESTINATION = getRemoteOriginURL(url);
      await test(
        CROSS_ORIGIN_DESTINATION,
        '[backgroundFetch.fetch] Failed inside fencedframe as expected',
        'backgroundFetch.fetch is disallowed inside a cross-origin fenced frame');
    }, 'backgroundFetch.fetch');

    promise_test(async () => {
      const method = "get";
      const fenced_frame_url = 'resources/background-fetch-inner.https.html';
      const url = generateURL(fenced_frame_url,
                              [background_fetch_register_key, method]);
      await test(
        url,
        '[backgroundFetch.get] Failed inside fencedframe as expected',
        'backgroundFetch.get is disallowed inside a same-origin fenced frame');

      const CROSS_ORIGIN_DESTINATION = getRemoteOriginURL(url);
      await test(
        CROSS_ORIGIN_DESTINATION,
        '[backgroundFetch.get] Failed inside fencedframe as expected',
        'backgroundFetch.get is disallowed inside a cross-origin fenced frame');
    }, 'backgroundFetch.get');

    promise_test(async () => {
      const method = "getIds";
      const fenced_frame_url = 'resources/background-fetch-inner.https.html';
      const url = generateURL(fenced_frame_url,
                              [background_fetch_register_key, method]);
      await test(
        url,
        '[backgroundFetch.getIds] Failed inside fencedframe as expected',
        'backgroundFetch.getIds is disallowed inside a same-origin fenced frame');

      const CROSS_ORIGIN_DESTINATION = getRemoteOriginURL(url);
      await test(
        CROSS_ORIGIN_DESTINATION,
        '[backgroundFetch.getIds] Failed inside fencedframe as expected',
        'backgroundFetch.getIds is disallowed inside a cross-origin fenced frame');
    }, 'backgroundFetch.getIds');

    promise_test(async () => {
      const method = "fetch";
      const fenced_frame_url = 'resources/background-fetch-sw-inner.https.html';
      const url = generateURL(fenced_frame_url,
                              [background_fetch_register_key, method]);

      await test(
        url,
        '[backgroundFetch.fetch] Failed inside fencedframe as expected',
        'backgroundFetch.fetch is disallowed inside a same-origin fenced frame');

      const CROSS_ORIGIN_DESTINATION = getRemoteOriginURL(url);
      await test(
        CROSS_ORIGIN_DESTINATION,
        '[backgroundFetch.fetch] Failed inside fencedframe as expected',
        'backgroundFetch.fetch is disallowed inside a cross-origin fenced frame');
    }, 'backgroundFetch.fetch in service worker');

    promise_test(async () => {
      const method = "get";
      const fenced_frame_url = 'resources/background-fetch-sw-inner.https.html';
      const url = generateURL(fenced_frame_url,
                              [background_fetch_register_key, method]);
      await test(
        url,
        '[backgroundFetch.get] Failed inside fencedframe as expected',
        'backgroundFetch.get is disallowed inside a same-origin fenced frame');

      const CROSS_ORIGIN_DESTINATION = getRemoteOriginURL(url);
      await test(
        CROSS_ORIGIN_DESTINATION,
        '[backgroundFetch.get] Failed inside fencedframe as expected',
        'backgroundFetch.get is disallowed inside a cross-origin fenced frame');
    }, 'backgroundFetch.get in service worker');

    promise_test(async () => {
      const method = "getIds";
      const fenced_frame_url = 'resources/background-fetch-sw-inner.https.html';
      const url = generateURL(fenced_frame_url,
                              [background_fetch_register_key, method]);
      await test(
        url,
        '[backgroundFetch.getIds] Failed inside fencedframe as expected',
        'backgroundFetch.getIds is disallowed inside a same-origin fenced frame');

      const CROSS_ORIGIN_DESTINATION = getRemoteOriginURL(url);
      await test(
        CROSS_ORIGIN_DESTINATION,
        '[backgroundFetch.getIds] Failed inside fencedframe as expected',
        'backgroundFetch.getIds is disallowed inside a cross-origin fenced frame');
    }, 'backgroundFetch.getIds in service worker');
  </script>

</body>