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

Unified Diff: LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/unregister.html

Issue 900793002: ServiceWorker: Support SWRegistration.unregister() in SWGlobalScope [2/2] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: return nullptr instead of 0 Created 5 years, 10 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/ServiceWorkerGlobalScope/unregister.html
diff --git a/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/unregister.html b/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/unregister.html
new file mode 100644
index 0000000000000000000000000000000000000000..4eeeac057c98dbce1a66facc266e8721a2b89f1c
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/unregister.html
@@ -0,0 +1,139 @@
+<!DOCTYPE html>
+<title>ServiceWorkerGlobalScope: unregister</title>
+<script src='../../resources/testharness.js'></script>
+<script src='../../resources/testharnessreport.js'></script>
+<script src='../resources/test-helpers.js'></script>
+<script>
+
+promise_test(function(t) {
+ var script = 'resources/unregister-worker.js?evaluation';
+ var scope = 'resources/scope/unregister-on-script-evaluation';
+
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(function(registration) {
+ return wait_for_state(t, registration.installing, 'redundant');
+ })
+ .then(function() {
+ return navigator.serviceWorker.getRegistration(scope);
+ })
+ .then(function(result) {
+ assert_equals(
+ result,
+ undefined,
+ 'After unregister(), the registration should not found');
+ return service_worker_unregister_and_done(t, scope);
+ });
+ }, 'Unregister on script evaluation');
+
+promise_test(function(t) {
+ var script = 'resources/unregister-worker.js?install';
+ var scope = 'resources/scope/unregister-on-install-event';
+
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(function(registration) {
+ return wait_for_state(t, registration.installing, 'redundant');
+ })
+ .then(function() {
+ return navigator.serviceWorker.getRegistration(scope);
+ })
+ .then(function(result) {
+ assert_equals(
+ result,
+ undefined,
+ 'After unregister(), the registration should not found');
+ return service_worker_unregister_and_done(t, scope);
+ });
+ }, 'Unregister on installing event');
+
+promise_test(function(t) {
+ var script = 'resources/unregister-worker.js?activate';
+ var scope = 'resources/scope/unregister-on-activate-event';
+
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(function(registration) {
+ return wait_for_state(t, registration.installing, 'redundant');
+ })
+ .then(function() {
+ return navigator.serviceWorker.getRegistration(scope);
+ })
+ .then(function(result) {
+ assert_equals(
+ result,
+ undefined,
+ 'After unregister(), the registration should not found');
+ return service_worker_unregister_and_done(t, scope);
+ });
+ }, 'Unregister on activate event');
+
+promise_test(function(t) {
+ var script = 'resources/unregister-worker.js';
+ var scope = 'resources/unregister-controlling-worker';
+ var frame_url = 'resources/unregister-controlling-worker-iframe.html';
+ var text_url = '../../resources/simple.txt?request';
+
+ var worker;
+ var frame1, frame2;
+
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(function(registration) {
+ worker = registration.installing;
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(function() { return with_iframe(frame_url); })
+ .then(function(f) {
+ frame1 = f;
+ return frame1.contentWindow.fetch_url(text_url);
+ })
+ .then(function(response) {
+ assert_equals(
+ response,
+ 'Intercepted by service worker',
+ 'Service worker should respond to fetch from iframe under control');
falken 2015/02/05 12:07:57 Our old tests did this because we didn't yet have
nhiroki 2015/02/06 03:49:29 That's a neat solution! Updated here and elsewhere
+
+ // Wait for the completion of unregistrer() on the worker.
falken 2015/02/05 12:07:57 nit: unregister()
nhiroki 2015/02/06 03:49:29 Done.
+ var channel = new MessageChannel();
+ var promise = new Promise(function(resolve) {
+ channel.port1.onmessage = t.step_func(function(e) {
+ assert_true(e.data.result,
+ 'unregister() should successfully finish');
+ resolve();
+ });
+ });
+ worker.postMessage({port: channel.port2}, [channel.port2]);
+ return promise;
+ })
+ .then(function() {
+ return navigator.serviceWorker.getRegistration(frame_url);
+ })
+ .then(function(result) {
+ assert_equals(
+ result,
+ undefined,
+ 'After unregister(), the registration should not found');
+ return frame1.contentWindow.fetch_url(text_url);
falken 2015/02/05 12:07:57 just check controller here and below
nhiroki 2015/02/06 03:49:29 Done.
+ })
+ .then(function(response) {
+ assert_equals(
+ response,
+ 'Intercepted by service worker',
+ 'Service worker should still control the iframe');
+ return with_iframe(frame_url);
+ })
+ .then(function(f) {
+ frame2 = f;
+ return frame2.contentWindow.fetch_url(text_url);
+ })
+ .then(function(response) {
+ assert_equals(
+ response,
+ 'a simple text file\n',
+ 'Service worker should not control newly opened iframe ' +
+ 'after unregister()');
+
+ frame1.remove();
+ frame2.remove();
+ return service_worker_unregister_and_done(t, scope);
+ })
+ }, 'Unregister controlling service worker');
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698