Chromium Code Reviews| Index: chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java |
| diff --git a/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java b/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java |
| index 4a93fe167e8f92c0b31728eb2138cf0be15dc7d0..137a8a4b29e7dd697a56b5435210e9eee531abeb 100644 |
| --- a/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java |
| +++ b/chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java |
| @@ -8,12 +8,21 @@ import android.content.ComponentName; |
| import android.content.Intent; |
| import android.net.Uri; |
| import android.test.ActivityInstrumentationTestCase2; |
| +import android.text.TextUtils; |
| + |
| +import java.util.concurrent.atomic.AtomicBoolean; |
|
Ted C
2012/10/29 17:49:18
I think java's go last.
http://source.android.com
David Trainor- moved to gerrit
2012/10/29 21:10:32
Done.
|
| + |
| +import org.chromium.chrome.browser.TabBase; |
| +import org.chromium.content.browser.test.util.Criteria; |
| +import org.chromium.content.browser.test.util.CriteriaHelper; |
| /** |
| * Base test class for all ChromiumTestShell based tests. |
| */ |
| public class ChromiumTestShellTestBase extends |
| ActivityInstrumentationTestCase2<ChromiumTestShellActivity> { |
| + /** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */ |
| + private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = 10000; |
| public ChromiumTestShellTestBase() { |
| super(ChromiumTestShellActivity.class); |
| @@ -32,4 +41,42 @@ public class ChromiumTestShellTestBase extends |
| setActivityIntent(intent); |
| return getActivity(); |
| } |
| + |
| + /** |
| + * Waits for the Active shell to finish loading. This times out after |
| + * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be used for long |
| + * loading pages. Instead it should be used more for test initialization. The proper way |
| + * to wait is to use a TestCallbackHelperContainer after the initial load is completed. |
| + * @return Whether or not the Shell was actually finished loading. |
| + * @throws Exception |
| + */ |
| + protected boolean waitForActiveShellToBeDoneLoading() throws Exception { |
| + final ChromiumTestShellActivity activity = getActivity(); |
| + |
| + // Wait for the Content Shell to be initialized. |
| + return CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + try { |
| + final AtomicBoolean isLoaded = new AtomicBoolean(false); |
| + runTestOnUiThread(new Runnable() { |
| + @Override |
| + public void run() { |
| + TabBase tab = activity.getActiveTab(); |
|
Ted C
2012/10/29 17:49:18
Any thoughts on exposing the load complete from th
David Trainor- moved to gerrit
2012/10/29 21:10:32
Since TabBase could be NULL before the SurfaceView
Ted C
2012/10/29 21:13:59
Sadness...but ok
|
| + if (tab != null) { |
| + isLoaded.set(!tab.isLoading() |
| + && !TextUtils.isEmpty(tab.getContentView().getUrl())); |
| + } else { |
| + isLoaded.set(false); |
| + } |
| + } |
| + }); |
| + |
| + return isLoaded.get(); |
| + } catch (Throwable e) { |
| + return false; |
| + } |
| + } |
| + }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
| + } |
| } |