tor-browser

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

mode-shared.https.any.js (1314B)


      1 // META: title=Web Locks API: Shared Mode
      2 // META: global=window,dedicatedworker,sharedworker,serviceworker
      3 
      4 'use strict';
      5 
      6 promise_test(async t => {
      7  const granted = [];
      8  function log_grant(n) { return () => { granted.push(n); }; }
      9 
     10  await Promise.all([
     11    navigator.locks.request('a', {mode: 'shared'}, log_grant(1)),
     12    navigator.locks.request('b', {mode: 'shared'}, log_grant(2)),
     13    navigator.locks.request('c', {mode: 'shared'}, log_grant(3)),
     14    navigator.locks.request('a', {mode: 'shared'}, log_grant(4)),
     15    navigator.locks.request('b', {mode: 'shared'}, log_grant(5)),
     16    navigator.locks.request('c', {mode: 'shared'}, log_grant(6)),
     17  ]);
     18 
     19  assert_array_equals(granted, [1, 2, 3, 4, 5, 6]);
     20 }, 'Lock requests are granted in order');
     21 
     22 promise_test(async t => {
     23  let a_acquired = false, a_acquired_again = false;
     24 
     25  await navigator.locks.request('a', {mode: 'shared'}, async lock => {
     26    a_acquired = true;
     27 
     28    // Since lock is held, this request would be blocked if the
     29    // lock was not 'shared', causing this test to time out.
     30 
     31    await navigator.locks.request('a', {mode: 'shared'}, lock => {
     32      a_acquired_again = true;
     33    });
     34  });
     35 
     36  assert_true(a_acquired, 'first lock acquired');
     37  assert_true(a_acquired_again, 'second lock acquired');
     38 }, 'Shared locks are not exclusive');