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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/service-workers/service-worker/resources/navigation-redirect-other-origin.html

Issue 2415873002: Import w3c tests for the service workers (Closed)
Patch Set: Rebase Created 4 years, 2 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 <script src="../../resources/get-host-info.js?pipe=sub"></script> 2 <script src="get-host-info.sub.js"></script>
3 <script src="test-helpers.js"></script> 3 <script src="test-helpers.sub.js"></script>
4 <script> 4 <script>
5 var host_info = get_host_info(); 5 var host_info = get_host_info();
6 var SCOPE = 'navigation-redirect-scope1.php'; 6 var SCOPE = 'navigation-redirect-scope1.py';
7 var SCRIPT = 'navigation-redirect-worker.js'; 7 var SCRIPT = 'navigation-redirect-worker.js';
8 8
9 var registration; 9 var registration;
10 var worker; 10 var worker;
11 var wait_for_worker_promise = navigator.serviceWorker.getRegistration(SCOPE) 11 var wait_for_worker_promise = navigator.serviceWorker.getRegistration(SCOPE)
12 .then(function(reg) { 12 .then(function(reg) {
13 if (reg) 13 if (reg)
14 return reg.unregister(); 14 return reg.unregister();
15 }) 15 })
16 .then(function() { 16 .then(function() {
17 return navigator.serviceWorker.register(SCRIPT, {scope: SCOPE}); 17 return navigator.serviceWorker.register(SCRIPT, {scope: SCOPE});
18 }) 18 })
19 .then(function(reg) { 19 .then(function(reg) {
20 registration = reg; 20 registration = reg;
21 worker = reg.installing; 21 worker = reg.installing;
22 return new Promise(function(resolve) { 22 return new Promise(function(resolve) {
23 worker.addEventListener('statechange', function() { 23 worker.addEventListener('statechange', function() {
24 if (worker.state == 'activated') 24 if (worker.state == 'activated')
25 resolve(); 25 resolve();
26 }); 26 });
27 }); 27 });
28 }); 28 });
29 29
30 function send_result(message_id, result) { 30 function send_result(message_id, result) {
31 window.parent.postMessage( 31 window.parent.postMessage(
32 {id: message_id, result: result}, 32 {id: message_id, result: result},
33 host_info['HTTP_ORIGIN']); 33 host_info['HTTPS_ORIGIN']);
34 } 34 }
35 35
36 function get_intercepted_urls(worker) { 36 function get_intercepted_urls(worker) {
37 return new Promise(function(resolve) { 37 return new Promise(function(resolve) {
38 var channel = new MessageChannel(); 38 var channel = new MessageChannel();
39 channel.port1.onmessage = function(msg) { resolve(msg.data.urls); }; 39 channel.port1.onmessage = function(msg) { resolve(msg.data.urls); };
40 worker.postMessage({port: channel.port2}, [channel.port2]); 40 worker.postMessage({port: channel.port2}, [channel.port2]);
41 }); 41 });
42 } 42 }
43 43
44 window.addEventListener('message', on_message, false); 44 window.addEventListener('message', on_message, false);
45 45
46 function on_message(e) { 46 function on_message(e) {
47 if (e.origin != host_info['HTTP_ORIGIN']) { 47 if (e.origin != host_info['HTTPS_ORIGIN']) {
48 console.error('invalid origin: ' + e.origin); 48 console.error('invalid origin: ' + e.origin);
49 return; 49 return;
50 } 50 }
51 if (e.data.message == 'wait_for_worker') { 51 if (e.data.message == 'wait_for_worker') {
52 wait_for_worker_promise.then(function() { send_result(e.data.id, 'ok'); }); 52 wait_for_worker_promise.then(function() { send_result(e.data.id, 'ok'); });
53 } else if (e.data.message == 'get_intercepted_urls') { 53 } else if (e.data.message == 'get_intercepted_urls') {
54 get_intercepted_urls(worker) 54 get_intercepted_urls(worker)
55 .then(function(urls) { 55 .then(function(urls) {
56 send_result(e.data.id, urls); 56 send_result(e.data.id, urls);
57 }); 57 });
58 } else if (e.data.message == 'unregister') { 58 } else if (e.data.message == 'unregister') {
59 registration.unregister() 59 registration.unregister()
60 .then(function() { 60 .then(function() {
61 send_result(e.data.id, 'ok'); 61 send_result(e.data.id, 'ok');
62 }); 62 });
63 } 63 }
64 } 64 }
65 65
66 </script> 66 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698