2 <title>Cache Storage: Verify that Window and Workers see same storage
</title>
3 <link rel=
"help" href=
"https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-storage">
4 <script src=
"/resources/testharness.js"></script>
5 <script src=
"/resources/testharnessreport.js"></script>
6 <script src=
"/resources/testharness-helpers.js"></script>
9 function wait_for_message(worker
) {
10 return new Promise(function(resolve
) {
11 worker
.addEventListener('message', function listener(e
) {
13 worker
.removeEventListener('message', listener
);
18 promise_test(function(t
) {
19 var cache_name
= 'common-test';
20 return self
.caches
.delete(cache_name
)
22 var worker
= new Worker('resources/common-worker.js');
23 worker
.postMessage({name
: cache_name
});
24 return wait_for_message(worker
);
26 .then(function(message
) {
27 return self
.caches
.open(cache_name
);
29 .then(function(cache
) {
31 cache
.match('https://example.com/a'),
32 cache
.match('https://example.com/b'),
33 cache
.match('https://example.com/c')
36 .then(function(responses
) {
37 return Promise
.all(responses
.map(
38 function(response
) { return response
.text(); }
41 .then(function(bodies
) {
42 assert_equals(bodies
[0], 'a',
43 'Body should match response put by worker');
44 assert_equals(bodies
[1], 'b',
45 'Body should match response put by worker');
46 assert_equals(bodies
[2], 'c',
47 'Body should match response put by worker');
49 }, 'Window sees cache puts by Worker');