tor-browser

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

samesite-cookies.https.html (2290B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <meta name="timeout" content="long">
      4 <title>Navigation Preload: SameSite cookies</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="../resources/test-helpers.sub.js"></script>
      8 <body>
      9 <script>
     10 const scope = 'resources/cookie.py';
     11 const script = 'resources/navigation-preload-worker.js';
     12 
     13 async function drop_cookie(t, same_site, cookie) {
     14    const frame = await with_iframe(scope + '?same-site=' + same_site + '&cookie-name=' + cookie + '&drop=1');
     15    t.add_cleanup(() => frame.remove());
     16 }
     17 
     18 async function same_site_cookies_test(t, same_site, cookie) {
     19  // Remove the cookie before the first visit.
     20  await drop_cookie(t, same_site, cookie);
     21 
     22  {
     23    const frame = await with_iframe(scope + '?same-site=' + same_site + '&cookie-name=' + cookie + '&drop=0');
     24    t.add_cleanup(() => frame.remove());
     25    // The body will be 0 because this is the first visit.
     26    assert_equals(frame.contentDocument.body.textContent, '0', 'first visit');
     27  }
     28 
     29  {
     30    const frame = await with_iframe(scope + '?same-site=' + same_site + '&cookie-name=' + cookie + '&drop=0');
     31    t.add_cleanup(() => frame.remove());
     32    // The body will be 1 because this is the second visit.
     33    assert_equals(frame.contentDocument.body.textContent, '1', 'second visit');
     34  }
     35 
     36  // Remove the cookie after the test.
     37  t.add_cleanup(() => drop_cookie(t, same_site, cookie));
     38 }
     39 
     40 promise_test(async t => {
     41  const registration =
     42    await service_worker_unregister_and_register(t, script, scope);
     43  promise_test(t => registration.unregister(), 'Unregister a service worker.');
     44 
     45  await wait_for_state(t, registration.installing, 'activated');
     46  await registration.navigationPreload.enable();
     47 }, 'Set up a service worker for navigation preload tests.');
     48 
     49 promise_test(async t => {
     50  await same_site_cookies_test(t, 'None', 'cookie-key-none');
     51 }, 'Navigation Preload for same site cookies (None).');
     52 
     53 promise_test(async t => {
     54  await same_site_cookies_test(t, 'Strict', 'cookie-key-strict');
     55 }, 'Navigation Preload for same site cookies (Strict).');
     56 
     57 promise_test(async t => {
     58  await same_site_cookies_test(t, 'Lax', 'cookie-key-lax');
     59 }, 'Navigation Preload for same site cookies (Lax).');
     60 </script>
     61 </body>