OLD | NEW |
---|---|
(Empty) | |
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-esti mate"> | |
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); | |
pwnall
2017/04/04 21:08:34
I think you can remove some boilerplate by using c
jsbell
2017/04/05 15:57:27
Don't want a test in storage/ to depend on Indexed
| |
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 large IndexedDB record is stored'); | |
pwnall
2017/04/04 21:08:34
large -> 1MB?
jsbell
2017/04/05 16:58:12
Done.
| |
67 | |
68 </script> | |
OLD | NEW |