Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: third_party/WebKit/LayoutTests/harness-tests/mojo-helpers.html

Issue 1470153002: [mojo] Enable ServiceRegistryImpl to override remote services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-testing-3
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5ec331d0961e9efdd538ffb399e6ab6c18d41f93 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.addServiceOverride('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.addServiceOverride('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.addServiceOverride('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>

Powered by Google App Engine
This is Rietveld 408576698