Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1845)

Side by Side Diff: third_party/WebKit/LayoutTests/storage/quota/storagemanager-estimate.html

Issue 1855623002: Implement quota estimation API from Storage spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>StorageManager: estimate()</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script src="resources/testharness-helpers.js"></script>
6 <script>
7
8 test(function(t) {
9 assert_true('estimate' in window.navigator.storage);
10 assert_equals(typeof window.navigator.storage.estimate, 'function');
11 assert_true(window.navigator.storage.estimate() instanceof Promise);
12 }, 'estimate() method exists and returns a Promise');
13
14 promise_test(function(t) {
15 return window.navigator.storage.estimate().then(function(result) {
16 assert_true(typeof result === 'object');
17 assert_true('usage' in result);
18 assert_equals(typeof result.usage, 'number');
19 assert_true('quota' in result);
20 assert_equals(typeof result.quota, 'number');
21 });
22 }, 'estimate() resolves to dictionary with members');
23
24
25 // Simple Promise wrappers for IndexedDB to make async testing easier.
26 function deleteDB(name) {
27 return new Promise(function(resolve, reject) {
28 var del = indexedDB.deleteDatabase(name);
29 del.onerror = function() { reject(del.error); };
30 del.onsuccess = function() { resolve(); };
31 });
32 }
33 function openDB(name, upgrade) {
34 return new Promise(function(resolve, reject) {
35 var open = indexedDB.open(name);
36 open.onerror = function() { reject(open.error); };
37 open.onupgradeneeded = function() { upgrade(open.result); };
38 open.onsuccess = function() { resolve(open.result); };
39 });
40 }
41 function transactionToPromise(tx) {
42 return new Promise(function(resolve, reject) {
43 tx.onabort = function() { reject(tx.error); };
44 tx.oncomplete = function() { resolve(); };
45 });
46 }
47
48 promise_test(function(t) {
49 var large_value = new Uint8Array(1e6);
50 var dbname = 'db' + window.location;
51 var db, before, after;
52
53 return deleteDB(name)
54 .then(() => openDB(name, db => { db.createObjectStore('store'); }))
55 .then(connection => {
56 db = connection;
57 return navigator.storage.estimate();
58 })
59 .then(estimate => {
60 before = estimate.usage;
61 var tx = db.transaction('store', 'readwrite');
62 tx.objectStore('store').put(large_value, 'k');
63 return transactionToPromise(tx);
64 })
65 .then(() => {
66 return navigator.storage.estimate();
67 })
68 .then(estimate => {
69 after = estimate.usage;
70 assert_greater_than(after, before,
71 'estimated usage should increase');
72 // This assertion may not hold, e.g. if the implementation compresse s
73 // the data or pre-allocate blocks larger than the value being store d.
74 assert_greater_than_equal(after - before, large_value.length,
75 'increase should be at least as large as value stored');
76
77 db.close();
78 return deleteDB(name);
79 });
80 }, 'estimate() shows usage increase after large value is stored');
81
82 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698