| Index: chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationTestUtils.java
|
| diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationTestUtils.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationTestUtils.java
|
| index 07768135a2bbee027f5794ca2ddb7a9e694a1ea2..85710eaff69e2bc289b79f2fbae82319b3030e3e 100644
|
| --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationTestUtils.java
|
| +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ApplicationTestUtils.java
|
| @@ -158,14 +158,24 @@ public class ApplicationTestUtils {
|
| /** Finishes all tasks Chrome has listed in Android's Overview. */
|
| @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
| public static void finishAllChromeTasks(final Context context) throws Exception {
|
| - // Close all of the tasks one by one.
|
| - ActivityManager activityManager =
|
| - (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
| - for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
|
| - task.finishAndRemoveTask();
|
| - }
|
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + try {
|
| + // Close all of the tasks one by one.
|
| + ActivityManager activityManager =
|
| + (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
| + for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
|
| + task.finishAndRemoveTask();
|
| + }
|
| + } catch (Exception e) {
|
| + // Ignore any exceptions the Android framework throws so that otherwise passing
|
| + // tests don't fail during tear down. See crbug.com/653731.
|
| + }
|
| + }
|
| + });
|
|
|
| - CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() {
|
| + CriteriaHelper.pollUiThread(Criteria.equals(0, new Callable<Integer>() {
|
| @Override
|
| public Integer call() {
|
| return getNumChromeTasks(context);
|
|
|