| Index: third_party/WebKit/LayoutTests/http/tests/security/suborigins/suborigin-foreign-fetch-service-worker.html
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/security/suborigins/suborigin-foreign-fetch-service-worker.html b/third_party/WebKit/LayoutTests/http/tests/security/suborigins/suborigin-foreign-fetch-service-worker.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1e58f2a54bbf9d5922d92071bd7f74cfe06df5aa
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/security/suborigins/suborigin-foreign-fetch-service-worker.html
|
| @@ -0,0 +1,68 @@
|
| +<!DOCTYPE html>
|
| +<meta charset="utf-8">
|
| +<title>ff</title>
|
| +<script src="../../resources/testharness.js"></script>
|
| +<script src="../../resources/testharnessreport.js"></script>
|
| +<script src="../../serviceworker/resources/test-helpers.js"></script>
|
| +<script src = "/resources/get-host-info.js?pipe=sub"></script>
|
| +<body>
|
| +<script>
|
| +var run;
|
| +
|
| +promise_test(t => {
|
| + var host_info = get_host_info();
|
| + var frame_url = host_info['HTTP_REMOTE_ORIGIN'] +
|
| + '/security/suborigins/resources/suborigin-foreign-fetch-service-worker-iframe.html';
|
| + var unregisteredPromise;
|
| + var frame;
|
| + var port;
|
| + return with_iframe(frame_url)
|
| + .then(f => {
|
| + frame = f;
|
| + var resolveActivated;
|
| + var activatedPromise = new Promise(r => { resolveActivated = r;});
|
| + var resolveUnregistered;
|
| + unregisteredPromise = new Promise(r => { resolveUnregistered = r;});
|
| + var channel = new MessageChannel();
|
| + port = channel.port1;
|
| + channel.port1.onmessage = function(e) {
|
| + if (e.data === 'activated') {
|
| + resolveActivated(e.data);
|
| + } else if (e.data === 'unregistered') {
|
| + resolveUnregistered(e.data);
|
| + }
|
| + };
|
| + frame.contentWindow.postMessage('register', '*', [channel.port2]);
|
| + return activatedPromise;
|
| + })
|
| + .then(data => {
|
| + assert_equals(data, 'activated');
|
| + var script = document.createElement('script');
|
| + script.src = host_info['HTTP_REMOTE_ORIGIN'] +
|
| + '/security/suborigins/resources/sw-scope/test.js';
|
| + var resolve;
|
| + var p = new Promise(r => { run = r; });
|
| + document.body.appendChild(script);
|
| + return p;
|
| + })
|
| + .then(data => {
|
| + assert_equals(data, 'from foreignfetch');
|
| + var resolve;
|
| + var p = new Promise(r => { resolve = r; });
|
| + window.onmessage = event => { resolve(event.data); };
|
| + with_iframe('./resources/suborigin-foreign-fetch-service-worker-iframe.php');
|
| + return p;
|
| + })
|
| + .then(data => {
|
| + // Suborigin is set for suborigin-foreign-fetch-service-worker-iframe.php.
|
| + // So the script loaded in the iframe must be served from server.
|
| + assert_equals(data, 'from server');
|
| + port.postMessage('unregister');
|
| + return unregisteredPromise;
|
| + })
|
| + .then(data => {
|
| + assert_equals(data, 'unregistered');
|
| + });
|
| +}, 'a.');
|
| +</script>
|
| +</body>
|
|
|