OLD | NEW |
(Empty) | |
| 1 // Service Worker helpers for testharness.js-based tests. |
| 2 |
| 3 // Use with unexpected event handlers or Promise rejection. Will |
| 4 // fail the test with a name/message is present on the error. |
| 5 // E.g.: |
| 6 // onbadevent = fail(t, 'Should only see good events'); |
| 7 // Promise.then(...).catch(fail(t, 'Rejection is never fun')); |
| 8 function fail(test, desc) { |
| 9 desc = desc || 'Failure'; |
| 10 return test.step_func(function(reason) { |
| 11 if (reason && 'name' in reason && 'message' in reason) { |
| 12 assert_unreached(desc + ': ' + reason.name + ' - ' + reason.message)
; |
| 13 } else if (reason && 'name' in reason) { |
| 14 assert_unreached(desc + ': ' + reason.name); |
| 15 } else { |
| 16 assert_unreached(desc); |
| 17 } |
| 18 }); |
| 19 } |
| 20 |
| 21 // Sends a message of {port, from} to the specified worker, and returns the |
| 22 // port at the local end of the channel. |
| 23 function sendMessagePort(worker, from) { |
| 24 var messageChannel = new MessageChannel(); |
| 25 worker.postMessage({from:from, port:messageChannel.port2}, [messageChannel.p
ort2]); |
| 26 return messageChannel.port1; |
| 27 } |
OLD | NEW |