Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/clients-get-other-origin.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/clients-get-other-origin.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/clients-get-other-origin.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2b2412d3ce421c893f75bbcb3df7580276bf590 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/clients-get-other-origin.html |
| @@ -0,0 +1,64 @@ |
| +<!DOCTYPE html> |
| +<script src="../../resources/get-host-info.js"></script> |
| +<script src="test-helpers.js"></script> |
| +<script> |
| +var host_info = get_host_info(); |
| +var SCOPE = 'blank.html?clients-get'; |
| +var SCRIPT = 'clients-get-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(); |
| + }); |
| + }); |
| + }); |
| + |
| +function send_result(result) { |
| + window.parent.postMessage( |
| + {result: result}, |
| + host_info['HTTP_ORIGIN']); |
| +} |
| + |
| +window.addEventListener("message", on_message, false); |
|
nhiroki
2016/02/03 09:40:00
"..." -> '...'
How about inlining 'on_message' ha
jungkees
2016/02/03 14:15:07
Done.
|
| + |
| +function on_message(e) { |
| + if (e.origin != host_info['HTTP_ORIGIN']) { |
| + console.error('invalid origin: ' + e.origin); |
|
nhiroki
2016/02/03 09:40:00
Can you use assert_equals() instead of console.err
jungkees
2016/02/03 14:15:07
Done.
|
| + return; |
| + } |
| + if (e.data.message == 'get_client_id') { |
| + var otherOriginClientId = e.data.clientId; |
| + wait_for_worker_promise |
| + .then(function() { |
| + return with_iframe(SCOPE); |
| + }) |
| + .then(function(iframe) { |
| + var channel = new MessageChannel(); |
| + channel.port1.onmessage = function(e) { |
| + navigator.serviceWorker.getRegistration(SCOPE) |
| + .then(function(reg) { |
| + reg.unregister(); |
| + send_result(e.data); |
| + }); |
| + }; |
| + iframe.contentWindow.navigator.serviceWorker.controller.postMessage( |
| + {port:channel.port2, clientId: otherOriginClientId, |
| + message: 'get_other_client_id'}, [channel.port2]); |
| + }) |
| + } |
| +} |
| +</script> |