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

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

Issue 2711183003: Import wpt@a7e9c2abcf65b78fcf1c246fec6681c74e1bc352 (Closed)
Patch Set: Update test expectations and baselines. Created 3 years, 9 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: Request end-to-end</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 var t = async_test('Request: end-to-end');
8 t.step(function() { 8 t.step(function() {
9 var url = 'resources/request-end-to-end-worker.js'; 9 var url = 'resources/request-end-to-end-worker.js';
10 var scope = 'resources/blank.html'; 10 var scope = 'resources/blank.html';
11 var frames = []; 11 var frames = [];
12 12
13 service_worker_unregister_and_register(t, url, scope) 13 service_worker_unregister_and_register(t, url, scope)
14 .then(onRegister) 14 .then(onRegister)
15 .catch(unreached_rejection(t)); 15 .catch(unreached_rejection(t));
16 16
17 function sendMessagePort(worker) { 17 function sendMessagePort(worker) {
18 var messageChannel = new MessageChannel(); 18 var messageChannel = new MessageChannel();
19 worker.postMessage({port:messageChannel.port2}, [messageChannel.port2]); 19 worker.postMessage({port:messageChannel.port2}, [messageChannel.port2]);
20 return messageChannel.port1; 20 return messageChannel.port1;
21 } 21 }
22 22
23 function onRegister(registration) { 23 function onRegister(registration) {
24 var sw = registration.installing; 24 var sw = registration.installing;
25 sw.addEventListener('statechange', t.step_func(function(event) {
26 if (event.target.state == 'activated') {
27 onActive(sw);
28 }
29 }));
30 }
31
32 function onActive(sw) {
25 var port = sendMessagePort(sw); 33 var port = sendMessagePort(sw);
26 port.addEventListener('message', t.step_func(function(event) { 34 port.addEventListener('message', t.step_func(function(event) {
27 onMessage(event); 35 onMessage(event);
28 }), false); 36 }), false);
29 port.start(); 37 port.start();
30 sw.addEventListener('statechange', t.step_func(function(event) {
31 if (event.target.state == 'activated')
32 onActive();
33 }));
34 } 38 }
35 39
36 function onActive() { 40 function onMessage(event) {
41 if (event.data === 'received port') {
42 onPortReady();
43 } else {
44 onResult(event);
45 }
46 }
47
48 function onPortReady() {
37 with_iframe(scope).then(function(f) { frames.push(f); }); 49 with_iframe(scope).then(function(f) { frames.push(f); });
38 } 50 }
39 51
40 function onMessage(event) { 52 function onResult(event) {
41 assert_equals( 53 assert_equals(
42 event.data.url, 54 event.data.url,
43 location.href.substring(0, location.href.lastIndexOf('/') + 1) + 55 location.href.substring(0, location.href.lastIndexOf('/') + 1) +
44 scope, 56 scope,
45 'request.url should be passed to onfetch event.'); 57 'request.url should be passed to onfetch event.');
46 assert_equals(event.data.mode, 'navigate', 58 assert_equals(event.data.mode, 'navigate',
47 'request.mode should be passed to onfetch event.'); 59 'request.mode should be passed to onfetch event.');
48 assert_equals(event.data.method, 'GET', 60 assert_equals(event.data.method, 'GET',
49 'request.method should be passed to onfetch event.'); 61 'request.method should be passed to onfetch event.');
50 assert_equals(event.data.referrer, location.href, 62 assert_equals(event.data.referrer, location.href,
51 'request.referrer should be passed to onfetch event.'); 63 'request.referrer should be passed to onfetch event.');
52 assert_equals(event.data.headers['user-agent'], undefined, 64 assert_equals(event.data.headers['user-agent'], undefined,
53 'Default User-Agent header should not be passed to onfetch event.') 65 'Default User-Agent header should not be passed to onfetch event.')
54 assert_equals(event.data.errorNameWhileAppendingHeader, 'TypeError', 66 assert_equals(event.data.errorNameWhileAppendingHeader, 'TypeError',
55 'Appending a new header to the request must throw a ' + 67 'Appending a new header to the request must throw a ' +
56 'TypeError.') 68 'TypeError.')
57 frames.forEach(function(f) { f.remove(); }); 69 frames.forEach(function(f) { f.remove(); });
58 service_worker_unregister_and_done(t, scope); 70 service_worker_unregister_and_done(t, scope);
59 } 71 }
60 }); 72 });
61 </script> 73 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698