Files
firefox/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js
Evan Stade 9ac8958689 Bug 1860683 [wpt PR 42700] - Deduplicate some WPT., a=testonly
Automatic update from web-platform-tests
Deduplicate some WPT.

storagemanager-estimate and estimate-indexeddb are more or less the
same tests, the latter having been ported from the former to use
`async`/`await`. The former probably should have been deleted when the
latter was introduced.

Since some of the tests are related to IndexedDB and some are not, this
change keeps the IndexedDB tests in the file called `estimate-indexeddb`
and keeps the basic tests in `storagemanager-estimate` (with minor
updates).

One wrinkle from the Chromium side is that the behavior of
`storageManager.estimate()` is not actually specced, and as the Chromium
implementation uses LevelDB, which behaves in mysterious ways, adding
things to the database does NOT always increase the reported usage size.
Both of these tests operate on large things, which typically do increase
usage, however we noticed that for one reason or another, the test that
adds an *uninitialized* ArrayBuffer starts failing on Windows if
durability is set to relaxed. There are other ways to make the test fail
as well: using a shorter name for the database, or putting small
values, does not reliably increase the reported usage. This is all fine
in the sense that it isn't defined behavior, but it does suggest that
working in this area or on tests of this ilk is a bit of a minefield.
These tests probably should not exist as WPT, at least not until quota
behavior is specced (see https://github.com/whatwg/storage/issues/110).
But it would also be sort of a shame to delete WPT that are passing, so
I've left them in place for now.

Bug: 1489517
Change-Id: I6619f504ce92e428054691ac6bf54a0e14e3ce5f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4968659
Commit-Queue: Evan Stade <[email protected]>
Reviewed-by: Ayu Ishii <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1214324}

--

wpt-commits: 446b9bce1ca9a174c11c64f4faa077a9e9d22e72
wpt-pr: 42700
2023-11-06 09:06:08 +00:00

49 lines
1.6 KiB
JavaScript

// META: title=StorageManager: estimate() for indexeddb
// META: script=/storage/buckets/resources/util.js
// Technically, this verifies unspecced behavior. See
// https://github.com/whatwg/storage/issues/110 for defining this behavior.
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');