summaryrefslogtreecommitdiffstats
path: root/mojo/android/javatests
diff options
context:
space:
mode:
authorqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 10:59:10 +0000
committerqsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 10:59:10 +0000
commitde92b86816f1269befd05d1b4f9a975ac3bf2d3e (patch)
treee1043491023e8bf45fee7ce3b53a1224c5b8a3dd /mojo/android/javatests
parent78d27bd4240151236713fad4ca3520557d898e25 (diff)
downloadchromium_src-de92b86816f1269befd05d1b4f9a975ac3bf2d3e.zip
chromium_src-de92b86816f1269befd05d1b4f9a975ac3bf2d3e.tar.gz
chromium_src-de92b86816f1269befd05d1b4f9a975ac3bf2d3e.tar.bz2
Adding an invalid handle in the public API.
Also cleanup of the implementation by removing the unused CoreSingleton class. R=bulach@chromium.org,viettrungluu@chromium.org BUG= Review URL: https://codereview.chromium.org/260623006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267516 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/android/javatests')
-rw-r--r--mojo/android/javatests/src/org/chromium/mojo/system/CoreTest.java75
1 files changed, 63 insertions, 12 deletions
diff --git a/mojo/android/javatests/src/org/chromium/mojo/system/CoreTest.java b/mojo/android/javatests/src/org/chromium/mojo/system/CoreTest.java
index 97f0912..bf941b0 100644
--- a/mojo/android/javatests/src/org/chromium/mojo/system/CoreTest.java
+++ b/mojo/android/javatests/src/org/chromium/mojo/system/CoreTest.java
@@ -99,7 +99,7 @@ public class CoreTest extends InstrumentationTestCase {
*/
@SmallTest
public void testWaitMany() {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe();
try {
@@ -135,7 +135,7 @@ public class CoreTest extends InstrumentationTestCase {
*/
@SmallTest
public void testMessagePipeEmpty() {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe();
try {
@@ -189,7 +189,7 @@ public class CoreTest extends InstrumentationTestCase {
*/
@SmallTest
public void testMessagePipeSend() {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe();
try {
@@ -207,7 +207,7 @@ public class CoreTest extends InstrumentationTestCase {
@SmallTest
public void testMessagePipeReceiveOnSmallBuffer() {
Random random = new Random();
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe();
try {
@@ -236,7 +236,7 @@ public class CoreTest extends InstrumentationTestCase {
*/
@SmallTest
public void testMessagePipeSendHandles() {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe();
Pair<MessagePipeHandle, MessagePipeHandle> handlesToShare = core.createMessagePipe();
@@ -266,7 +266,7 @@ public class CoreTest extends InstrumentationTestCase {
}
private static void createAndCloseDataPipe(DataPipe.CreateOptions options) {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> handles = core.createDataPipe(
options);
handles.first.close();
@@ -297,7 +297,7 @@ public class CoreTest extends InstrumentationTestCase {
*/
@SmallTest
public void testDataPipeSend() {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Random random = new Random();
Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> handles = core.createDataPipe(null);
@@ -337,7 +337,7 @@ public class CoreTest extends InstrumentationTestCase {
@SmallTest
public void testDataPipeTwoPhaseSend() {
Random random = new Random();
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> handles = core.createDataPipe(null);
try {
@@ -371,7 +371,7 @@ public class CoreTest extends InstrumentationTestCase {
@SmallTest
public void testDataPipeDiscard() {
Random random = new Random();
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> handles = core.createDataPipe(null);
try {
@@ -410,7 +410,7 @@ public class CoreTest extends InstrumentationTestCase {
*/
@SmallTest
public void testSharedBufferCreation() {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
// Test creation with empty options.
core.createSharedBuffer(null, 8).close();
// Test creation with default options.
@@ -422,7 +422,7 @@ public class CoreTest extends InstrumentationTestCase {
*/
@SmallTest
public void testSharedBufferDuplication() {
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
SharedBufferHandle handle = core.createSharedBuffer(null, 8);
try {
// Test duplication with empty options.
@@ -440,7 +440,7 @@ public class CoreTest extends InstrumentationTestCase {
@SmallTest
public void testSharedBufferSending() {
Random random = new Random();
- Core core = CoreSingleton.getInstance();
+ Core core = CoreImpl.getInstance();
SharedBufferHandle handle = core.createSharedBuffer(null, 8);
SharedBufferHandle newHandle = handle.duplicate(null);
@@ -467,5 +467,56 @@ public class CoreTest extends InstrumentationTestCase {
}
}
+ /**
+ * Testing that invalid handle can be used with this implementation.
+ */
+ @SmallTest
+ public void testInvalidHandle() {
+ Core core = CoreImpl.getInstance();
+ Handle handle = new InvalidHandle();
+
+ // Checking wait.
+ boolean exception = false;
+ try {
+ core.wait(handle, WaitFlags.all(), 0);
+ } catch (MojoException e) {
+ assertEquals(MojoResult.INVALID_ARGUMENT, e.getMojoResult());
+ exception = true;
+ }
+ assertTrue(exception);
+
+ // Checking waitMany.
+ exception = false;
+ try {
+ List<Pair<Handle, WaitFlags>> handles = new ArrayList<Pair<Handle, WaitFlags>>();
+ handles.add(Pair.create(handle, WaitFlags.all()));
+ core.waitMany(handles, 0);
+ } catch (MojoException e) {
+ assertEquals(MojoResult.INVALID_ARGUMENT, e.getMojoResult());
+ exception = true;
+ }
+ assertTrue(exception);
+
+ // Checking sending an invalid handle.
+ // Until the behavior is changed on the C++ side, handle gracefully 2 different use case:
+ // - Receive a INVALID_ARGUMENT exception
+ // - Receive an invalid handle on the other side.
+ Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe();
+ try {
+ handles.first.writeMessage(null,
+ Collections.<Handle> singletonList(handle),
+ WriteFlags.none());
+ ReadMessageResult readMessageResult = handles.second.readMessage(null, 1,
+ ReadFlags.none());
+ assertEquals(1, readMessageResult.getHandlesCount());
+ assertFalse(readMessageResult.getHandles().get(0).isValid());
+ } catch (MojoException e) {
+ assertEquals(MojoResult.INVALID_ARGUMENT, e.getMojoResult());
+ } finally {
+ handles.first.close();
+ handles.second.close();
+ }
+ }
+
private native void nativeInitApplicationContext(Context context);
}