| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="test-helpers.js?pipe=sub"></script> | 2 <script src="test-helpers.js?pipe=sub"></script> |
| 3 <script> | 3 <script> |
| 4 var SCOPE = 'fetch-mixed-content-iframe-inscope.html'; | 4 var SCOPE = 'fetch-mixed-content-iframe-inscope.html'; |
| 5 var URL = 'fetch-rewrite-worker.js'; | 5 var URL = 'fetch-rewrite-worker.js'; |
| 6 var host_info = get_host_info(); | 6 var host_info = get_host_info(); |
| 7 | 7 |
| 8 window.addEventListener('message', on_message, false); | 8 window.addEventListener('message', on_message, false); |
| 9 | 9 |
| 10 navigator.serviceWorker.unregister(SCOPE) | 10 navigator.serviceWorker.unregister(SCOPE) |
| 11 .then(function() { | 11 .then(function() { |
| 12 return navigator.serviceWorker.register(URL, {scope: SCOPE}); | 12 return navigator.serviceWorker.register(URL, {scope: SCOPE}); |
| 13 }) | 13 }) |
| 14 .then(function(registration) { |
| 15 return new Promise(function(resolve, reject) { |
| 16 registration.addEventListener('updatefound', function() { |
| 17 resolve(registration.installing); |
| 18 }); |
| 19 }); |
| 20 }) |
| 14 .then(function(worker) { | 21 .then(function(worker) { |
| 15 worker.addEventListener('statechange', on_state_change); | 22 worker.addEventListener('statechange', on_state_change); |
| 16 }); | 23 }); |
| 17 | 24 |
| 18 function on_state_change(event) { | 25 function on_state_change(event) { |
| 19 if (event.target.state != 'activated') | 26 if (event.target.state != 'activated') |
| 20 return; | 27 return; |
| 21 var frame = document.createElement('iframe'); | 28 var frame = document.createElement('iframe'); |
| 22 frame.src = SCOPE; | 29 frame.src = SCOPE; |
| 23 document.body.appendChild(frame); | 30 document.body.appendChild(frame); |
| 24 } | 31 } |
| 25 | 32 |
| 26 function on_message(e) { | 33 function on_message(e) { |
| 27 navigator.serviceWorker.unregister(SCOPE) | 34 navigator.serviceWorker.unregister(SCOPE) |
| 28 .then(function() { | 35 .then(function() { |
| 29 window.parent.postMessage(e.data, host_info['HTTP_ORIGIN']); | 36 window.parent.postMessage(e.data, host_info['HTTP_ORIGIN']); |
| 30 }); | 37 }); |
| 31 } | 38 } |
| 32 </script> | 39 </script> |
| OLD | NEW |