OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.testing.local; | 5 package org.chromium.testing.local; |
6 | 6 |
7 import static org.junit.Assert.fail; | 7 import static org.junit.Assert.fail; |
8 | 8 |
9 import android.os.AsyncTask; | 9 import android.os.AsyncTask; |
10 | 10 |
| 11 import org.robolectric.Robolectric; |
11 import org.robolectric.annotation.Implementation; | 12 import org.robolectric.annotation.Implementation; |
12 import org.robolectric.annotation.Implements; | 13 import org.robolectric.annotation.Implements; |
13 import org.robolectric.shadows.ShadowApplication; | |
14 import org.robolectric.shadows.ShadowAsyncTask; | 14 import org.robolectric.shadows.ShadowAsyncTask; |
15 | 15 |
16 import java.util.concurrent.Callable; | 16 import java.util.concurrent.Callable; |
17 import java.util.concurrent.ExecutorService; | 17 import java.util.concurrent.ExecutorService; |
18 import java.util.concurrent.Executors; | 18 import java.util.concurrent.Executors; |
19 | 19 |
20 /** | 20 /** |
21 * Executes async tasks on a background thread and waits on the result on the ma
in thread. | 21 * Executes async tasks on a background thread and waits on the result on the ma
in thread. |
22 * This is useful for users of AsyncTask on Roboelectric who check if the code i
s actually being | 22 * This is useful for users of AsyncTask on Roboelectric who check if the code i
s actually being |
23 * run on a background thread (i.e. through the use of {@link ThreadUtils#runnin
gOnUiThread()}). | 23 * run on a background thread (i.e. through the use of {@link ThreadUtils#runnin
gOnUiThread()}). |
(...skipping 20 matching lines...) Expand all Loading... |
44 } catch (Exception ex) { | 44 } catch (Exception ex) { |
45 fail(ex.getMessage()); | 45 fail(ex.getMessage()); |
46 return null; | 46 return null; |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 public static void runBackgroundTasks() throws Exception { | 50 public static void runBackgroundTasks() throws Exception { |
51 sExecutorService.submit(new Runnable() { | 51 sExecutorService.submit(new Runnable() { |
52 @Override | 52 @Override |
53 public void run() { | 53 public void run() { |
54 ShadowApplication.runBackgroundTasks(); | 54 Robolectric.runBackgroundTasks(); |
55 } | 55 } |
56 }).get(); | 56 }).get(); |
57 } | 57 } |
58 } | 58 } |
OLD | NEW |