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

Unified Diff: testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java

Issue 10663024: Run APK tests on the main thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 8 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ec978c453ed6501215bfa7b7a2eb0e5fc7e4855a 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,16 @@ 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";
+ // We post a delayed task to run tests so that we do not block onCreate().
+ private static long RUN_TESTS_DELAY_IN_MS = 300;
// Name of our shlib as obtained from a string resource.
private String mLibrary;
@@ -33,16 +33,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 +48,12 @@ public class ChromeNativeTestActivity extends Activity {
}
}
+ private void runTests() {
+ Log.d(TAG, ">>nativeRunTests");
+ nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext());
+ 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.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698