2 <title>ExtendableEvent: waitUntil
</title>
3 <script src=
"../resources/testharness.js"></script>
4 <script src=
"../resources/testharnessreport.js"></script>
5 <script src=
"resources/test-helpers.js"></script>
7 function runTest(test
, scope
, onRegister
) {
8 var script
= 'resources/extendable-event-waituntil.js?' + scope
;
9 service_worker_unregister_and_register(test
, script
, scope
)
10 .then(function(registration
) {
11 onRegister(registration
.installing
);
15 // Sends a SYN to the worker and asynchronously listens for an ACK; sets
16 // |obj.synced| to true once ack'd.
17 function syncWorker(test
, worker
, obj
) {
18 var channel
= new MessageChannel();
19 channel
.port1
.onmessage
= test
.step_func(function(e
) {
21 assert_equals(message
, 'SYNC',
22 'Should receive sync message from worker.');
24 channel
.port1
.postMessage('ACK');
26 worker
.postMessage({port
: channel
.port2
}, [channel
.port2
]);
29 async_test(function(t
) {
30 // Passing scope as the test switch for worker script.
31 var scope
= 'resources/install-fulfilled';
32 var onRegister = function(worker
) {
34 wait_for_state(t
, worker
, 'installed')
38 'state should be "installed" after the waitUntil promise ' +
39 'for "oninstall" is fulfilled.');
40 service_worker_unregister_and_done(t
, scope
);
42 .catch(unreached_rejection(t
));
43 syncWorker(t
, worker
, obj
);
45 runTest(t
, scope
, onRegister
);
46 }, 'Test install event waitUntil fulfilled');
48 async_test(function(t
) {
49 var scope
= 'resources/install-multiple-fulfilled';
50 var onRegister = function(worker
) {
53 wait_for_state(t
, worker
, 'installed')
56 obj1
.synced
&& obj2
.synced
,
57 'state should be "installed" after all waitUntil promises ' +
58 'for "oninstall" are fulfilled.');
59 service_worker_unregister_and_done(t
, scope
);
61 .catch(unreached_rejection(t
));
62 syncWorker(t
, worker
, obj1
);
63 syncWorker(t
, worker
, obj2
);
65 runTest(t
, scope
, onRegister
);
66 }, 'Test ExtendableEvent multiple waitUntil fulfilled.');
68 async_test(function(t
) {
69 var scope
= 'resources/install-reject-precedence';
70 var onRegister = function(worker
) {
71 wait_for_state(t
, worker
, 'redundant')
73 service_worker_unregister_and_done(t
, scope
);
75 .catch(unreached_rejection(t
));
77 runTest(t
, scope
, onRegister
);
78 }, 'Test ExtendableEvent waitUntil reject precedence.');
80 async_test(function(t
) {
81 var scope
= 'resources/activate-fulfilled';
82 var onRegister = function(worker
) {
84 wait_for_state(t
, worker
, 'activating')
86 syncWorker(t
, worker
, obj
);
87 return wait_for_state(t
, worker
, 'activated');
92 'state should be "activated" after the waitUntil promise ' +
93 'for "onactivate" is fulfilled.');
94 service_worker_unregister_and_done(t
, scope
);
96 .catch(unreached_rejection(t
));
98 runTest(t
, scope
, onRegister
);
99 }, 'Test activate event waitUntil fulfilled');
101 async_test(function(t
) {
102 var scope
= 'resources/install-rejected';
103 var onRegister = function(worker
) {
104 wait_for_state(t
, worker
, 'redundant')
106 service_worker_unregister_and_done(t
, scope
);
108 .catch(unreached_rejection(t
));
110 runTest(t
, scope
, onRegister
);
111 }, 'Test install event waitUntil rejected');
113 async_test(function(t
) {
114 var scope
= 'resources/activate-rejected';
115 var onRegister = function(worker
) {
116 wait_for_state(t
, worker
, 'activated')
118 service_worker_unregister_and_done(t
, scope
);
120 .catch(unreached_rejection(t
));
122 runTest(t
, scope
, onRegister
);
123 }, 'Test activate event waitUntil rejected.');