tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

controller-with-no-fetch-event-handler.https.html (1826B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Service Worker: controller without a fetch event handler</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/common/get-host-info.sub.js"></script>
      7 <script src="resources/test-helpers.sub.js?pipe=sub"></script>
      8 <body>
      9 <script>
     10 let registration;
     11 let frame;
     12 const host_info = get_host_info();
     13 const remote_base_url =
     14    new URL(`${host_info.HTTPS_REMOTE_ORIGIN}${base_path()}resources/`);
     15 
     16 promise_test(async t => {
     17  const script = 'resources/empty.js'
     18  const scope = 'resources/';
     19 
     20  promise_test(async t => {
     21    if (frame)
     22      frame.remove();
     23 
     24    if (registration)
     25      await registration.unregister();
     26  }, 'cleanup global state');
     27 
     28  registration = await
     29      service_worker_unregister_and_register(t, script, scope);
     30  await wait_for_state(t, registration.installing, 'activated');
     31  frame = await with_iframe(scope + 'blank.html');
     32 }, 'global setup');
     33 
     34 promise_test(async t => {
     35    const url = new URL('cors-approved.txt', remote_base_url);
     36    const response = await frame.contentWindow.fetch(url, {mode:'no-cors'});
     37    const text = await response.text();
     38    assert_equals(text, '');
     39 }, 'cross-origin request, no-cors mode');
     40 
     41 
     42 promise_test(async t => {
     43    const url = new URL('cors-denied.txt', remote_base_url);
     44    const response = frame.contentWindow.fetch(url);
     45    await promise_rejects_js(t, frame.contentWindow.TypeError, response);
     46 }, 'cross-origin request, cors denied');
     47 
     48 promise_test(async t => {
     49    const url = new URL('cors-approved.txt', remote_base_url);
     50    response = await frame.contentWindow.fetch(url);
     51    let text = await response.text();
     52    text = text.trim();
     53    assert_equals(text, 'plaintext');
     54 }, 'cross-origin request, cors approved');
     55 </script>
     56 </body>