OLD | NEW |
1 if (self.importScripts) { | 1 if (self.importScripts) { |
2 importScripts('/resources/testharness.js'); | 2 importScripts('/resources/testharness.js'); |
3 importScripts('../resources/test-helpers.js'); | 3 importScripts('../resources/test-helpers.js'); |
4 } | 4 } |
5 | 5 |
6 var test_url = 'https://example.com/foo'; | 6 var test_url = 'https://example.com/foo'; |
7 var test_body = 'Hello world!'; | 7 var test_body = 'Hello world!'; |
8 | 8 |
9 cache_test(function(cache) { | 9 cache_test(function(cache) { |
10 var request = new Request(test_url); | 10 var request = new Request(test_url); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 assert_equals(result.headers.get('Content-Type'), 'text/plain', | 95 assert_equals(result.headers.get('Content-Type'), 'text/plain', |
96 'Cache.put should store headers.'); | 96 'Cache.put should store headers.'); |
97 return result.text(); | 97 return result.text(); |
98 }) | 98 }) |
99 .then(function(body) { | 99 .then(function(body) { |
100 assert_equals(body, '', | 100 assert_equals(body, '', |
101 'Cache.put should store response body.'); | 101 'Cache.put should store response body.'); |
102 }); | 102 }); |
103 }, 'Cache.put with an empty response body'); | 103 }, 'Cache.put with an empty response body'); |
104 | 104 |
105 cache_test(function(cache) { | 105 cache_test(function(cache, test) { |
106 var request = new Request(test_url); | 106 var request = new Request(test_url); |
107 var response = new Response('', { | 107 var response = new Response('', { |
108 status: 206, | 108 status: 206, |
109 headers: [['Content-Type', 'text/plain']] | 109 headers: [['Content-Type', 'text/plain']] |
110 }); | 110 }); |
111 | 111 |
112 return assert_promise_rejects( | 112 return promise_rejects( |
| 113 test, |
| 114 new TypeError(), |
113 cache.put(request, response), | 115 cache.put(request, response), |
114 new TypeError(), | |
115 'Cache.put should reject 206 Responses with a TypeError.'); | 116 'Cache.put should reject 206 Responses with a TypeError.'); |
116 }, 'Cache.put with 206 response'); | 117 }, 'Cache.put with synthetic 206 response'); |
| 118 |
| 119 cache_test(function(cache, test) { |
| 120 var test_url = new URL('../resources/fetch-status.py?status=206', location.h
ref).href; |
| 121 var request = new Request(test_url); |
| 122 var response; |
| 123 return fetch(test_url) |
| 124 .then(function(fetch_result) { |
| 125 assert_equals(fetch_result.status, 206, |
| 126 'Test framework error: The status code should be 206.'); |
| 127 response = fetch_result.clone(); |
| 128 return promise_rejects(test, new TypeError, cache.put(request, fetch_r
esult)); |
| 129 }); |
| 130 }, 'Cache.put with HTTP 206 response'); |
117 | 131 |
118 cache_test(function(cache) { | 132 cache_test(function(cache) { |
119 var test_url = new URL('../resources/fetch-status.py?status=500', location.h
ref).href; | 133 var test_url = new URL('../resources/fetch-status.py?status=500', location.h
ref).href; |
120 var request = new Request(test_url); | 134 var request = new Request(test_url); |
121 var response; | 135 var response; |
122 return fetch(test_url) | 136 return fetch(test_url) |
123 .then(function(fetch_result) { | 137 .then(function(fetch_result) { |
124 assert_equals(fetch_result.status, 500, | 138 assert_equals(fetch_result.status, 500, |
125 'Test framework error: The status code should be 500.'); | 139 'Test framework error: The status code should be 500.'); |
126 response = fetch_result.clone(); | 140 response = fetch_result.clone(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 }) | 329 }) |
316 .then(function(response) { | 330 .then(function(response) { |
317 assert_response_equals(response, redirectResponse, | 331 assert_response_equals(response, redirectResponse, |
318 'Redirect response is reproduced by the Cache A
PI'); | 332 'Redirect response is reproduced by the Cache A
PI'); |
319 assert_equals(response.headers.get('Location'), redirectURL, | 333 assert_equals(response.headers.get('Location'), redirectURL, |
320 'Location header is preserved by Cache API.'); | 334 'Location header is preserved by Cache API.'); |
321 }); | 335 }); |
322 }, 'Cache.put should store Response.redirect() correctly'); | 336 }, 'Cache.put should store Response.redirect() correctly'); |
323 | 337 |
324 done(); | 338 done(); |
OLD | NEW |