tor-browser

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

shared-storage-writable-fetch-request-in-sandboxed-frame.tentative.https.html (3283B)


      1 <!doctype html>
      2 <body>
      3  <script src=/resources/testharness.js></script>
      4  <script src=/resources/testharnessreport.js></script>
      5  <script src=/common/utils.js></script>
      6  <script src=/fenced-frame/resources/utils.js></script>
      7  <script src=/shared-storage/resources/util.js></script>
      8  <script>
      9    async function
     10      test_shared_storage_writable_fetch_request_in_sandboxed_iframe(
     11          test, key, value, sandbox_flags, expect_success) {
     12      // Create sandboxed iframe.
     13      let frame = document.createElement('iframe');
     14      frame.sandbox = sandbox_flags;
     15      let url = new URL(
     16        '/shared-storage/resources/'
     17        + 'shared-storage-writable-fetch-request-in-sandboxed-iframe-'
     18        + 'inner.https.sub.html',
     19        location.href);
     20      url = appendExpectedKeyAndValue(url, key, value);
     21      frame.src = url;
     22 
     23      // We expect a message to bubble up via the sandboxed iframe.
     24      const promise = new Promise((resolve, reject) => {
     25        window.addEventListener('message', async function handler(evt) {
     26          if (evt.source === frame.contentWindow &&
     27              evt.data.sharedStorageFetchStatus) {
     28            if (expect_success) {
     29              assert_true(!!evt.data.sharedStorageWritableHeader,
     30                          "sharedStorageWritableHeader expected in event data");
     31              assert_equals(evt.data.sharedStorageWritableHeader, '?1');
     32              assert_equals(evt.data.sharedStorageFetchStatus, "success");
     33            } else {
     34              assert_equals(evt.data.sharedStorageFetchStatus.toString(),
     35                            "TypeError: Failed to execute 'fetch' on 'Window':"
     36                            + " sharedStorageWritable: sharedStorage operations"
     37                            + " are not available for opaque origins.");
     38            }
     39            document.body.removeChild(frame);
     40            window.removeEventListener('message', handler);
     41            resolve();
     42          }
     43        });
     44        window.addEventListener('error', () => {
     45          reject(new Error('Navigation error'));
     46        });
     47      });
     48 
     49      // Navigate and wait for notification.
     50      document.body.appendChild(frame);
     51      await promise;
     52 
     53      if (expect_success) {
     54        // Verify that the value has been set.
     55        await verifyKeyValueForOrigin(key, value, location.origin);
     56      } else {
     57        // Verify that the value has not been set.
     58        await verifyKeyNotFoundForOrigin(key, location.origin);
     59      }
     60 
     61      // Clean up and finish.
     62      await sharedStorage.delete(key);
     63      test.done();
     64    }
     65 
     66    async_test(t => {
     67      test_shared_storage_writable_fetch_request_in_sandboxed_iframe(
     68        t,
     69        /*key=*/'a',
     70        /*value=*/'b',
     71        /*sandbox_flags=*/'allow-scripts allow-same-origin',
     72        /*expect_success=*/true);
     73    }, 'test sharedStorageWritable fetch request in sandboxed iframe with '
     74         + '"allow-same-origin"');
     75 
     76    async_test(t => {
     77      test_shared_storage_writable_fetch_request_in_sandboxed_iframe(
     78        t,
     79        /*key=*/'c',
     80        /*value=*/'d',
     81        /*sandbox_flags=*/'allow-scripts',
     82        /*expect_success=*/true);
     83    }, 'test sharedStorageWritable fetch request in sandboxed iframe without '
     84         + '"allow-same-origin"');
     85  </script>
     86 </body>