diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/web-locks/storage-buckets.tentative.https.any.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/web-locks/storage-buckets.tentative.https.any.js')
-rw-r--r-- | testing/web-platform/tests/web-locks/storage-buckets.tentative.https.any.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-locks/storage-buckets.tentative.https.any.js b/testing/web-platform/tests/web-locks/storage-buckets.tentative.https.any.js new file mode 100644 index 0000000000..a6b4f59a95 --- /dev/null +++ b/testing/web-platform/tests/web-locks/storage-buckets.tentative.https.any.js @@ -0,0 +1,56 @@ +// META: title=Web Locks API: Storage Buckets have independent lock sets +// META: script=resources/helpers.js +// META: script=/storage/buckets/resources/util.js +// META: global=window,dedicatedworker,sharedworker,serviceworker + +'use strict'; + +/** + * Returns whether bucket1 and bucket2 share locks + * @param {*} t test runner object + * @param {*} bucket1 Storage bucket + * @param {*} bucket2 Storage bucket + */ +async function locksAreShared(t, bucket1, bucket2) { + const lock_name = self.uniqueName(t); + let callback_called = false; + let locks_are_shared; + await bucket1.locks.request(lock_name, async lock => { + await bucket2.locks.request( + lock_name, { ifAvailable: true }, async lock => { + callback_called = true; + locks_are_shared = lock == null; + }); + }); + assert_true(callback_called, 'callback should be called'); + return locks_are_shared; +} + +promise_test(async t => { + await prepareForBucketTest(t); + + const inboxBucket = await navigator.storageBuckets.open('inbox'); + const draftsBucket = await navigator.storageBuckets.open('drafts'); + + assert_true( + await locksAreShared(t, navigator, navigator), + 'The default bucket should share locks with itself'); + + assert_true( + await locksAreShared(t, inboxBucket, inboxBucket), + 'A non default bucket should share locks with itself'); + + assert_false( + await locksAreShared(t, navigator, inboxBucket), + 'The default bucket shouldn\'t share locks with a non default bucket'); + + assert_false( + await locksAreShared(t, draftsBucket, inboxBucket), + 'Two different non default buckets shouldn\'t share locks'); + + const inboxBucket2 = await navigator.storageBuckets.open('inbox'); + + assert_true( + await self.locksAreShared(t, inboxBucket, inboxBucket2), + 'A two instances of the same non default bucket should share locks with theirselves'); +}, 'Storage buckets have independent locks'); |