| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>InstallPhaseEvent: 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 // 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 | |
| 9 // test that timed out. | |
| 10 // FIXME: Remove after the cause of timeout is fixed. | |
| 11 var properties = {timeout: 5500}; | |
| 12 | |
| 13 function runTest(test, scope, onRegister) { | |
| 14 var script = 'resources/install-phase-event-waituntil.js'; | |
| 15 service_worker_unregister_and_register(test, script, scope) | |
| 16 .then(function(registration) { | |
| 17 return get_newest_worker(registration); | |
| 18 }) | |
| 19 .then(test.step_func(onRegister)); | |
| 20 } | |
| 21 | |
| 22 function syncWorker(test, worker, obj) { | |
| 23 var channel = new MessageChannel(); | |
| 24 channel.port1.onmessage = test.step_func(function(e) { | |
| 25 var message = e.data; | |
| 26 assert_equals(message, 'SYNC', | |
| 27 'Should receive sync message from worker.'); | |
| 28 obj.synced = true; | |
| 29 channel.port1.postMessage('ACK'); | |
| 30 }); | |
| 31 worker.postMessage({port: channel.port2}, [channel.port2]); | |
| 32 } | |
| 33 | |
| 34 async_test(function(t) { | |
| 35 // Passing scope as the test switch for worker script. | |
| 36 var scope = 'install-fulfilled'; | |
| 37 var onRegister = function(worker) { | |
| 38 var obj = {}; | |
| 39 wait_for_state(t, worker, 'installed') | |
| 40 .then(function() { | |
| 41 assert_true( | |
| 42 obj.synced, | |
| 43 'state should be "installed" after the waitUntil promise ' + | |
| 44 'for "oninstall" is fulfilled.'); | |
| 45 service_worker_unregister_and_done(t, scope); | |
| 46 }) | |
| 47 .catch(unreached_rejection(t)); | |
| 48 syncWorker(t, worker, obj); | |
| 49 }; | |
| 50 runTest(t, scope, onRegister); | |
| 51 }, 'Test install event waitUntil fulfilled', properties); | |
| 52 | |
| 53 async_test(function(t) { | |
| 54 var scope = 'activate-fulfilled'; | |
| 55 var onRegister = function(worker) { | |
| 56 var obj = {}; | |
| 57 wait_for_state(t, worker, 'activating') | |
| 58 .then(function() { | |
| 59 syncWorker(t, worker, obj); | |
| 60 return wait_for_state(t, worker, 'activated'); | |
| 61 }) | |
| 62 .then(function() { | |
| 63 assert_true( | |
| 64 obj.synced, | |
| 65 'state should be "activated" after the waitUntil promise ' + | |
| 66 'for "onactivate" is fulfilled.'); | |
| 67 service_worker_unregister_and_done(t, scope); | |
| 68 }) | |
| 69 .catch(unreached_rejection(t)); | |
| 70 }; | |
| 71 runTest(t, scope, onRegister); | |
| 72 }, 'Test activate event waitUntil fulfilled', properties); | |
| 73 | |
| 74 async_test(function(t) { | |
| 75 var scope = 'install-rejected'; | |
| 76 var onRegister = function(worker) { | |
| 77 wait_for_state(t, worker, 'redundant') | |
| 78 .then(function() { | |
| 79 service_worker_unregister_and_done(t, scope); | |
| 80 }) | |
| 81 .catch(unreached_rejection(t)); | |
| 82 }; | |
| 83 runTest(t, scope, onRegister); | |
| 84 }, 'Test install event waitUntil rejected', properties); | |
| 85 | |
| 86 async_test(function(t) { | |
| 87 var scope = 'activate-rejected'; | |
| 88 var onRegister = function(worker) { | |
| 89 wait_for_state(t, worker, 'redundant') | |
| 90 .then(function() { | |
| 91 service_worker_unregister_and_done(t, scope); | |
| 92 }) | |
| 93 .catch(unreached_rejection(t)); | |
| 94 }; | |
| 95 runTest(t, scope, onRegister); | |
| 96 }, 'Test activate event waitUntil rejected.', properties); | |
| 97 | |
| 98 async_test(function(t) { | |
| 99 var scope = 'activate-multiple-fulfilled'; | |
| 100 var onRegister = function(worker) { | |
| 101 var obj1 = {}; | |
| 102 var obj2 = {}; | |
| 103 wait_for_state(t, worker, 'activating') | |
| 104 .then(function() { | |
| 105 syncWorker(t, worker, obj1); | |
| 106 syncWorker(t, worker, obj2); | |
| 107 return wait_for_state(t, worker, 'activated'); | |
| 108 }) | |
| 109 .then(function() { | |
| 110 assert_true( | |
| 111 obj1.synced && obj2.synced, | |
| 112 'state should be "activated" after all waitUntil promises ' + | |
| 113 'for "onactivate" are fulfilled.'); | |
| 114 service_worker_unregister_and_done(t, scope); | |
| 115 }) | |
| 116 .catch(unreached_rejection(t)); | |
| 117 }; | |
| 118 runTest(t, scope, onRegister); | |
| 119 }, 'Test InstallPhaseEvent multiple waitUntil fulfilled.', properties); | |
| 120 | |
| 121 async_test(function(t) { | |
| 122 var scope = 'activate-reject-precedence'; | |
| 123 var onRegister = function(worker) { | |
| 124 wait_for_state(t, worker, 'redundant') | |
| 125 .then(function() { | |
| 126 service_worker_unregister_and_done(t, scope); | |
| 127 }) | |
| 128 .catch(unreached_rejection(t)); | |
| 129 }; | |
| 130 runTest(t, scope, onRegister); | |
| 131 }, 'Test InstallPhaseEvent waitUntil reject precedence.', properties); | |
| 132 </script> | |
| OLD | NEW |