| Index: testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
|
| diff --git a/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java b/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
|
| index 4352205a23aa611bda3d7fc587056f336dfc1810..3e27274c40e610295fd5891df874efc58395f5c8 100644
|
| --- a/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
|
| +++ b/testing/android/native_test/java/src/org/chromium/native_test/NativeTest.java
|
| @@ -128,23 +128,40 @@ public class NativeTest {
|
| }
|
|
|
| public void postStart(final Activity activity, boolean forceRunInSubThread) {
|
| + final Runnable runTestsTask = new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + runTests(activity);
|
| + }
|
| + };
|
| +
|
| if (mRunInSubThread || forceRunInSubThread) {
|
| - // Create a new thread and run tests on it.
|
| - new Thread() {
|
| + // Post a task that posts a task that creates a new thread and runs tests on it.
|
| +
|
| + // On L and M, the system posts a task to the main thread that prints to stdout
|
| + // from android::Layout (https://goo.gl/vZA38p). Chaining the subthread creation
|
| + // through multiple tasks executed on the main thread ensures that this task
|
| + // runs before we start running tests s.t. its output doesn't interfere with
|
| + // the test output. See crbug.com/678146 for additional context.
|
| +
|
| + final Handler handler = new Handler();
|
| + final Runnable startTestThreadTask = new Runnable() {
|
| @Override
|
| public void run() {
|
| - runTests(activity);
|
| + new Thread(runTestsTask).start();
|
| }
|
| - }.start();
|
| - } else {
|
| - // Post a task to run the tests. This allows us to not block
|
| - // onCreate and still run tests on the main thread.
|
| - new Handler().post(new Runnable() {
|
| + };
|
| + final Runnable postTestStarterTask = new Runnable() {
|
| @Override
|
| public void run() {
|
| - runTests(activity);
|
| + handler.post(startTestThreadTask);
|
| }
|
| - });
|
| + };
|
| + handler.post(postTestStarterTask);
|
| + } else {
|
| + // Post a task to run the tests. This allows us to not block
|
| + // onCreate and still run tests on the main thread.
|
| + new Handler().post(runTestsTask);
|
| }
|
| }
|
|
|
|
|