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

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: Fix findbugs issue 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
44 public final List<Pair<MessageWithHeader, MessageReceiver>> messagesWith Receivers =
45 new ArrayList<Pair<MessageWithHeader, MessageReceiver>>();
46
47 /**
48 * @see MessageReceiverWithResponder#acceptWithResponder(MessageWithHead er,
49 * MessageReceiver)
50 */
51 @Override
52 public boolean acceptWithResponder(MessageWithHeader message, MessageRec eiver responder) {
53 messagesWithReceivers.add(Pair.create(message, responder));
54 return true;
55 }
56 }
57
58 /**
59 * {@link ConnectionErrorHandler} that records any error it received.
60 */
61 public static class CapturingErrorHandler implements ConnectionErrorHandler {
38 62
39 public MojoException exception = null; 63 public MojoException exception = null;
40 64
41 /** 65 /**
42 * @see Connector.ErrorHandler#onError(MojoException) 66 * @see ConnectionErrorHandler#onConnectionError(MojoException)
43 */ 67 */
44 @Override 68 @Override
45 public void onError(MojoException e) { 69 public void onConnectionError(MojoException e) {
46 exception = e; 70 exception = e;
47 } 71 }
48 } 72 }
49 73
74 /**
75 * Creates a new valid {@link MessageWithHeader}.
76 */
77 public static MessageWithHeader newRandomMessageWithHeader(int size) {
78 assert size > 16;
79 ByteBuffer message = TestUtils.newRandomBuffer(size);
80 int[] headerAsInts = { 16, 2, 0, 0 };
81 for (int i = 0; i < 4; ++i) {
82 message.putInt(4 * i, headerAsInts[i]);
83 }
84 message.position(0);
85 return new MessageWithHeader(new Message(message, new ArrayList<Handle>( )));
86 }
50 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698