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

Side by Side Diff: LayoutTests/http/tests/serviceworker/install-phase-event-waituntil.html

Issue 580033002: ServiceWorker: Stabilize install-phase-event-waituntil.html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/resources/test-helpers.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>InstallPhaseEvent: waitUntil</title> 2 <title>InstallPhaseEvent: waitUntil</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src="resources/test-helpers.js"></script> 5 <script src="resources/test-helpers.js"></script>
6 <script> 6 <script>
7 // Temporary measure to diagnose timeouts on Win XP. Let the W3C harness 7 // Temporary measure to diagnose timeouts on Win XP. Let the W3C harness
8 // timeout before run-webkit-tests does, so it can report the particular 8 // timeout before run-webkit-tests does, so it can report the particular
9 // test that timed out. 9 // test that timed out.
10 // FIXME: Remove after the cause of timeout is fixed. 10 // FIXME: Remove after the cause of timeout is fixed.
11 var properties = {timeout: 5500}; 11 var properties = {timeout: 5500};
12 12
13 // FIXME: Use the test-helpers.js version once it can handle workers that 13 function runTest(test, scope, onRegister) {
14 // don't install successfully. 14 var script = 'resources/install-phase-event-waituntil.js';
15 function unregisterAndRegister(test, script, scope) { 15 navigator.serviceWorker.getRegistration(scope)
16 var empty_worker = 'resources/empty-worker.js';
17 return navigator.serviceWorker.register(empty_worker, {scope: scope})
18 .then(function(registration) { 16 .then(function(registration) {
19 return registration.unregister(); 17 if (registration)
18 return registration.unregister();
20 }) 19 })
21 .then(function() { 20 .then(function() {
22 return navigator.serviceWorker.register(script, {scope: scope}); 21 return navigator.serviceWorker.register(script, {scope: scope});
23 }) 22 })
24 .catch(unreached_rejection(test)); 23 .then(function(registration) {
25 } 24 return get_newest_worker(registration);
26 25 })
27 function runTest(test, scope, onRegister) { 26 .then(test.step_func(onRegister));
28 var script = 'resources/install-phase-event-waituntil.js';
29 test.step(function() {
30 unregisterAndRegister(test, script, scope)
31 .then(function(registration) {
32 return wait_for_update(test, registration);
33 })
34 .then(test.step_func(onRegister));
35 });
36 } 27 }
37 28
38 function syncWorker(test, worker, obj) { 29 function syncWorker(test, worker, obj) {
39 var channel = new MessageChannel(); 30 var channel = new MessageChannel();
40 channel.port1.onmessage = test.step_func(function(e) { 31 channel.port1.onmessage = test.step_func(function(e) {
41 var message = e.data; 32 var message = e.data;
42 assert_equals(message, 'SYNC', 33 assert_equals(message, 'SYNC',
43 'Should receive sync message from worker.'); 34 'Should receive sync message from worker.');
44 obj.synced = true; 35 obj.synced = true;
45 channel.port1.postMessage('ACK'); 36 channel.port1.postMessage('ACK');
46 }); 37 });
47 worker.postMessage({port: channel.port2}, [channel.port2]); 38 worker.postMessage({port: channel.port2}, [channel.port2]);
48 } 39 }
49 40
50 async_test(function(t) { 41 async_test(function(t) {
51 // Passing scope as the test switch for worker script. 42 // Passing scope as the test switch for worker script.
52 var scope = 'install-fulfilled'; 43 var scope = 'install-fulfilled';
53 var onRegister = function(worker) { 44 var onRegister = function(worker) {
54 var obj = {}; 45 var obj = {};
55 assert_equals(worker.state, 46 wait_for_state(t, worker, 'installed')
56 'installing', 47 .then(function() {
57 'Should be in the "installing" state upon updatefound');
58 worker.onstatechange = t.step_func(function() {
59 if (worker.state == 'installed') {
60 assert_true( 48 assert_true(
61 obj.synced, 49 obj.synced,
62 'state should be "installed" after the waitUntil promise ' + 50 'state should be "installed" after the waitUntil promise ' +
63 'for "oninstall" is fulfilled.'); 51 'for "oninstall" is fulfilled.');
64 service_worker_unregister_and_done(t, scope); 52 service_worker_unregister_and_done(t, scope);
65 } 53 })
66 }); 54 .catch(unreached_rejection(t));
67 syncWorker(t, worker, obj); 55 syncWorker(t, worker, obj);
68 }; 56 };
69 runTest(t, scope, onRegister); 57 runTest(t, scope, onRegister);
70 }, 'Test install event waitUntil fulfilled', properties); 58 }, 'Test install event waitUntil fulfilled', properties);
71 59
72 async_test(function(t) { 60 async_test(function(t) {
73 var scope = 'activate-fulfilled'; 61 var scope = 'activate-fulfilled';
74 var onRegister = function(worker) { 62 var onRegister = function(worker) {
75 var obj = {}; 63 var obj = {};
76 worker.onstatechange = t.step_func(function() { 64 wait_for_state(t, worker, 'activating')
77 if (worker.state == 'activating') { 65 .then(function() {
78 syncWorker(t, worker, obj); 66 syncWorker(t, worker, obj);
79 } else if (worker.state == 'activated') { 67 return wait_for_state(t, worker, 'activated');
68 })
69 .then(function() {
80 assert_true( 70 assert_true(
81 obj.synced, 71 obj.synced,
82 'state should be "activated" after the waitUntil promise ' + 72 'state should be "activated" after the waitUntil promise ' +
83 'for "onactivate" is fulfilled.'); 73 'for "onactivate" is fulfilled.');
84 service_worker_unregister_and_done(t, scope); 74 service_worker_unregister_and_done(t, scope);
85 } 75 })
86 }); 76 .catch(unreached_rejection(t));
87 }; 77 };
88 runTest(t, scope, onRegister); 78 runTest(t, scope, onRegister);
89 }, 'Test activate event waitUntil fulfilled', properties); 79 }, 'Test activate event waitUntil fulfilled', properties);
90 80
91 async_test(function(t) { 81 async_test(function(t) {
92 var scope = 'install-rejected'; 82 var scope = 'install-rejected';
93 var onRegister = function(worker) { 83 var onRegister = function(worker) {
94 worker.onstatechange = t.step_func(function() { 84 wait_for_state(t, worker, 'redundant')
95 if (worker.state == 'redundant') 85 .then(function() {
96 service_worker_unregister_and_done(t, scope); 86 service_worker_unregister_and_done(t, scope);
97 }); 87 })
88 .catch(unreached_rejection(t));
98 }; 89 };
99 runTest(t, scope, onRegister); 90 runTest(t, scope, onRegister);
100 }, 'Test install event waitUntil rejected', properties); 91 }, 'Test install event waitUntil rejected', properties);
101 92
102 async_test(function(t) { 93 async_test(function(t) {
103 var scope = 'activate-rejected'; 94 var scope = 'activate-rejected';
104 var onRegister = function(worker) { 95 var onRegister = function(worker) {
105 worker.onstatechange = t.step_func(function() { 96 wait_for_state(t, worker, 'redundant')
106 if (worker.state == 'redundant') 97 .then(function() {
107 service_worker_unregister_and_done(t, scope); 98 service_worker_unregister_and_done(t, scope);
108 }); 99 })
100 .catch(unreached_rejection(t));
109 }; 101 };
110 runTest(t, scope, onRegister); 102 runTest(t, scope, onRegister);
111 }, 'Test activate event waitUntil rejected.', properties); 103 }, 'Test activate event waitUntil rejected.', properties);
112 104
113 async_test(function(t) { 105 async_test(function(t) {
114 var scope = 'activate-multiple-fulfilled'; 106 var scope = 'activate-multiple-fulfilled';
115 var onRegister = function(worker) { 107 var onRegister = function(worker) {
116 var obj1 = {}; 108 var obj1 = {};
117 var obj2 = {}; 109 var obj2 = {};
118 worker.onstatechange = t.step_func(function() { 110 wait_for_state(t, worker, 'activating')
119 if (worker.state == 'activating') { 111 .then(function() {
120 syncWorker(t, worker, obj1); 112 syncWorker(t, worker, obj1);
121 syncWorker(t, worker, obj2); 113 syncWorker(t, worker, obj2);
122 } else if (worker.state == 'activated') { 114 return wait_for_state(t, worker, 'activated');
115 })
116 .then(function() {
123 assert_true( 117 assert_true(
124 obj1.synced && obj2.synced, 118 obj1.synced && obj2.synced,
125 'state should be "activated" after all waitUntil promises ' + 119 'state should be "activated" after all waitUntil promises ' +
126 'for "onactivate" are fulfilled.'); 120 'for "onactivate" are fulfilled.');
127 service_worker_unregister_and_done(t, scope); 121 service_worker_unregister_and_done(t, scope);
128 } 122 })
129 }); 123 .catch(unreached_rejection(t));
130 }; 124 };
131 runTest(t, scope, onRegister); 125 runTest(t, scope, onRegister);
132 }, 'Test InstallPhaseEvent multiple waitUntil fulfilled.', properties); 126 }, 'Test InstallPhaseEvent multiple waitUntil fulfilled.', properties);
133 127
134 async_test(function(t) { 128 async_test(function(t) {
135 var scope = 'activate-reject-precedence'; 129 var scope = 'activate-reject-precedence';
136 var onRegister = function(worker) { 130 var onRegister = function(worker) {
137 worker.onstatechange = t.step_func(function() { 131 wait_for_state(t, worker, 'redundant')
138 if (worker.state == 'redundant') 132 .then(function() {
139 service_worker_unregister_and_done(t, scope); 133 service_worker_unregister_and_done(t, scope);
140 }); 134 })
135 .catch(unreached_rejection(t));
141 }; 136 };
142 runTest(t, scope, onRegister); 137 runTest(t, scope, onRegister);
143 }, 'Test InstallPhaseEvent waitUntil reject precedence.', properties); 138 }, 'Test InstallPhaseEvent waitUntil reject precedence.', properties);
144 </script> 139 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/resources/test-helpers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698