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

Unified Diff: chrome/android/testshell/javatests/src/org/chromium/chrome/testshell/ChromiumTestShellTestBase.java

Issue 11351002: Fix ChromiumTestShellTestBase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Nits Created 8 years, 2 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
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..cab24fd42840885ac5202de4c621968e1d2fc1a7 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 org.chromium.chrome.browser.TabBase;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* 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();
+ 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);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698