Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / extendable-event-waituntil.html
blob4a5d7dd772b0665e1725069595aca5e9420e2168
1 <!DOCTYPE html>
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>
6 <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);
12 });
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) {
20 var message = e.data;
21 assert_equals(message, 'SYNC',
22 'Should receive sync message from worker.');
23 obj.synced = true;
24 channel.port1.postMessage('ACK');
25 });
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) {
33 var obj = {};
34 wait_for_state(t, worker, 'installed')
35 .then(function() {
36 assert_true(
37 obj.synced,
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) {
51 var obj1 = {};
52 var obj2 = {};
53 wait_for_state(t, worker, 'installed')
54 .then(function() {
55 assert_true(
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')
72 .then(function() {
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) {
83 var obj = {};
84 wait_for_state(t, worker, 'activating')
85 .then(function() {
86 syncWorker(t, worker, obj);
87 return wait_for_state(t, worker, 'activated');
89 .then(function() {
90 assert_true(
91 obj.synced,
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')
105 .then(function() {
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')
117 .then(function() {
118 service_worker_unregister_and_done(t, scope);
120 .catch(unreached_rejection(t));
122 runTest(t, scope, onRegister);
123 }, 'Test activate event waitUntil rejected.');
125 </script>