Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="/js-test-resources/js-test.js"></script> | |
| 3 <body> | |
| 4 <script> | |
| 5 window.jsTestIsAsync = true; | |
| 6 description('Test that a registered Service Worker with an event handler is not garbage collected prematurely'); | |
| 7 swObservation = null; | |
| 8 scope = 'gc'; | |
| 9 | |
| 10 if (!window.internals) { | |
| 11 testFailed('This test requires internals.observeGC'); | |
| 12 finishJSTest(); | |
| 13 } else { | |
| 14 setup(); | |
| 15 } | |
| 16 | |
| 17 function setup() { | |
| 18 var worker = 'resources/empty-worker.js'; | |
| 19 unregisterAndRegister(worker, scope).then(onRegister); | |
| 20 } | |
| 21 | |
| 22 function unregisterAndRegister(url, scope) { | |
| 23 return navigator.serviceWorker.unregister(scope).then(function() { | |
| 24 return navigator.serviceWorker.register(url, { scope: scope }); | |
| 25 }).catch(function(error) { | |
| 26 testFailed('Could not register worker: ' + error); | |
| 27 finishJSTest(); | |
| 28 }); | |
| 29 } | |
| 30 | |
| 31 function assertServiceWorkerIsNotCollected() { | |
| 32 gc(); | |
| 33 shouldBeFalse('swObservation.wasCollected') | |
| 34 } | |
| 35 | |
| 36 function onRegister(sw) { | |
| 37 swObservation = internals.observeGC(sw); | |
| 38 sw.addEventListener('statechange', onStateChange); | |
| 39 setTimeout(assertServiceWorkerIsNotCollected, 0); | |
| 40 } | |
| 41 | |
| 42 function onStateChange(event) { | |
| 43 gc(); | |
|
dominicc (has gone to gerrit)
2014/06/16 05:00:23
Maybe just call assertServiceWorkerIsNotCollected
falken
2014/06/16 08:29:20
Good point, done.
| |
| 44 shouldBeFalse('swObservation.wasCollected'); | |
| 45 | |
| 46 if (event.target.state != 'active') | |
| 47 return; | |
| 48 navigator.serviceWorker.unregister(scope).then(onUnregister); | |
| 49 } | |
| 50 | |
| 51 function onUnregister() | |
| 52 { | |
| 53 gc(); | |
| 54 // FIXME: Assert that the ServiceWorker *is* collected when the 'redundant' state is implemented. | |
| 55 shouldBeFalse('swObservation.wasCollected') | |
| 56 | |
| 57 finishJSTest(); | |
| 58 } | |
| 59 </script> | |
| 60 </body> | |
| OLD | NEW |