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

Unified Diff: base/test/android/java/src/org/chromium/base/JavaHandlerThreadTest.java

Issue 2774363003: android: Java-based launcher thread (Closed)
Patch Set: gab review 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/android/java_handler_thread_for_testing.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/android/java/src/org/chromium/base/JavaHandlerThreadTest.java
diff --git a/base/test/android/java/src/org/chromium/base/JavaHandlerThreadTest.java b/base/test/android/java/src/org/chromium/base/JavaHandlerThreadTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e516000b5e29e549af0d1233f8a4e508e1021537
--- /dev/null
+++ b/base/test/android/java/src/org/chromium/base/JavaHandlerThreadTest.java
@@ -0,0 +1,48 @@
+// Copyright 2017 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.base;
+
+import android.os.Handler;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+
+@JNINamespace("base")
+class JavaHandlerThreadTest {
+ private static boolean sTaskExecuted;
+ // This is executed as part of base_unittests. This tests that JavaHandlerThread can be used
+ // by itself without attaching to its native peer.
+ @CalledByNative
+ private static JavaHandlerThread testAndGetJavaHandlerThread() {
+ sTaskExecuted = false;
+ final Object lock = new Object();
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ synchronized (lock) {
+ sTaskExecuted = true;
+ lock.notifyAll();
+ }
+ }
+ };
+
+ JavaHandlerThread thread = new JavaHandlerThread("base_unittests_java");
+ thread.maybeStart();
+
+ Handler handler = new Handler(thread.getLooper());
+ handler.post(runnable);
+ synchronized (lock) {
+ while (!sTaskExecuted) {
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ // ignore interrupts
+ }
+ }
+ }
+
+ return thread;
+ }
+}
« no previous file with comments | « base/test/BUILD.gn ('k') | base/test/android/java_handler_thread_for_testing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698