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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/fetch-request-fallback.html

Issue 2858933003: Upstream service worker `fetch` test to WPT (Closed)
Patch Set: Resolve conflict in `enable-blink-features=LayoutNG` 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 <title>Service Worker: the fallback behavior of FetchEvent</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="../resources/get-host-info.js?pipe=sub"></script>
6 <script src="resources/test-helpers.js"></script>
7 <script>
8
9 function assert_resolves(promise, description) {
10 return new Promise(function(resolve, reject) {
11 promise
12 .then(
13 function() { resolve(); },
14 function() { reject(description); });
15 });
16 }
17
18 function assert_rejects(promise, description) {
19 return new Promise(function(resolve, reject) {
20 promise
21 .then(
22 function() { reject(description); },
23 function() { resolve(); });
24 });
25 }
26
27 function get_fetched_urls(worker) {
28 return new Promise(function(resolve) {
29 var channel = new MessageChannel();
30 channel.port1.onmessage = function(msg) { resolve(msg); };
31 worker.postMessage({port: channel.port2}, [channel.port2]);
32 });
33 }
34
35 function check_urls(worker, expected_requests, description) {
36 return get_fetched_urls(worker)
37 .then(function(msg) {
38 var requests = msg.data.requests;
39 assert_object_equals(requests, expected_requests, description);
40 });
41 }
42
43 async_test(function(t) {
44 var SCOPE = 'resources/fetch-request-fallback-iframe.html';
45 var SCRIPT = 'resources/fetch-request-fallback-worker.js';
46 var host_info = get_host_info();
47 var BASE_URL = host_info['HTTP_ORIGIN'] +
48 '/serviceworker/resources/fetch-access-control.php?';
49 var BASE_PNG_URL = BASE_URL + 'PNGIMAGE&';
50 var OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] +
51 '/serviceworker/resources/fetch-access-control.php?';
52 var OTHER_BASE_PNG_URL = OTHER_BASE_URL + 'PNGIMAGE&';
53 var REDIRECT_URL = host_info['HTTP_ORIGIN'] +
54 '/serviceworker/resources/redirect.php?Redirect=';
55 var frame;
56 var worker;
57 service_worker_unregister_and_register(t, SCRIPT, SCOPE)
58 .then(function(registration) {
59 worker = registration.installing;
60 return wait_for_state(t, worker, 'activated');
61 })
62 .then(function() { return with_iframe(SCOPE); })
63 .then(function(f) {
64 frame = f;
65 return check_urls(
66 worker,
67 [{
68 url: host_info['HTTP_ORIGIN'] + '/serviceworker/' + SCOPE,
69 mode: 'navigate'
70 }],
71 'The SW must intercept the request for a main resourc.');
72 })
73 .then(function() {
74 return assert_resolves(
75 frame.contentWindow.xhr(BASE_URL),
76 'SW fallbacked same origin XHR should succeed.');
77 })
78 .then(function() {
79 return check_urls(
80 worker,
81 [{ url: BASE_URL, mode: 'cors' }],
82 'The SW must intercept the request of same origin XHR.');
83 })
84 .then(function() {
85 return assert_rejects(
86 frame.contentWindow.xhr(OTHER_BASE_URL),
87 'SW fallbacked CORS-unsupported other origin XHR should fail.');
88 })
89 .then(function() {
90 return check_urls(
91 worker,
92 [{ url: OTHER_BASE_URL, mode: 'cors' }],
93 'The SW must intercept the request of CORS-unsupported other ' +
94 'origin XHR.');
95 })
96 .then(function() {
97 return assert_resolves(
98 frame.contentWindow.xhr(OTHER_BASE_URL + 'ACAOrigin=*'),
99 'SW fallbacked CORS-supported other origin XHR should succeed.');
100 })
101 .then(function() {
102 return check_urls(
103 worker,
104 [{ url: OTHER_BASE_URL + 'ACAOrigin=*', mode: 'cors' }],
105 'The SW must intercept the request of CORS-supported other ' +
106 'origin XHR.');
107 })
108 .then(function() {
109 return assert_resolves(
110 frame.contentWindow.xhr(
111 REDIRECT_URL + encodeURIComponent(BASE_URL)),
112 'SW fallbacked redirected XHR should succeed.');
113 })
114 .then(function() {
115 return check_urls(
116 worker,
117 [{
118 url: REDIRECT_URL + encodeURIComponent(BASE_URL),
119 mode: 'cors'
120 }],
121 'The SW must intercept only the first request of redirected ' +
122 'XHR.');
123 })
124 .then(function() {
125 return assert_rejects(
126 frame.contentWindow.xhr(
127 REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL)),
128 'SW fallbacked XHR which is redirected to CORS-unsupported ' +
129 'other origin should fail.');
130 })
131 .then(function() {
132 return check_urls(
133 worker,
134 [{
135 url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL),
136 mode: 'cors'
137 }],
138 'The SW must intercept only the first request for XHR which is' +
139 ' redirected to CORS-unsupported other origin.');
140 })
141 .then(function() {
142 return assert_resolves(
143 frame.contentWindow.xhr(
144 REDIRECT_URL +
145 encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*')),
146 'SW fallbacked XHR which is redirected to CORS-supported other ' +
147 'origin should succeed.');
148 })
149 .then(function() {
150 return check_urls(
151 worker,
152 [{
153 url: REDIRECT_URL +
154 encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
155 mode: 'cors'
156 }],
157 'The SW must intercept only the first request for XHR which is ' +
158 'redirected to CORS-supported other origin.');
159 })
160 .then(function() {
161 return assert_resolves(
162 frame.contentWindow.load_image(BASE_PNG_URL, ''),
163 'SW fallbacked image request should succeed.');
164 })
165 .then(function() {
166 return check_urls(
167 worker,
168 [{ url: BASE_PNG_URL, mode: 'no-cors' }],
169 'The SW must intercept the request for image.');
170 })
171 .then(function() {
172 return assert_resolves(
173 frame.contentWindow.load_image(OTHER_BASE_PNG_URL, ''),
174 'SW fallbacked other origin image request should succeed.');
175 })
176 .then(function() {
177 return check_urls(
178 worker,
179 [{ url: OTHER_BASE_PNG_URL, mode: 'no-cors' }],
180 'The SW must intercept the request for other origin image.')
181 })
182 .then(function() {
183 return assert_rejects(
184 frame.contentWindow.load_image(OTHER_BASE_PNG_URL, 'anonymous'),
185 'SW fallbacked CORS-unsupported other origin image request ' +
186 'should fail.');
187 })
188 .then(function() {
189 return check_urls(
190 worker,
191 [{ url: OTHER_BASE_PNG_URL, mode: 'cors' }],
192 'The SW must intercept the request for CORS-unsupported other ' +
193 'origin image.')
194 })
195 .then(function() {
196 return assert_resolves(
197 frame.contentWindow.load_image(
198 OTHER_BASE_PNG_URL + 'ACAOrigin=*', 'anonymous'),
199 'SW fallbacked CORS-supported other origin image request should' +
200 ' succeed.');
201 })
202 .then(function() {
203 return check_urls(
204 worker,
205 [{ url: OTHER_BASE_PNG_URL + 'ACAOrigin=*', mode: 'cors' }],
206 'The SW must intercept the request for CORS-supported other ' +
207 'origin image.')
208 })
209 .then(function() {
210 return assert_resolves(
211 frame.contentWindow.load_image(
212 REDIRECT_URL + encodeURIComponent(BASE_PNG_URL), ''),
213 'SW fallbacked redirected image request should succeed.');
214 })
215 .then(function() {
216 return check_urls(
217 worker,
218 [{
219 url: REDIRECT_URL + encodeURIComponent(BASE_PNG_URL),
220 mode: 'no-cors'
221 }],
222 'The SW must intercept only the first request for redirected ' +
223 'image resource.');
224 })
225 .then(function() {
226 return assert_resolves(
227 frame.contentWindow.load_image(
228 REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL), ''),
229 'SW fallbacked image request which is redirected to other ' +
230 'origin should succeed.');
231 })
232 .then(function() {
233 return check_urls(
234 worker,
235 [{
236 url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL),
237 mode: 'no-cors'
238 }],
239 'The SW must intercept only the first request for image ' +
240 'resource which is redirected to other origin.');
241 })
242 .then(function() {
243 return assert_rejects(
244 frame.contentWindow.load_image(
245 REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL),
246 'anonymous'),
247 'SW fallbacked image request which is redirected to ' +
248 'CORS-unsupported other origin should fail.');
249 })
250 .then(function() {
251 return check_urls(
252 worker,
253 [{
254 url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL),
255 mode: 'cors'
256 }],
257 'The SW must intercept only the first request for image ' +
258 'resource which is redirected to CORS-unsupported other origin.');
259 })
260 .then(function() {
261 return assert_resolves(
262 frame.contentWindow.load_image(
263 REDIRECT_URL +
264 encodeURIComponent(OTHER_BASE_PNG_URL + 'ACAOrigin=*'),
265 'anonymous'),
266 'SW fallbacked image request which is redirected to ' +
267 'CORS-supported other origin should succeed.');
268 })
269 .then(function() {
270 return check_urls(
271 worker,
272 [{
273 url: REDIRECT_URL +
274 encodeURIComponent(OTHER_BASE_PNG_URL + 'ACAOrigin=*'),
275 mode: 'cors'
276 }],
277 'The SW must intercept only the first request for image ' +
278 'resource which is redirected to CORS-supported other origin.');
279 })
280 .then(function() {
281 frame.remove();
282 service_worker_unregister_and_done(t, SCOPE);
283 })
284 .catch(unreached_rejection(t));
285 }, 'Verify the fallback behavior of FetchEvent');
286 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698