Skip to content

Commit

Permalink
Bug 1860683 [wpt PR 42700] - Deduplicate some WPT., a=testonly
Browse files Browse the repository at this point in the history
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 whatwg/storage#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 <estade@chromium.org>
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1214324}

--

wpt-commits: 446b9bce1ca9a174c11c64f4faa077a9e9d22e72
wpt-pr: 42700
  • Loading branch information
Evan Stade authored and moz-wptsync-bot committed Nov 6, 2023
1 parent 9d12f81 commit 8b892fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 71 deletions.
17 changes: 2 additions & 15 deletions testing/web-platform/tests/storage/estimate-indexeddb.https.any.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
// 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');

// 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";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,16 @@
// META: title=StorageManager: estimate()

test(function(t) {
assert_true(navigator.storage.estimate() instanceof Promise);
}, 'estimate() method returns a Promise');
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(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');
});
promise_test(async t => {
const result = await navigator.storage.estimate();
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');

0 comments on commit 8b892fa

Please sign in to comment.