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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/request-end-to-end.https.html

Issue 2889153004: Upstream service worker "request" tests to WPT (Closed)
Patch Set: Add "use strict" directive 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Service Worker: Request end-to-end</title> 2 <title>Service Worker: FetchEvent.request passed to onfetch</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/test-helpers.sub.js"></script> 5 <script src="resources/test-helpers.sub.js"></script>
6 <script> 6 <script>
7 var t = async_test('Request: end-to-end'); 7 'use strict';
8 t.step(function() { 8
9 promise_test(t => {
9 var url = 'resources/request-end-to-end-worker.js'; 10 var url = 'resources/request-end-to-end-worker.js';
10 var scope = 'resources/blank.html?request-end-to-end'; 11 var scope = 'resources/blank.html';
12 return service_worker_unregister_and_register(t, url, scope)
13 .then(r => {
14 add_completion_callback(() => { r.unregister(); });
15 return wait_for_state(t, r.installing, 'activated');
16 })
17 .then(() => { return with_iframe(scope); })
18 .then(frame => {
19 add_completion_callback(() => { frame.remove(); });
11 20
12 service_worker_unregister_and_register(t, url, scope) 21 var result = JSON.parse(frame.contentDocument.body.textContent);
13 .then(onRegister) 22 assert_equals(result.url, frame.src, 'request.url');
14 .catch(unreached_rejection(t)); 23 assert_equals(result.method, 'GET', 'request.method');
15 24 assert_equals(result.referrer, location.href, 'request.referrer');
16 function sendMessagePort(worker) { 25 assert_equals(result.mode, 'navigate', 'request.mode');
17 var messageChannel = new MessageChannel(); 26 assert_equals(result.request_construct_error, 'TypeError',
18 worker.postMessage({port:messageChannel.port2}, [messageChannel.port2]); 27 'Constructing a Request with a Request whose mode ' +
19 return messageChannel.port1; 28 'is navigate and non-empty RequestInit must throw a ' +
20 } 29 'TypeError.')
21 30 assert_equals(result.credentials, 'include', 'request.credentials');
22 function onRegister(registration) { 31 assert_equals(result.redirect, 'manual', 'request.redirect');
23 var sw = registration.installing; 32 assert_equals(result.headers['user-agent'], undefined,
24 sw.addEventListener('statechange', t.step_func(function(event) { 33 'Default User-Agent header should not be passed to ' +
25 if (event.target.state == 'activated') { 34 'onfetch event.')
26 onActive(sw); 35 assert_equals(result.append_header_error, 'TypeError',
27 } 36 'Appending a new header to the request must throw a ' +
28 })); 37 'TypeError.')
29 } 38 });
30 39 }, 'Test FetchEvent.request passed to onfetch');
31 function onActive(sw) {
32 var port = sendMessagePort(sw);
33 port.addEventListener('message', t.step_func(function(event) {
34 onMessage(event);
35 }), false);
36 port.start();
37 }
38
39 function onMessage(event) {
40 if (event.data === 'received port') {
41 onPortReady();
42 } else {
43 onResult(event);
44 }
45 }
46
47 function onPortReady() {
48 // The only purpose of the iframe created here is to generate an HTTP
49 // request, so the element may be removed as soon as the frame has
50 // completed loading.
51 with_iframe(scope).then(function(f) { f.remove(); })
52 .catch(unreached_rejection(t));
53 }
54
55 function onResult(event) {
56 assert_equals(
57 event.data.url,
58 location.href.substring(0, location.href.lastIndexOf('/') + 1) +
59 scope,
60 'request.url should be passed to onfetch event.');
61 assert_equals(event.data.mode, 'navigate',
62 'request.mode should be passed to onfetch event.');
63 assert_equals(event.data.method, 'GET',
64 'request.method should be passed to onfetch event.');
65 assert_equals(event.data.referrer, location.href,
66 'request.referrer should be passed to onfetch event.');
67 assert_equals(event.data.headers['user-agent'], undefined,
68 'Default User-Agent header should not be passed to onfetch event.')
69 assert_equals(event.data.errorNameWhileAppendingHeader, 'TypeError',
70 'Appending a new header to the request must throw a ' +
71 'TypeError.')
72 service_worker_unregister_and_done(t, scope);
73 }
74 });
75 </script> 40 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698