Index: testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java |
diff --git a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java |
index 35e381f4e4ebaedbb08d77cab41fabadad6ae6d7..7e087273cc0f27bbe23d2d002039ecc2d947f0e2 100644 |
--- a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java |
+++ b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java |
@@ -7,16 +7,15 @@ package org.chromium.native_test; |
import android.app.Activity; |
import android.content.Context; |
import android.os.Bundle; |
+import android.os.Handler; |
import android.util.Log; |
// Android's NativeActivity is mostly useful for pure-native code. |
// Our tests need to go up to our own java classes, which is not possible using |
// the native activity class loader. |
-// We start a background thread in here to run the tests and avoid an ANR. |
-// TODO(bulach): watch out for tests that implicitly assume they run on the main |
-// thread. |
public class ChromeNativeTestActivity extends Activity { |
private final String TAG = "ChromeNativeTestActivity"; |
+ private static long RUN_TESTS_DELAY_IN_MS = 300; |
John Grabowski
2012/06/25 20:51:37
Comment why we need a delay of any kind
nilesh
2012/06/25 21:26:26
Done.
|
// Name of our shlib as obtained from a string resource. |
private String mLibrary; |
@@ -33,16 +32,14 @@ public class ChromeNativeTestActivity extends Activity { |
try { |
loadLibrary(); |
- new Thread() { |
+ // Post a task to run the tests. This allows us to not block onCreate and |
+ // still run tests on the main thread. |
+ new Handler().postDelayed(new Runnable() { |
@Override |
public void run() { |
- Log.d(TAG, ">>nativeRunTests"); |
- nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext()); |
- // TODO(jrg): make sure a crash in native code |
- // triggers nativeTestFailed(). |
- Log.d(TAG, "<<nativeRunTests"); |
+ runTests(); |
} |
- }.start(); |
+ }, RUN_TESTS_DELAY_IN_MS); |
} catch (UnsatisfiedLinkError e) { |
Log.e(TAG, "Unable to load lib" + mLibrary + ".so: " + e); |
nativeTestFailed(); |
@@ -50,6 +47,14 @@ public class ChromeNativeTestActivity extends Activity { |
} |
} |
+ private void runTests() { |
+ Log.d(TAG, ">>nativeRunTests"); |
+ nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext()); |
+ // TODO(jrg): make sure a crash in native code |
John Grabowski
2012/06/25 20:51:37
You fixed this, right Nilesh?
Can we remove the TO
nilesh
2012/06/25 21:26:26
Yes, removed.
|
+ // triggers nativeTestFailed(). |
+ Log.d(TAG, "<<nativeRunTests"); |
+ } |
+ |
// Signal a failure of the native test loader to python scripts |
// which run tests. For example, we look for |
// RUNNER_FAILED build/android/test_package.py. |