OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>ExtendableEvent: waitUntil</title> | 2 <title>ExtendableEvent: 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.sub.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
6 <script> | 6 <script> |
7 function runTest(test, scope, onRegister) { | 7 function runTest(test, scope, onRegister) { |
8 var script = 'resources/extendable-event-waituntil.js?' + scope; | 8 var script = 'resources/extendable-event-waituntil.js?' + scope; |
9 service_worker_unregister_and_register(test, script, scope) | 9 service_worker_unregister_and_register(test, script, scope) |
10 .then(function(registration) { | 10 .then(function(registration) { |
11 onRegister(registration.installing); | 11 onRegister(registration.installing); |
12 }); | 12 }); |
13 } | 13 } |
14 | 14 |
15 // Sends a SYN to the worker and asynchronously listens for an ACK; sets | 15 // Sends a SYN to the worker and asynchronously listens for an ACK; sets |
16 // |obj.synced| to true once ack'd. | 16 // |obj.synced| to true once ack'd. |
17 function syncWorker(test, worker, obj) { | 17 function syncWorker(test, worker, obj) { |
18 var channel = new MessageChannel(); | 18 var channel = new MessageChannel(); |
19 channel.port1.onmessage = test.step_func(function(e) { | 19 worker.postMessage({port: channel.port2}, [channel.port2]); |
20 var message = e.data; | 20 return new Promise(function(resolve) { |
21 assert_equals(message, 'SYNC', | 21 channel.port1.onmessage = test.step_func(function(e) { |
22 'Should receive sync message from worker.'); | 22 var message = e.data; |
23 obj.synced = true; | 23 assert_equals(message, 'SYNC', |
24 channel.port1.postMessage('ACK'); | 24 'Should receive sync message from worker.'); |
| 25 obj.synced = true; |
| 26 channel.port1.postMessage('ACK'); |
| 27 resolve(); |
| 28 }); |
25 }); | 29 }); |
26 worker.postMessage({port: channel.port2}, [channel.port2]); | |
27 } | 30 } |
28 | 31 |
29 async_test(function(t) { | 32 async_test(function(t) { |
30 // Passing scope as the test switch for worker script. | 33 // Passing scope as the test switch for worker script. |
31 var scope = 'resources/install-fulfilled'; | 34 var scope = 'resources/install-fulfilled'; |
32 var onRegister = function(worker) { | 35 var onRegister = function(worker) { |
33 var obj = {}; | 36 var obj = {}; |
34 wait_for_state(t, worker, 'installed') | 37 wait_for_state(t, worker, 'installed') |
35 .then(function() { | 38 .then(function() { |
36 assert_true( | 39 assert_true( |
(...skipping 24 matching lines...) Expand all Loading... |
61 .catch(unreached_rejection(t)); | 64 .catch(unreached_rejection(t)); |
62 syncWorker(t, worker, obj1); | 65 syncWorker(t, worker, obj1); |
63 syncWorker(t, worker, obj2); | 66 syncWorker(t, worker, obj2); |
64 }; | 67 }; |
65 runTest(t, scope, onRegister); | 68 runTest(t, scope, onRegister); |
66 }, 'Test ExtendableEvent multiple waitUntil fulfilled.'); | 69 }, 'Test ExtendableEvent multiple waitUntil fulfilled.'); |
67 | 70 |
68 async_test(function(t) { | 71 async_test(function(t) { |
69 var scope = 'resources/install-reject-precedence'; | 72 var scope = 'resources/install-reject-precedence'; |
70 var onRegister = function(worker) { | 73 var onRegister = function(worker) { |
71 var obj = {}; | 74 var obj1 = {}; |
| 75 var obj2 = {}; |
72 wait_for_state(t, worker, 'redundant') | 76 wait_for_state(t, worker, 'redundant') |
73 .then(function() { | 77 .then(function() { |
| 78 assert_true( |
| 79 obj1.synced, |
| 80 'The "redundant" state was entered after the first "extend ' + |
| 81 'lifetime promise" resolved.' |
| 82 ); |
| 83 assert_true( |
| 84 obj2.synced, |
| 85 'The "redundant" state was entered after the third "extend ' + |
| 86 'lifetime promise" resolved.' |
| 87 ); |
74 service_worker_unregister_and_done(t, scope); | 88 service_worker_unregister_and_done(t, scope); |
75 }) | 89 }) |
76 .catch(unreached_rejection(t)); | 90 .catch(unreached_rejection(t)); |
77 syncWorker(t, worker, obj); | 91 |
| 92 syncWorker(t, worker, obj1) |
| 93 .then(function() { |
| 94 syncWorker(t, worker, obj2); |
| 95 }); |
78 }; | 96 }; |
79 runTest(t, scope, onRegister); | 97 runTest(t, scope, onRegister); |
80 }, 'Test ExtendableEvent waitUntil reject precedence.'); | 98 }, 'Test ExtendableEvent waitUntil reject precedence.'); |
81 | 99 |
82 async_test(function(t) { | 100 async_test(function(t) { |
83 var scope = 'resources/activate-fulfilled'; | 101 var scope = 'resources/activate-fulfilled'; |
84 var onRegister = function(worker) { | 102 var onRegister = function(worker) { |
85 var obj = {}; | 103 var obj = {}; |
86 wait_for_state(t, worker, 'activating') | 104 wait_for_state(t, worker, 'activating') |
87 .then(function() { | 105 .then(function() { |
(...skipping 30 matching lines...) Expand all Loading... |
118 wait_for_state(t, worker, 'activated') | 136 wait_for_state(t, worker, 'activated') |
119 .then(function() { | 137 .then(function() { |
120 service_worker_unregister_and_done(t, scope); | 138 service_worker_unregister_and_done(t, scope); |
121 }) | 139 }) |
122 .catch(unreached_rejection(t)); | 140 .catch(unreached_rejection(t)); |
123 }; | 141 }; |
124 runTest(t, scope, onRegister); | 142 runTest(t, scope, onRegister); |
125 }, 'Test activate event waitUntil rejected.'); | 143 }, 'Test activate event waitUntil rejected.'); |
126 | 144 |
127 </script> | 145 </script> |
OLD | NEW |