File: cross-partition.https.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (513 lines) | stat: -rw-r--r-- 21,006 bytes parent folder | download | duplicates (7)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<!DOCTYPE html>
<meta charset=utf-8>
<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="/common/dispatcher/dispatcher.js"></script>
<!-- Pull in executor_path needed by newPopup / newIframe -->
<script src="/html/cross-origin-embedder-policy/credentialless/resources/common.js"></script>
<!-- Pull in importScript / newPopup / newIframe -->
<script src="/html/anonymous-iframe/resources/common.js"></script>
<body>
<script>

const fetch_unsuccessful_response = "Fetch failed";
const fetch_successful_response = "Fetch succeeded";
const js_finished = "revoking blob_url js finished";

// Fetches a previously revoked blob_url to see if the revoking was successful.
async function fetch_contents_check(blob_url) {
  try {
    const blob = await fetch(blob_url).then(response => response.blob());
    await blob.text();
  } catch(e) {
    return fetch_unsuccessful_response;
  }
  return fetch_successful_response;
}

const can_blob_url_be_revoked_js = (blob_url, response_queue_name) => `
  async function test() {
    if (!('revokeObjectURL' in URL)) {
      return send("${response_queue_name}", "URL.revokeObjectURL is not exposed");
    }
    try {
      URL.revokeObjectURL("${blob_url}");
    } catch(e) {
      return send("${response_queue_name}", e.toString());
    }

    // Create, fetch, and revoke a separate blob URL to better ensure that the
    // revoke call above has had time to take effect before we return.
    const blob_1 = new Blob(["blob data"], {type : "text/plain"});
    const blob_url_1 = URL.createObjectURL(blob_1);
    await fetch(blob_url_1).then(response => response.blob());
    URL.revokeObjectURL(blob_url_1);

    return send("${response_queue_name}", "${js_finished}");
  }
  await test();
`;

const can_blob_url_be_fetched_js = (blob_url, response_queue_name) => `
  async function test() {
    try {
      const blob = await fetch("${blob_url}").then(response => response.blob());
      await blob.text();
    } catch(e) {
      return send("${response_queue_name}", "${fetch_unsuccessful_response}");
    }

    return send("${response_queue_name}", "${fetch_successful_response}");
  }
  await test();
`;

const add_iframe_js = (iframe_origin, response_queue_uuid) => `
  const importScript = ${importScript};
  await importScript("/html/cross-origin-embedder-policy/credentialless" +
                   "/resources/common.js");
  await importScript("/html/anonymous-iframe/resources/common.js");
  await importScript("/common/utils.js");

  // dispatcher.js has already been loaded by the popup this is running in.
  await send("${response_queue_uuid}", newIframe("${iframe_origin}"));
`;

const same_site_origin = get_host_info().HTTPS_ORIGIN;
const cross_site_origin = get_host_info().HTTPS_NOTSAMESITE_ORIGIN;

async function create_test_iframes(t, response_queue_uuid) {
  assert_equals("https://" + window.location.host, same_site_origin,
  "this test assumes that the page's window.location.host corresponds to " +
  "get_host_info().HTTPS_ORIGIN");

  // Create a same-origin iframe in a cross-site popup.
  const not_same_site_popup_uuid = newPopup(t, cross_site_origin);
  await send(not_same_site_popup_uuid,
       add_iframe_js(same_site_origin, response_queue_uuid));
  const cross_site_iframe_uuid = await receive(response_queue_uuid);

  // Create a same-origin iframe in a same-site popup.
  const same_origin_popup_uuid = newPopup(t, same_site_origin);
  await send(same_origin_popup_uuid,
       add_iframe_js(same_site_origin, response_queue_uuid));
  const same_site_iframe_uuid = await receive(response_queue_uuid);

  return [cross_site_iframe_uuid, same_site_iframe_uuid];
}

// Tests revoking blob URL for same and cross partition iframes.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      // Creates blob URL.
      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);

      // Fetches blob URL to ensure that it's valid.
      const blob_fetch = await fetch_contents_check(blob_url);
      if (blob_fetch !== fetch_successful_response) {
        reject("Blob URL invalid");
      }

      // Creates same and cross partition iframes.
      const response_queue_uuid = token();

      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      // Attempt to revoke blob URL in cross partition iframe.
      await send(cross_site_iframe_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
      var response_1 = await receive(response_queue_uuid);
      if (response_1 !== js_finished) {
        reject(response_1);
      }
      response_1 = await fetch_contents_check(blob_url);
      if (response_1 !== fetch_successful_response) {
        reject(`Blob URL was revoked in not-same-top-level-site iframe: ${response_1}`);
      }

      // Attempt to revoke blob URL in same partition iframe.
      await send(same_site_iframe_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
      var response_2 = await receive(response_queue_uuid);
      if (response_2 !== js_finished) {
        reject(response_2);
      }
      response_2 = await fetch_contents_check(blob_url);
      if (response_2 !== fetch_unsuccessful_response) {
        t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
        reject(`Blob URL wasn't revoked in same-top-level-site iframe: ${response_2}`);
      }

      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be revocable from a cross-partition iframe");

const newWorker = (origin) => {
  const worker_token = token();
  const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
  const worker = new Worker(worker_url);
  return worker_token;
}

const create_dedicated_worker_js = (origin, response_queue_uuid) => `
  const importScript = ${importScript};
  await importScript("/html/cross-origin-embedder-policy/credentialless" +
                    "/resources/common.js");
  await importScript("/html/anonymous-iframe/resources/common.js");
  await importScript("/common/utils.js");

  // dispatcher.js has already been loaded by the popup this is running in.
  const newWorker = ${newWorker};
  await send("${response_queue_uuid}", newWorker("${origin}"));
`;

// Tests revoking blob URL from same and cross partition dedicated worker.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      const response_queue_uuid = token();

      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      await send(cross_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
      const worker_1_uuid = await receive(response_queue_uuid);

      await send(same_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
      const worker_2_uuid = await receive(response_queue_uuid);

      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);

      await send(worker_1_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
      var response_1 = await receive(response_queue_uuid);
      if (response_1 !== js_finished) {
        reject(response_1);
      }
      response_1 = await fetch_contents_check(blob_url);
      if (response_1 !== fetch_successful_response) {
        reject(`Blob URL was revoked in not-same-top-level-site dedicated worker: ${response_1}`);
      }

      await send(worker_2_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
      var response_2 = await receive(response_queue_uuid);
      if (response_2 !== js_finished) {
        reject(response_2);
      }
      response_2 = await fetch_contents_check(blob_url);
      if (response_2 !== fetch_unsuccessful_response) {
        t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
        reject(`Blob URL wasn't revoked in same-top-level-site dedicated worker: ${response_2}`);
      }

      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be revocable from a cross-partition dedicated worker");

const newSharedWorker = (origin) => {
  const worker_token = token();
  const worker_url = origin + executor_worker_path + `&uuid=${worker_token}`;
  const worker = new SharedWorker(worker_url, worker_token);
  return worker_token;
}

const create_shared_worker_js = (origin, response_queue_uuid) => `
  const importScript = ${importScript};
  await importScript("/html/cross-origin-embedder-policy/credentialless" +
                    "/resources/common.js");
  await importScript("/html/anonymous-iframe/resources/common.js");
  await importScript("/common/utils.js");

  // dispatcher.js has already been loaded by the popup this is running in.
  const newSharedWorker = ${newSharedWorker};
  await send("${response_queue_uuid}", newSharedWorker("${origin}"));
`;

// Tests revoking blob URL from same and cross partition shared worker.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      const response_queue_uuid = token();

      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      // Create a shared worker in the cross-top-level-site iframe.
      await send(cross_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
      const worker_1_uuid = await receive(response_queue_uuid);

      // Create a shared worker in the same-top-level-site iframe.
      await send(same_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
      const worker_2_uuid = await receive(response_queue_uuid);

      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);

      await send(worker_1_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
      var response_1 = await receive(response_queue_uuid);
      if (response_1 !== js_finished) {
        reject(response_1);
      }
      response_1 = await fetch_contents_check(blob_url);
      if (response_1 !== fetch_successful_response) {
        reject(`Blob URL was revoked in not-same-top-level-site shared worker: ${response_1}`);
      }

      await send(worker_2_uuid, can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
      var response_2 = await receive(response_queue_uuid);
      if (response_2 !== js_finished) {
        reject(response_2);
      }
      response_2 = await fetch_contents_check(blob_url);
      if (response_2 !== fetch_unsuccessful_response) {
        t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));
        reject(`Blob URL wasn't revoked in same-top-level-site shared worker: ${response_2}`);
      }

      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be revocable from a cross-partition shared worker");

const newServiceWorker = async (origin) => {
  const worker_token = token();
  const worker_url = origin + executor_service_worker_path +
                     `&uuid=${worker_token}`;
  const worker_url_path = executor_service_worker_path.substring(0,
                              executor_service_worker_path.lastIndexOf('/'));
  const scope = worker_url_path + "/not-used/";
  const reg = await navigator.serviceWorker.register(worker_url,
                                                     {'scope': scope});
  return worker_token;
}

const create_service_worker_js = (origin, response_queue_uuid) => `
  const importScript = ${importScript};
  await importScript("/html/cross-origin-embedder-policy/credentialless" +
                    "/resources/common.js");
  await importScript("/html/anonymous-iframe/resources/common.js");
  await importScript("/common/utils.js");

  // dispatcher.js has already been loaded by the popup this is running in.
  const newServiceWorker = ${newServiceWorker};
  await send("${response_queue_uuid}", await newServiceWorker("${origin}"));
`;

// Tests revoking blob URL from a service worker.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      const response_queue_uuid = token();

      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      // Create a service worker in either iframe.
      await send(cross_site_iframe_uuid, create_service_worker_js(same_site_origin, response_queue_uuid));
      var worker_1_uuid = await receive(response_queue_uuid);
      t.add_cleanup(() =>
        send(worker_1_uuid, "self.registration.unregister();"));

      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);
      t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));

      await send(worker_1_uuid,
           can_blob_url_be_revoked_js(blob_url, response_queue_uuid));
      const response = await receive(response_queue_uuid);
      if (response !== "URL.revokeObjectURL is not exposed") {
        reject(`URL.revokeObjectURL is exposed in a Service Worker context: ${response}`);
      }
      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be revocable from a service worker");

// Tests fetching blob URL for same and cross partition iframes.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      // Creates blob URL.
      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);
      t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));

      // Fetches blob URL to ensure that it's valid.
      const blob_fetch = await fetch_contents_check(blob_url);
      if (blob_fetch !== fetch_successful_response) {
        reject("Blob URL invalid");
      }

      // Creates same and cross partition iframes.
      const response_queue_uuid = token();

      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      // Attempt to fetch blob URL in cross partition iframe.
      await send(cross_site_iframe_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      var response_1 = await receive(response_queue_uuid);
      if (response_1 !== fetch_unsuccessful_response) {
        reject(`Blob URL was fetched in not-same-top-level-site iframe: ${response_1}`);
      }

      // Attempt to fetch blob URL in same partition iframe.
      await send(same_site_iframe_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      var response_2 = await receive(response_queue_uuid);
      if (response_2 !== fetch_successful_response) {
        reject(`Blob URL wasn't fetched in same-top-level-site iframe: ${response_2}`);
      }

      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be fetched from a cross-partition iframe");

// Tests fetching blob URL from same and cross partition dedicated worker.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      const response_queue_uuid = token();

      // Creates same and cross partition iframes.
      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      // Creates a dedicated worker in the cross-top-level-site iframe.
      await send(cross_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
      const worker_1_uuid = await receive(response_queue_uuid);

      // Creates a dedicated worker in the same-top-level-site iframe.
      await send(same_site_iframe_uuid, create_dedicated_worker_js(same_site_origin, response_queue_uuid));
      const worker_2_uuid = await receive(response_queue_uuid);

      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);
      t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));

      // Attempts to fetch in the cross-top-level-site dedicated worker.
      await send(worker_1_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      var response_1 = await receive(response_queue_uuid);
      if (response_1 !== fetch_unsuccessful_response) {
        reject(`Blob URL was fetched in not-same-top-level-site dedicated worker: ${response_1}`);
      }

      // Attempts to fetch in the same-top-level-site dedicated worker.
      await send(worker_2_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      var response_2 = await receive(response_queue_uuid);
      if (response_2 !== fetch_successful_response) {
        reject(`Blob URL wasn't fetched in same-top-level-site dedicated worker: ${response_2}`);
      }

      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be fetched from a cross-partition dedicated worker");

// Tests fetching blob URL from same and cross partition shared worker.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      const response_queue_uuid = token();

      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      // Create a shared worker in the cross-top-level-site iframe.
      await send(cross_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
      const worker_1_uuid = await receive(response_queue_uuid);

      // Create a shared worker in the same-top-level-site iframe.
      await send(same_site_iframe_uuid, create_shared_worker_js(same_site_origin, response_queue_uuid));
      const worker_2_uuid = await receive(response_queue_uuid);

      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);
      t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));

      // Attempts to fetch in the cross-top-level-site shared worker.
      await send(worker_1_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      var response_1 = await receive(response_queue_uuid);
      if (response_1 !== fetch_unsuccessful_response) {
        reject(`Blob URL was fetched in not-same-top-level-site shared worker: ${response_1}`);
      }

      // Attempts to fetch in the same-top-level-site shared worker.
      await send(worker_2_uuid, can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      var response_2 = await receive(response_queue_uuid);
      if (response_2 !== fetch_successful_response) {
        reject(`Blob URL wasn't fetched in same-top-level-site shared worker: ${response_2}`);
      }

      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be fetched from a cross-partition shared worker");

// Tests fetching blob URL from a cross partition service worker.
promise_test(t => {
  return new Promise(async (resolve, reject) => {
    try {
      const response_queue_uuid = token();

      const [cross_site_iframe_uuid, same_site_iframe_uuid] =
        await create_test_iframes(t, response_queue_uuid);

      const blob = new Blob(["blob data"], {type : "text/plain"});
      const blob_url = window.URL.createObjectURL(blob);
      t.add_cleanup(() => window.URL.revokeObjectURL(blob_url));

      // Create a service worker in cross-top-level-site iframe.
      await send(cross_site_iframe_uuid, create_service_worker_js(same_site_origin, response_queue_uuid));
      var worker_1_uuid = await receive(response_queue_uuid);
      t.add_cleanup(() =>
        send(worker_1_uuid, "self.registration.unregister();"));

      await send(worker_1_uuid,
           can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      const response_1 = await receive(response_queue_uuid);
      if (response_1 !== fetch_unsuccessful_response) {
        reject(`Blob URL was fetched in not-same-top-level-site service worker: ${response_1}`);
      }

      // Create a service worker in same-top-level-site iframe.
      await send(same_site_iframe_uuid, create_service_worker_js(same_site_origin, response_queue_uuid));
      var worker_2_uuid = await receive(response_queue_uuid);
      t.add_cleanup(() =>
        send(worker_2_uuid, "self.registration.unregister();"));

      await send(worker_2_uuid,
           can_blob_url_be_fetched_js(blob_url, response_queue_uuid));
      const response_2 = await receive(response_queue_uuid);
      if (response_2 !== fetch_successful_response) {
        reject(`Blob URL wasn't fetched in same-top-level-site service worker: ${response_2}`);
      }
      resolve();
    } catch (e) {
      reject(e);
    }
  });
}, "Blob URL shouldn't be fetched from a cross-partition service worker");

</script>
</body>