From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- testing/web-platform/tests/storage/META.yml | 4 + testing/web-platform/tests/storage/README.md | 7 ++ .../web-platform/tests/storage/buckets/META.yml | 5 + .../tests/storage/estimate-indexeddb.https.any.js | 101 +++++++++++++++++++++ .../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 +++ testing/web-platform/tests/storage/helpers.js | 46 ++++++++++ .../tests/storage/idlharness.https.any.js | 18 ++++ .../tests/storage/opaque-origin.https.window.js | 80 ++++++++++++++++ ...e-usage-details-caches.tentative.https.sub.html | 69 ++++++++++++++ ...sage-details-indexeddb.tentative.https.sub.html | 82 +++++++++++++++++ ...etails-service-workers.tentative.https.sub.html | 86 ++++++++++++++++++ .../tests/storage/permission-query.https.any.js | 10 ++ .../storage/persist-permission-manual.https.html | 27 ++++++ .../tests/storage/persisted.https.any.js | 14 +++ ...achange-in-detached-iframe.tentative.https.html | 21 +++++ ...estimate-usage-details-caches-helper-frame.html | 28 ++++++ ...imate-usage-details-indexeddb-helper-frame.html | 26 ++++++ ...usage-details-service-workers-helper-frame.html | 28 ++++++ .../web-platform/tests/storage/resources/worker.js | 3 + .../storage/storagemanager-estimate.https.any.js | 60 ++++++++++++ .../storage/storagemanager-persist.https.window.js | 10 ++ .../storage/storagemanager-persist.https.worker.js | 8 ++ .../storage/storagemanager-persisted.https.any.js | 10 ++ 27 files changed, 885 insertions(+) create mode 100644 testing/web-platform/tests/storage/META.yml create mode 100644 testing/web-platform/tests/storage/README.md create mode 100644 testing/web-platform/tests/storage/buckets/META.yml create mode 100644 testing/web-platform/tests/storage/estimate-indexeddb.https.any.js create mode 100644 testing/web-platform/tests/storage/estimate-parallel.https.any.js create mode 100644 testing/web-platform/tests/storage/estimate-usage-details-caches.https.tentative.any.js create mode 100644 testing/web-platform/tests/storage/estimate-usage-details-indexeddb.https.tentative.any.js create mode 100644 testing/web-platform/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js create mode 100644 testing/web-platform/tests/storage/estimate-usage-details.https.tentative.any.js create mode 100644 testing/web-platform/tests/storage/helpers.js create mode 100644 testing/web-platform/tests/storage/idlharness.https.any.js create mode 100644 testing/web-platform/tests/storage/opaque-origin.https.window.js create mode 100644 testing/web-platform/tests/storage/partitioned-estimate-usage-details-caches.tentative.https.sub.html create mode 100644 testing/web-platform/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html create mode 100644 testing/web-platform/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html create mode 100644 testing/web-platform/tests/storage/permission-query.https.any.js create mode 100644 testing/web-platform/tests/storage/persist-permission-manual.https.html create mode 100644 testing/web-platform/tests/storage/persisted.https.any.js create mode 100644 testing/web-platform/tests/storage/quotachange-in-detached-iframe.tentative.https.html create mode 100644 testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html create mode 100644 testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html create mode 100644 testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html create mode 100644 testing/web-platform/tests/storage/resources/worker.js create mode 100644 testing/web-platform/tests/storage/storagemanager-estimate.https.any.js create mode 100644 testing/web-platform/tests/storage/storagemanager-persist.https.window.js create mode 100644 testing/web-platform/tests/storage/storagemanager-persist.https.worker.js create mode 100644 testing/web-platform/tests/storage/storagemanager-persisted.https.any.js (limited to 'testing/web-platform/tests/storage') diff --git a/testing/web-platform/tests/storage/META.yml b/testing/web-platform/tests/storage/META.yml new file mode 100644 index 0000000000..2aad1fb513 --- /dev/null +++ b/testing/web-platform/tests/storage/META.yml @@ -0,0 +1,4 @@ +spec: https://storage.spec.whatwg.org/ +suggested_reviewers: + - annevk + - inexorabletash diff --git a/testing/web-platform/tests/storage/README.md b/testing/web-platform/tests/storage/README.md new file mode 100644 index 0000000000..8d0dca31b4 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/buckets/META.yml b/testing/web-platform/tests/storage/buckets/META.yml new file mode 100644 index 0000000000..4f215060f5 --- /dev/null +++ b/testing/web-platform/tests/storage/buckets/META.yml @@ -0,0 +1,5 @@ +spec: https://github.com/WICG/storage-buckets +suggested_reviewers: + - ayui + - jsbell + - pwnall diff --git a/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js b/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js new file mode 100644 index 0000000000..b0c6b944dd --- /dev/null +++ b/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js @@ -0,0 +1,101 @@ +// META: title=StorageManager: estimate() for indexeddb + +function indexedDbOpenRequest(t, dbname, upgrade_func) { + return new Promise((resolve, reject) => { + const openRequest = indexedDB.open(dbname); + t.add_cleanup(() => { + indexedDbDeleteRequest(dbname); + }); + + openRequest.onerror = () => { + reject(openRequest.error); + }; + openRequest.onsuccess = () => { + resolve(openRequest.result); + }; + openRequest.onupgradeneeded = event => { + upgrade_func(openRequest.result); + }; + }); +} + +function indexedDbDeleteRequest(name) { + return new Promise((resolve, reject) => { + const deleteRequest = indexedDB.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(); + }; + }); +} + +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(dbname); + let estimate = await navigator.storage.estimate(); + + const usageBeforeCreate = estimate.usage; + const db = await indexedDbOpenRequest(t, 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/testing/web-platform/tests/storage/estimate-parallel.https.any.js b/testing/web-platform/tests/storage/estimate-parallel.https.any.js new file mode 100644 index 0000000000..090f004b85 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/estimate-usage-details-caches.https.tentative.any.js b/testing/web-platform/tests/storage/estimate-usage-details-caches.https.tentative.any.js new file mode 100644 index 0000000000..bf889f8418 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/estimate-usage-details-indexeddb.https.tentative.any.js b/testing/web-platform/tests/storage/estimate-usage-details-indexeddb.https.tentative.any.js new file mode 100644 index 0000000000..551cede9c6 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js b/testing/web-platform/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js new file mode 100644 index 0000000000..cf3a2aa943 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/estimate-usage-details.https.tentative.any.js b/testing/web-platform/tests/storage/estimate-usage-details.https.tentative.any.js new file mode 100644 index 0000000000..2a1cea5fb8 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/helpers.js b/testing/web-platform/tests/storage/helpers.js new file mode 100644 index 0000000000..b524c1b82c --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/idlharness.https.any.js b/testing/web-platform/tests/storage/idlharness.https.any.js new file mode 100644 index 0000000000..773fac4e4a --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/opaque-origin.https.window.js b/testing/web-platform/tests/storage/opaque-origin.https.window.js new file mode 100644 index 0000000000..cc1d31fdf2 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html b/testing/web-platform/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html new file mode 100644 index 0000000000..a58d542654 --- /dev/null +++ b/testing/web-platform/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html @@ -0,0 +1,82 @@ + + +Partitioned estimate() usage details for indexeddb test + + + + + + + + + diff --git a/testing/web-platform/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html b/testing/web-platform/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html new file mode 100644 index 0000000000..9f283e300a --- /dev/null +++ b/testing/web-platform/tests/storage/partitioned-estimate-usage-details-service-workers.tentative.https.sub.html @@ -0,0 +1,86 @@ + + +Partitioned estimate() usage details for service workers test + + + + + + diff --git a/testing/web-platform/tests/storage/permission-query.https.any.js b/testing/web-platform/tests/storage/permission-query.https.any.js new file mode 100644 index 0000000000..9984bdab79 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/persist-permission-manual.https.html b/testing/web-platform/tests/storage/persist-permission-manual.https.html new file mode 100644 index 0000000000..aa49900d69 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/persisted.https.any.js b/testing/web-platform/tests/storage/persisted.https.any.js new file mode 100644 index 0000000000..57e15f0e81 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/quotachange-in-detached-iframe.tentative.https.html b/testing/web-platform/tests/storage/quotachange-in-detached-iframe.tentative.https.html new file mode 100644 index 0000000000..123af50e3c --- /dev/null +++ b/testing/web-platform/tests/storage/quotachange-in-detached-iframe.tentative.https.html @@ -0,0 +1,21 @@ + + +quotachange event on DOMWindow of detached iframe + + + + + diff --git a/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html b/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html new file mode 100644 index 0000000000..13786d7cea --- /dev/null +++ b/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-caches-helper-frame.html @@ -0,0 +1,28 @@ + + + +Helper frame + + diff --git a/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html b/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html new file mode 100644 index 0000000000..80f9cca27d --- /dev/null +++ b/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-indexeddb-helper-frame.html @@ -0,0 +1,26 @@ + + +Helper frame + + diff --git a/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html b/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html new file mode 100644 index 0000000000..29d91a95d7 --- /dev/null +++ b/testing/web-platform/tests/storage/resources/partitioned-estimate-usage-details-service-workers-helper-frame.html @@ -0,0 +1,28 @@ + + +Helper frame + + diff --git a/testing/web-platform/tests/storage/resources/worker.js b/testing/web-platform/tests/storage/resources/worker.js new file mode 100644 index 0000000000..9271c769b2 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/storagemanager-estimate.https.any.js b/testing/web-platform/tests/storage/storagemanager-estimate.https.any.js new file mode 100644 index 0000000000..c2f5c569dc --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/storagemanager-persist.https.window.js b/testing/web-platform/tests/storage/storagemanager-persist.https.window.js new file mode 100644 index 0000000000..13e17a16e1 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/storagemanager-persist.https.worker.js b/testing/web-platform/tests/storage/storagemanager-persist.https.worker.js new file mode 100644 index 0000000000..fcf8175f70 --- /dev/null +++ b/testing/web-platform/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/testing/web-platform/tests/storage/storagemanager-persisted.https.any.js b/testing/web-platform/tests/storage/storagemanager-persisted.https.any.js new file mode 100644 index 0000000000..7099940669 --- /dev/null +++ b/testing/web-platform/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