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

Side by Side Diff: LayoutTests/http/tests/serviceworker/request-end-to-end.html

Issue 466723002: ServiceWorker: Enable ServiceWorkerRegistration and update layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@updatefound
Patch Set: apply horo@'s patch (PatchSet 28 on https://codereview.chromium.org/468753003/) Created 6 years, 4 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.js"></script> 5 <script src="resources/test-helpers.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 11
12 service_worker_unregister_and_register(t, url, scope).then(onRegister); 12 service_worker_unregister_and_register(t, url, scope)
13 .then(t.step_func(function(registration) {
14 return wait_for_update(t, registration);
15 }))
16 .then(t.step_func(onUpdateFound))
17 .catch(unreached_rejection(t));
13 18
14 function sendMessagePort(worker) { 19 function sendMessagePort(worker) {
15 var messageChannel = new MessageChannel(); 20 var messageChannel = new MessageChannel();
16 worker.postMessage({port:messageChannel.port2}, [messageChannel.port2]); 21 worker.postMessage({port:messageChannel.port2}, [messageChannel.port2]);
17 return messageChannel.port1; 22 return messageChannel.port1;
18 } 23 }
19 24
20 function onRegister(sw) { 25 function onUpdateFound(sw) {
21 var port = sendMessagePort(sw); 26 var port = sendMessagePort(sw);
22 port.addEventListener('message', t.step_func(function(event) { 27 port.addEventListener('message', t.step_func(function(event) {
23 onMessage(event); 28 onMessage(event);
24 }), false); 29 }), false);
25 port.start(); 30 port.start();
26 sw.addEventListener('statechange', t.step_func(function(event) { 31 sw.addEventListener('statechange', t.step_func(function(event) {
27 if (event.target.state == 'activated') 32 if (event.target.state == 'activated')
28 onActive(); 33 onActive();
29 })); 34 }));
30 } 35 }
31 36
32 function onActive() { 37 function onActive() {
33 with_iframe(scope, t.step_func(function(frame) {})); 38 with_iframe(scope, t.step_func(function(frame) {}));
34 } 39 }
35 40
36 function onMessage(event) { 41 function onMessage(event) {
37 assert_equals( 42 assert_equals(
38 event.data.url, 43 event.data.url,
39 location.href.substring(0, location.href.lastIndexOf('/') + 1) + sco pe, 44 location.href.substring(0, location.href.lastIndexOf('/') + 1) + sco pe,
40 'request.url should be passed to onfetch event.'); 45 'request.url should be passed to onfetch event.');
41 assert_equals(event.data.method, 'GET', 46 assert_equals(event.data.method, 'GET',
42 'request.method should be passed to onfetch event.'); 47 'request.method should be passed to onfetch event.');
43 assert_equals(event.data.headers['user-agent'], navigator.userAgent, 48 assert_equals(event.data.headers['user-agent'], navigator.userAgent,
44 'User-Agent header should be passed to onfetch event.') 49 'User-Agent header should be passed to onfetch event.')
45 service_worker_unregister_and_done(t, scope); 50 service_worker_unregister_and_done(t, scope);
46 } 51 }
47 }); 52 });
48 </script> 53 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698