From 8b892fa3f1dad8aa83a37dd877544a6d9d43f5dd Mon Sep 17 00:00:00 2001 From: Evan Stade Date: Wed, 1 Nov 2023 08:56:38 +0000 Subject: [PATCH] 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 Reviewed-by: Ayu Ishii Cr-Commit-Position: refs/heads/main@{#1214324} -- wpt-commits: 446b9bce1ca9a174c11c64f4faa077a9e9d22e72 wpt-pr: 42700 --- .../storage/estimate-indexeddb.https.any.js | 17 +---- .../storagemanager-estimate.https.any.js | 68 ++++--------------- 2 files changed, 14 insertions(+), 71 deletions(-) diff --git a/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js b/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js index f0b82b9fa09fb..6577b021ad52e 100644 --- a/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js +++ b/testing/web-platform/tests/storage/estimate-indexeddb.https.any.js @@ -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"; diff --git a/testing/web-platform/tests/storage/storagemanager-estimate.https.any.js b/testing/web-platform/tests/storage/storagemanager-estimate.https.any.js index c2f5c569dc528..3b6f4d8edc4c2 100644 --- a/testing/web-platform/tests/storage/storagemanager-estimate.https.any.js +++ b/testing/web-platform/tests/storage/storagemanager-estimate.https.any.js @@ -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');