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

Side by Side Diff: mojo/android/javatests/src/org/chromium/mojo/bindings/BindingsTestUtils.java

Issue 371603003: Adding a router class to handle messages that expect responses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FOllow review Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.mojo.bindings; 5 package org.chromium.mojo.bindings;
6 6
7 import org.chromium.mojo.TestUtils;
8 import org.chromium.mojo.system.Handle;
7 import org.chromium.mojo.system.MojoException; 9 import org.chromium.mojo.system.MojoException;
10 import org.chromium.mojo.system.Pair;
8 11
12 import java.nio.ByteBuffer;
9 import java.util.ArrayList; 13 import java.util.ArrayList;
10 import java.util.List; 14 import java.util.List;
11 15
12 /** 16 /**
13 * Utility class for bindings tests. 17 * Utility class for bindings tests.
14 */ 18 */
15 public class BindingsTestUtils { 19 public class BindingsTestUtils {
16 20
17 /** 21 /**
18 * {@link MessageReceiver} that records any message it receives. 22 * {@link MessageReceiver} that records any message it receives.
19 */ 23 */
20 public static class RecordingMessageReceiver implements MessageReceiver { 24 public static class RecordingMessageReceiver implements MessageReceiver {
21 25
22 public final List<Message> messages = new ArrayList<Message>(); 26 public final List<MessageWithHeader> messages = new ArrayList<MessageWit hHeader>();
23 27
24 /** 28 /**
25 * @see MessageReceiver#accept(Message) 29 * @see MessageReceiver#accept(MessageWithHeader)
26 */ 30 */
27 @Override 31 @Override
28 public boolean accept(Message message) { 32 public boolean accept(MessageWithHeader message) {
29 messages.add(message); 33 messages.add(message);
30 return true; 34 return true;
31 } 35 }
32 } 36 }
33 37
34 /** 38 /**
35 * {@link Connector.ErrorHandler} that records any error it received. 39 * {@link MessageReceiverWithResponder} that records any message it receives .
36 */ 40 */
37 public static class CapturingErrorHandler implements Connector.ErrorHandler { 41 public static class RecordingMessageReceiverWithResponder extends RecordingM essageReceiver
42 implements MessageReceiverWithResponder {
43 public final List<Pair<MessageWithHeader, MessageReceiver>> messagesWith Receivers =
rmcilroy 2014/07/16 15:06:44 nit - newline above
qsr 2014/07/16 15:58:38 Done.
44 new ArrayList<Pair<MessageWithHeader, MessageReceiver>>();
45
46 /**
47 * @see MessageReceiverWithResponder#acceptWithResponder(MessageWithHead er,
48 * MessageReceiver)
49 */
50 @Override
51 public boolean acceptWithResponder(MessageWithHeader message, MessageRec eiver responder) {
52 messagesWithReceivers.add(Pair.create(message, responder));
53 return true;
54 }
55 }
56
57 /**
58 * {@link ConnectionErrorHandler} that records any error it received.
59 */
60 public static class CapturingErrorHandler implements ConnectionErrorHandler {
38 61
39 public MojoException exception = null; 62 public MojoException exception = null;
40 63
41 /** 64 /**
42 * @see Connector.ErrorHandler#onError(MojoException) 65 * @see ConnectionErrorHandler#onConnectionError(MojoException)
43 */ 66 */
44 @Override 67 @Override
45 public void onError(MojoException e) { 68 public void onConnectionError(MojoException e) {
46 exception = e; 69 exception = e;
47 } 70 }
48 } 71 }
49 72
73 /**
74 * Creates a new valid {@link MessageWithHeader}.
75 */
76 public static MessageWithHeader newRandomMessageWithHeader(int size) {
77 assert size > 16;
78 ByteBuffer message = TestUtils.newRandomBuffer(size);
79 int[] headerAsInts = { 16, 2, 0, 0 };
80 for (int i = 0; i < 4; ++i) {
81 message.putInt(4 * i, headerAsInts[i]);
82 }
83 message.position(0);
84 return new MessageWithHeader(new Message(message, new ArrayList<Handle>( )));
85 }
50 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698