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

Side by Side 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: update layout tests and header comment 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>ServiceWorkerGlobalScope: unregister</title>
3 <script src='../../resources/testharness.js'></script>
4 <script src='../../resources/testharnessreport.js'></script>
5 <script src='../resources/test-helpers.js'></script>
6 <script>
7
8 promise_test(function(t) {
9 var script = 'resources/unregister-worker.js?evaluation';
10 var scope = 'resources/scope/unregister-on-script-evaluation';
11
12 return service_worker_unregister_and_register(t, script, scope)
13 .then(function(registration) {
14 return wait_for_state(t, registration.installing, 'redundant');
15 })
16 .then(function() {
17 return navigator.serviceWorker.getRegistration(scope);
18 })
19 .then(function(result) {
20 assert_equals(
21 result,
22 undefined,
23 'After unregister(), the registration should not found');
24 return service_worker_unregister_and_done(t, scope);
25 });
26 }, 'Unregister on script evaluation');
27
28 promise_test(function(t) {
29 var script = 'resources/unregister-worker.js?install';
30 var scope = 'resources/scope/unregister-on-install-event';
31
32 return service_worker_unregister_and_register(t, script, scope)
33 .then(function(registration) {
34 return wait_for_state(t, registration.installing, 'redundant');
35 })
36 .then(function() {
37 return navigator.serviceWorker.getRegistration(scope);
38 })
39 .then(function(result) {
40 assert_equals(
41 result,
42 undefined,
43 'After unregister(), the registration should not found');
44 return service_worker_unregister_and_done(t, scope);
45 });
46 }, 'Unregister on installing event');
47
48 promise_test(function(t) {
49 var script = 'resources/unregister-worker.js?activate';
50 var scope = 'resources/scope/unregister-on-activate-event';
51
52 return service_worker_unregister_and_register(t, script, scope)
53 .then(function(registration) {
54 return wait_for_state(t, registration.installing, 'redundant');
55 })
56 .then(function() {
57 return navigator.serviceWorker.getRegistration(scope);
58 })
59 .then(function(result) {
60 assert_equals(
61 result,
62 undefined,
63 'After unregister(), the registration should not found');
64 return service_worker_unregister_and_done(t, scope);
65 });
66 }, 'Unregister on activate event');
67
68 promise_test(function(t) {
69 var script = 'resources/unregister-worker.js';
70 var scope = 'resources/unregister-controlling-worker';
71
72 var controller;
73 var frame;
74
75 return service_worker_unregister_and_register(t, script, scope)
76 .then(function(registration) {
77 return wait_for_state(t, registration.installing, 'activated');
78 })
79 .then(function() { return with_iframe(scope); })
80 .then(function(f) {
81 frame = f;
82 controller = frame.contentWindow.navigator.serviceWorker.controller;
83
84 assert_equals(
85 controller.scriptURL,
86 normalizeURL(script),
87 'Service worker should control a new document')
88
89 // Wait for the completion of unregister() on the worker.
90 var channel = new MessageChannel();
91 var promise = new Promise(function(resolve) {
92 channel.port1.onmessage = t.step_func(function(e) {
93 assert_true(e.data.result,
94 'unregister() should successfully finish');
95 resolve();
96 });
97 });
98 controller.postMessage({port: channel.port2}, [channel.port2]);
99 return promise;
100 })
101 .then(function() {
102 return navigator.serviceWorker.getRegistration(scope);
103 })
104 .then(function(result) {
105 assert_equals(
106 result,
107 undefined,
108 'After unregister(), the registration should not found');
109 assert_equals(
110 frame.contentWindow.navigator.serviceWorker.controller,
111 controller,
112 'After unregister(), the worker should still control the document');
113 return with_iframe(scope);
114 })
115 .then(function(new_frame) {
116 assert_equals(
117 new_frame.contentWindow.navigator.serviceWorker.controller,
118 null,
119 'After unregister(), the worker should not control a new document');
120
121 frame.remove();
122 new_frame.remove();
123 return service_worker_unregister_and_done(t, scope);
124 })
125 }, 'Unregister controlling service worker');
126
127 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698