| Index: third_party/WebKit/LayoutTests/http/tests/security/suborigins/resources/suborigin-foreign-fetch-service-worker-iframe.html
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/security/suborigins/resources/suborigin-foreign-fetch-service-worker-iframe.html b/third_party/WebKit/LayoutTests/http/tests/security/suborigins/resources/suborigin-foreign-fetch-service-worker-iframe.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0beda1d03d4c5f0b0e5a2f6cb01164954d744125
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/security/suborigins/resources/suborigin-foreign-fetch-service-worker-iframe.html
|
| @@ -0,0 +1,50 @@
|
| +<!DOCTYPE html>
|
| +<script>
|
| +var scope = './sw-scope/';
|
| +var script = 'suborigin-foreign-fetch-service-worker-worker.js';
|
| +var registration;
|
| +var port;
|
| +
|
| +function wait_for_activated(worker) {
|
| + var state = 'activated';
|
| + if (!worker)
|
| + return Promise.reject(new Error('No ServiceWorker'));
|
| + if (worker.state === 'redundant')
|
| + return Promise.reject(new Error('Worker is redundant'));
|
| + if (worker.state === state)
|
| + return Promise.resolve(state);
|
| + return new Promise(resolve => {
|
| + worker.addEventListener('statechange', _ => {
|
| + if (worker.state === state)
|
| + resolve(state);
|
| + });
|
| + });
|
| +}
|
| +
|
| +self.onmessage = function(e) {
|
| + if (e.data == 'register') {
|
| + port = e.ports[0];
|
| + port.onmessage = function(e) {
|
| + if (e.data == 'unregister') {
|
| + registration.unregister()
|
| + .then(function() {
|
| + port.postMessage('unregistered');
|
| + });
|
| + }
|
| + };
|
| + }
|
| +
|
| + navigator.serviceWorker.register(script, { scope: scope })
|
| + .then(function(r) {
|
| + registration = r;
|
| + var worker = registration.active;
|
| + if (!worker) {
|
| + worker = registration.installing;
|
| + }
|
| + return wait_for_activated(worker);
|
| + })
|
| + .then(function() {
|
| + e.ports[0].postMessage('activated');
|
| + });
|
| +};
|
| +</script>
|
|
|