Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/TopActivityListener.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/TopActivityListener.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/TopActivityListener.java |
index e746f7ef9e885cf561e4b790229c33aee216002c..7e3f5b863f15d5dbc9e9f24911b3aee398471a87 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/TopActivityListener.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/TopActivityListener.java |
@@ -16,21 +16,29 @@ import org.chromium.base.ApplicationStatus.ActivityStateListener; |
import org.chromium.content.browser.test.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
+import java.util.concurrent.TimeUnit; |
+ |
import javax.annotation.Nullable; |
/** |
* Test rule tracking which Chrome activity is currently at the top of the task. |
*/ |
public class TopActivityListener implements TestRule { |
+ private static final long ONE_SECOND_IN_MILLIS = TimeUnit.SECONDS.toMillis(1); |
+ |
private final ActivityStateListener mListener = new ActivityStateListener() { |
@Override |
public void onActivityStateChange(Activity activity, int newState) { |
if (newState == ActivityState.RESUMED) { |
mMostRecentActivity = activity; |
+ } else if (activity == mMostRecentActivity && newState == ActivityState.PAUSED) { |
+ mMostRecentActivity = null; |
+ mTimeWhenSetToNullMillis = System.currentTimeMillis(); |
} |
} |
}; |
+ private long mTimeWhenSetToNullMillis; |
private Activity mMostRecentActivity; |
@Override |
@@ -61,4 +69,15 @@ public class TopActivityListener implements TestRule { |
}); |
return (T) mMostRecentActivity; |
} |
+ |
+ public void waitForExternalApp() { |
+ CriteriaHelper.pollUiThread(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return mMostRecentActivity == null |
Ted C
2017/07/10 18:10:15
Just use ApplicationStatus.getStateForApplication
piotrs
2017/07/10 23:40:54
An Oversight. I deleted this whole class.
|
+ && (System.currentTimeMillis() - mTimeWhenSetToNullMillis) |
Ted C
2017/07/10 18:10:15
this delay is very much specific to your test. In
piotrs
2017/07/10 23:40:54
I don't quite follow. My intention was to ensure t
Ted C
2017/07/11 00:05:38
In general, any explicit time is likely to give yo
|
+ > ONE_SECOND_IN_MILLIS; |
+ } |
+ }); |
+ } |
} |