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..dd7ae79fc2cccc565a0b12b001fad2aeaa34dc96 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/claim-with-redirect-iframe.html |
| @@ -0,0 +1,74 @@ |
| +<!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 14:32:53
Is this no longer necessary?
shimazu
2016/08/22 02:38:10
Yes, sorry!
Removed.
|
| + 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 |
| + if (params.has('register')) { |
| + var worker_url = decodeURIComponent(params.get('register')); |
| + var scope = decodeURIComponent(params.get('scope')); |
| + return navigator.serviceWorker.register(worker_url, {scope: scope}) |
| + .then(function(r) { |
| + send_result('registered'); |
| + }); |
| + } else if (params.has('redirected')) { |
| + send_result('redirected'); |
| + return Promise.resolve(); |
| + } else if (params.has('update')) { |
| + var scope = decodeURIComponent(params.get('update')); |
| + return navigator.serviceWorker.getRegistration(scope) |
| + .then(function(r) { |
| + return r.update(); |
| + }) |
| + .then(function() { |
| + send_result('updated'); |
| + }); |
| + } else if (params.has('unregister')) { |
| + var scope = decodeURIComponent(params.get('unregister')); |
| + return navigator.serviceWorker.getRegistration(scope) |
| + .then(function(r) { |
| + return r.unregister(); |
| + }) |
| + .then(function(succeeded) { |
| + if (succeeded) { |
| + send_result('unregistered'); |
| + } else { |
| + send_result('failure: unregister'); |
| + } |
| + }); |
| + } |
| + return Promise.reject('unknown parameter: ' + params.toString()); |
| +} |
| + |
| +addEventListener('message', function(e) { |
|
nhiroki
2016/08/19 14:32:53
Who sends a message to this frame?
shimazu
2016/08/22 02:38:10
Ah, I just forgot to remove it. This was used for
|
| + e.waitUntil(executeTask(e.data)); |
|
nhiroki
2016/08/19 14:32:53
Oops, sorry!! I assumed this file is a sw script,
shimazu
2016/08/22 02:38:10
Oh, I don't know the message event doesn't have wa
|
| + }); |
| + |
| +var params = new URLSearchParams(location.search.slice(1)); |
| +executeTask(params); |
| +</script> |
| +</body> |