Skip to content

Commit 66b0c40

Browse files
inexorabletash
authored and
committed
Upstream StorageManager estimate() test to WPT
BUG=692147 Review-Url: https://codereview.chromium.org/2791963004 Cr-Commit-Position: refs/heads/master@{#462147}
1 parent af6f835 commit 66b0c40

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Diff for: storage/storagemanager-estimate.https.html

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!DOCTYPE html>
2+
<meta charset=utf-8>
3+
<title>StorageManager: estimate()</title>
4+
<meta name="help" href="https://storage.spec.whatwg.org/#dom-storagemanager-estimate">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script>
8+
9+
test(function(t) {
10+
assert_true(navigator.storage.estimate() instanceof Promise);
11+
}, 'estimate() method returns a Promise');
12+
13+
promise_test(function(t) {
14+
return navigator.storage.estimate().then(function(result) {
15+
assert_true(typeof result === 'object');
16+
assert_true('usage' in result);
17+
assert_equals(typeof result.usage, 'number');
18+
assert_true('quota' in result);
19+
assert_equals(typeof result.quota, 'number');
20+
});
21+
}, 'estimate() resolves to dictionary with members');
22+
23+
promise_test(function(t) {
24+
const large_value = new Uint8Array(1e6);
25+
const dbname = `db-${location}-${t.name}`;
26+
let db, before, after;
27+
28+
indexedDB.deleteDatabase(dbname);
29+
return new Promise((resolve, reject) => {
30+
const open = indexedDB.open(dbname);
31+
open.onerror = () => { reject(open.error); };
32+
open.onupgradeneeded = () => {
33+
const connection = open.result;
34+
connection.createObjectStore('store');
35+
};
36+
open.onsuccess = () => {
37+
const connection = open.result;
38+
t.add_cleanup(() => {
39+
connection.close();
40+
indexedDB.deleteDatabase(dbname);
41+
});
42+
resolve(connection);
43+
};
44+
})
45+
.then(connection => {
46+
db = connection;
47+
return navigator.storage.estimate();
48+
})
49+
.then(estimate => {
50+
before = estimate.usage;
51+
return new Promise((resolve, reject) => {
52+
const tx = db.transaction('store', 'readwrite');
53+
tx.objectStore('store').put(large_value, 'key');
54+
tx.onabort = () => { reject(tx.error); };
55+
tx.oncomplete = () => { resolve(); };
56+
});
57+
})
58+
.then(() => {
59+
return navigator.storage.estimate();
60+
})
61+
.then(estimate => {
62+
after = estimate.usage;
63+
assert_greater_than(after, before,
64+
'estimated usage should increase');
65+
});
66+
}, 'estimate() shows usage increase after 1MB IndexedDB record is stored');
67+
68+
</script>

0 commit comments

Comments
 (0)