tor-browser

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

hasStorageAccess-insecure.sub.window.js (2324B)


      1 // META: script=helpers.js
      2 'use strict';
      3 
      4 const {testPrefix, topLevelDocument} = processQueryParams();
      5 
      6 // Common tests to run in all frames.
      7 promise_test(async () => {
      8  assert_not_equals(document.hasStorageAccess, undefined);
      9 }, "[" + testPrefix + "] document.hasStorageAccess() should be supported on the document interface");
     10 
     11 promise_test(async () => {
     12  const hasAccess = await document.hasStorageAccess();
     13  assert_false(hasAccess, "Access should be disallowed in insecure contexts");
     14 }, "[" + testPrefix + "] document.hasStorageAccess() should be disallowed in insecure contexts");
     15 
     16 promise_test(async (t) => {
     17  const description = "Promise should reject when called on a generated document not part of the DOM.";
     18  const createdDocument = document.implementation.createDocument("", null);
     19 
     20  // Can't use `promise_rejects_dom` here, since the error comes from the wrong global.
     21  await createdDocument.hasStorageAccess().then(
     22    t.unreached_func("Should have rejected: " + description), (e) => {
     23      assert_equals(e.name, 'InvalidStateError', description);
     24    });
     25 }, "[" + testPrefix + "] document.hasStorageAccess() should reject in a document that isn't fully active.");
     26 
     27 // Logic to load test cases within combinations of iFrames.
     28 if (topLevelDocument) {
     29  // This specific test will run only as a top level test (not as a worker).
     30  // Specific hasStorageAccess() scenarios will be tested within the context
     31  // of various iFrames
     32 
     33  // Create a test with a single-child same-origin iframe.
     34  RunTestsInIFrame("resources/hasStorageAccess-iframe.html?testCase=same-origin-frame");
     35 
     36  // Create a test with a single-child cross-origin iframe.
     37  RunTestsInIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/resources/hasStorageAccess-iframe.html?testCase=cross-origin-frame");
     38 
     39  // Validate the nested-iframe scenario where the same-origin frame containing
     40  // the tests is not the first child.
     41  RunTestsInNestedIFrame("resources/hasStorageAccess-iframe.html?testCase=nested-same-origin-frame");
     42 
     43  // Validate the nested-iframe scenario where the cross-origin frame containing
     44  //  the tests is not the first child.
     45  RunTestsInNestedIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/resources/hasStorageAccess-iframe.html?testCase=nested-cross-origin-frame");
     46 }