Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.redirected-response.html

Issue 2878003003: Upstream srvc wrkr "redirected resp" test to WPT (Closed)
Patch Set: Incorporate review feedback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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. -->
falken 2017/05/18 01:48:06 To make more clear the purpose of this test, and t
mike3 2017/05/18 17:49:29 Done.
8 <title>Service Worker: Redirected response</title>
falken 2017/05/18 01:48:07 maybe modify the title to say "Redirected response
mike3 2017/05/18 17:49:28 Done.
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.options.expected_redirected|: The value of response.redirected
falken 2017/05/18 01:48:06 can remove this one
mike3 2017/05/18 17:49:28 Done.
26 // |options.expected_url_list|: an array of string values describing the
27 // internal URL list; this information is not
28 // available via a standard API
29 function redirected_test(options) {
30 return options.fetch_method.call(null, options.url, options.fetch_option).then (response => {
31 var cloned_response = response.clone();
32 assert_equals(
33 response.redirected, options.expected_redirected,
34 'The redirected flag of response must match. URL: ' + options.url);
35 assert_equals(
36 cloned_response.redirected, options.expected_redirected,
37 'The redirected flag of cloned response must match. URL: ' + options .url);
38 if (self.internals) {
falken 2017/05/18 01:48:07 can remove lines 32-38
mike3 2017/05/18 17:49:29 Done.
39 assert_array_equals(
40 self.internals.getInternalResponseURLList(response),
41 options.expected_url_list,
42 'The URL list of response must match. URL: ' + options.url);
43 assert_array_equals(
44 self.internals.getInternalResponseURLList(cloned_response),
45 options.expected_url_list,
46 'The URL list of cloned response must match. URL: ' + options.url) ;
47 }
48 return options.cache.put(options.url, response);
49 })
50 .then(_ => options.cache.match(options.url))
51 .then(response => {
52 assert_equals(response.redirected, options.expected_redirected,
53 'The redirected flag of response in CacheStorage must match. URL: ' +
54 options.url);
55 if (self.internals) {
falken 2017/05/18 01:48:07 can remove lines 52-55
mike3 2017/05/18 17:49:28 Done.
56 assert_array_equals(
57 self.internals.getInternalResponseURLList(response),
58 options.expected_url_list,
59 'The URL list of response in CacheStorage must match. URL: ' +
60 options.url);
61 }
62 });
63 }
64
65 var host_info = get_host_info();
66 var REDIRECT_URL = host_info['HTTP_ORIGIN'] +
67 '/serviceworker/resources/redirect.php?Redirect=';
68 var TARGET_URL = host_info['HTTP_ORIGIN'] +
69 '/serviceworker/resources/simple.txt';
70 var REDIRECT_TO_TARGET_URL = REDIRECT_URL + encodeURIComponent(TARGET_URL);
71 var frame;
72 var cache;
73 var setup;
74
75 promise_test(t => {
76 var SCOPE = 'resources/blank.html?redirected-response';
77 var SCRIPT = 'resources/fetch-rewrite-worker.js';
78 var CACHE_NAME = 'serviceworker/redirected-response';
falken 2017/05/18 01:48:07 if (!self.internals) return Promise.reject('this t
mike3 2017/05/18 17:49:29 I took a slightly different approach here: rejecti
79 setup = service_worker_unregister_and_register(t, SCRIPT, SCOPE)
80 .then(registration => {
81 promise_test(function() {
82 return registration.unregister();
83 }, 'restore global state (service worker registration)');
84
85 return wait_for_state(t, registration.installing, 'activated');
86 })
87 .then(_ => self.caches.open(CACHE_NAME))
88 .then(c => {
89 cache = c;
90
91 promise_test(function() {
92 return self.caches.delete(CACHE_NAME);
93 }, 'restore global state (caches)');
94
95 return with_iframe(SCOPE);
96 })
97 .then(f => {
98 frame = f;
99
100 add_completion_callback(function() {
101 f.remove();
102 });
103 });
104 return setup;
105 }, 'initialize global state (service worker registration and caches)');
106
107 // Tests without service workers.
108 promise_test(t => setup
109 .then(() => redirected_test({url: TARGET_URL,
110 fetch_option: {},
111 fetch_method: self.fetch,
112 cache: cache,
113 expected_redirected: false,
114 expected_url_list: [TARGET_URL]})),
115 'mode: "follow", non-intercepted request, no server redirect');
116
117 promise_test(t => setup
118 .then(() => redirected_test({url: REDIRECT_TO_TARGET_URL,
119 fetch_option: {},
120 fetch_method: self.fetch,
121 cache: cache,
122 expected_redirected: true,
123 expected_url_list: [REDIRECT_TO_TARGET_URL, TARGE T_URL]})),
124 'mode: "follow", non-intercepted request');
125
126 promise_test(t => setup
127 .then(() => redirected_test({url: REDIRECT_TO_TARGET_URL + '&manual',
128 fetch_option: {redirect: 'manual'},
129 fetch_method: self.fetch,
130 cache: cache,
131 expected_redirected: false,
132 expected_url_list: [REDIRECT_TO_TARGET_URL + '&ma nual']})),
133 'mode: "manual", non-intercepted request');
134
135 promise_test(t => setup
136 .then(() => promise_rejects(
137 t, new TypeError(),
138 self.fetch(REDIRECT_TO_TARGET_URL + '&error',
139 {redirect:'error'}),
140 'The redirect response from the server should be treated as' +
141 ' an error when the redirect flag of request was \'error\'.') ),
142 'mode: "error", non-intercepted request');
falken 2017/05/18 01:48:06 we can remove these ones that don't call redirecte
mike3 2017/05/18 17:49:29 Done.
143
144 promise_test(t => setup
145 .then(() => redirected_test({url: './?url=' + encodeURIComponent(TARGET_URL),
146 fetch_option: {},
147 fetch_method: frame.contentWindow.fetch,
148 cache: cache,
149 expected_redirected: false,
150 expected_url_list: [TARGET_URL]})),
151 'mode: "follow", no mode change, no server redirect');
152
153
154 // The service worker returns a redirected response.
155 promise_test(t => setup
156 .then(() => redirected_test({url: './?url=' + encodeURIComponent(REDIRECT_TO_T ARGET_URL) +
157 '&original-redirect-mode=follow',
158 fetch_option: {redirect: 'follow'},
159 fetch_method: frame.contentWindow.fetch,
160 cache: cache,
161 expected_redirected: true,
162 expected_url_list: [REDIRECT_TO_TARGET_URL, TARGE T_URL]})),
163 'mode: "follow", no mode change');
164
165 promise_test(t => setup
166 .then(() => promise_rejects(
167 t, new TypeError(),
168 frame.contentWindow.fetch(
169 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
170 '&original-redirect-mode=error&redirect-mode=follow',
171 {redirect: 'error'}),
172 'The redirected response from the service worker should be ' +
173 'treated as an error when the redirect flag of request was ' +
174 '\'error\'.')),
175 'mode: "error", mode change: "follow"');
falken 2017/05/18 01:48:07 remove
mike3 2017/05/18 17:49:29 Done.
176
177 promise_test(t => setup
178 .then(() => promise_rejects(
179 t, new TypeError(),
180 frame.contentWindow.fetch(
181 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
182 '&original-redirect-mode=manual&redirect-mode=follow',
183 {redirect: 'manual'}),
184 'The redirected response from the service worker should be ' +
185 'treated as an error when the redirect flag of request was ' +
186 '\'manual\'.')),
187 'mode: "manual", mode change: "follow"');
falken 2017/05/18 01:48:07 remove
mike3 2017/05/18 17:49:28 Done.
188
189 // The service worker returns an opaqueredirect response.
190 promise_test(t => setup
191 .then(() => promise_rejects(
192 t, new TypeError(),
193 frame.contentWindow.fetch(
194 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
195 '&original-redirect-mode=follow&redirect-mode=manual',
196 {redirect: 'follow'}),
197 'The opaqueredirect response from the service worker should ' +
198 'be treated as an error when the redirect flag of request wa s' +
199 ' \'follow\'.')),
200 'mode: "follow", mode change: "redirect"');
falken 2017/05/18 01:48:06 remove
mike3 2017/05/18 17:49:28 Done.
201
202 promise_test(t => setup
203 .then(() => promise_rejects(
204 t, new TypeError(),
205 frame.contentWindow.fetch(
206 './?url=' + encodeURIComponent(REDIRECT_TO_TARGET_URL) +
207 '&original-redirect-mode=error&redirect-mode=manual',
208 {redirect: 'error'}),
209 'The opaqueredirect response from the service worker should ' +
210 'be treated as an error when the redirect flag of request wa s' +
211 ' \'error\'.')),
212 'mode: "error", mode change: "manual"');
falken 2017/05/18 01:48:06 remove
mike3 2017/05/18 17:49:28 Done.
213
214 promise_test(t => setup
215 .then(() => redirected_test({url: './?url=' + encodeURIComponent(REDIRECT_TO_T ARGET_URL) +
216 '&original-redirect-mode=manual&redirect- mode=manual',
217 fetch_option: {redirect: 'manual'},
218 fetch_method: frame.contentWindow.fetch,
219 cache: cache,
220 expected_redirected: false,
221 expected_url_list: [REDIRECT_TO_TARGET_URL]})),
222 'mode: "manual", no mode change');
223 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698