Reland "Add quota usage details tests for all other storage backends."
This is a reland of 548e7b5e622ad79155ff95ef26738d7a40fe9397
Original change's description:
> Add quota usage details tests for all other storage backends.
>
> IndexedDB test was included in parent CL.
>
> Bug: 904000
> Test:
> Change-Id: Icc3462f13d0dce0197a8ec54f22d5ad794a51292
> Reviewed-on: https://chromium-review.googlesource.com/c/1334659
> Reviewed-by: Victor Costan <pwnall@chromium.org>
> Reviewed-by: Joshua Bell <jsbell@chromium.org>
> Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#616398}
Bug: 904000
Change-Id: I507ec17eabc8e323a7c6418075d4be4787d4c5df
Reviewed-on: https://chromium-review.googlesource.com/c/1378805
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#617285}
diff --git a/storage/estimate-usage-details-application-cache.https.tentative.html b/storage/estimate-usage-details-application-cache.https.tentative.html
new file mode 100644
index 0000000..464a998
--- /dev/null
+++ b/storage/estimate-usage-details-application-cache.https.tentative.html
@@ -0,0 +1,29 @@
+<!doctype html>
+<html>
+<title>Quota Estimate: usage details reflect application cache changes.</title>
+<meta charset='utf-8'>
+<link rel='author' href='jarrydg@chromium.org' 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 => {
+ let estimate = await navigator.storage.estimate();
+
+ const usageBeforeCreate = estimate.usageDetails.applicationCache || 0;
+
+ const iframe = await
+ createIframe('./resources/iframe_with_appcache_manifest.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>
diff --git a/storage/estimate-usage-details-caches.https.tentative.any.js b/storage/estimate-usage-details-caches.https.tentative.any.js
new file mode 100644
index 0000000..bf889f8
--- /dev/null
+++ b/storage/estimate-usage-details-caches.https.tentative.any.js
@@ -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');
diff --git a/storage/estimate-usage-details.https.tentative.any.js b/storage/estimate-usage-details.https.tentative.any.js
new file mode 100644
index 0000000..2a1cea5
--- /dev/null
+++ b/storage/estimate-usage-details.https.tentative.any.js
@@ -0,0 +1,12 @@
+// META: title=StorageManager: estimate() should have usage details
+
+promise_test(async t => {
+ const estimate = await navigator.storage.estimate();
+ assert_equals(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');
+ assert_true('usageDetails' in estimate);
+ assert_equals(typeof estimate.usageDetails, 'object');
+}, 'estimate() resolves to dictionary with members, including usageDetails');
diff --git a/storage/resources/appcache.manifest b/storage/resources/appcache.manifest
new file mode 100644
index 0000000..ce90baf
--- /dev/null
+++ b/storage/resources/appcache.manifest
@@ -0,0 +1,3 @@
+CACHE MANIFEST
+# iframe_with_appcache_manifest.html references this manifest to get cached in
+# AppCache.
diff --git a/storage/resources/iframe_with_appcache_manifest.html b/storage/resources/iframe_with_appcache_manifest.html
new file mode 100644
index 0000000..8365ce4
--- /dev/null
+++ b/storage/resources/iframe_with_appcache_manifest.html
@@ -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='jarrydg@chromium.org' title='Jarryd Goodman'>
+<script>
+(async () => {
+ const initPromise = new Promise(resolve => {
+ applicationCache.addEventListener('cached', resolve);
+ applicationCache.addEventListener('noupdate', resolve);
+ });
+ await initPromise;
+
+ window.parent.postMessage('document cached');
+})();
+</script>
+</html>