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 456974 74de088a6426612ef61f37b6e153a28c30a70710
parent 456973 492697a5506c7beab87cfbf9663bc9b9fc668a7f
child 456975 88f5d2d1bc3fb5eb77e0c74bdf29e6478283bcc3
push id111705
push userjames@hoppipolla.co.uk
push dateTue, 05 Feb 2019 18:07:20 +0000
treeherdermozilla-inbound@9592b19c9b09 [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');