Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(874)

Unified Diff: LayoutTests/http/tests/serviceworker/service-worker-gc.html

Issue 330173003: Make ServiceWorker an ActiveDOMObject (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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>

Powered by Google App Engine
This is Rietveld 408576698