Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/service-worker-gc.html |
| diff --git a/LayoutTests/http/tests/serviceworker/service-worker-gc.html b/LayoutTests/http/tests/serviceworker/service-worker-gc.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fcdc4290ee2796a05526feb3363d422bcd858c48 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/service-worker-gc.html |
| @@ -0,0 +1,56 @@ |
| +<!DOCTYPE html> |
| +<script src="/js-test-resources/js-test.js"></script> |
| +<body> |
| +<script> |
| +(function() { |
| + window.jsTestIsAsync = true; |
| + description('Test that a registered Service Worker with an event handler is not garbage collected'); |
|
dominicc (has gone to gerrit)
2014/06/13 19:55:13
Maybe add '...prematurely'?
falken
2014/06/13 22:34:18
Done.
|
| + var worker = 'resources/empty-worker.js'; |
| + var scope = 'gc'; |
| + swObservation = null; |
| + |
| + unregister_and_register(worker, scope).then(onRegister); |
| + |
| + function unregister_and_register(url, scope) { |
| + return navigator.serviceWorker.unregister(scope).then(function() { |
| + return navigator.serviceWorker.register(url, { scope: scope }); |
| + }).catch(function(error) { |
| + debug('Could not register worker: ' + error); |
| + finishJSTest(); |
| + }); |
| + } |
| + |
| + function collectGarbage(shouldBeCollected, description) { |
|
dominicc (has gone to gerrit)
2014/06/13 19:55:13
I'm not sure this function is pulling its weight.
falken
2014/06/13 22:34:18
I tried but there's a couple problems with that:
1
|
| + gc(); |
| + if (swObservation) { |
|
dominicc (has gone to gerrit)
2014/06/13 19:55:13
Would it be better to fail if this is not set up?
falken
2014/06/13 22:34:18
I agree this is making the test more complex and c
|
| + debug(description); |
| + if (shouldBeCollected) |
| + shouldBeTrue('swObservation.wasCollected'); |
| + else |
| + shouldBeFalse('swObservation.wasCollected'); |
| + } |
| + } |
| + |
| + function onUnregister() { |
| + // FIXME: The expectation should be reversed, but our implementation currently fails it. |
| + // When properly implemented, the SW not leak here. It may be better to move this test into a separate, targeted file. |
| + collectGarbage(false, 'Service Worker should not leak after unregistration'); |
| + finishJSTest(); |
| + } |
| + |
| + function onRegister(sw) { |
| + sw.addEventListener('statechange', onStateChange); |
| + if (window.internals) |
| + swObservation = internals.observeGC(sw); |
|
dominicc (has gone to gerrit)
2014/06/13 19:55:13
Is this a global just so shouldBe works?
falken
2014/06/13 22:34:18
That, and onRegister needs it.
|
| + setTimeout(collectGarbage.bind(undefined, false, 'Service Worker should not be gc\'d after registration'), 0); |
| + } |
| + |
| + function onStateChange(event) { |
| + collectGarbage(false, 'Service Worker should not be gc\'d in ' + event.target.state + ' state'); |
|
dominicc (has gone to gerrit)
2014/06/13 19:55:13
If it is garbage collected, won't event.target be
falken
2014/06/13 22:34:18
From what I've seen on the timing out test, if we
|
| + if (event.target.state != 'active') |
| + return; |
| + navigator.serviceWorker.unregister(scope).then(onUnregister); |
| + } |
| +}()); |
| +</script> |
| +</body> |