OLD | NEW |
| (Empty) |
1 importScripts('worker-testharness.js'); | |
2 importScripts('../../resources/testharness-helpers.js'); | |
3 importScripts('override_assert_object_equals.js'); | |
4 | |
5 (function() { | |
6 var next_index = 1; | |
7 | |
8 // Returns a transaction (request, response, and url) for a unique URL. | |
9 function create_unique_transaction(test) { | |
10 var uniquifier = String(next_index++); | |
11 var url = 'http://example.com/' + uniquifier; | |
12 | |
13 return { | |
14 request: new Request(url), | |
15 response: new Response('hello'), | |
16 url: url | |
17 }; | |
18 } | |
19 | |
20 self.create_unique_transaction = create_unique_transaction; | |
21 })(); | |
22 | |
23 cache_test(function(cache) { | |
24 var transaction = create_unique_transaction(); | |
25 | |
26 return cache.put(transaction.request.clone(), transaction.response.clone()) | |
27 .then(function() { | |
28 return self.caches.match(transaction.request); | |
29 }) | |
30 .then(function(response) { | |
31 assert_object_equals(response, transaction.response, | |
32 'The response should not have changed.'); | |
33 }); | |
34 }, 'CacheStorageMatch with no cache name provided'); | |
35 | |
36 cache_test(function(cache) { | |
37 var transaction = create_unique_transaction(); | |
38 | |
39 var test_cache_list = ['a', 'b', 'c']; | |
40 return cache.put(transaction.request.clone(), transaction.response.clone()) | |
41 .then(function() { | |
42 return Promise.all(test_cache_list.map(function(key) { | |
43 return self.caches.open(key); | |
44 })); | |
45 }) | |
46 .then(function() { | |
47 return self.caches.match(transaction.request); | |
48 }) | |
49 .then(function(response) { | |
50 assert_object_equals(response, transaction.response, | |
51 'The response should not have changed.'); | |
52 }); | |
53 }, 'CacheStorageMatch from one of many caches'); | |
54 | |
55 promise_test(function(test) { | |
56 var transaction = create_unique_transaction(); | |
57 | |
58 var test_cache_list = ['x', 'y', 'z']; | |
59 return Promise.all(test_cache_list.map(function(key) { | |
60 return self.caches.open(key); | |
61 })) | |
62 .then(function() { return caches.open('x'); }) | |
63 .then(function(cache) { | |
64 return cache.put(transaction.request.clone(), | |
65 transaction.response.clone()); | |
66 }) | |
67 .then(function() { | |
68 return self.caches.match(transaction.request, {cacheName: 'x'}); | |
69 }) | |
70 .then(function(response) { | |
71 assert_object_equals(response, transaction.response, | |
72 'The response should not have changed.'); | |
73 }) | |
74 .then(function() { | |
75 return self.caches.match(transaction.request, {cacheName: 'y'}); | |
76 }) | |
77 .then(function(response) { | |
78 assert_equals(response, undefined, | |
79 'Cache y should not have a response for the request.'); | |
80 }); | |
81 }, 'CacheStorageMatch from one of many caches by name'); | |
82 | |
83 cache_test(function(cache) { | |
84 var transaction = create_unique_transaction(); | |
85 return cache.put(transaction.url, transaction.response.clone()) | |
86 .then(function() { | |
87 return self.caches.match(transaction.request); | |
88 }) | |
89 .then(function(response) { | |
90 assert_object_equals(response, transaction.response, | |
91 'The response should not have changed.'); | |
92 }); | |
93 }, 'CacheStorageMatch a string request'); | |
94 | |
95 promise_test(function(test) { | |
96 var transaction = create_unique_transaction(); | |
97 return self.caches.match(transaction.request) | |
98 .then(function(response) { | |
99 assert_equals(response, undefined, | |
100 'The response should not be found.'); | |
101 }) | |
102 }, 'CacheStorageMatch with no cached entry'); | |
103 | |
104 promise_test(function(test) { | |
105 var transaction = create_unique_transaction(); | |
106 return self.caches.has('foo') | |
107 .then(function(has_foo) { | |
108 assert_false(has_foo, "The cache should not exist."); | |
109 return self.caches.match(transaction.request, {cacheName: 'foo'}); | |
110 }) | |
111 .then(function(response) { | |
112 assert_equals(response, undefined, | |
113 'The response should not be found.'); | |
114 return self.caches.has('foo'); | |
115 }) | |
116 .then(function(has_foo) { | |
117 assert_false(has_foo, "The cache should still not exist."); | |
118 }) | |
119 }, 'CacheStorageMatch with no caches available but name provided'); | |
OLD | NEW |