Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created May 19, 2017 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugglinmike/52ab1358ab0c5ce0ef51e314bedd4427 to your computer and use it in GitHub Desktop.
Save jugglinmike/52ab1358ab0c5ce0ef51e314bedd4427 to your computer and use it in GitHub Desktop.
sw-migration-iframe-sandbox.diff
2,5c2,5
< <script src="../resources/testharness.js"></script>
< <script src="../resources/testharnessreport.js"></script>
< <script src="resources/test-helpers.js"></script>
< <script src="resources/registration-tests.js"></script>
---
> <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>
8,16c8,17
< async_test(function(t) {
< window.addEventListener('message', function(e) {
< if (e.data == 'error') {
< t.step(function() {
< t.done();
< });
< } else {
< t.step(function() {
< assert_unreached('iframe successfully loaded service worker');
---
> '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);
> });
18a20,49
>
> 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');
20c51
< }, 'Sandboxed iframe should not be able to register service worker with link rel');
---
> }, 'registration via <link> element `rel` accepted in presence of `allow-same-origin` directive');
22d52
< <iframe src="resources/iframe-register-link-element.html" sandbox="allow-scripts"></iframe>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment