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

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: 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 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 var frame_url = 'resources/unregister-controlling-worker-iframe.html';
72 var text_url = '../../resources/simple.txt?request';
73
74 var worker;
75 var frame1, frame2;
76
77 return service_worker_unregister_and_register(t, script, scope)
78 .then(function(registration) {
79 worker = registration.installing;
80 return wait_for_state(t, worker, 'activated');
81 })
82 .then(function() { return with_iframe(frame_url); })
83 .then(function(f) {
84 frame1 = f;
85 return frame1.contentWindow.fetch_url(text_url);
86 })
87 .then(function(response) {
88 assert_equals(
89 response,
90 'Intercepted by service worker',
91 '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
92
93 // 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.
94 var channel = new MessageChannel();
95 var promise = new Promise(function(resolve) {
96 channel.port1.onmessage = t.step_func(function(e) {
97 assert_true(e.data.result,
98 'unregister() should successfully finish');
99 resolve();
100 });
101 });
102 worker.postMessage({port: channel.port2}, [channel.port2]);
103 return promise;
104 })
105 .then(function() {
106 return navigator.serviceWorker.getRegistration(frame_url);
107 })
108 .then(function(result) {
109 assert_equals(
110 result,
111 undefined,
112 'After unregister(), the registration should not found');
113 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.
114 })
115 .then(function(response) {
116 assert_equals(
117 response,
118 'Intercepted by service worker',
119 'Service worker should still control the iframe');
120 return with_iframe(frame_url);
121 })
122 .then(function(f) {
123 frame2 = f;
124 return frame2.contentWindow.fetch_url(text_url);
125 })
126 .then(function(response) {
127 assert_equals(
128 response,
129 'a simple text file\n',
130 'Service worker should not control newly opened iframe ' +
131 'after unregister()');
132
133 frame1.remove();
134 frame2.remove();
135 return service_worker_unregister_and_done(t, scope);
136 })
137 }, 'Unregister controlling service worker');
138
139 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698