Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <script src="test-helpers.js?pipe=sub"></script> | |
| 2 <script> | |
| 3 var port = undefined; | |
| 4 var scope = 'fetch-request-body-file-test'; | |
| 5 var script = 'fetch-request-body-file-worker.js'; | |
| 6 | |
| 7 window.addEventListener('message', function(evt) { | |
| 8 port = evt.ports[0]; | |
| 9 start(); | |
| 10 }, false); | |
| 11 | |
| 12 function start() { | |
| 13 if (location.search == '?register') { | |
| 14 navigator.serviceWorker.register(script, {scope: scope}) | |
| 15 .then(function(registration) { | |
| 16 return registration.unregister(); | |
| 17 }) | |
| 18 .then(function() { | |
| 19 return navigator.serviceWorker.register(script, {scope: scope}); | |
| 20 }) | |
| 21 .then(function(registration) { | |
| 22 return new Promise(function(resolve) { | |
| 23 registration.addEventListener('updatefound', function() { | |
| 24 resolve(registration.installing); | |
| 25 }); | |
| 26 }); | |
|
nhiroki
2014/08/25 04:29:37
How about factoring out this to 'wait_for_update()
horo
2014/08/25 11:20:23
Done.
| |
| 27 }) | |
| 28 .then(function(worker) { | |
| 29 return new Promise(function(resolve) { | |
| 30 worker.addEventListener('statechange', function() { | |
| 31 if (worker.state == 'activated') { | |
| 32 resolve(worker); | |
| 33 } | |
| 34 }); | |
| 35 }); | |
|
nhiroki
2014/08/25 04:29:37
ditto.
horo
2014/08/25 11:20:23
Done.
| |
| 36 }) | |
| 37 .then(function(worker) { | |
| 38 port.postMessage({msg: 'registered'}); | |
| 39 }); | |
| 40 } else if (location.search == '?unregister') { | |
| 41 navigator.serviceWorker.register(script, {scope: scope}) | |
| 42 .then(function(registration) { | |
| 43 return registration.unregister(); | |
| 44 }) | |
| 45 .then(function() { | |
| 46 port.postMessage({msg: 'unregistered'}); | |
| 47 }); | |
| 48 } | |
| 49 } | |
| 50 </script> | |
| OLD | NEW |