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

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

Issue 364063006: JAVA BINDINGS WIP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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.system.Core;
7 import org.chromium.mojo.system.MojoException; 8 import org.chromium.mojo.system.MojoException;
9 import org.chromium.mojo.system.Pair;
8 10
9 import java.util.ArrayList; 11 import java.util.ArrayList;
10 import java.util.List; 12 import java.util.List;
11 13
12 /** 14 /**
13 * Utility class for bindings tests. 15 * Utility class for bindings tests.
14 */ 16 */
15 public class BindingsTestUtils { 17 public class BindingsTestUtils {
16 18
17 /** 19 /**
18 * {@link MessageReceiver} that records any message it receives. 20 * {@link MessageReceiver} that records any message it receives.
19 */ 21 */
20 public static class RecordingMessageReceiver implements MessageReceiver { 22 public static class RecordingMessageReceiver implements MessageReceiver {
21 23
22 public final List<Message> messages = new ArrayList<Message>(); 24 public final List<Message> messages = new ArrayList<Message>();
23 25
24 /** 26 /**
25 * @see MessageReceiver#accept(Message) 27 * @see MessageReceiver#accept(Message)
26 */ 28 */
27 @Override 29 @Override
28 public boolean accept(Message message) { 30 public boolean accept(Message message) {
29 messages.add(message); 31 messages.add(message);
30 return true; 32 return true;
31 } 33 }
32 } 34 }
33 35
34 /** 36 /**
35 * {@link Connector.ErrorHandler} that records any error it received. 37 * {@link MessageReceiverWithResponder} that records any message it receives .
36 */ 38 */
37 public static class CapturingErrorHandler implements Connector.ErrorHandler { 39 public static class RecordingMessageReceiverWithResponder extends RecordingM essageReceiver
40 implements MessageReceiverWithResponder {
41 public final List<Pair<Message, MessageReceiver>> messagesWithReceivers =
42 new ArrayList<Pair<Message, MessageReceiver>>();
43
44 /**
45 * @see MessageReceiverWithResponder#acceptWithResponder(Message, Messag eReceiver)
46 */
47 @Override
48 public boolean acceptWithResponder(Message message, MessageReceiver rece iver) {
49 messagesWithReceivers.add(Pair.create(message, receiver));
50 return true;
51 }
52 }
53
54 /**
55 * {@link ConnectionErrorHandler} that records any error it received.
56 */
57 public static class CapturingErrorHandler implements ConnectionErrorHandler {
38 58
39 public MojoException exception = null; 59 public MojoException exception = null;
40 60
41 /** 61 /**
42 * @see Connector.ErrorHandler#onError(MojoException) 62 * @see ConnectionErrorHandler#onConnectionError(MojoException)
43 */ 63 */
44 @Override 64 @Override
45 public void onError(MojoException e) { 65 public void onConnectionError(MojoException e) {
46 exception = e; 66 exception = e;
47 } 67 }
48 } 68 }
49 69
70 /**
71 * TODO(qsr):
72 *
73 * @param core
74 * @param s
75 * @return
76 */
77 public static Message serialize(Core core, Struct s) {
78 Encoder encoder = new Encoder(core, s.mEncodedBaseSize);
79 s.encode(encoder);
80 return encoder.getMessage();
81 }
82
50 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698