From a4f6ff7bb0dd0f5c04a8aa41c98ae120abec182c Mon Sep 17 00:00:00 2001 From: Evan Stade Date: Thu, 13 Oct 2022 16:06:27 +0000 Subject: [PATCH] Bug 1793125 [wpt PR 36204] - Storage Buckets: hook up CacheStorage (part 3/3), a=testonly Automatic update from web-platform-tests Storage Buckets: hook up CacheStorage (part 3/3) Bug: 1218097 Change-Id: I59939c05933fe404e97888b9810580c5029e470d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3880834 Reviewed-by: Ayu Ishii Reviewed-by: Ben Kelly Reviewed-by: Nasko Oskov Commit-Queue: Evan Stade Commit-Queue: Nasko Oskov Auto-Submit: Evan Stade Cr-Commit-Position: refs/heads/main@{#1056452} -- wpt-commits: eee708c4a74589371201151a153b988502401fd1 wpt-pr: 36204 --- .../cache-storage/cache-put.https.any.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/testing/web-platform/tests/service-workers/cache-storage/cache-put.https.any.js b/testing/web-platform/tests/service-workers/cache-storage/cache-put.https.any.js index 15aadc96f3571..e4675d96afc10 100644 --- a/testing/web-platform/tests/service-workers/cache-storage/cache-put.https.any.js +++ b/testing/web-platform/tests/service-workers/cache-storage/cache-put.https.any.js @@ -390,4 +390,38 @@ cache_test(async (cache) => { assert_true(cachedResponseText.indexOf("name=\"name\"\r\n\r\nvalue") !== -1); }, 'Cache.put called with simple Request and form data Response'); +promise_test(async function(test) { + var inboxBucket = await navigator.storageBuckets.open('inbox'); + var draftsBucket = await navigator.storageBuckets.open('drafts'); + + test.add_cleanup(async function() { + await navigator.storageBuckets.delete('inbox'); + await navigator.storageBuckets.delete('drafts'); + }); + + const cacheName = 'attachments'; + const cacheKey = 'receipt1.txt'; + + var inboxCache = await inboxBucket.caches.open(cacheName); + var draftsCache = await draftsBucket.caches.open(cacheName); + + await inboxCache.put(cacheKey, new Response('bread x 2')) + await draftsCache.put(cacheKey, new Response('eggs x 1')); + + return inboxCache.match(cacheKey) + .then(function(result) { + return result.text(); + }) + .then(function(body) { + assert_equals(body, 'bread x 2', 'Wrong cache contents'); + return draftsCache.match(cacheKey); + }) + .then(function(result) { + return result.text(); + }) + .then(function(body) { + assert_equals(body, 'eggs x 1', 'Wrong cache contents'); + }); +}, 'caches from different buckets have different contents'); + done();