OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <!-- This test is prefixed with `chromium.` because it asserts internal | |
3 implementation details using non-standard API that is only available via | |
4 Chromium's content_shell. It should be maintained only in so far as those | |
5 implementation details need to be held stable; assertions that can be | |
6 expressed using standard interfaces should be added to the equivalent version | |
7 of this test in the Web Platform Tests project. --> | |
8 <title>Service Worker: Redirected response URL list (uses Chromium-internal API) </title> | |
9 <script src="../resources/testharness.js"></script> | |
10 <script src="../resources/testharnessreport.js"></script> | |
11 <script src="../resources/get-host-info.js?pipe=sub"></script> | |
12 <script src="resources/test-helpers.js"></script> | |
13 <script> | |
14 // Tests redirect behavior. It calls fetch_method(url, fetch_option) and tests | |
15 // the resulting response against the expected values. It also adds the | |
16 // response to |cache| and checks the cached response matches the expected | |
17 // values. | |
18 // | |
19 // |options|: a dictionary of parameters for the test | |
20 // |options.url|: the URL to fetch | |
21 // |options.fetch_option|: the options passed to |fetch_method| | |
22 // |options.fetch_method|: the method used to fetch. Useful for testing an | |
23 // iframe's fetch() vs. this page's fetch(). | |
24 // |options.cache|: A Cache to add the response to | |
25 // |options.expected_url_list|: an array of string values describing the | |
26 // internal URL list; this information is not | |
27 // available via a standard API | |
28 function redirected_test(options) { | |
29 return options.fetch_method.call(null, options.url, options.fetch_option).then (response => { | |
30 var cloned_response = response.clone(); | |
31 assert_array_equals( | |
32 self.internals.getInternalResponseURLList(response), | |
33 options.expected_url_list, | |
34 'The URL list of response must match. URL: ' + options.url); | |
35 assert_array_equals( | |
36 self.internals.getInternalResponseURLList(cloned_response), | |
37 options.expected_url_list, | |
38 'The URL list of cloned response must match. URL: ' + options.url); | |
39 return options.cache.put(options.url, response); | |
40 }) | |
41 .then(_ => options.cache.match(options.url)) | |
42 .then(response => { | |
43 assert_array_equals( | |
44 self.internals.getInternalResponseURLList(response), | |
45 options.expected_url_list, | |
46 'The URL list of response in CacheStorage must match. URL: ' + | |
47 options.url); | |
48 }); | |
49 } | |
50 | |
51 var host_info = get_host_info(); | |
52 var REDIRECT_URL = host_info['HTTP_ORIGIN'] + | |
53 '/serviceworker/resources/redirect.php?Redirect='; | |
54 var TARGET_URL = host_info['HTTP_ORIGIN'] + | |
55 '/serviceworker/resources/simple.txt'; | |
56 var REDIRECT_TO_TARGET_URL = REDIRECT_URL + encodeURIComponent(TARGET_URL); | |
57 var frame; | |
58 var cache; | |
59 var setup; | |
60 | |
61 promise_test(t => { | |
62 var SCOPE = 'resources/blank.html?redirected-response'; | |
63 var SCRIPT = 'resources/fetch-rewrite-worker.js'; | |
64 var CACHE_NAME = 'serviceworker/redirected-response'; | |
65 setup = new Promise(function(resolve) { | |
66 assert_true(!!self.internals, 'Chromium "internals" are exposed.'); | |
67 resolve(); | |
68 }) | |
69 .then(() => service_worker_unregister_and_register(t, SCRIPT, SCOPE)) | |
70 .then(registration => { | |
71 promise_test(function() { | |
72 return registration.unregister(); | |
73 }, 'restore global state (service worker registration)'); | |
74 | |
75 return wait_for_state(t, registration.installing, 'activated'); | |
76 }) | |
77 .then(_ => self.caches.open(CACHE_NAME)) | |
78 .then(c => { | |
79 cache = c; | |
80 | |
81 promise_test(function() { | |
82 return self.caches.delete(CACHE_NAME); | |
83 }, 'restore global state (caches)'); | |
84 | |
85 return with_iframe(SCOPE); | |
86 }) | |
87 .then(f => { | |
88 frame = f; | |
89 | |
90 add_completion_callback(function() { | |
91 f.remove(); | |
92 }); | |
93 }); | |
94 return setup; | |
95 }, 'initialize global state (service worker registration and caches)'); | |
96 | |
97 // Tests without service workers. | |
falken
2017/05/19 01:58:43
I missed it in the first review, but it's hard to
mike3
2017/05/19 15:45:32
Done.
| |
98 promise_test(t => setup | |
99 .then(() => redirected_test({url: TARGET_URL, | |
100 fetch_option: {}, | |
101 fetch_method: self.fetch, | |
102 cache: cache, | |
103 expected_url_list: [TARGET_URL]})), | |
104 'mode: "follow", non-intercepted request, no server redirect'); | |
105 | |
106 promise_test(t => setup | |
107 .then(() => redirected_test({url: REDIRECT_TO_TARGET_URL, | |
108 fetch_option: {}, | |
109 fetch_method: self.fetch, | |
110 cache: cache, | |
111 expected_url_list: [REDIRECT_TO_TARGET_URL, TARGE T_URL]})), | |
112 'mode: "follow", non-intercepted request'); | |
113 | |
114 promise_test(t => setup | |
115 .then(() => redirected_test({url: REDIRECT_TO_TARGET_URL + '&manual', | |
116 fetch_option: {redirect: 'manual'}, | |
117 fetch_method: self.fetch, | |
118 cache: cache, | |
119 expected_url_list: [REDIRECT_TO_TARGET_URL + '&ma nual']})), | |
120 'mode: "manual", non-intercepted request'); | |
121 | |
122 promise_test(t => setup | |
123 .then(() => redirected_test({url: './?url=' + encodeURIComponent(TARGET_URL), | |
124 fetch_option: {}, | |
125 fetch_method: frame.contentWindow.fetch, | |
126 cache: cache, | |
127 expected_url_list: [TARGET_URL]})), | |
128 'mode: "follow", no mode change, no server redirect'); | |
129 | |
130 | |
131 // The service worker returns a redirected response. | |
falken
2017/05/19 01:58:44
indentation, and
// =============================
mike3
2017/05/19 15:45:32
Done.
| |
132 promise_test(t => setup | |
133 .then(() => redirected_test({url: './?url=' + encodeURIComponent(REDIRECT_TO_T ARGET_URL) + | |
134 '&original-redirect-mode=follow', | |
135 fetch_option: {redirect: 'follow'}, | |
136 fetch_method: frame.contentWindow.fetch, | |
137 cache: cache, | |
138 expected_url_list: [REDIRECT_TO_TARGET_URL, TARGE T_URL]})), | |
139 'mode: "follow", no mode change'); | |
140 | |
141 promise_test(t => setup | |
142 .then(() => redirected_test({url: './?url=' + encodeURIComponent(REDIRECT_TO_T ARGET_URL) + | |
143 '&original-redirect-mode=manual&redirect- mode=manual', | |
144 fetch_option: {redirect: 'manual'}, | |
145 fetch_method: frame.contentWindow.fetch, | |
146 cache: cache, | |
147 expected_url_list: [REDIRECT_TO_TARGET_URL]})), | |
148 'mode: "manual", no mode change'); | |
149 </script> | |
OLD | NEW |