aboutsummaryrefslogtreecommitdiff
path: root/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java')
-rw-r--r--mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java265
1 files changed, 1 insertions, 264 deletions
diff --git a/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java b/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java
index 16c16f2..77a9bda 100644
--- a/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java
+++ b/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java
@@ -4,12 +4,9 @@
package org.chromium.mojo.system.impl;
-import android.test.suitebuilder.annotation.SmallTest;
+import android.support.test.filters.SmallTest;
import org.chromium.mojo.MojoTestCase;
-import org.chromium.mojo.system.AsyncWaiter;
-import org.chromium.mojo.system.AsyncWaiter.Callback;
-import org.chromium.mojo.system.AsyncWaiter.Cancellable;
import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Core.HandleSignals;
import org.chromium.mojo.system.Core.HandleSignalsState;
@@ -584,266 +581,6 @@ public class CoreImplTest extends MojoTestCase {
}
}
- private static class AsyncWaiterResult implements Callback {
- private int mResult = Integer.MIN_VALUE;
- private MojoException mException = null;
-
- /**
- * @see Callback#onResult(int)
- */
- @Override
- public void onResult(int result) {
- this.mResult = result;
- }
-
- /**
- * @see Callback#onError(MojoException)
- */
- @Override
- public void onError(MojoException exception) {
- this.mException = exception;
- }
-
- /**
- * @return the result
- */
- public int getResult() {
- return mResult;
- }
-
- /**
- * @return the exception
- */
- public MojoException getException() {
- return mException;
- }
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterCorrectResult() {
- Core core = CoreImpl.getInstance();
-
- // Checking a correct result.
- Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null);
- addHandlePairToClose(handles);
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- core.getDefaultAsyncWaiter().asyncWait(handles.first, Core.HandleSignals.READABLE,
- Core.DEADLINE_INFINITE, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- handles.second.writeMessage(
- ByteBuffer.allocateDirect(1), null, MessagePipeHandle.WriteFlags.NONE);
- runLoopUntilIdle();
- assertNull(asyncWaiterResult.getException());
- assertEquals(MojoResult.OK, asyncWaiterResult.getResult());
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterClosingPeerHandle() {
- Core core = CoreImpl.getInstance();
-
- // Closing the peer handle.
- Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null);
- addHandlePairToClose(handles);
-
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- core.getDefaultAsyncWaiter().asyncWait(handles.first, Core.HandleSignals.READABLE,
- Core.DEADLINE_INFINITE, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- runLoopUntilIdle();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- handles.second.close();
- runLoopUntilIdle();
- assertNull(asyncWaiterResult.getException());
- assertEquals(MojoResult.FAILED_PRECONDITION, asyncWaiterResult.getResult());
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterClosingWaitingHandle() {
- Core core = CoreImpl.getInstance();
-
- // Closing the peer handle.
- Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null);
- addHandlePairToClose(handles);
-
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- core.getDefaultAsyncWaiter().asyncWait(handles.first, Core.HandleSignals.READABLE,
- Core.DEADLINE_INFINITE, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- runLoopUntilIdle();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- handles.first.close();
- runLoopUntilIdle();
- // TODO(qsr) Re-enable when MojoWaitMany handles it correctly.
- // assertNull(asyncWaiterResult.getException());
- // assertEquals(MojoResult.CANCELLED, asyncWaiterResult.getResult());
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterWaitingOnInvalidHandle() {
- Core core = CoreImpl.getInstance();
-
- // Closing the peer handle.
- Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null);
- addHandlePairToClose(handles);
-
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- handles.first.close();
- core.getDefaultAsyncWaiter().asyncWait(handles.first, Core.HandleSignals.READABLE,
- Core.DEADLINE_INFINITE, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- runLoopUntilIdle();
- assertNotNull(asyncWaiterResult.getException());
- assertEquals(MojoResult.INVALID_ARGUMENT,
- asyncWaiterResult.getException().getMojoResult());
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterWaitingOnDefaultInvalidHandle() {
- Core core = CoreImpl.getInstance();
-
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- core.getDefaultAsyncWaiter().asyncWait(InvalidHandle.INSTANCE, Core.HandleSignals.READABLE,
- Core.DEADLINE_INFINITE, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- runLoopUntilIdle();
- assertNotNull(asyncWaiterResult.getException());
- assertEquals(MojoResult.INVALID_ARGUMENT, asyncWaiterResult.getException().getMojoResult());
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterWaitingWithTimeout() {
- Core core = CoreImpl.getInstance();
-
- // Closing the peer handle.
- Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null);
- addHandlePairToClose(handles);
-
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- core.getDefaultAsyncWaiter().asyncWait(
- handles.first, Core.HandleSignals.READABLE, RUN_LOOP_TIMEOUT_MS, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- runLoopUntilIdle();
- assertNull(asyncWaiterResult.getException());
- assertEquals(MojoResult.DEADLINE_EXCEEDED, asyncWaiterResult.getResult());
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterCancelWaiting() {
- Core core = CoreImpl.getInstance();
-
- // Closing the peer handle.
- Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null);
- addHandlePairToClose(handles);
-
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- Cancellable cancellable = core.getDefaultAsyncWaiter().asyncWait(handles.first,
- Core.HandleSignals.READABLE, Core.DEADLINE_INFINITE, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- runLoopUntilIdle();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- cancellable.cancel();
- runLoopUntilIdle();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- handles.second.writeMessage(
- ByteBuffer.allocateDirect(1), null, MessagePipeHandle.WriteFlags.NONE);
- runLoopUntilIdle();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
- }
-
- /**
- * Testing core {@link AsyncWaiter} implementation.
- */
- @SmallTest
- public void testAsyncWaiterImmediateCancelOnInvalidHandle() {
- Core core = CoreImpl.getInstance();
-
- // Closing the peer handle.
- Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null);
- addHandlePairToClose(handles);
-
- final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult();
- handles.first.close();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
-
- Cancellable cancellable = core.getDefaultAsyncWaiter().asyncWait(handles.first,
- Core.HandleSignals.READABLE, Core.DEADLINE_INFINITE, asyncWaiterResult);
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
- cancellable.cancel();
-
- runLoopUntilIdle();
- assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult());
- assertEquals(null, asyncWaiterResult.getException());
- }
-
/**
* Testing the pass method on message pipes.
*/