storage-buckets.tentative.https.any.js (1907B)
1 // META: title=Web Locks API: Storage Buckets have independent lock sets 2 // META: script=resources/helpers.js 3 // META: script=/storage/buckets/resources/util.js 4 // META: global=window,dedicatedworker,sharedworker,serviceworker 5 6 'use strict'; 7 8 /** 9 * Returns whether bucket1 and bucket2 share locks 10 * @param {*} t test runner object 11 * @param {*} bucket1 Storage bucket 12 * @param {*} bucket2 Storage bucket 13 */ 14 async function locksAreShared(t, bucket1, bucket2) { 15 const lock_name = self.uniqueName(t); 16 let callback_called = false; 17 let locks_are_shared; 18 await bucket1.locks.request(lock_name, async lock => { 19 await bucket2.locks.request( 20 lock_name, { ifAvailable: true }, async lock => { 21 callback_called = true; 22 locks_are_shared = lock == null; 23 }); 24 }); 25 assert_true(callback_called, 'callback should be called'); 26 return locks_are_shared; 27 } 28 29 promise_test(async t => { 30 await prepareForBucketTest(t); 31 32 const inboxBucket = await navigator.storageBuckets.open('inbox'); 33 const draftsBucket = await navigator.storageBuckets.open('drafts'); 34 35 assert_true( 36 await locksAreShared(t, navigator, navigator), 37 'The default bucket should share locks with itself'); 38 39 assert_true( 40 await locksAreShared(t, inboxBucket, inboxBucket), 41 'A non default bucket should share locks with itself'); 42 43 assert_false( 44 await locksAreShared(t, navigator, inboxBucket), 45 'The default bucket shouldn\'t share locks with a non default bucket'); 46 47 assert_false( 48 await locksAreShared(t, draftsBucket, inboxBucket), 49 'Two different non default buckets shouldn\'t share locks'); 50 51 const inboxBucket2 = await navigator.storageBuckets.open('inbox'); 52 53 assert_true( 54 await self.locksAreShared(t, inboxBucket, inboxBucket2), 55 'A two instances of the same non default bucket should share locks with theirselves'); 56 }, 'Storage buckets have independent locks');