Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/claim-with-redirect-iframe.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/claim-with-redirect-iframe.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/claim-with-redirect-iframe.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..837635c719e62ac6758151c2c1806949b0c84522 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/claim-with-redirect-iframe.html |
| @@ -0,0 +1,69 @@ |
| +<!DOCTYPE html> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="../resources/test-helpers.js"></script> |
| +<script src="../../resources/get-host-info.js"></script> |
| +<body> |
| +<script> |
| +var host_info = get_host_info(); |
| + |
| +function get_query_params(url) { |
|
nhiroki
2016/08/19 05:26:52
URLSearchParams could be available instead of this
shimazu
2016/08/19 09:43:15
Done.
|
| + var search = (new URL(url)).search; |
| + if (!search) { |
| + return {}; |
| + } |
| + var ret = {}; |
| + var params = search.substring(1).split('&'); |
| + params.forEach(function(param) { |
| + var element = param.split('='); |
| + ret[decodeURIComponent(element[0])] = decodeURIComponent(element[1]); |
| + }); |
| + return ret; |
| +} |
| + |
| +function send_result(result) { |
| + window.parent.postMessage({message: result}, |
| + host_info['HTTP_ORIGIN']); |
| +} |
| + |
| +function executeTask(params) { |
| + /* Execute task for each parameter */ |
|
nhiroki
2016/08/19 05:26:52
ditto(comment format)
shimazu
2016/08/19 09:43:15
Done.
|
| + if (params.hasOwnProperty('register')) { |
| + var worker_url = decodeURIComponent(params.register); |
| + var scope = decodeURIComponent(params.scope); |
| + console.log('[iframe] register: ', worker_url); |
|
nhiroki
2016/08/19 05:26:52
Can you remove these console outputs?
shimazu
2016/08/19 09:43:15
Done.
|
| + navigator.serviceWorker.register(worker_url, {scope: scope}) |
| + .then(function(r) { |
| + send_result('registered'); |
| + }); |
| + } else if (params.hasOwnProperty('unregister')) { |
| + var scope = decodeURIComponent(params.unregister); |
| + console.log('[iframe] unregister: ', scope); |
| + navigator.serviceWorker.getRegistration(scope) |
| + .then(function(r) { |
| + r.unregister(); |
|
nhiroki
2016/08/19 05:26:52
Probably we should wait until unregister() is comp
shimazu
2016/08/19 09:43:15
Done.
|
| + send_result('unregistered'); |
| + }); |
| + } else if (params.hasOwnProperty('update')) { |
| + var scope = decodeURIComponent(params.update); |
| + navigator.serviceWorker.getRegistration(scope) |
| + .then(function(r) { |
| + return r.update(); |
| + }) |
| + .then(function() { |
| + send_result('updated'); |
| + }); |
| + } else if (params.hasOwnProperty('redirected')) { |
| + console.log('[iframe] redirected: ', document.referrer); |
| + send_result('redirected'); |
| + } |
|
nhiroki
2016/08/19 05:26:52
Can you reorder these if/else-if blocks in registe
shimazu
2016/08/19 09:43:15
Done.
|
| +} |
| + |
| +addEventListener('message', function(e) { |
| + executeTask(e.data); |
|
nhiroki
2016/08/19 05:26:52
We may want to wait until the task is complete lik
shimazu
2016/08/19 09:43:16
Done.
|
| + }); |
| + |
| +var params = get_query_params(location.href); |
| +executeTask(params); |
| +</script> |
| +</body> |