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

Unified Diff: mojo/android/javatests/src/org/chromium/mojo/bindings/ExecutorFactoryTest.java

Issue 364063006: JAVA BINDINGS WIP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates 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 side-by-side diff with in-line comments
Download patch
Index: mojo/android/javatests/src/org/chromium/mojo/bindings/ExecutorFactoryTest.java
diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/ExecutorFactoryTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/ExecutorFactoryTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..ab8f960865850ab335b1b71dc68569e364bb58d7
--- /dev/null
+++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/ExecutorFactoryTest.java
@@ -0,0 +1,86 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.mojo.bindings;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.mojo.MojoTestCase;
+import org.chromium.mojo.system.impl.CoreImpl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * Testing the executor factory.
+ */
+public class ExecutorFactoryTest extends MojoTestCase {
+
+ private static final long RUN_LOOP_TIMEOUT_MS = 50;
+ private static final ScheduledExecutorService WORKER =
+ Executors.newSingleThreadScheduledExecutor();
+
+ private Executor mExecutor;
+ private List<Thread> mThreadContainer;
+
+ /**
+ * @see MojoTestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mExecutor = ExecutorFactory.getExecutorForCurrentThread(CoreImpl.getInstance());
+ mThreadContainer = new ArrayList<Thread>();
+ }
+
+ /**
+ * Testing the {@link Executor} when called from the executor thread.
+ */
+ @SmallTest
+ public void testExecutorOnCurrentThread() {
+ mExecutor.execute(new Runnable() {
+ @Override
+ public void run() {
+ mThreadContainer.add(Thread.currentThread());
+ }
+ });
+ assertEquals(0, mThreadContainer.size());
+ nativeRunLoop(RUN_LOOP_TIMEOUT_MS);
+ assertEquals(1, mThreadContainer.size());
+ assertEquals(Thread.currentThread(), mThreadContainer.get(0));
+ }
+
+ /**
+ * Testing the {@link Executor} when called from another thread.
+ */
+ @SmallTest
+ public void testExecutorOnOtherThread() throws InterruptedException {
+ final Object lock = new Object();
+ synchronized (lock) {
+ WORKER.execute(new Runnable() {
+ @Override
+ public void run() {
+ synchronized (lock) {
+ mExecutor.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ mThreadContainer.add(Thread.currentThread());
+ }
+ });
+ lock.notify();
+ }
+ }
+ });
+ lock.wait();
+ }
+ assertEquals(0, mThreadContainer.size());
+ nativeRunLoop(RUN_LOOP_TIMEOUT_MS);
+ assertEquals(1, mThreadContainer.size());
+ assertEquals(Thread.currentThread(), mThreadContainer.get(0));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698