forked from mirrors/gecko-dev
Automatic update from web-platform-tests Adds partitioned storage manager estimate() usage tests. This CL contains WPTs test coverage for estimate() usage details of caches, indexedDB, service workers storages. ToDo: The expectation files for the virtual test suite will need to be updated once the partitioning of these APIs is completed and the tests are finally passing, as it's to be expected when third party storage partitioning is enabled. Change-Id: I02049498372bbb924578e989ef388b249f764b0e Bug: 1322922 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3614147 Reviewed-by: Mike Taylor <miketaylr@chromium.org> Commit-Queue: Jonathan Njeunje <njeunje@chromium.org> Reviewed-by: Stephen Chenney <schenney@chromium.org> Cr-Commit-Position: refs/heads/main@{#1000541} -- wpt-commits: 30a8cb8ae22e9d8c0a2b036e6fb10a348fd4c8a8 wpt-pr: 33843
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
/**
|
|
* @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();
|
|
};
|
|
});
|
|
}
|