From 0b6210cd37b68b94252cb798598b12974a20e1c1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 21 May 2024 22:56:19 +0200 Subject: Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3. Signed-off-by: Daniel Baumann --- test/wpt/tests/storage/META.yml | 4 + test/wpt/tests/storage/README.md | 7 ++ test/wpt/tests/storage/buckets/META.yml | 5 ++ .../bucket-quota-indexeddb.tentative.https.any.js | 35 +++++++++ .../bucket-storage-policy.tentative.https.any.js | 21 ++++++ .../storage/buckets/resources/cached-resource.txt | 1 + test/wpt/tests/storage/buckets/resources/util.js | 57 ++++++++++++++ .../tests/storage/estimate-indexeddb.https.any.js | 61 +++++++++++++++ .../tests/storage/estimate-parallel.https.any.js | 13 ++++ ...ate-usage-details-caches.https.tentative.any.js | 20 +++++ ...-usage-details-indexeddb.https.tentative.any.js | 59 +++++++++++++++ ...tails-service-workers.https.tentative.window.js | 38 ++++++++++ .../estimate-usage-details.https.tentative.any.js | 12 +++ test/wpt/tests/storage/helpers.js | 46 +++++++++++ test/wpt/tests/storage/idlharness.https.any.js | 18 +++++ .../tests/storage/opaque-origin.https.window.js | 80 ++++++++++++++++++++ ...e-usage-details-caches.tentative.https.sub.html | 74 ++++++++++++++++++ ...sage-details-indexeddb.tentative.https.sub.html | 84 +++++++++++++++++++++ ...etails-service-workers.tentative.https.sub.html | 88 ++++++++++++++++++++++ .../tests/storage/permission-query.https.any.js | 10 +++ .../storage/persist-permission-manual.https.html | 27 +++++++ test/wpt/tests/storage/persisted.https.any.js | 14 ++++ ...achange-in-detached-iframe.tentative.https.html | 21 ++++++ ...estimate-usage-details-caches-helper-frame.html | 30 ++++++++ ...imate-usage-details-indexeddb-helper-frame.html | 28 +++++++ ...usage-details-service-workers-helper-frame.html | 30 ++++++++ test/wpt/tests/storage/resources/worker.js | 3 + .../storage/storagemanager-estimate.https.any.js | 60 +++++++++++++++ ...agemanager-persist-persisted-match.https.any.js | 9 +++ .../storage/storagemanager-persist.https.window.js | 10 +++ .../storage/storagemanager-persist.https.worker.js | 8 ++ .../storage/storagemanager-persisted.https.any.js | 10 +++ 32 files changed, 983 insertions(+) create mode 100644 test/wpt/tests/storage/META.yml create mode 100644 test/wpt/tests/storage/README.md create mode 100644 test/wpt/tests/storage/buckets/META.yml create mode 100644 test/wpt/tests/storage/buckets/bucket-quota-indexeddb.tentative.https.any.js create mode 100644 test/wpt/tests/storage/buckets/bucket-storage-policy.tentative.https.any.js create mode 100644 test/wpt/tests/storage/buckets/resources/cached-resource.txt create mode 100644 test/wpt/tests/storage/buckets/resources/util.js create mode 100644 test/wpt/tests/storage/estimate-indexeddb.https.any.js create mode 100644 test/wpt/tests/storage/estimate-parallel.https.any.js create mode 100644 test/wpt/tests/storage/estimate-usage-details-caches.https.tentative.any.js create mode 100644 test/wpt/tests/storage/estimate-usage-details-indexeddb.https.tentative.any.js create mode 100644 test/wpt/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js create mode 100644 test/wpt/tests/storage/estimate-usage-details.https.tentative.any.js create mode 100644 test/wpt/tests/storage/helpers.js create mode 100644 test/wpt/tests/storage/idlharness.https.any.js create mode 100644 test/wpt/tests/storage/opaque-origin.https.window.js create mode 100644 test/wpt/tests/storage/partitioned-estimate-usage-details-caches.tentative.https.sub.html create mode 100644 test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html create mode 100644 test/wpt/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html create mode 100644 test/wpt/tests/storage/permission-query.https.any.js create mode 100644 test/wpt/tests/storage/persist-permission-manual.https.html create mode 100644 test/wpt/tests/storage/persisted.https.any.js create mode 100644 test/wpt/tests/storage/quotachange-in-detached-iframe.tentative.https.html create mode 100644 test/wpt/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html create mode 100644 test/wpt/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html create mode 100644 test/wpt/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html create mode 100644 test/wpt/tests/storage/resources/worker.js create mode 100644 test/wpt/tests/storage/storagemanager-estimate.https.any.js create mode 100644 test/wpt/tests/storage/storagemanager-persist-persisted-match.https.any.js create mode 100644 test/wpt/tests/storage/storagemanager-persist.https.window.js create mode 100644 test/wpt/tests/storage/storagemanager-persist.https.worker.js create mode 100644 test/wpt/tests/storage/storagemanager-persisted.https.any.js (limited to 'test/wpt/tests/storage') diff --git a/test/wpt/tests/storage/META.yml b/test/wpt/tests/storage/META.yml new file mode 100644 index 0000000..2aad1fb --- /dev/null +++ b/test/wpt/tests/storage/META.yml @@ -0,0 +1,4 @@ +spec: https://storage.spec.whatwg.org/ +suggested_reviewers: + - annevk + - inexorabletash diff --git a/test/wpt/tests/storage/README.md b/test/wpt/tests/storage/README.md new file mode 100644 index 0000000..8d0dca3 --- /dev/null +++ b/test/wpt/tests/storage/README.md @@ -0,0 +1,7 @@ +This directory contains the Storage test suite. + +To run the tests in this test suite within a browser, go to: . + +The living standard is: + +The API is at: diff --git a/test/wpt/tests/storage/buckets/META.yml b/test/wpt/tests/storage/buckets/META.yml new file mode 100644 index 0000000..4f21506 --- /dev/null +++ b/test/wpt/tests/storage/buckets/META.yml @@ -0,0 +1,5 @@ +spec: https://github.com/WICG/storage-buckets +suggested_reviewers: + - ayui + - jsbell + - pwnall diff --git a/test/wpt/tests/storage/buckets/bucket-quota-indexeddb.tentative.https.any.js b/test/wpt/tests/storage/buckets/bucket-quota-indexeddb.tentative.https.any.js new file mode 100644 index 0000000..ba82edb --- /dev/null +++ b/test/wpt/tests/storage/buckets/bucket-quota-indexeddb.tentative.https.any.js @@ -0,0 +1,35 @@ +// META: title=Bucket quota enforcement for indexeddb +// META: script=/storage/buckets/resources/util.js + +promise_test(async t => { + const arraySize = 1e6; + const objectStoreName = "storageManager"; + const dbname = + this.window ? window.location.pathname : 'estimate-worker.https.html'; + + let quota = arraySize / 2; + const bucket = await navigator.storageBuckets.open('idb', {quota}); + + await indexedDbDeleteRequest(bucket.indexedDB, dbname); + + const db = + await indexedDbOpenRequest(t, bucket.indexedDB, dbname, (db_to_upgrade) => { + db_to_upgrade.createObjectStore(objectStoreName); + }); + + const txn = db.transaction(objectStoreName, 'readwrite'); + const buffer = new ArrayBuffer(arraySize); + const view = new Uint8Array(buffer); + + for (let i = 0; i < arraySize; i++) { + view[i] = Math.floor(Math.random() * 255); + } + + const testBlob = new Blob([buffer], {type: 'binary/random'}); + txn.objectStore(objectStoreName).add(testBlob, 1); + + await promise_rejects_dom( + t, 'QuotaExceededError', transactionPromise(txn)); + + db.close(); +}, 'IDB respects bucket quota'); diff --git a/test/wpt/tests/storage/buckets/bucket-storage-policy.tentative.https.any.js b/test/wpt/tests/storage/buckets/bucket-storage-policy.tentative.https.any.js new file mode 100644 index 0000000..d6dce36 --- /dev/null +++ b/test/wpt/tests/storage/buckets/bucket-storage-policy.tentative.https.any.js @@ -0,0 +1,21 @@ +// META: title=Buckets API: Tests for bucket storage policies. +// META: script=/storage/buckets/resources/util.js +// META: global=window,worker + +'use strict'; + +promise_test(async testCase => { + await prepareForBucketTest(testCase); + + await promise_rejects_js( + testCase, TypeError, + navigator.storageBuckets.open('negative', {quota: -1})); + + await promise_rejects_js( + testCase, TypeError, navigator.storageBuckets.open('zero', {quota: 0})); + + await promise_rejects_js( + testCase, TypeError, + navigator.storageBuckets.open( + 'above_max', {quota: Number.MAX_SAFE_INTEGER + 1})); +}, 'The open promise should reject with a TypeError when quota is requested outside the range of 1 to Number.MAX_SAFE_INTEGER.'); diff --git a/test/wpt/tests/storage/buckets/resources/cached-resource.txt b/test/wpt/tests/storage/buckets/resources/cached-resource.txt new file mode 100644 index 0000000..c57eff5 --- /dev/null +++ b/test/wpt/tests/storage/buckets/resources/cached-resource.txt @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/test/wpt/tests/storage/buckets/resources/util.js b/test/wpt/tests/storage/buckets/resources/util.js new file mode 100644 index 0000000..425303c --- /dev/null +++ b/test/wpt/tests/storage/buckets/resources/util.js @@ -0,0 +1,57 @@ +'use strict'; + +// Makes sure initial bucket state is as expected and to clean up after the test +// is over (whether it passes or fails). +async function prepareForBucketTest(test) { + // Verify initial state. + assert_equals('', (await navigator.storageBuckets.keys()).join()); + // Clean up after test. + test.add_cleanup(async function() { + const keys = await navigator.storageBuckets.keys(); + for (const key of keys) { + await navigator.storageBuckets.delete(key); + } + }); +} + +function indexedDbOpenRequest(t, idb, dbname, upgrade_func) { + return new Promise((resolve, reject) => { + const openRequest = idb.open(dbname); + t.add_cleanup(() => { + indexedDbDeleteRequest(idb, dbname); + }); + + openRequest.onerror = () => { + reject(openRequest.error); + }; + openRequest.onsuccess = () => { + resolve(openRequest.result); + }; + openRequest.onupgradeneeded = event => { + upgrade_func(openRequest.result); + }; + }); +} + +function indexedDbDeleteRequest(idb, name) { + return new Promise((resolve, reject) => { + const deleteRequest = idb.deleteDatabase(name); + deleteRequest.onerror = () => { + reject(deleteRequest.error); + }; + deleteRequest.onsuccess = () => { + resolve(); + }; + }); +} + +function transactionPromise(txn) { + return new Promise((resolve, reject) => { + txn.onabort = () => { + reject(txn.error); + }; + txn.oncomplete = () => { + resolve(); + }; + }); +} diff --git a/test/wpt/tests/storage/estimate-indexeddb.https.any.js b/test/wpt/tests/storage/estimate-indexeddb.https.any.js new file mode 100644 index 0000000..f0b82b9 --- /dev/null +++ b/test/wpt/tests/storage/estimate-indexeddb.https.any.js @@ -0,0 +1,61 @@ +// META: title=StorageManager: estimate() for indexeddb +// META: script=/storage/buckets/resources/util.js + +test(t => { + assert_true('estimate' in navigator.storage); + assert_equals(typeof navigator.storage.estimate, 'function'); + assert_true(navigator.storage.estimate() instanceof Promise); +}, 'estimate() method exists and returns a Promise'); + +promise_test(async t => { + const estimate = await navigator.storage.estimate(); + assert_equals(typeof estimate, 'object'); + assert_true('usage' in estimate); + assert_equals(typeof estimate.usage, 'number'); + assert_true('quota' in estimate); + assert_equals(typeof estimate.quota, 'number'); +}, 'estimate() resolves to dictionary with members'); + +promise_test(async t => { + const arraySize = 1e6; + const objectStoreName = "storageManager"; + const dbname = + this.window ? window.location.pathname : 'estimate-worker.https.html'; + + await indexedDbDeleteRequest(indexedDB, dbname); + let estimate = await navigator.storage.estimate(); + + const usageBeforeCreate = estimate.usage; + const db = + await indexedDbOpenRequest(t, indexedDB, dbname, (db_to_upgrade) => { + db_to_upgrade.createObjectStore(objectStoreName); + }); + + estimate = await navigator.storage.estimate(); + const usageAfterCreate = estimate.usage; + + assert_greater_than( + usageAfterCreate, usageBeforeCreate, + 'estimated usage should increase after object store is created'); + + const txn = db.transaction(objectStoreName, 'readwrite'); + const buffer = new ArrayBuffer(arraySize); + const view = new Uint8Array(buffer); + + for (let i = 0; i < arraySize; i++) { + view[i] = Math.floor(Math.random() * 255); + } + + const testBlob = new Blob([buffer], {type: 'binary/random'}); + txn.objectStore(objectStoreName).add(testBlob, 1); + + await transactionPromise(txn); + + estimate = await navigator.storage.estimate(); + const usageAfterPut = estimate.usage; + assert_greater_than( + usageAfterPut, usageAfterCreate, + 'estimated usage should increase after large value is stored'); + + db.close(); +}, 'estimate() shows usage increase after large value is stored'); diff --git a/test/wpt/tests/storage/estimate-parallel.https.any.js b/test/wpt/tests/storage/estimate-parallel.https.any.js new file mode 100644 index 0000000..090f004 --- /dev/null +++ b/test/wpt/tests/storage/estimate-parallel.https.any.js @@ -0,0 +1,13 @@ +// META: title=StorageManager: multiple estimate() calls in parallel + +promise_test(async t => { + let r1, r2; + await Promise.all([ + navigator.storage.estimate().then(r => { r1 = r; }), + navigator.storage.estimate().then(r => { r2 = r; }) + ]); + assert_true(('usage' in r1) && ('quota' in r1), + 'first response should have expected fields'); + assert_true(('usage' in r2) && ('quota' in r2), + 'second response should have expected fields'); +}, 'Multiple estimate() calls in parallel should complete'); diff --git a/test/wpt/tests/storage/estimate-usage-details-caches.https.tentative.any.js b/test/wpt/tests/storage/estimate-usage-details-caches.https.tentative.any.js new file mode 100644 index 0000000..bf889f8 --- /dev/null +++ b/test/wpt/tests/storage/estimate-usage-details-caches.https.tentative.any.js @@ -0,0 +1,20 @@ +// META: title=StorageManager: estimate() for caches + +promise_test(async t => { + let estimate = await navigator.storage.estimate(); + + const cachesUsageBeforeCreate = estimate.usageDetails.caches || 0; + + const cacheName = 'testCache'; + const cache = await caches.open(cacheName); + t.add_cleanup(() => caches.delete(cacheName)); + + await cache.put('/test.json', new Response('x'.repeat(1024*1024))); + + estimate = await navigator.storage.estimate(); + assert_true('caches' in estimate.usageDetails); + const cachesUsageAfterPut = estimate.usageDetails.caches; + assert_greater_than( + cachesUsageAfterPut, cachesUsageBeforeCreate, + 'estimated usage should increase after value is stored'); +}, 'estimate() shows usage increase after large value is stored'); diff --git a/test/wpt/tests/storage/estimate-usage-details-indexeddb.https.tentative.any.js b/test/wpt/tests/storage/estimate-usage-details-indexeddb.https.tentative.any.js new file mode 100644 index 0000000..551cede --- /dev/null +++ b/test/wpt/tests/storage/estimate-usage-details-indexeddb.https.tentative.any.js @@ -0,0 +1,59 @@ +// META: title=StorageManager: estimate() usage details for indexeddb +// META: script=helpers.js +// META: script=../IndexedDB/resources/support-promises.js + +promise_test(async t => { + const estimate = await navigator.storage.estimate() + assert_equals(typeof estimate.usageDetails, 'object'); +}, 'estimate() resolves to dictionary with usageDetails member'); + +promise_test(async t => { + // We use 100KB here because db compaction usually happens every few MB + // 100KB is large enough to avoid a false positive (small amounts of metadata + // getting written for some random reason), and small enough to avoid + // compaction with a reasonably high probability. + const writeSize = 1024 * 100; + const objectStoreName = 'store'; + const dbname = self.location.pathname; + + await indexedDB.deleteDatabase(dbname); + let usageAfterWrite, usageBeforeWrite; + // TODO(crbug.com/906867): Refactor this test to better deal with db/log + // compaction flakiness + // The for loop here is to help make this test less flaky. The reason it is + // flaky is that database and/or log compaction could happen in the middle of + // this loop. The problem is that this test runs in a large batch of tests, + // and previous tests might have created a lot of garbage which could trigger + // compaction. Suppose the initial estimate shows 1MB usage before creating + // the db. Compaction could happen after this step and before we measure + // usage at the end, meaning the 1MB could be wiped to 0, an extra 1024 * 100 + // is put in, and the actual increase in usage does not reach our expected + // increase. Loop 10 times here to be safe (and reduce the number of bot + // builds that fail); all it takes is one iteration without compaction for + // this to pass. + for (let i = 0; i < 10; i++) { + const db = await createDB(dbname, objectStoreName, t); + let estimate = await navigator.storage.estimate(); + + // If usage is 0, usageDetails does not include the usage (undefined) + usageBeforeWrite = estimate.usageDetails.indexedDB || 0; + + const txn = db.transaction(objectStoreName, 'readwrite'); + const valueToStore = largeValue(writeSize, Math.random() * 255); + txn.objectStore(objectStoreName).add(valueToStore, 1); + + await transactionPromise(txn); + + estimate = await navigator.storage.estimate(); + usageAfterWrite = estimate.usageDetails.indexedDB; + db.close(); + + if (usageAfterWrite - usageBeforeWrite >= writeSize) { + break; + } + } + + assert_greater_than_equal(usageAfterWrite - usageBeforeWrite, + writeSize); +}, 'estimate() usage details reflects increase in indexedDB after large ' + + 'value is stored'); diff --git a/test/wpt/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js b/test/wpt/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js new file mode 100644 index 0000000..cf3a2aa --- /dev/null +++ b/test/wpt/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js @@ -0,0 +1,38 @@ +// META: title=StorageManager: estimate() for service worker registrations +const wait_for_active = worker => new Promise(resolve =>{ + if (worker.active) { resolve(worker.active); } + + const listen_for_active = worker => e => { + if (e.target.state === 'activated') { resolve(worker.active); } + } + + if (worker.waiting) { + worker.waiting + .addEventListener('statechange', listen_for_active(worker.waiting)); + } + if (worker.installing) { + worker.installing + .addEventListener('statechange', listen_for_active(worker.installing)); + } +}); + +promise_test(async t => { + let estimate = await navigator.storage.estimate(); + const usageBeforeCreate = estimate.usageDetails.serviceWorkerRegistrations || + 0; + // Note: helpers.js is an arbitrary file; it could be any file that + // exists, but this test does not depend on the contents of said file. + const serviceWorkerRegistration = await + navigator.serviceWorker.register('./helpers.js'); + + t.add_cleanup(() => serviceWorkerRegistration.unregister()); + await wait_for_active(serviceWorkerRegistration); + + estimate = await navigator.storage.estimate(); + assert_true('serviceWorkerRegistrations' in estimate.usageDetails); + + const usageAfterCreate = estimate.usageDetails.serviceWorkerRegistrations; + assert_greater_than( + usageAfterCreate, usageBeforeCreate, + 'estimated usage should increase after service worker is registered'); +}, 'estimate() shows usage increase after large value is stored'); diff --git a/test/wpt/tests/storage/estimate-usage-details.https.tentative.any.js b/test/wpt/tests/storage/estimate-usage-details.https.tentative.any.js new file mode 100644 index 0000000..2a1cea5 --- /dev/null +++ b/test/wpt/tests/storage/estimate-usage-details.https.tentative.any.js @@ -0,0 +1,12 @@ +// META: title=StorageManager: estimate() should have usage details + +promise_test(async t => { + const estimate = await navigator.storage.estimate(); + assert_equals(typeof estimate, 'object'); + assert_true('usage' in estimate); + assert_equals(typeof estimate.usage, 'number'); + assert_true('quota' in estimate); + assert_equals(typeof estimate.quota, 'number'); + assert_true('usageDetails' in estimate); + assert_equals(typeof estimate.usageDetails, 'object'); +}, 'estimate() resolves to dictionary with members, including usageDetails'); diff --git a/test/wpt/tests/storage/helpers.js b/test/wpt/tests/storage/helpers.js new file mode 100644 index 0000000..b524c1b --- /dev/null +++ b/test/wpt/tests/storage/helpers.js @@ -0,0 +1,46 @@ +/** + * @description - Function will create a database with the supplied name + * and also create an object store with the specified name. + * If a db with the name dbName exists, this will raze the + * existing DB beforehand. + * @param {string} dbName + * @param {string} objectStoreName + * @param {testCase} t + * @returns {Promise} - A promise that resolves to an indexedDB open request + */ +function createDB(dbName, objectStoreName, t) { + return new Promise((resolve, reject) => { + const openRequest = indexedDB.open(dbName); + t.add_cleanup(() => { + indexedDB.deleteDatabase(dbName); + }); + openRequest.onerror = () => { + reject(openRequest.error); + }; + openRequest.onsuccess = () => { + resolve(openRequest.result); + }; + openRequest.onupgradeneeded = (event) => { + openRequest.result.createObjectStore(objectStoreName); + }; + }); +} + +/** + * @description - This function will wrap an IDBTransaction in a promise, + * resolving in the oncomplete() method and rejecting with the + * transaction error in the onabort() case. + * @param {IDBTransaction} transaction - The transaction to wrap in a promise. + * @returns {Promise} - A promise that resolves when the transaction is either + * aborted or completed. + */ +function transactionPromise(transaction) { + return new Promise((resolve, reject) => { + transaction.onabort = () => { + reject(transaction.error); + }; + transaction.oncomplete = () => { + resolve(); + }; + }); +} diff --git a/test/wpt/tests/storage/idlharness.https.any.js b/test/wpt/tests/storage/idlharness.https.any.js new file mode 100644 index 0000000..773fac4 --- /dev/null +++ b/test/wpt/tests/storage/idlharness.https.any.js @@ -0,0 +1,18 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +'use strict'; + +idl_test( + ['storage'], + ['html'], + idl_array => { + idl_array.add_objects({ StorageManager: ['navigator.storage'] }); + if (self.Window) { + idl_array.add_objects({ Navigator: ['navigator'] }); + } else { + idl_array.add_objects({ WorkerNavigator: ['navigator'] }); + } + } +); diff --git a/test/wpt/tests/storage/opaque-origin.https.window.js b/test/wpt/tests/storage/opaque-origin.https.window.js new file mode 100644 index 0000000..cc1d31f --- /dev/null +++ b/test/wpt/tests/storage/opaque-origin.https.window.js @@ -0,0 +1,80 @@ +// META: title=StorageManager API and opaque origins + +function load_iframe(src, sandbox) { + return new Promise(resolve => { + const iframe = document.createElement('iframe'); + iframe.onload = () => { resolve(iframe); }; + if (sandbox) + iframe.sandbox = sandbox; + iframe.srcdoc = src; + iframe.style.display = 'none'; + document.documentElement.appendChild(iframe); + }); +} + +function wait_for_message(iframe) { + return new Promise(resolve => { + self.addEventListener('message', function listener(e) { + if (e.source === iframe.contentWindow && "result" in e.data) { + resolve(e.data); + self.removeEventListener('message', listener); + } + }); + }); +} + +function make_script(snippet) { + return '' + + ' + + + + + + diff --git a/test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html b/test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html new file mode 100644 index 0000000..98a1ed8 --- /dev/null +++ b/test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html @@ -0,0 +1,84 @@ + + +Partitioned estimate() usage details for indexeddb test + + + + + + + + + diff --git a/test/wpt/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html b/test/wpt/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html new file mode 100644 index 0000000..c52ca34 --- /dev/null +++ b/test/wpt/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html @@ -0,0 +1,88 @@ + + +Partitioned estimate() usage details for service workers test + + + + + + diff --git a/test/wpt/tests/storage/permission-query.https.any.js b/test/wpt/tests/storage/permission-query.https.any.js new file mode 100644 index 0000000..9984bda --- /dev/null +++ b/test/wpt/tests/storage/permission-query.https.any.js @@ -0,0 +1,10 @@ +// META: title=The Permission API registration for "persistent-storage" + +promise_test(async t => { + const status = + await navigator.permissions.query({name: 'persistent-storage'}); + assert_equals(status.constructor, PermissionStatus, + 'query() result should resolve to a PermissionStatus'); + assert_true(['granted','denied', 'prompt'].includes(status.state), + 'state should be a PermissionState'); +}, 'The "persistent-storage" permission is recognized'); diff --git a/test/wpt/tests/storage/persist-permission-manual.https.html b/test/wpt/tests/storage/persist-permission-manual.https.html new file mode 100644 index 0000000..aa49900 --- /dev/null +++ b/test/wpt/tests/storage/persist-permission-manual.https.html @@ -0,0 +1,27 @@ + + + + + StorageManager: permission state is granted +

Clear all persistent storage permissions before running this test.

+

Test passes if there is a permission prompt and click allow store persistent data

+ + + + + + + + + diff --git a/test/wpt/tests/storage/persisted.https.any.js b/test/wpt/tests/storage/persisted.https.any.js new file mode 100644 index 0000000..57e15f0 --- /dev/null +++ b/test/wpt/tests/storage/persisted.https.any.js @@ -0,0 +1,14 @@ +// META: title=StorageManager: persisted() + +test(function(t) { + assert_true('persisted' in navigator.storage); + assert_equals(typeof navigator.storage.persisted, 'function'); + assert_true(navigator.storage.persisted() instanceof Promise); +}, 'persisted() method exists and returns a Promise'); + +promise_test(function(t) { + return navigator.storage.persisted().then(function(result) { + assert_equals(typeof result, 'boolean'); + assert_equals(result, false); + }); +}, 'persisted() returns a promise and resolves as boolean with false'); diff --git a/test/wpt/tests/storage/quotachange-in-detached-iframe.tentative.https.html b/test/wpt/tests/storage/quotachange-in-detached-iframe.tentative.https.html new file mode 100644 index 0000000..123af50 --- /dev/null +++ b/test/wpt/tests/storage/quotachange-in-detached-iframe.tentative.https.html @@ -0,0 +1,21 @@ + + +quotachange event on DOMWindow of detached iframe + + + + + diff --git a/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html b/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html new file mode 100644 index 0000000..0679c1d --- /dev/null +++ b/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html @@ -0,0 +1,30 @@ + + + +Helper frame + + diff --git a/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html b/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html new file mode 100644 index 0000000..fd2cfb6 --- /dev/null +++ b/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html @@ -0,0 +1,28 @@ + + +Helper frame + + diff --git a/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html b/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html new file mode 100644 index 0000000..25d7554 --- /dev/null +++ b/test/wpt/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html @@ -0,0 +1,30 @@ + + +Helper frame + + diff --git a/test/wpt/tests/storage/resources/worker.js b/test/wpt/tests/storage/resources/worker.js new file mode 100644 index 0000000..9271c76 --- /dev/null +++ b/test/wpt/tests/storage/resources/worker.js @@ -0,0 +1,3 @@ +// Dummy service worker to observe some weight when querying the storage usage +// details from of the service worker from estimate(). +globalThis.oninstall = e => {}; diff --git a/test/wpt/tests/storage/storagemanager-estimate.https.any.js b/test/wpt/tests/storage/storagemanager-estimate.https.any.js new file mode 100644 index 0000000..c2f5c56 --- /dev/null +++ b/test/wpt/tests/storage/storagemanager-estimate.https.any.js @@ -0,0 +1,60 @@ +// META: title=StorageManager: estimate() + +test(function(t) { + assert_true(navigator.storage.estimate() instanceof Promise); +}, 'estimate() method returns a Promise'); + +promise_test(function(t) { + return navigator.storage.estimate().then(function(result) { + assert_equals(typeof result, 'object'); + assert_true('usage' in result); + assert_equals(typeof result.usage, 'number'); + assert_true('quota' in result); + assert_equals(typeof result.quota, 'number'); + }); +}, 'estimate() resolves to dictionary with members'); + +promise_test(function(t) { + const large_value = new Uint8Array(1e6); + const dbname = `db-${location}-${t.name}`; + let db, before, after; + + indexedDB.deleteDatabase(dbname); + return new Promise((resolve, reject) => { + const open = indexedDB.open(dbname); + open.onerror = () => { reject(open.error); }; + open.onupgradeneeded = () => { + const connection = open.result; + connection.createObjectStore('store'); + }; + open.onsuccess = () => { + const connection = open.result; + t.add_cleanup(() => { + connection.close(); + indexedDB.deleteDatabase(dbname); + }); + resolve(connection); + }; + }) + .then(connection => { + db = connection; + return navigator.storage.estimate(); + }) + .then(estimate => { + before = estimate.usage; + return new Promise((resolve, reject) => { + const tx = db.transaction('store', 'readwrite'); + tx.objectStore('store').put(large_value, 'key'); + tx.onabort = () => { reject(tx.error); }; + tx.oncomplete = () => { resolve(); }; + }); + }) + .then(() => { + return navigator.storage.estimate(); + }) + .then(estimate => { + after = estimate.usage; + assert_greater_than(after, before, + 'estimated usage should increase'); + }); +}, 'estimate() shows usage increase after 1MB IndexedDB record is stored'); diff --git a/test/wpt/tests/storage/storagemanager-persist-persisted-match.https.any.js b/test/wpt/tests/storage/storagemanager-persist-persisted-match.https.any.js new file mode 100644 index 0000000..edbe67f --- /dev/null +++ b/test/wpt/tests/storage/storagemanager-persist-persisted-match.https.any.js @@ -0,0 +1,9 @@ +// META: title=StorageManager: result of persist() matches result of persisted() + +promise_test(async t => { + var persistResult = await navigator.storage.persist(); + assert_equals(typeof persistResult, 'boolean', persistResult + ' should be boolean'); + var persistedResult = await navigator.storage.persisted(); + assert_equals(typeof persistedResult, 'boolean', persistedResult + ' should be boolean'); + assert_equals(persistResult, persistedResult); +}, 'navigator.storage.persist() resolves to a value that matches navigator.storage.persisted()'); diff --git a/test/wpt/tests/storage/storagemanager-persist.https.window.js b/test/wpt/tests/storage/storagemanager-persist.https.window.js new file mode 100644 index 0000000..13e17a1 --- /dev/null +++ b/test/wpt/tests/storage/storagemanager-persist.https.window.js @@ -0,0 +1,10 @@ +// META: title=StorageManager: persist() + +promise_test(function() { + var promise = navigator.storage.persist(); + assert_true(promise instanceof Promise, + 'navigator.storage.persist() returned a Promise.'); + return promise.then(function(result) { + assert_equals(typeof result, 'boolean', result + ' should be boolean'); + }); +}, 'navigator.storage.persist() returns a promise that resolves.'); diff --git a/test/wpt/tests/storage/storagemanager-persist.https.worker.js b/test/wpt/tests/storage/storagemanager-persist.https.worker.js new file mode 100644 index 0000000..fcf8175 --- /dev/null +++ b/test/wpt/tests/storage/storagemanager-persist.https.worker.js @@ -0,0 +1,8 @@ +// META: title=StorageManager: persist() (worker) +importScripts("/resources/testharness.js"); + +test(function() { + assert_false('persist' in navigator.storage); +}, 'navigator.storage.persist should not exist in workers'); + +done(); diff --git a/test/wpt/tests/storage/storagemanager-persisted.https.any.js b/test/wpt/tests/storage/storagemanager-persisted.https.any.js new file mode 100644 index 0000000..7099940 --- /dev/null +++ b/test/wpt/tests/storage/storagemanager-persisted.https.any.js @@ -0,0 +1,10 @@ +// META: title=StorageManager: persisted() + +promise_test(function() { + var promise = navigator.storage.persisted(); + assert_true(promise instanceof Promise, + 'navigator.storage.persisted() returned a Promise.'); + return promise.then(function (result) { + assert_equals(typeof result, 'boolean', result + ' should be boolean'); + }); +}, 'navigator.storage.persisted() returns a promise that resolves.'); -- cgit v1.2.3