Bug 1518724 [wpt PR 14756] - Quota: Test service worker registrations in StorageEstimate.usageDetails., a=testonly
authorJarryd <jarrydg@chromium.org>
Thu, 31 Jan 2019 18:55:41 +0000
changeset 457997 281cd53bc00a7f028d964cdb05cc7b2f40684348
parent 457996 b21a254b73cb3c8a7ed0067eab69de0c57ad4e8f
child 457998 c083343997d0544a73083a4deb81bbd3edf5d6a3
push id35518
push useropoprus@mozilla.com
push dateFri, 08 Feb 2019 09:55:14 +0000
treeherdermozilla-central@3a3e393396f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1518724, 14756, 1381142, 623034
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1518724 [wpt PR 14756] - Quota: Test service worker registrations in StorageEstimate.usageDetails., a=testonly Automatic update from web-platform-tests Quota: Test service worker registrations in StorageEstimate.usageDetails. Change-Id: Iaaf3910e0a9273a993053267b2a8a118c19f260a Reviewed-on: https://chromium-review.googlesource.com/c/1381142 Commit-Queue: Jarryd Goodman <jarrydg@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Cr-Commit-Position: refs/heads/master@{#623034} -- wpt-commits: 19dd778901e43bfe6e40f0d7d567e65317dc3626 wpt-pr: 14756
testing/web-platform/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/storage/estimate-usage-details-service-workers.https.tentative.window.js
@@ -0,0 +1,38 @@
+// META: title=StorageManager: estimate() for service worker registrations
+const wait_for_active = worker => new Promise(resolve =>{
+  if (worker.active) { resolve(worker.active); }
+
+  const listen_for_active = worker => e => {
+    if (e.target.state === 'activated') { resolve(worker.active); }
+  }
+
+  if (worker.waiting) {
+    worker.waiting
+        .addEventListener('statechange', listen_for_active(worker.waiting));
+  }
+  if (worker.installing) {
+    worker.installing
+        .addEventListener('statechange', listen_for_active(worker.installing));
+  }
+});
+
+promise_test(async t => {
+  let estimate = await navigator.storage.estimate();
+  const usageBeforeCreate = estimate.usageDetails.serviceWorkerRegistrations ||
+      0;
+  // Note: helpers.js is an arbitrary file; it could be any file that
+  // exists, but this test does not depend on the contents of said file.
+  const serviceWorkerRegistration = await
+      navigator.serviceWorker.register('./helpers.js');
+
+  t.add_cleanup(() => serviceWorkerRegistration.unregister());
+  await wait_for_active(serviceWorkerRegistration);
+
+  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');