OLD | NEW |
1 /* | 1 /* |
2 * mojo-helpers contains extensions to testharness.js useful for consuming | 2 * mojo-helpers contains extensions to testharness.js useful for consuming |
3 * and mocking Mojo services directly within test code. | 3 * and mocking Mojo services directly within test code. |
4 */ | 4 */ |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 // Runs a promise_test which depends on the Mojo system API modules available to | 7 // Runs a promise_test which depends on the Mojo system API modules available to |
8 // all layout tests. The test implementation function is called with an Object | 8 // all layout tests. The test implementation function is called with an Object |
9 // that exposes common Mojo module interfaces. | 9 // that exposes common Mojo module interfaces. |
10 function mojo_test(func, name, properties) { | 10 function mojo_test(func, name, properties) { |
(...skipping 17 matching lines...) Expand all Loading... |
28 // called |serviceRegistry|, so let's call it that here. | 28 // called |serviceRegistry|, so let's call it that here. |
29 serviceRegistry: serviceProvider, | 29 serviceRegistry: serviceProvider, |
30 })); | 30 })); |
31 } catch (e) { | 31 } catch (e) { |
32 reject(e); | 32 reject(e); |
33 } | 33 } |
34 }); | 34 }); |
35 }); | 35 }); |
36 }, name, properties); | 36 }, name, properties); |
37 } | 37 } |
| 38 |
| 39 // Polls aggressively for a message to become available on a pipe. |
| 40 function mojo_wait_for_incoming_message(mojo, pipe) { |
| 41 return new Promise((resolve, reject) => { |
| 42 let wait = () => { |
| 43 let result = mojo.core.readMessage(pipe, 0); |
| 44 if (result.result === mojo.core.RESULT_SHOULD_WAIT) { |
| 45 setTimeout(wait); |
| 46 return; |
| 47 } |
| 48 |
| 49 if (result.result !== mojo.core.RESULT_OK) { |
| 50 reject(result.result); |
| 51 return; |
| 52 } |
| 53 |
| 54 resolve({ buffer: result.buffer, handles: result.handles }); |
| 55 }; |
| 56 |
| 57 wait(); |
| 58 }); |
| 59 }; |
OLD | NEW |