OLD | NEW |
1 // Adapter for testharness.js-style tests with Service Workers | 1 // Adapter for testharness.js-style tests with Service Workers |
2 | 2 |
3 function service_worker_test(url, description) { | 3 function service_worker_test(url, description) { |
4 var t = async_test(description); | 4 var t = async_test(description); |
5 t.step(function() { | 5 t.step(function() { |
6 | 6 |
7 navigator.serviceWorker.register(url).then( | 7 navigator.serviceWorker.register(url).then( |
8 t.step_func(function(worker) { | 8 t.step_func(function(worker) { |
9 var messageChannel = new MessageChannel(); | 9 var messageChannel = new MessageChannel(); |
10 messageChannel.port1.onmessage = t.step_func(onMessage); | 10 messageChannel.port1.onmessage = t.step_func(onMessage); |
11 worker.postMessage({port:messageChannel.port2}, [messageChannel.
port2]); | 11 worker.postMessage({port:messageChannel.port2}, [messageChannel.
port2]); |
12 }), | 12 }), |
13 t.step_func(function(reason) { | 13 t.step_func(function(reason) { |
14 assert_unreached('Registration should succeed, but failed: ' + r
eason.name); | 14 assert_unreached('Registration should succeed, but failed: ' + r
eason.name); |
15 })); | 15 })); |
16 | 16 |
17 function onMessage(e) { | 17 function onMessage(e) { |
18 assert_equals(e.data, 'pass'); | 18 assert_equals(e.data, 'pass'); |
19 t.done(); | 19 t.done(); |
20 } | 20 } |
21 }); | 21 }); |
22 } | 22 } |
| 23 |
| 24 // FIXME: Replace this with test.unreached_func(desc) once testharness.js is upd
ated |
| 25 // Use with unexpected event handlers or Promise rejection. |
| 26 // E.g.: |
| 27 // onbadevent = fail(t, 'Should only see good events'); |
| 28 // Promise.then(...).catch(fail(t, 'Rejection is never fun')); |
| 29 function unreached_func(test, desc) { |
| 30 return test.step_func(function() { |
| 31 assert_unreached(desc); |
| 32 }); |
| 33 } |
OLD | NEW |