-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quota usage details tests for all other storage backends.
IndexedDB test was included in parent CL. Test: add test for usageDetails with caches. Change-Id: Icc3462f13d0dce0197a8ec54f22d5ad794a51292
- Loading branch information
1 parent
48d5d50
commit 69114e4
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
storage/estimate-usage-details-application-cache.https.tentative.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!doctype html> | ||
<html> | ||
<title>Quota Estimate: usage details reflect application cache changes.</title> | ||
<meta charset='utf-8'> | ||
<link rel='author' href='[email protected]' title='Jarryd Goodman'> | ||
<script src='/resources/testharness.js'></script> | ||
<script src='/resources/testharnessreport.js'></script> | ||
<script src='../cookie-store/resources/helpers.js'></script> | ||
<script> | ||
'use strict'; | ||
|
||
promise_test(async t => { | ||
const estimate = await navigator.storage.estimate(); | ||
assert_true(typeof estimate === 'object'); | ||
assert_true('usage' in estimate); | ||
assert_equals(typeof estimate.usage, 'number'); | ||
assert_true('quota' in estimate); | ||
assert_equals(typeof estimate.quota, 'number'); | ||
}, 'estimate() resolves to dictionary with members'); | ||
|
||
promise_test(async t => { | ||
let estimate = await navigator.storage.estimate(); | ||
|
||
const usageBeforeCreate = estimate.usageDetails.applicationCache || 0; | ||
|
||
const iframe = await createIframe('./resources/helper_iframe.html', t); | ||
await waitForMessage(); | ||
|
||
estimate = await navigator.storage.estimate(); | ||
assert_true('applicationCache' in estimate.usageDetails); | ||
const usageAfterCreate = estimate.usageDetails.applicationCache; | ||
|
||
assert_greater_than( | ||
usageAfterCreate, usageBeforeCreate); | ||
}, 'estimate() shows usage increase after app is cached'); | ||
</script> | ||
</html> |
20 changes: 20 additions & 0 deletions
20
storage/estimate-usage-details-caches.https.tentative.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// META: title=StorageManager: estimate() for caches | ||
|
||
promise_test(async t => { | ||
let estimate = await navigator.storage.estimate(); | ||
|
||
const cachesUsageBeforeCreate = estimate.usageDetails.caches || 0; | ||
|
||
const cacheName = 'testCache'; | ||
const cache = await caches.open(cacheName); | ||
t.add_cleanup(() => caches.delete(cacheName)); | ||
|
||
await cache.put('/test.json', new Response('x'.repeat(1024*1024))); | ||
|
||
estimate = await navigator.storage.estimate(); | ||
assert_true('caches' in estimate.usageDetails); | ||
const cachesUsageAfterPut = estimate.usageDetails.caches; | ||
assert_greater_than( | ||
cachesUsageAfterPut, cachesUsageBeforeCreate, | ||
'estimated usage should increase after value is stored'); | ||
}, 'estimate() shows usage increase after large value is stored'); |
22 changes: 22 additions & 0 deletions
22
storage/estimate-usage-details-service-workers.https.tentative.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// META: title=StorageManager: estimate() for service worker registrations | ||
|
||
promise_test(async t => { | ||
let estimate = await navigator.storage.estimate(); | ||
|
||
const usageBeforeCreate = estimate.usageDetails.serviceWorkerRegistrations || | ||
0; | ||
|
||
// Note: helpers.js is just an arbitrary selection, it could be any file | ||
// as this test does not depend on the contents of the file. | ||
const serviceWorkerRegistration = await | ||
navigator.serviceWorker.register('./helpers.js'); | ||
t.add_cleanup(() => serviceWorkerRegistration.unregister()); | ||
|
||
estimate = await navigator.storage.estimate(); | ||
assert_true('serviceWorkerRegistrations' in estimate.usageDetails); | ||
const usageAfterCreate = estimate.usageDetails.serviceWorkerRegistrations; | ||
|
||
assert_greater_than( | ||
usageAfterCreate, usageBeforeCreate, | ||
'estimated usage should increase after service worker is registered'); | ||
}, 'estimate() shows usage increase after large value is stored'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CACHE MANIFEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html manifest="appcache.manifest"> | ||
<title>Iframe that will be cached using application cache.</title> | ||
<meta charset='utf-8'> | ||
<link rel='author' href='[email protected]' title='Jarryd Goodman'> | ||
<script> | ||
(async () => { | ||
const initPromise = new Promise(resolve => { | ||
applicationCache.addEventListener('cached', resolve, false); | ||
applicationCache.addEventListener('noupdate', resolve, false); | ||
}); | ||
await initPromise; | ||
|
||
window.parent.postMessage('document cached'); | ||
})(); | ||
</script> | ||
</html> |