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

Unified Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/util/ActivityUtils.java

Issue 2928653003: Ensure only one live search engine promo. (Closed)
Patch Set: Fix findbugs Created 3 years, 6 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
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialogTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/android/javatests/src/org/chromium/chrome/test/util/ActivityUtils.java
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ActivityUtils.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ActivityUtils.java
index 1150ffebc93bcd34e91267a4d2a7f26bddbe6c6e..ca044d484667cf0aacbd1da899793aa357c0d0b9 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ActivityUtils.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/ActivityUtils.java
@@ -9,10 +9,17 @@ import android.app.DialogFragment;
import android.app.Fragment;
import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.ActivityOptionsCompat;
import junit.framework.Assert;
+import org.chromium.base.test.util.ScalableTimeout;
+import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.Preferences;
+import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
@@ -20,7 +27,7 @@ import org.chromium.content.browser.test.util.CriteriaHelper;
* Collection of activity utilities.
*/
public class ActivityUtils {
- private static final long ACTIVITY_START_TIMEOUT_MS = 3000;
+ private static final long ACTIVITY_START_TIMEOUT_MS = ScalableTimeout.scaleTimeout(3000);
private static final long CONDITION_POLL_INTERVAL_MS = 100;
/**
@@ -50,6 +57,35 @@ public class ActivityUtils {
}
}
+ /**
+ * Captures an activity of a particular type by launching an intent explicitly targeting the
+ * activity.
+ *
+ * @param <T> The type of activity to wait for.
+ * @param activityType The class type of the activity.
+ * @return The spawned activity.
+ */
+ public static <T> T waitForActivity(
+ final Instrumentation instrumentation, final Class<T> activityType) {
+ Runnable intentTrigger = new Runnable() {
+ @Override
+ public void run() {
+ Context context = instrumentation.getTargetContext().getApplicationContext();
+ Intent activityIntent = new Intent();
+ activityIntent.setClass(context, activityType);
+ activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
+
+ Bundle optionsBundle =
+ ActivityOptionsCompat
+ .makeCustomAnimation(context, R.anim.activity_open_enter, 0)
+ .toBundle();
+ IntentUtils.safeStartActivity(context, activityIntent, optionsBundle);
+ }
+ };
+ return waitForActivity(instrumentation, activityType, intentTrigger);
+ }
+
/**
* Captures an activity of a particular type that is triggered from some action.
*
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialogTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698