tor-browser

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

fetch-event-respond-with-custom-response.https.html (2957B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>respondWith with a new Response</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="resources/test-helpers.sub.js"></script>
      7 <script>
      8 'use strict';
      9 
     10 const WORKER =
     11  'resources/fetch-event-respond-with-custom-response-worker.js';
     12 const SCOPE =
     13  'resources/blank.html';
     14 
     15 // Register a service worker, then create an iframe at url.
     16 function iframeTest(url, callback, name) {
     17  return promise_test(async t => {
     18    const reg = await service_worker_unregister_and_register(t, WORKER, SCOPE);
     19    add_completion_callback(() => reg.unregister());
     20    await wait_for_state(t, reg.installing, 'activated');
     21    const iframe = await with_iframe(url);
     22    const iwin = iframe.contentWindow;
     23    t.add_cleanup(() => iframe.remove());
     24    await callback(t, iwin);
     25  }, name);
     26 }
     27 
     28 iframeTest(SCOPE, async (t, iwin) => {
     29  const response = await iwin.fetch('?type=string');
     30  assert_equals(await response.text(), 'PASS');
     31 }, 'Subresource built from a string');
     32 
     33 iframeTest(SCOPE, async (t, iwin) => {
     34  const response = await iwin.fetch('?type=blob');
     35  assert_equals(await response.text(), 'PASS');
     36 }, 'Subresource built from a blob');
     37 
     38 iframeTest(SCOPE, async (t, iwin) => {
     39  const response = await iwin.fetch('?type=buffer');
     40  assert_equals(await response.text(), 'PASS');
     41 }, 'Subresource built from a buffer');
     42 
     43 iframeTest(SCOPE, async (t, iwin) => {
     44  const response = await iwin.fetch('?type=buffer-view');
     45  assert_equals(await response.text(), 'PASS');
     46 }, 'Subresource built from a buffer-view');
     47 
     48 iframeTest(SCOPE, async (t, iwin) => {
     49  const response = await iwin.fetch('?type=form-data');
     50  const data = await response.formData();
     51  assert_equals(data.get('result'), 'PASS');
     52 }, 'Subresource built from form-data');
     53 
     54 iframeTest(SCOPE, async (t, iwin) => {
     55  const response = await iwin.fetch('?type=search-params');
     56  assert_equals(await response.text(), 'result=PASS');
     57 }, 'Subresource built from search-params');
     58 
     59 // As above, but navigations
     60 
     61 iframeTest(SCOPE + '?type=string', (t, iwin) => {
     62  assert_equals(iwin.document.body.textContent, 'PASS');
     63 }, 'Navigation resource built from a string');
     64 
     65 iframeTest(SCOPE + '?type=blob', (t, iwin) => {
     66  assert_equals(iwin.document.body.textContent, 'PASS');
     67 }, 'Navigation resource built from a blob');
     68 
     69 iframeTest(SCOPE + '?type=buffer', (t, iwin) => {
     70  assert_equals(iwin.document.body.textContent, 'PASS');
     71 }, 'Navigation resource built from a buffer');
     72 
     73 iframeTest(SCOPE + '?type=buffer-view', (t, iwin) => {
     74  assert_equals(iwin.document.body.textContent, 'PASS');
     75 }, 'Navigation resource built from a buffer-view');
     76 
     77 // Note: not testing form data for a navigation as the boundary header is lost.
     78 
     79 iframeTest(SCOPE + '?type=search-params', (t, iwin) => {
     80  assert_equals(iwin.document.body.textContent, 'result=PASS');
     81 }, 'Navigation resource built from search-params');
     82 </script>