Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/storage/quota/storagemanager-estimate.html |
| diff --git a/third_party/WebKit/LayoutTests/storage/quota/storagemanager-estimate.html b/third_party/WebKit/LayoutTests/storage/quota/storagemanager-estimate.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3d00e0684c0b0e84bc0394521033d8320e898d8f |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/storage/quota/storagemanager-estimate.html |
| @@ -0,0 +1,77 @@ |
| +<!DOCTYPE html> |
| +<title>StorageManager: estimate()</title> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="resources/testharness-helpers.js"></script> |
| +<script> |
| + |
| +test(function(t) { |
| + assert_true('estimate' in window.navigator.storage); |
| + assert_equals(typeof window.navigator.storage.estimate, 'function'); |
| + assert_true(window.navigator.storage.estimate() instanceof Promise); |
| +}, 'estimate() method exists and returns a Promise'); |
| + |
| +promise_test(function(t) { |
| + return window.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'); |
| + |
| + |
| +// Simple Promise wrappers for IndexedDB to make async testing easier. |
| +function deleteDB(name) { |
| + return new Promise(function(resolve, reject) { |
| + var del = indexedDB.deleteDatabase(name); |
| + del.onerror = function() { reject(del.error); }; |
| + del.onsuccess = function() { resolve(); }; |
| + }); |
| +} |
| +function openDB(name, upgrade) { |
| + return new Promise(function(resolve, reject) { |
| + var open = indexedDB.open(name); |
| + open.onerror = function() { reject(open.error); }; |
| + open.onupgradeneeded = function() { upgrade(open.result); }; |
| + open.onsuccess = function() { resolve(open.result); }; |
| + }); |
| +} |
| +function transactionToPromise(tx) { |
| + return new Promise(function(resolve, reject) { |
| + tx.onabort = function() { reject(tx.error); }; |
| + tx.oncomplete = function() { resolve(); }; |
| + }); |
| +} |
| + |
| +promise_test(function(t) { |
| + var large_value = new Uint8Array(1e6); |
| + var dbname = 'db' + window.location; |
| + var db, before, after; |
| + |
| + return deleteDB(name) |
| + .then(() => openDB(name, db => { db.createObjectStore('store'); })) |
| + .then(connection => { |
| + db = connection; |
| + return navigator.storage.estimate(); |
| + }) |
| + .then(estimate => { |
| + before = estimate.usage; |
| + var tx = db.transaction('store', 'readwrite'); |
| + tx.objectStore('store').put(large_value, 'k'); |
| + return transactionToPromise(tx); |
| + }) |
| + .then(() => { |
| + return navigator.storage.estimate(); |
| + }) |
| + .then(estimate => { |
| + after = estimate.usage; |
| + assert_greater_than(after, before, |
| + 'estimated usage should increase'); |
| + assert_greater_than_equal(after - before, large_value.length, |
| + 'increase should be at least as large as value stored'); |
|
kinuko
2016/04/20 05:56:32
This may not always hold depending on implementati
jsbell
2016/04/20 19:38:04
Done.
|
| + }); |
|
kinuko
2016/04/20 05:56:32
not sure how other idb/storage tests are doing tod
jsbell
2016/04/20 19:38:04
I do delete the database before (deleteDB above) b
|
| +}, 'estimate() shows usage increase after large value is stored'); |
| + |
| +</script> |