summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/background-sync.https.html
blob: 72eb44750b4f818d97f65af773d381b333966fb5 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<title>Test fenced frame does not allow to register background sync</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_sync_register_key = token();
const fenced_frame_url = 'resources/background-sync-inner.https.html';
const fenced_frame_url_for_service_worker_test =
  'resources/background-sync-sw-inner.https.html';

const generateFencedFrameUrl = (params, is_worker_test = false) => {
  const searchParams = new URLSearchParams(params);
  const frame_url = is_worker_test ?
    fenced_frame_url_for_service_worker_test : fenced_frame_url;

  return generateURL(`${frame_url}?${searchParams.toString()}`,
    [background_sync_register_key]);
};

async function background_sync_test(url, expected_text, message) {
  attachFencedFrame(url)

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

const background_sync_message =
  "Background Sync is not allowed in fenced frames.";
const periodic_background_sync_message =
  "Periodic Background Sync is not allowed in fenced frames.";

promise_test(async (t) => {
  const method = 'register';
  const frame_url = generateFencedFrameUrl({method});
  const expected_message = "Failed to execute 'register' on 'SyncManager': " +
    background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'register() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'register() is disallowed inside a cross-origin fenced frame');
}, 'background sync register');

promise_test(async (t) => {
  const method = 'getTags';
  const frame_url = generateFencedFrameUrl({method});
  const expected_message = background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'getTags() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'getTags() is disallowed inside a cross-origin fenced frame');
}, 'background sync getTags');

promise_test(async (t) => {
  const method = 'register';
  const frame_url = generateFencedFrameUrl({method}, true);
  const expected_message = "Failed to execute 'register' on 'SyncManager': " +
    background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'register() is disallowed inside a same-origin fenced frame');
  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'register() is disallowed inside a cross-origin fenced frame');
}, 'background sync register in service worker');

promise_test(async (t) => {
  const method = 'getTags';
  const frame_url = generateFencedFrameUrl({method}, true);
  const expected_message = background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'getTags() is disallowed inside a same-origin fenced frame');
  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'getTags() is disallowed inside a cross-origin fenced frame');
}, 'background sync getTags in service worker');

promise_test(async (t) => {
  const params = {
    method: 'register',
    periodic: true
  };
  const frame_url = generateFencedFrameUrl(params)
  const expected_message = "Failed to execute 'register' on " +
    "'PeriodicSyncManager': " + periodic_background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'register() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'register() is disallowed inside a cross-origin fenced frame');
}, 'periodic sync register');

promise_test(async (t) => {
  const params = {
    method: 'getTags',
    periodic: true
  };
  const frame_url = generateFencedFrameUrl(params)
  const expected_message = periodic_background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'getTags() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'getTags() is disallowed inside a cross-origin fenced frame');
}, 'periodic sync getTags');

promise_test(async (t) => {
  const params = {
    method: 'unregister',
    periodic: true
  };
  const frame_url = generateFencedFrameUrl(params)
  const expected_message = periodic_background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'unregister() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'unregister() is disallowed inside a cross-origin fenced frame');
}, 'periodic sync unregister');

promise_test(async (t) => {
  const params = {
    method: 'register',
    periodic: true
  };
  const frame_url = generateFencedFrameUrl(params, true)
  const expected_message = "Failed to execute 'register' on " +
    "'PeriodicSyncManager': " + periodic_background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'register() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'register() is disallowed inside a cross-origin fenced frame');
}, 'periodic sync register in service worker');

promise_test(async (t) => {
  const params = {
    method: 'getTags',
    periodic: true
  };
  const frame_url = generateFencedFrameUrl(params, true)
  const expected_message = periodic_background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'getTags() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'getTags() is disallowed inside a cross-origin fenced frame');
}, 'periodic sync getTags in service worker');

promise_test(async (t) => {
  const params = {
    method: 'unregister',
    periodic: true
  };
  const frame_url = generateFencedFrameUrl(params, true)
  const expected_message = periodic_background_sync_message;
  await background_sync_test(
      frame_url,
      expected_message,
      'unregister() is disallowed inside a same-origin fenced frame');

  const cross_origin_frame_url = getRemoteOriginURL(frame_url);
  await background_sync_test(
      cross_origin_frame_url,
      expected_message,
      'unregister() is disallowed inside a cross-origin fenced frame');
}, 'periodic sync unregister in service worker');
</script>
</body>