OLD | NEW |
1 if (self.importScripts) { | 1 if (self.importScripts) { |
2 importScripts('/resources/testharness.js'); | 2 importScripts('/resources/testharness.js'); |
3 importScripts('/resources/testharness-helpers.js'); | 3 importScripts('/resources/testharness-helpers.js'); |
4 importScripts('../resources/test-helpers.js'); | 4 importScripts('../resources/test-helpers.js'); |
5 } | 5 } |
6 | 6 |
7 prepopulated_cache_test(simple_entries, function(cache, entries) { | 7 prepopulated_cache_test(simple_entries, function(cache, entries) { |
8 return cache.match('not-present-in-the-cache') | 8 return cache.match('not-present-in-the-cache') |
9 .then(function(result) { | 9 .then(function(result) { |
10 assert_equals(result, undefined, | 10 assert_equals(result, undefined, |
11 'Cache.match failures should resolve with undefined.'); | 11 'Cache.match failures should resolve with undefined.'); |
12 }); | 12 }); |
13 }, 'Cache.match with no matching entries'); | 13 }, 'Cache.match with no matching entries'); |
14 | 14 |
15 prepopulated_cache_test(simple_entries, function(cache, entries) { | 15 prepopulated_cache_test(simple_entries, function(cache, entries) { |
16 return cache.match(entries.a.request.url) | 16 return cache.match(entries.a.request.url) |
17 .then(function(result) { | 17 .then(function(result) { |
18 assert_object_equals_fixed(result, entries.a.response, | 18 assert_response_equals(result, entries.a.response, |
19 'Cache.match should match by URL.'); | 19 'Cache.match should match by URL.'); |
20 }); | 20 }); |
21 }, 'Cache.match with URL'); | 21 }, 'Cache.match with URL'); |
22 | 22 |
23 prepopulated_cache_test(simple_entries, function(cache, entries) { | 23 prepopulated_cache_test(simple_entries, function(cache, entries) { |
24 return cache.match(entries.a.request) | 24 return cache.match(entries.a.request) |
25 .then(function(result) { | 25 .then(function(result) { |
26 assert_object_equals_fixed(result, entries.a.response, | 26 assert_response_equals(result, entries.a.response, |
27 'Cache.match should match by Request.'); | 27 'Cache.match should match by Request.'); |
28 }); | 28 }); |
29 }, 'Cache.match with Request'); | 29 }, 'Cache.match with Request'); |
30 | 30 |
31 prepopulated_cache_test(simple_entries, function(cache, entries) { | 31 prepopulated_cache_test(simple_entries, function(cache, entries) { |
32 return cache.match(new Request(entries.a.request.url)) | 32 return cache.match(new Request(entries.a.request.url)) |
33 .then(function(result) { | 33 .then(function(result) { |
34 assert_object_equals_fixed(result, entries.a.response, | 34 assert_response_equals(result, entries.a.response, |
35 'Cache.match should match by Request.'); | 35 'Cache.match should match by Request.'); |
36 }); | 36 }); |
37 }, 'Cache.match with new Request'); | 37 }, 'Cache.match with new Request'); |
38 | 38 |
39 prepopulated_cache_test(simple_entries, function(cache, entries) { | 39 prepopulated_cache_test(simple_entries, function(cache, entries) { |
40 return cache.match(entries.a.request, | 40 return cache.match(entries.a.request, |
41 {ignoreSearch: true}) | 41 {ignoreSearch: true}) |
42 .then(function(result) { | 42 .then(function(result) { |
43 assert_object_in_array( | 43 assert_response_in_array( |
44 result, | 44 result, |
45 [ | 45 [ |
46 entries.a.response, | 46 entries.a.response, |
47 entries.a_with_query.response | 47 entries.a_with_query.response |
48 ], | 48 ], |
49 'Cache.match with ignoreSearch should ignore the ' + | 49 'Cache.match with ignoreSearch should ignore the ' + |
50 'search parameters of cached request.'); | 50 'search parameters of cached request.'); |
51 }); | 51 }); |
52 }, | 52 }, |
53 'Cache.match with ignoreSearch option (request with no search ' + | 53 'Cache.match with ignoreSearch option (request with no search ' + |
54 'parameters)'); | 54 'parameters)'); |
55 | 55 |
56 prepopulated_cache_test(simple_entries, function(cache, entries) { | 56 prepopulated_cache_test(simple_entries, function(cache, entries) { |
57 return cache.match(entries.a_with_query.request, | 57 return cache.match(entries.a_with_query.request, |
58 {ignoreSearch: true}) | 58 {ignoreSearch: true}) |
59 .then(function(result) { | 59 .then(function(result) { |
60 assert_object_in_array( | 60 assert_response_in_array( |
61 result, | 61 result, |
62 [ | 62 [ |
63 entries.a.response, | 63 entries.a.response, |
64 entries.a_with_query.response | 64 entries.a_with_query.response |
65 ], | 65 ], |
66 'Cache.match with ignoreSearch should ignore the ' + | 66 'Cache.match with ignoreSearch should ignore the ' + |
67 'search parameters of request.'); | 67 'search parameters of request.'); |
68 }); | 68 }); |
69 }, | 69 }, |
70 'Cache.match with ignoreSearch option (request with search parameter)'); | 70 'Cache.match with ignoreSearch option (request with search parameter)'); |
71 | 71 |
72 prepopulated_cache_test(simple_entries, function(cache, entries) { | 72 prepopulated_cache_test(simple_entries, function(cache, entries) { |
73 return cache.match(entries.cat.request.url + '#mouse') | 73 return cache.match(entries.cat.request.url + '#mouse') |
74 .then(function(result) { | 74 .then(function(result) { |
75 assert_object_equals_fixed(result, entries.cat.response, | 75 assert_response_equals(result, entries.cat.response, |
76 'Cache.match should ignore URL fragment.'); | 76 'Cache.match should ignore URL fragment.'); |
77 }); | 77 }); |
78 }, 'Cache.match with URL containing fragment'); | 78 }, 'Cache.match with URL containing fragment'); |
79 | 79 |
80 prepopulated_cache_test(simple_entries, function(cache, entries) { | 80 prepopulated_cache_test(simple_entries, function(cache, entries) { |
81 return cache.match('http') | 81 return cache.match('http') |
82 .then(function(result) { | 82 .then(function(result) { |
83 assert_equals( | 83 assert_equals( |
84 result, undefined, | 84 result, undefined, |
85 'Cache.match should treat query as a URL and not ' + | 85 'Cache.match should treat query as a URL and not ' + |
86 'just a string fragment.'); | 86 'just a string fragment.'); |
87 }); | 87 }); |
88 }, 'Cache.match with string fragment "http" as query'); | 88 }, 'Cache.match with string fragment "http" as query'); |
89 | 89 |
90 prepopulated_cache_test(simple_entries, function(cache, entries) { | 90 prepopulated_cache_test(simple_entries, function(cache, entries) { |
91 return cache.match(entries.secret_cat.request.url) | 91 return cache.match(entries.secret_cat.request.url) |
92 .then(function(result) { | 92 .then(function(result) { |
93 assert_object_equals_fixed( | 93 assert_response_equals( |
94 result, entries.secret_cat.response, | 94 result, entries.secret_cat.response, |
95 'Cache.match should not ignore embedded credentials'); | 95 'Cache.match should not ignore embedded credentials'); |
96 }); | 96 }); |
97 }, 'Cache.match with URL containing credentials'); | 97 }, 'Cache.match with URL containing credentials'); |
98 | 98 |
99 prepopulated_cache_test(vary_entries, function(cache, entries) { | 99 prepopulated_cache_test(vary_entries, function(cache, entries) { |
100 return cache.match('http://example.com/c') | 100 return cache.match('http://example.com/c') |
101 .then(function(result) { | 101 .then(function(result) { |
102 assert_object_in_array( | 102 assert_response_in_array( |
103 result, | 103 result, |
104 [ | 104 [ |
105 entries.vary_wildcard.response, | 105 entries.vary_wildcard.response, |
106 entries.vary_cookie_absent.response | 106 entries.vary_cookie_absent.response |
107 ], | 107 ], |
108 'Cache.match should honor "Vary" header.'); | 108 'Cache.match should honor "Vary" header.'); |
109 }); | 109 }); |
110 }, 'Cache.match with responses containing "Vary" header'); | 110 }, 'Cache.match with responses containing "Vary" header'); |
111 | 111 |
112 cache_test(function(cache) { | 112 cache_test(function(cache) { |
113 var request = new Request('http://example.com'); | 113 var request = new Request('http://example.com'); |
114 var response; | 114 var response; |
115 var request_url = new URL('../resources/simple.txt', location.href).href; | 115 var request_url = new URL('../resources/simple.txt', location.href).href; |
116 return fetch(request_url) | 116 return fetch(request_url) |
117 .then(function(fetch_result) { | 117 .then(function(fetch_result) { |
118 response = fetch_result; | 118 response = fetch_result; |
119 assert_equals( | 119 assert_equals( |
120 response.url, request_url, | 120 response.url, request_url, |
121 '[https://fetch.spec.whatwg.org/#dom-response-url] ' + | 121 '[https://fetch.spec.whatwg.org/#dom-response-url] ' + |
122 'Reponse.url should return the URL of the response.'); | 122 'Reponse.url should return the URL of the response.'); |
123 return cache.put(request, response.clone()); | 123 return cache.put(request, response.clone()); |
124 }) | 124 }) |
125 .then(function() { | 125 .then(function() { |
126 return cache.match(request.url); | 126 return cache.match(request.url); |
127 }) | 127 }) |
128 .then(function(result) { | 128 .then(function(result) { |
129 assert_object_equals_fixed( | 129 assert_response_equals( |
130 result, response, | 130 result, response, |
131 'Cache.match should return a Response object that has the same ' + | 131 'Cache.match should return a Response object that has the same ' + |
132 'properties as the stored response.'); | 132 'properties as the stored response.'); |
133 return cache.match(response.url); | 133 return cache.match(response.url); |
134 }) | 134 }) |
135 .then(function(result) { | 135 .then(function(result) { |
136 assert_equals( | 136 assert_equals( |
137 result, undefined, | 137 result, undefined, |
138 'Cache.match should not match cache entry based on response URL.'); | 138 'Cache.match should not match cache entry based on response URL.'); |
139 }); | 139 }); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 .then(function(result) { | 175 .then(function(result) { |
176 assert_equals(result, undefined, | 176 assert_equals(result, undefined, |
177 'Cache.match should not find a match'); | 177 'Cache.match should not find a match'); |
178 }); | 178 }); |
179 }, 'Cache.match with POST Request'); | 179 }, 'Cache.match with POST Request'); |
180 | 180 |
181 prepopulated_cache_test(simple_entries, function(cache, entries) { | 181 prepopulated_cache_test(simple_entries, function(cache, entries) { |
182 var response = entries.non_2xx_response.response; | 182 var response = entries.non_2xx_response.response; |
183 return cache.match(entries.non_2xx_response.request.url) | 183 return cache.match(entries.non_2xx_response.request.url) |
184 .then(function(result) { | 184 .then(function(result) { |
185 assert_object_equals_fixed( | 185 assert_response_equals( |
186 result, entries.non_2xx_response.response, | 186 result, entries.non_2xx_response.response, |
187 'Cache.match should return a Response object that has the ' + | 187 'Cache.match should return a Response object that has the ' + |
188 'same properties as a stored non-2xx response.'); | 188 'same properties as a stored non-2xx response.'); |
189 }); | 189 }); |
190 }, 'Cache.match with a non-2xx Response'); | 190 }, 'Cache.match with a non-2xx Response'); |
191 | 191 |
192 prepopulated_cache_test(simple_entries, function(cache, entries) { | 192 prepopulated_cache_test(simple_entries, function(cache, entries) { |
193 var response = entries.error_response.response; | 193 var response = entries.error_response.response; |
194 return cache.match(entries.error_response.request.url) | 194 return cache.match(entries.error_response.request.url) |
195 .then(function(result) { | 195 .then(function(result) { |
196 assert_object_equals_fixed( | 196 assert_response_equals( |
197 result, entries.error_response.response, | 197 result, entries.error_response.response, |
198 'Cache.match should return a Response object that has the ' + | 198 'Cache.match should return a Response object that has the ' + |
199 'same properties as a stored network error response.'); | 199 'same properties as a stored network error response.'); |
200 }); | 200 }); |
201 }, 'Cache.match with a network error Response'); | 201 }, 'Cache.match with a network error Response'); |
202 | 202 |
203 done(); | 203 done(); |
OLD | NEW |