| <!DOCTYPE html> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="resources/test-helpers.sub.js"></script> |
| <title>Service worker registration from within sandboxed iframe</title> |
| <body> |
| <script> |
| 'use strict'; |
| function waitForMsg(id) { |
| return new Promise(function(resolve) { |
| window.addEventListener('message', function onMessage(event) { |
| if (!event.data || event.data.id !== id) { |
| return; |
| } |
| window.removeEventListener('message', onMessage); |
| resolve(event.data.result); |
| }); |
| }); |
| } |
| |
| promise_test(function(t) { |
| var iframe = document.createElement('iframe'); |
| iframe.setAttribute('src', 'resources/iframe-register-link-element.html?subtest1'); |
| iframe.setAttribute('sandbox', 'allow-scripts'); |
| |
| document.body.appendChild(iframe); |
| t.add_cleanup(function() { |
| iframe.remove(); |
| }); |
| |
| return waitForMsg('?subtest1') |
| .then(function(data) { |
| assert_equals(data, 'error'); |
| }); |
| }, 'registration via <link> element `rel` rejected'); |
| |
| promise_test(function(t) { |
| var iframe = document.createElement('iframe'); |
| iframe.setAttribute('src', 'resources/iframe-register-link-element.html?subtest2'); |
| iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin'); |
| |
| document.body.appendChild(iframe); |
| t.add_cleanup(function() { |
| iframe.remove(); |
| }); |
| |
| return waitForMsg('?subtest2') |
| .then(function(data) { |
| assert_equals(data, 'loaded'); |
| }); |
| }, 'registration via <link> element `rel` accepted in presence of `allow-same-origin` directive'); |
| </script> |
| </body> |