| 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); | |
| 13 assert_true(mojo.router instanceof Object); | 12 assert_true(mojo.router instanceof Object); |
| 14 assert_true(mojo.frameInterfaces instanceof Object); | 13 assert_true(mojo.frameInterfaces instanceof Object); |
| 15 assert_true(mojo.interfaces instanceof Object); | 14 assert_true(mojo.interfaces instanceof Object); |
| 16 }, 'Mojo system APIs should be available to layout tests.'); | 15 }, 'Mojo system APIs should be available to layout tests.'); |
| 17 | 16 |
| 18 mojo_test(mojo => { | 17 mojo_test(mojo => { |
| 19 return new Promise(resolve => { | 18 return new Promise(resolve => { |
| 20 let calls = 0; | 19 let calls = 0; |
| 21 // Complete the test as soon as two requests come in for a Frobinator | 20 // Complete the test as soon as two requests come in for a Frobinator |
| 22 // interface. | 21 // interface. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 54 |
| 56 mojo.interfaces.addInterfaceOverrideForTesting('Frobinator', pipe => { | 55 mojo.interfaces.addInterfaceOverrideForTesting('Frobinator', pipe => { |
| 57 resolve(mojo_wait_for_incoming_message(mojo, pipe) | 56 resolve(mojo_wait_for_incoming_message(mojo, pipe) |
| 58 .then(message => { | 57 .then(message => { |
| 59 assert_array_equals(new Uint8Array(message.buffer), TEST_REQUEST); | 58 assert_array_equals(new Uint8Array(message.buffer), TEST_REQUEST); |
| 60 assert_array_equals(message.handles, []); | 59 assert_array_equals(message.handles, []); |
| 61 })); | 60 })); |
| 62 }); | 61 }); |
| 63 | 62 |
| 64 let pipe = mojo.interfaces.getInterface('Frobinator'); | 63 let pipe = mojo.interfaces.getInterface('Frobinator'); |
| 65 assert_equals(mojo.core.writeMessage(pipe, TEST_REQUEST, [], 0), | 64 assert_equals(pipe.writeMessage(TEST_REQUEST, []), Mojo.RESULT_OK); |
| 66 mojo.core.RESULT_OK); | |
| 67 }); | 65 }); |
| 68 }, 'Mock interfaces can receive messages from test code.'); | 66 }, 'Mock interfaces can receive messages from test code.'); |
| 69 | 67 |
| 70 mojo_test(mojo => { | 68 mojo_test(mojo => { |
| 71 let TEST_REQUEST = new Uint8Array([1, 2, 3, 4, 5]); | 69 let TEST_REQUEST = new Uint8Array([1, 2, 3, 4, 5]); |
| 72 let EXPECTED_RESPONSE = new Uint8Array([5, 4, 3, 2, 1]); | 70 let EXPECTED_RESPONSE = new Uint8Array([5, 4, 3, 2, 1]); |
| 73 | 71 |
| 74 // Mock interface should respond to any message with its reverse. | 72 // Mock interface should respond to any message with its reverse. |
| 75 mojo.interfaces.addInterfaceOverrideForTesting('Reversinator', pipe => { | 73 mojo.interfaces.addInterfaceOverrideForTesting('Reversinator', pipe => { |
| 76 mojo_wait_for_incoming_message(mojo, pipe) | 74 mojo_wait_for_incoming_message(mojo, pipe) |
| 77 .then(message => { | 75 .then(message => { |
| 78 let response = new Uint8Array(message.buffer); | 76 let response = new Uint8Array(message.buffer); |
| 79 response.reverse(); | 77 response.reverse(); |
| 80 assert_equals(mojo.core.writeMessage(pipe, response, [], 0), | 78 assert_equals(pipe.writeMessage(response, []), Mojo.RESULT_OK); |
| 81 mojo.core.RESULT_OK); | |
| 82 }); | 79 }); |
| 83 }); | 80 }); |
| 84 | 81 |
| 85 let pipe = mojo.interfaces.getInterface('Reversinator'); | 82 let pipe = mojo.interfaces.getInterface('Reversinator'); |
| 86 assert_equals(mojo.core.writeMessage(pipe, TEST_REQUEST, [], 0), | 83 assert_equals(pipe.writeMessage(TEST_REQUEST, []), Mojo.RESULT_OK); |
| 87 mojo.core.RESULT_OK); | |
| 88 | 84 |
| 89 return mojo_wait_for_incoming_message(mojo, pipe) | 85 return mojo_wait_for_incoming_message(mojo, pipe) |
| 90 .then(response => { | 86 .then(response => { |
| 91 assert_array_equals(new Uint8Array(response.buffer), EXPECTED_RESPONSE); | 87 assert_array_equals(new Uint8Array(response.buffer), EXPECTED_RESPONSE); |
| 92 assert_array_equals(response.handles, []); | 88 assert_array_equals(response.handles, []); |
| 93 }); | 89 }); |
| 94 }, 'Test code can receive response messages from mock interfaces.'); | 90 }, 'Test code can receive response messages from mock interfaces.'); |
| 95 | 91 |
| 96 mojo_test(() => { | 92 mojo_test(() => { |
| 97 return loadMojoModules( | 93 return loadMojoModules( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 126 popup.close(); | 122 popup.close(); |
| 127 window.removeEventListener('message', listener); | 123 window.removeEventListener('message', listener); |
| 128 assert_true(result.data); | 124 assert_true(result.data); |
| 129 resolve(); | 125 resolve(); |
| 130 } | 126 } |
| 131 window.addEventListener('message', listener); | 127 window.addEventListener('message', listener); |
| 132 popup = window.open('resources/mojo-helpers-inner.html'); | 128 popup = window.open('resources/mojo-helpers-inner.html'); |
| 133 }); | 129 }); |
| 134 }, 'Mojo bindings are accessible from popups'); | 130 }, 'Mojo bindings are accessible from popups'); |
| 135 </script> | 131 </script> |
| OLD | NEW |