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

Side by Side Diff: mojo/android/javatests/src/org/chromium/mojo/system/impl/WatcherImplTest.java

Issue 2725133002: Mojo: Armed Watchers (Closed)
Patch Set: docs Created 3 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.system.impl; 5 package org.chromium.mojo.system.impl;
6 6
7 import android.support.test.filters.SmallTest; 7 import android.support.test.filters.SmallTest;
8 8
9 import org.chromium.mojo.MojoTestCase; 9 import org.chromium.mojo.MojoTestCase;
10 import org.chromium.mojo.system.Core; 10 import org.chromium.mojo.system.Core;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 super.tearDown(); 61 super.tearDown();
62 } 62 }
63 63
64 private void addHandlePairToClose(Pair<? extends Handle, ? extends Handle> h andles) { 64 private void addHandlePairToClose(Pair<? extends Handle, ? extends Handle> h andles) {
65 mHandlesToClose.add(handles.first); 65 mHandlesToClose.add(handles.first);
66 mHandlesToClose.add(handles.second); 66 mHandlesToClose.add(handles.second);
67 } 67 }
68 68
69 private static class WatcherResult implements Callback { 69 private static class WatcherResult implements Callback {
70 private int mResult = Integer.MIN_VALUE; 70 private int mResult = Integer.MIN_VALUE;
71 private MessagePipeHandle mReadPipe;
72
73 /**
74 * @param readPipe A MessagePipeHandle to read from when onResult trigge rs success.
75 */
76 public WatcherResult(MessagePipeHandle readPipe) {
77 mReadPipe = readPipe;
78 }
79 public WatcherResult() {
80 this(null);
81 }
71 82
72 /** 83 /**
73 * @see Callback#onResult(int) 84 * @see Callback#onResult(int)
74 */ 85 */
75 @Override 86 @Override
76 public void onResult(int result) { 87 public void onResult(int result) {
77 this.mResult = result; 88 this.mResult = result;
89
90 if (result == MojoResult.OK && mReadPipe != null) {
91 mReadPipe.readMessage(
92 null, 0, MessagePipeHandle.ReadFlags.none().setMayDiscar d(true));
93 }
78 } 94 }
79 95
80 /** 96 /**
81 * @return the result 97 * @return the result
82 */ 98 */
83 public int getResult() { 99 public int getResult() {
84 return mResult; 100 return mResult;
85 } 101 }
86 } 102 }
87 103
88 /** 104 /**
89 * Testing {@link Watcher} implementation. 105 * Testing {@link Watcher} implementation.
90 */ 106 */
91 @SmallTest 107 @SmallTest
92 public void testCorrectResult() { 108 public void testCorrectResult() {
93 // Checking a correct result. 109 // Checking a correct result.
94 Pair<MessagePipeHandle, MessagePipeHandle> handles = mCore.createMessage Pipe(null); 110 Pair<MessagePipeHandle, MessagePipeHandle> handles = mCore.createMessage Pipe(null);
95 addHandlePairToClose(handles); 111 addHandlePairToClose(handles);
96 final WatcherResult watcherResult = new WatcherResult(); 112 final WatcherResult watcherResult = new WatcherResult(handles.first);
97 assertEquals(Integer.MIN_VALUE, watcherResult.getResult()); 113 assertEquals(Integer.MIN_VALUE, watcherResult.getResult());
98 114
99 mWatcher.start(handles.first, Core.HandleSignals.READABLE, watcherResult ); 115 mWatcher.start(handles.first, Core.HandleSignals.READABLE, watcherResult );
100 assertEquals(Integer.MIN_VALUE, watcherResult.getResult()); 116 assertEquals(Integer.MIN_VALUE, watcherResult.getResult());
101 117
102 handles.second.writeMessage( 118 handles.second.writeMessage(
103 ByteBuffer.allocateDirect(1), null, MessagePipeHandle.WriteFlags .NONE); 119 ByteBuffer.allocateDirect(1), null, MessagePipeHandle.WriteFlags .NONE);
104 runLoopUntilIdle(); 120 runLoopUntilIdle();
105 assertEquals(MojoResult.OK, watcherResult.getResult()); 121 assertEquals(MojoResult.OK, watcherResult.getResult());
106 } 122 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 assertEquals(Integer.MIN_VALUE, watcherResult.getResult()); 246 assertEquals(Integer.MIN_VALUE, watcherResult.getResult());
231 247
232 mWatcher.start(handles.first, Core.HandleSignals.READABLE, watcherResult ); 248 mWatcher.start(handles.first, Core.HandleSignals.READABLE, watcherResult );
233 assertEquals(Integer.MIN_VALUE, watcherResult.getResult()); 249 assertEquals(Integer.MIN_VALUE, watcherResult.getResult());
234 mWatcher.cancel(); 250 mWatcher.cancel();
235 251
236 runLoopUntilIdle(); 252 runLoopUntilIdle();
237 assertEquals(Integer.MIN_VALUE, watcherResult.getResult()); 253 assertEquals(Integer.MIN_VALUE, watcherResult.getResult());
238 } 254 }
239 } 255 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698