Index: third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html |
diff --git a/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html b/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html |
index c16f63c0bdc2c57eb1e150b3ab628235ac195208..79cbcec02d37a55fdd74b426eb1258f945a70e06 100644 |
--- a/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html |
+++ b/third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html |
@@ -13,4 +13,59 @@ mojo_test(mojo => { |
assert_true(mojo.router instanceof Object); |
assert_true(mojo.serviceRegistry instanceof Object); |
}, 'Mojo system APIs should be available to layout tests.'); |
+ |
+mojo_test(mojo => { |
+ return new Promise(resolve => { |
+ // Complete the test as soon as a request comes in for a Frobinator service. |
+ mojo.serviceRegistry.addServiceOverrideForTesting('Frobinator', resolve); |
+ |
+ // Try to connect to the browser's Frobinator service. This should be |
+ // intercepted by the above override. |
+ mojo.serviceRegistry.connectToService('Frobinator'); |
+ }); |
+}, 'Service registry overrides should be properly intercepted.'); |
+ |
+mojo_test(mojo => { |
+ return new Promise(resolve => { |
+ let TEST_REQUEST = new Uint8Array([42, 0, 2, 3, 5, 7, 11, 13, 17, 19, 23]); |
+ |
+ mojo.serviceRegistry.addServiceOverrideForTesting('Frobinator', pipe => { |
+ resolve(mojo_wait_for_incoming_message(mojo, pipe) |
+ .then(message => { |
+ assert_array_equals(new Uint8Array(message.buffer), TEST_REQUEST); |
+ assert_array_equals(message.handles, []); |
+ })); |
+ }); |
+ |
+ let pipe = mojo.serviceRegistry.connectToService('Frobinator'); |
+ assert_equals(mojo.core.writeMessage(pipe, TEST_REQUEST, [], 0), |
+ mojo.core.RESULT_OK); |
+ }); |
+}, 'Mock services can receive messages from test code.'); |
+ |
+mojo_test(mojo => { |
+ let TEST_REQUEST = new Uint8Array([1, 2, 3, 4, 5]); |
+ let EXPECTED_RESPONSE = new Uint8Array([5, 4, 3, 2, 1]); |
+ |
+ // Mock service should respond to any message with its reverse. |
+ mojo.serviceRegistry.addServiceOverrideForTesting('Reversinator', pipe => { |
+ mojo_wait_for_incoming_message(mojo, pipe) |
+ .then(message => { |
+ let response = new Uint8Array(message.buffer); |
+ response.reverse(); |
+ assert_equals(mojo.core.writeMessage(pipe, response, [], 0), |
+ mojo.core.RESULT_OK); |
+ }); |
+ }); |
+ |
+ let pipe = mojo.serviceRegistry.connectToService('Reversinator'); |
+ assert_equals(mojo.core.writeMessage(pipe, TEST_REQUEST, [], 0), |
+ mojo.core.RESULT_OK); |
+ |
+ return mojo_wait_for_incoming_message(mojo, pipe) |
+ .then(response => { |
+ assert_array_equals(new Uint8Array(response.buffer), EXPECTED_RESPONSE); |
+ assert_array_equals(response.handles, []); |
+ }); |
+}, 'Test code can receive response messages from mock services.'); |
</script> |