OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Redirected response</title> | 2 <title>Service Worker: Redirected response</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="../resources/get-host-info.js?pipe=sub"></script> | 5 <script src="../resources/get-host-info.js?pipe=sub"></script> |
6 <script src="resources/test-helpers.js"></script> | 6 <script src="resources/test-helpers.js"></script> |
7 <script> | 7 <script> |
8 | 8 |
9 function redirected_test(url, | 9 function redirected_test(url, |
10 fetch_method, | 10 fetch_method, |
11 cache, | 11 cache, |
| 12 expected_redirected, |
12 expected_url_list) { | 13 expected_url_list) { |
13 return fetch_method(url).then(response => { | 14 return fetch_method(url).then(response => { |
14 var cloned_response = response.clone(); | 15 var cloned_response = response.clone(); |
| 16 assert_equals( |
| 17 response.redirected, expected_redirected, |
| 18 'The redirected flag of response must match. URL: ' + url); |
| 19 assert_equals( |
| 20 cloned_response.redirected, expected_redirected, |
| 21 'The redirected flag of cloned response must match. URL: ' + url); |
15 if (self.internals) { | 22 if (self.internals) { |
16 assert_array_equals( | 23 assert_array_equals( |
17 self.internals.getInternalResponseURLList(response), | 24 self.internals.getInternalResponseURLList(response), |
18 expected_url_list, | 25 expected_url_list, |
19 'The URL list of response must match. URL: ' + url); | 26 'The URL list of response must match. URL: ' + url); |
20 assert_array_equals( | 27 assert_array_equals( |
21 self.internals.getInternalResponseURLList(cloned_response), | 28 self.internals.getInternalResponseURLList(cloned_response), |
22 expected_url_list, | 29 expected_url_list, |
23 'The URL list of cloned response must match. URL: ' + url); | 30 'The URL list of cloned response must match. URL: ' + url); |
24 } | 31 } |
25 return cache.put(url, response); | 32 return cache.put(url, response); |
26 }) | 33 }) |
27 .then(_ => cache.match(url)) | 34 .then(_ => cache.match(url)) |
28 .then(response => { | 35 .then(response => { |
| 36 assert_equals(response.redirected, expected_redirected, |
| 37 'The redirected flag of response in CacheStorage must match. URL: ' + |
| 38 url); |
29 if (self.internals) { | 39 if (self.internals) { |
30 assert_array_equals( | 40 assert_array_equals( |
31 self.internals.getInternalResponseURLList(response), | 41 self.internals.getInternalResponseURLList(response), |
32 expected_url_list, | 42 expected_url_list, |
33 'The URL list of response in CacheStorage must match. URL: ' + | 43 'The URL list of response in CacheStorage must match. URL: ' + |
34 url); | 44 url); |
35 } | 45 } |
36 }); | 46 }); |
37 } | 47 } |
38 | 48 |
(...skipping 16 matching lines...) Expand all Loading... |
55 }) | 65 }) |
56 .then(_ => self.caches.open(CACHE_NAME)) | 66 .then(_ => self.caches.open(CACHE_NAME)) |
57 .then(c => { | 67 .then(c => { |
58 cache = c; | 68 cache = c; |
59 return with_iframe(SCOPE); | 69 return with_iframe(SCOPE); |
60 }) | 70 }) |
61 .then(f => { | 71 .then(f => { |
62 frame = f; | 72 frame = f; |
63 return Promise.all([ | 73 return Promise.all([ |
64 redirected_test(TARGET_URL, self.fetch, cache, | 74 redirected_test(TARGET_URL, self.fetch, cache, |
| 75 false /* expected_redirected */, |
65 [TARGET_URL]), | 76 [TARGET_URL]), |
66 redirected_test(REDIRECT_TO_TARGET_URL, self.fetch, cache, | 77 redirected_test(REDIRECT_TO_TARGET_URL, self.fetch, cache, |
| 78 true /* expected_redirected */, |
67 [REDIRECT_TO_TARGET_URL, TARGET_URL]), | 79 [REDIRECT_TO_TARGET_URL, TARGET_URL]), |
68 redirected_test('./?url=' + encodeURIComponent(TARGET_URL), | 80 redirected_test('./?url=' + encodeURIComponent(TARGET_URL), |
69 frame.contentWindow.fetch, | 81 frame.contentWindow.fetch, |
70 cache, | 82 cache, |
| 83 false /* expected_redirected */, |
71 [TARGET_URL]), | 84 [TARGET_URL]), |
72 redirected_test( | 85 redirected_test( |
73 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL), | 86 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL), |
74 frame.contentWindow.fetch, | 87 frame.contentWindow.fetch, |
75 cache, | 88 cache, |
| 89 true /* expected_redirected */, |
76 [REDIRECT_TO_TARGET_URL, TARGET_URL]), | 90 [REDIRECT_TO_TARGET_URL, TARGET_URL]), |
77 ]); | 91 ]); |
78 }) | 92 }) |
79 .then(_ => self.caches.delete(CACHE_NAME)) | 93 .then(_ => self.caches.delete(CACHE_NAME)) |
80 .then(_ => { | 94 .then(_ => { |
81 frame.remove(); | 95 frame.remove(); |
82 return service_worker_unregister(t, SCOPE); | 96 return service_worker_unregister(t, SCOPE); |
83 }); | 97 }); |
84 }, 'Verify URL list of responses.'); | 98 }, 'Verify redirected flag of responses.'); |
85 </script> | 99 </script> |
OLD | NEW |