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

Side by Side Diff: LayoutTests/http/tests/serviceworker/skip-waiting.html

Issue 765323002: ServiceWorker: Add support for .skipWaiting and controllerchange event(3/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add new test Created 6 years 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>Service Worker: Skip waiting</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharness-helpers.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.js"></script>
7 <script>
8
9 promise_test(function(t) {
10 var scope = 'resources/simple.html';
11 var url = 'resources/skip-waiting-worker.js';
12 var frame, frame_sw;
13
14 return service_worker_unregister(t, scope)
15 .then(function() {
16 return with_iframe(scope);
17 })
18 .then(function(f) {
19 frame = f;
20 frame_sw = f.contentWindow.navigator.serviceWorker;
21 assert_equals(frame_sw.controller, null,
22 'Document controller should be null');
23 return navigator.serviceWorker.register(url, {scope: scope});
24 })
25 .then(function(registration) {
26 return wait_for_state(t, registration.installing, 'activated');
27 })
28 .then(function() {
29 assert_equals(frame_sw.controller, null,
30 'Document controller should still be null');
31 })
32 .then(function() {
33 frame.remove();
34 return service_worker_unregister_and_done(t, scope);
35 });
36 }, 'Test skipWaiting while a client is not being controlled');
37
38 promise_test(function(t) {
39 var scope = 'resources/blank.html';
40 var url1 = 'resources/empty.js';
41 var url2 = 'resources/skip-waiting-worker.js';
42 var frame, frame_sw, oncontrollerchanged;
43 var saw_controllerchanged = new Promise(function(resolve) {
44 oncontrollerchanged = function(e) {
45 assert_equals(e.type, 'controllerchange',
46 'Event name should be "controllerchange"');
47 assert_true(
48 e.target instanceof frame.contentWindow.ServiceWorkerContainer,
49 'Event target should be a ServiceWorkerContainer');
50 assert_equals(e.target.controller.state, 'activating',
51 'Controller state should be activating');
52 assert_equals(
53 frame_sw.controller.scriptURL, normalizeURL(url2),
54 'Controller scriptURL should change to the second one');
55 resolve();
56 };
57 });
58 return service_worker_unregister_and_register(t, url1, scope)
59 .then(function(registration) {
60 return wait_for_state(t, registration.installing, 'activated');
61 })
62 .then(function() {
63 return with_iframe(scope);
64 })
65 .then(function(f) {
66 frame = f;
67 frame_sw = f.contentWindow.navigator.serviceWorker;
68 assert_equals(
69 frame_sw.controller.scriptURL, normalizeURL(url1),
70 'Document controller scriptURL should equal to the first one');
71 frame_sw.oncontrollerchange = t.step_func(oncontrollerchanged);
72 return navigator.serviceWorker.register(url2, {scope: scope});
73 })
74 .then(function(registration) {
75 return Promise.all([saw_controllerchanged,
76 fetch_tests_from_worker(registration.installing)]) ;
77 })
78 .then(function() {
79 frame.remove();
80 return service_worker_unregister_and_done(t, scope);
81 });
82 }, 'Test skipWaiting while a client is using the registration');
83
84 promise_test(function(t) {
85 var scope = 'resources/other.html';
86 var url1 = 'resources/empty.js';
87 var url2 = 'resources/empty-worker.js';
88 var url3 = 'resources/skip-waiting-worker.js';
89 var frame, sw_registration, activated_worker, waiting_worker;
90 return service_worker_unregister_and_register(t, url1, scope)
91 .then(function(registration) {
92 sw_registration = registration;
93 return wait_for_state(t, registration.installing, 'activated');
94 })
95 .then(function() {
96 return with_iframe(scope);
97 })
98 .then(function(f) {
99 frame = f;
100 return navigator.serviceWorker.register(url2, {scope: scope});
101 })
102 .then(function(registration) {
103 return wait_for_state(t, registration.installing, 'installed');
104 })
105 .then(function() {
106 activated_worker = sw_registration.active;
107 waiting_worker = sw_registration.waiting;
108 assert_equals(activated_worker.scriptURL, normalizeURL(url1),
109 'Worker with url1 should be activated');
110 assert_equals(waiting_worker.scriptURL, normalizeURL(url2),
111 'Worker with url2 should be waiting');
112 return navigator.serviceWorker.register(url3, {scope: scope});
113 })
114 .then(function(registration) {
115 return wait_for_state(t, registration.installing, 'activated');
116 })
117 .then(function() {
118 assert_equals(activated_worker.state, 'redundant',
119 'Worker with url1 should be redundant');
120 assert_equals(waiting_worker.state, 'redundant',
121 'Worker with url2 should be redundant');
122 assert_equals(sw_registration.active.scriptURL, normalizeURL(url3),
123 'Worker with url3 should be activated');
124 frame.remove();
125 return service_worker_unregister_and_done(t, scope);
126 });
127 }, 'Test skipWaiting with both active and waiting workers');
128
129 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698