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

Side by Side Diff: LayoutTests/http/tests/serviceworker/unregister-controller.html

Issue 474193002: Migrate some tests to use ServiceWorkerRegistration.unregister() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: forgot a file Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script> 4 <script src="resources/test-helpers.js"></script>
5 <script> 5 <script>
6 var worker_url = 'resources/simple-intercept-worker.js'; 6 var worker_url = 'resources/simple-intercept-worker.js';
7 7
8 async_test(function(t) { 8 async_test(function(t) {
9 var scope =
10 'resources/unregister-controller-page.html?load-before-unregister';
11 var worker;
12 var frame_window;
13 var controller;
14
15 service_worker_unregister_and_register(t, worker_url, scope)
16 .then(function(registration) {
17 return wait_for_update(t, registration);
18 })
19 .then(function(registered_worker) {
20 worker = registered_worker;
21 return wait_for_state(t, worker, 'activated');
22 })
23 .then(function() {
24 return with_iframe(scope);
25 })
26 .then(function(frame) {
27 frame_window = frame.contentWindow;
28 controller = frame_window.navigator.serviceWorker.controller;
29 assert_true(controller instanceof frame_window.ServiceWorker,
30 'document should load with a controller');
31 return navigator.serviceWorker.unregister(scope);
32 })
33 .then(function() {
34 assert_equals(frame_window.navigator.serviceWorker.controller,
35 controller,
36 'unregistration should not modify controller');
37 return frame_window.fetch_url('simple.txt');
38 })
39 .then(function(response) {
40 assert_equals(response, 'intercepted by service worker',
41 'controller should intercept requests');
42 t.done();
43 })
44 .catch(unreached_rejection(t));
45 }, 'Unregister does not affect existing controller');
46
47 async_test(function(t) {
48 var scope =
49 'resources/unregister-controller-page.html?load-after-unregister';
50
51 service_worker_unregister_and_register(t, worker_url, scope)
52 .then(function(registration) {
53 return wait_for_update(t, registration);
54 })
55 .then(function(worker) {
56 return wait_for_state(t, worker, 'activated');
57 })
58 .then(function() {
59 return navigator.serviceWorker.unregister(scope);
60 })
61 .then(function() {
62 return with_iframe(scope);
63 })
64 .then(function(frame) {
65 var frame_window = frame.contentWindow;
66 assert_equals(frame_window.navigator.serviceWorker.controller, null,
67 'document should not have a controller');
68 return frame_window.fetch_url('simple.txt');
69 })
70 .then(function(response) {
71 assert_equals(response, 'a simple text file\n',
72 'requests should not be intercepted');
73 t.done();
74 })
75 .catch(unreached_rejection(t));
76 }, 'Unregister prevents control of subsequent navigations');
77
78 async_test(function(t) {
79 var scope = 9 var scope =
80 'scope/no-new-controllee-even-if-registration-is-still-used'; 10 'resources/unregister-controller-page.html?load-before-unregister';
11 var frame_window;
12 var controller;
13 var registration;
81 14
82 service_worker_unregister_and_register(t, worker_url, scope) 15 service_worker_unregister_and_register(t, worker_url, scope)
83 .then(function(registration) { 16 .then(function(r) {
17 registration = r;
84 return wait_for_update(t, registration); 18 return wait_for_update(t, registration);
85 }) 19 })
86 .then(function(registered_worker) { 20 .then(function(worker) {
87 return wait_for_state(t, registered_worker, 'activated'); 21 return wait_for_state(t, worker, 'activated');
88 }) 22 })
89 .then(function() { 23 .then(function() {
90 return with_iframe(scope); 24 return with_iframe(scope);
91 }) 25 })
92 .then(function(frame) { 26 .then(function(frame) {
93 return navigator.serviceWorker.unregister(scope); 27 frame_window = frame.contentWindow;
28 controller = frame_window.navigator.serviceWorker.controller;
29 assert_true(controller instanceof frame_window.ServiceWorker,
30 'document should load with a controller');
31 return registration.unregister();
32 })
33 .then(function() {
34 assert_equals(frame_window.navigator.serviceWorker.controller,
35 controller,
36 'unregistration should not modify controller');
37 return frame_window.fetch_url('simple.txt');
38 })
39 .then(function(response) {
40 assert_equals(response, 'intercepted by service worker',
41 'controller should intercept requests');
42 t.done();
43 })
44 .catch(unreached_rejection(t));
45 }, 'Unregister does not affect existing controller');
46
47 async_test(function(t) {
48 var scope =
49 'resources/unregister-controller-page.html?load-after-unregister';
50 var registration;
51
52 service_worker_unregister_and_register(t, worker_url, scope)
53 .then(function(r) {
54 registration = r;
55 return wait_for_update(t, registration);
56 })
57 .then(function(worker) {
58 return wait_for_state(t, worker, 'activated');
59 })
60 .then(function() {
61 return registration.unregister(scope);
nhiroki 2014/08/15 09:53:40 You don't have to pass |scope| to registration.unr
94 }) 62 })
95 .then(function() { 63 .then(function() {
96 return with_iframe(scope); 64 return with_iframe(scope);
65 })
66 .then(function(frame) {
67 var frame_window = frame.contentWindow;
68 assert_equals(frame_window.navigator.serviceWorker.controller, null,
69 'document should not have a controller');
70 return frame_window.fetch_url('simple.txt');
71 })
72 .then(function(response) {
73 assert_equals(response, 'a simple text file\n',
74 'requests should not be intercepted');
75 t.done();
76 })
77 .catch(unreached_rejection(t));
78 }, 'Unregister prevents control of subsequent navigations');
79
80 async_test(function(t) {
81 var scope =
82 'scope/no-new-controllee-even-if-registration-is-still-used';
83 var registration;
84
85 service_worker_unregister_and_register(t, worker_url, scope)
86 .then(function(r) {
87 registration = r;
88 return wait_for_update(t, registration);
89 })
90 .then(function(worker) {
91 return wait_for_state(t, worker, 'activated');
92 })
93 .then(function() {
94 return with_iframe(scope);
95 })
96 .then(function(frame) {
97 return registration.unregister(scope);
nhiroki 2014/08/15 09:53:40 ditto. |scope| is no longer necessary.
98 })
99 .then(function() {
100 return with_iframe(scope);
97 }) 101 })
98 .then(function(frame) { 102 .then(function(frame) {
99 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, 103 assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
100 null, 104 null,
101 'document should not have a controller'); 105 'document should not have a controller');
102 t.done(); 106 t.done();
103 }) 107 })
104 .catch(unreached_rejection(t)); 108 .catch(unreached_rejection(t));
105 }, 'Unregister prevents new controllee even if registration is still in use'); 109 }, 'Unregister prevents new controllee even if registration is still in use');
106 </script> 110 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698