tor-browser

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

web-locks-worklet-modifier-method.tentative.https.sub.html (2924B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="/common/utils.js"></script>
      5 <script src="/shared-storage/resources/util.js"></script>
      6 <script src="/fenced-frame/resources/utils.js"></script>
      7 
      8 <body>
      9 <script>
     10 'use strict';
     11 
     12 promise_test(async t => {
     13  let worklet1 = await sharedStorage.createWorklet('resources/simple-module.js');
     14  let worklet2 = await sharedStorage.createWorklet('resources/simple-module.js');
     15 
     16  const ancestor_key1 = token();
     17  let url1_0 = generateURL("/shared-storage/resources/frame0.html",
     18                         [ancestor_key1]);
     19  let url1_1 = generateURL("/shared-storage/resources/frame1.html",
     20                         [ancestor_key1]);
     21 
     22  const ancestor_key2 = token();
     23  let url2_0 = generateURL("/shared-storage/resources/frame0.html",
     24                         [ancestor_key2]);
     25  let url2_1 = generateURL("/shared-storage/resources/frame1.html",
     26                         [ancestor_key2]);
     27 
     28  // Invoke `selectURL()` to perform the following steps:
     29  // 1. Acquires the lock.
     30  // 2. Reads the current value at the given key.
     31  // 3. Waits for 500ms.
     32  // 4. Sets the shared storage value to the read value appended with the given letter.
     33  // 5. Releases the lock.
     34  //
     35  // In parallel, invoke another `selectURL()`, which subsequently invokes
     36  // `sharedStorage.append()` with the same lock and the same letter to append.
     37  //
     38  // Expected behavior: After both of them finish, the value at the given key
     39  // should contain the letter repeated twice.
     40  //
     41  // Note: This test remains valid even if the `append()` call happens outside
     42  // the critical section protected by the lock within the worklet. The test
     43  // effectively demonstrates mutual exclusion as long as there's a reasonable
     44  // chance for `append()` to occur while the worklet is still running.
     45  let select_url_result1 = await worklet1.selectURL(
     46      "get-wait-set-within-lock",
     47      [{url: url1_0}, {url: url1_1}],
     48      {data: {'key': 'key',
     49              'lock_name': 'lock1',
     50              'append_letter': 'a'},
     51      resolveToConfig: true});
     52 
     53  let select_url_result2 = await worklet2.selectURL(
     54      "append-with-lock-option",
     55      [{url: url2_0}, {url: url2_1}],
     56      {data: {'key': 'key',
     57              'lock_name': 'lock1',
     58              'append_letter': 'a'},
     59      resolveToConfig: true});
     60 
     61  attachFencedFrame(select_url_result1, 'opaque-ads');
     62  const result1 = await nextValueFromServer(ancestor_key1);
     63  assert_equals(result1, "frame1_loaded");
     64 
     65  attachFencedFrame(select_url_result2, 'opaque-ads');
     66  const result2 = await nextValueFromServer(ancestor_key2);
     67  assert_equals(result2, "frame1_loaded");
     68 
     69  await verifyKeyValueForOrigin('key', 'aa', location.origin);
     70 
     71  await deleteKeyForOrigin('key', location.origin);
     72 }, 'Test for withLock option in a SharedStorageWorklet context');
     73 
     74 </script>
     75 </body>