Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html |
| diff --git a/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html b/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..27ff0e54efd43b62f6a4d39207c4ea1e2424edf8 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/resources/navigation-redirect-other-origin.html |
| @@ -0,0 +1,66 @@ |
| +<!DOCTYPE html> |
| +<script src="../../resources/get-host-info.js"></script> |
| +<script src="test-helpers.js?pipe=sub"></script> |
| +<script> |
| +var host_info = get_host_info(); |
| +var SCOPE = 'navigation-redirect-scope1.php'; |
| +var SCRIPT = 'navigation-redirect-worker.js'; |
| + |
| +var registration; |
| +var worker; |
| +var wait_for_worker_promise = navigator.serviceWorker.getRegistration(SCOPE) |
| + .then(function(reg) { |
| + if (reg) |
| + return reg.unregister(); |
| + }) |
| + .then(function() { |
| + return navigator.serviceWorker.register(SCRIPT, {scope: SCOPE}); |
| + }) |
| + .then(function(reg) { |
| + registration = reg; |
| + worker = reg.installing; |
| + return new Promise(function(resolve) { |
| + worker.addEventListener('statechange', function() { |
| + if (worker.state == 'activated') |
| + resolve(); |
| + }); |
|
falken
2015/08/17 06:18:29
+2 indent
horo
2015/08/19 08:33:00
Done.
|
| + }); |
|
falken
2015/08/17 06:18:28
can this just be return wait_for_state(worker, 'ac
horo
2015/08/19 08:33:00
I think we can use wait_for_state() only when we h
|
| + }); |
| + |
| +function send_result(message_id, result) { |
| + window.parent.postMessage( |
| + {id: message_id, result: result}, |
| + host_info['HTTP_ORIGIN']); |
| +} |
| + |
| +function get_intercepted_urls(worker) { |
| + return new Promise(function(resolve) { |
| + var channel = new MessageChannel(); |
| + channel.port1.onmessage = function(msg) { resolve(msg.data.urls); }; |
| + worker.postMessage({port: channel.port2}, [channel.port2]); |
| + }); |
| +} |
| + |
| +window.addEventListener('message', on_message, false); |
| + |
| +function on_message(e) { |
| + if (e.origin != host_info['HTTP_ORIGIN']) { |
| + console.error('invalid origin: ' << e.origin); |
|
falken
2015/08/17 06:18:28
<< should be +
horo
2015/08/19 08:33:00
Done.
|
| + return; |
| + } |
| + if (e.data.message == 'wait_for_worker') { |
| + wait_for_worker_promise.then(function() { send_result(e.data.id, 'ok'); }); |
| + } else if (e.data.message == 'get_intercepted_urls') { |
| + get_intercepted_urls(worker) |
| + .then(function(urls) { |
| + send_result(e.data.id, urls); |
| + }) |
| + } else if (e.data.message == 'unregister') { |
| + registration.unregister() |
| + .then(function() { |
| + send_result(e.data.id, 'ok'); |
| + }) |
|
falken
2015/08/17 06:18:29
missing ;
horo
2015/08/19 08:33:00
Done.
|
| + } |
| +} |
| + |
| +</script> |