OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="../resources/mojo-helpers.js"></script> | 4 <script src="../resources/mojo-helpers.js"></script> |
5 <script> | 5 <script> |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 // Verify that the mojo_test helper functions properly and Mojo bindings | 8 // Verify that the mojo_test helper functions properly and Mojo bindings |
9 // are available. | 9 // are available. |
10 mojo_test(mojo => { | 10 mojo_test(mojo => { |
11 assert_true(mojo instanceof Object); | 11 assert_true(mojo instanceof Object); |
12 assert_true(mojo.core instanceof Object); | 12 assert_true(mojo.core instanceof Object); |
13 assert_true(mojo.router instanceof Object); | 13 assert_true(mojo.router instanceof Object); |
14 assert_true(mojo.serviceRegistry instanceof Object); | 14 assert_true(mojo.serviceRegistry instanceof Object); |
15 }, 'Mojo system APIs should be available to layout tests.'); | 15 }, 'Mojo system APIs should be available to layout tests.'); |
| 16 |
| 17 mojo_test(mojo => { |
| 18 return new Promise(resolve => { |
| 19 // Complete the test as soon as a request comes in for a Frobinator service. |
| 20 mojo.serviceRegistry.addServiceOverride('Frobinator', resolve); |
| 21 |
| 22 // Try to connect to the browser's Frobinator service. This should be |
| 23 // intercepted by the above override. |
| 24 mojo.serviceRegistry.connectToService('Frobinator'); |
| 25 }); |
| 26 }, 'Service registry overrides should be properly intercepted.'); |
| 27 |
| 28 mojo_test(mojo => { |
| 29 return new Promise(resolve => { |
| 30 let TEST_REQUEST = new Uint8Array([42, 0, 2, 3, 5, 7, 11, 13, 17, 19, 23]); |
| 31 |
| 32 mojo.serviceRegistry.addServiceOverride('Frobinator', pipe => { |
| 33 resolve(mojo_wait_for_incoming_message(mojo, pipe) |
| 34 .then(message => { |
| 35 assert_array_equals(new Uint8Array(message.buffer), TEST_REQUEST); |
| 36 assert_array_equals(message.handles, []); |
| 37 })); |
| 38 }); |
| 39 |
| 40 let pipe = mojo.serviceRegistry.connectToService('Frobinator'); |
| 41 assert_equals(mojo.core.writeMessage(pipe, TEST_REQUEST, [], 0), |
| 42 mojo.core.RESULT_OK); |
| 43 }); |
| 44 }, 'Mock services can receive messages from test code.'); |
| 45 |
| 46 mojo_test(mojo => { |
| 47 let TEST_REQUEST = new Uint8Array([1, 2, 3, 4, 5]); |
| 48 let EXPECTED_RESPONSE = new Uint8Array([5, 4, 3, 2, 1]); |
| 49 |
| 50 // Mock service should respond to any message with its reverse. |
| 51 mojo.serviceRegistry.addServiceOverride('Reversinator', pipe => { |
| 52 mojo_wait_for_incoming_message(mojo, pipe) |
| 53 .then(message => { |
| 54 let response = new Uint8Array(message.buffer); |
| 55 response.reverse(); |
| 56 assert_equals(mojo.core.writeMessage(pipe, response, [], 0), |
| 57 mojo.core.RESULT_OK); |
| 58 }); |
| 59 }); |
| 60 |
| 61 let pipe = mojo.serviceRegistry.connectToService('Reversinator'); |
| 62 assert_equals(mojo.core.writeMessage(pipe, TEST_REQUEST, [], 0), |
| 63 mojo.core.RESULT_OK); |
| 64 |
| 65 return mojo_wait_for_incoming_message(mojo, pipe) |
| 66 .then(response => { |
| 67 assert_array_equals(new Uint8Array(response.buffer), EXPECTED_RESPONSE); |
| 68 assert_array_equals(response.handles, []); |
| 69 }); |
| 70 }, 'Test code can receive response messages from mock services.'); |
16 </script> | 71 </script> |
OLD | NEW |