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..e924445b1151985d18a4897c07d5ab7b310baa97 |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/service-worker-gc.html |
| @@ -0,0 +1,43 @@ |
| +<!DOCTYPE html> |
| +<script src="../resources/testharness.js"></script> |
|
dominicc (has gone to gerrit)
2014/06/12 22:23:38
This should use the Blink test harness. GC is an i
falken
2014/06/13 19:22:59
Done.
|
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="resources/test-helpers.js"></script> |
| +<script src="resources/gc.js"></script> |
| +<body> |
| +<script> |
| +(function() { |
| + var t = async_test('A registered Service Worker with an event handler is not garbage collected'); |
|
dominicc (has gone to gerrit)
2014/06/12 22:23:38
FYI I have started doing
async_test(function(t) {
|
| + var worker = 'resources/empty-worker.js' |
| + var scope = 'gc'; |
| + var swObservation = null; |
| + service_worker_unregister_and_register(t, worker, scope, onRegister); |
| + |
| + function collectGarbage(shouldBeCollected, description) { |
| + gc(); |
| + if (swObservation) |
| + assert_equals(swObservation.wasCollected, shouldBeCollected, description); |
| + } |
| + |
| + function onUnregister() { |
| + // FIXME: The expectation should be reversed, but our implementation currently fails it. |
|
dominicc (has gone to gerrit)
2014/06/12 22:23:38
I think you want to rephrase this as a "leak test"
falken
2014/06/13 19:22:59
OK, the idea being that the test would succeed on
|
| + // When properly implemented, the SW should be garbage collected here. |
| + t.step(collectGarbage.bind(undefined, false, 'Service Worker should be gc\'d after unregistration')); |
| + t.done(); |
| + } |
| + |
| + function onRegister(sw) { |
|
dominicc (has gone to gerrit)
2014/06/12 22:23:38
FYI I am moving to using promises instead of callb
falken
2014/06/13 19:22:59
Done. Yes, I think that's a good idea. Our test-he
|
| + sw.addEventListener('statechange', t.step_func(onStateChange)); |
| + if (window.internals) |
| + swObservation = internals.observeGC(sw); |
| + setTimeout(t.step_func(collectGarbage.bind(undefined, false, 'Service Worker should not be gc\'d after registration')), 0); |
| + } |
| + |
| + function onStateChange(event) { |
| + t.step(collectGarbage.bind(undefined, false, 'Service Worker should not be gc\'d inside onStateChange handler')); |
| + if (event.target.state != 'active') |
| + return; |
| + navigator.serviceWorker.unregister(scope).then(t.step_func(onUnregister)); |
| + } |
| +}()); |
| +</script> |
| +</body> |