tor-browser

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

storage-access-beyond-cookies.localStorage.sub.https.window.js (1822B)


      1 // META: script=/resources/testdriver.js
      2 // META: script=/resources/testdriver-vendor.js
      3 
      4 'use strict';
      5 
      6 // Here's the set-up for this test:
      7 // Step 1 (top-frame) Set up listener for "HasAccess" message and set data for window_event if so.
      8 // Step 2 (top-frame) Add data to first-party local storage and set up listener for handle_event.
      9 // Step 3 (top-frame) Embed an iframe that's cross-site with top-frame.
     10 // Step 4 (sub-frame) Try to use storage access API and read first-party data.
     11 // Step 5 (sub-frame) Embed an iframe that's same-origin with top-frame.
     12 // Step 6 (sub-sub-frame) Try to use storage access API and read first-party data.
     13 // Step 7 (sub-sub-frame) Send "HasAccess for localStorage" message to top-frame.
     14 // Step 8 (top-frame) Expect new data to be set and properly trigger listener.
     15 
     16 async_test(t => {
     17  // Step 1
     18  window.addEventListener("message", t.step_func(e => {
     19    if (e.data.type != "result") {
     20      return;
     21    }
     22    assert_equals(e.data.message, "HasAccess for localStorage", "Storage Access API should be accessible and return first-party data");
     23    window.localStorage.setItem("window_event", id);
     24  }));
     25 
     26  // Step 2
     27  const id = String(Date.now());
     28  window.localStorage.setItem("test", id);
     29  window.addEventListener("storage", t.step_func(e => {
     30    if (e.key == "handle_event") {
     31      // Step 8
     32      assert_equals(e.newValue, id);
     33      assert_equals(e.storageArea, window.localStorage);
     34      window.localStorage.clear();
     35      t.done();
     36    }
     37  }));
     38 
     39  // Step 3
     40  let iframe = document.createElement("iframe");
     41  iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=localStorage&id="+id;
     42  document.body.appendChild(iframe);
     43 }, "Verify StorageAccessAPIBeyondCookies for Local Storage");