gecko-dev/testing/web-platform/tests/storage/storagemanager-estimate.https.any.js
Joshua Bell 2d0b83d996 Bug 1486832 [wpt PR 12723] - Storage API: Use .any.js (etc) in Web Platform Tests, a=testonly
Automatic update from web-platform-testsStorage API: Use .any.js (etc) in Web Platform Tests

Use ".any.js" tests [1] rather than redundant files for window and
worker variations, and increase coverage where window-only tests
existed. Also use ".worker.js" and ".window.js" to eliminate some
boilerplate. The one manual test is left untouched for ease of
running... manually.

[1] https://web-platform-tests.org/writing-tests/testharness.html

Change-Id: I7be790e0134854c804dbf82072589f07fa6e0bfb
Reviewed-on: https://chromium-review.googlesource.com/1194324
Reviewed-by: Chase Phillips <cmp@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586773}

--

wpt-commits: ba92a402d8f994a92c73b22a153fd7aea89247c3
wpt-pr: 12723
2018-09-05 13:08:33 +00:00

60 lines
2.2 KiB
JavaScript

// 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_true(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');