Bug 1464351 - Look for initial about:blank load for cached session; r?snorp
We can get multiple initial loads for the cached session, so we must
specifically look for an about:blank load to wait on.
MozReview-Commit-ID: 6RxEmiSF2ti
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -92,24 +92,27 @@ public class GeckoSessionTestRule extend
private static final long DEFAULT_ARM_EMULATOR_TIMEOUT_MILLIS = 120000;
private static final long DEFAULT_X86_DEVICE_TIMEOUT_MILLIS = 30000;
private static final long DEFAULT_X86_EMULATOR_TIMEOUT_MILLIS = 5000;
private static final long DEFAULT_IDE_DEBUG_TIMEOUT_MILLIS = 86400000;
public static final String APK_URI_PREFIX = "resource://android/";
private static final Method sGetNextMessage;
+ private static final Method sOnPageStart;
private static final Method sOnPageStop;
private static final Method sOnNewSession;
private static final Method sOnCrash;
static {
try {
sGetNextMessage = MessageQueue.class.getDeclaredMethod("next");
sGetNextMessage.setAccessible(true);
+ sOnPageStart = GeckoSession.ProgressDelegate.class.getMethod(
+ "onPageStart", GeckoSession.class, String.class);
sOnPageStop = GeckoSession.ProgressDelegate.class.getMethod(
"onPageStop", GeckoSession.class, boolean.class);
sOnNewSession = GeckoSession.NavigationDelegate.class.getMethod(
"onNewSession", GeckoSession.class, String.class, GeckoResponse.class);
sOnCrash = GeckoSession.ContentDelegate.class.getMethod(
"onCrash", GeckoSession.class);
} catch (final NoSuchMethodException e) {
throw new RuntimeException(e);
@@ -1349,27 +1352,35 @@ public class GeckoSessionTestRule extend
}
}
private void waitForInitialLoad(final GeckoSession session) {
// We receive an initial about:blank load; don't expose that to the test. The initial
// load ends with the first onPageStop call, so ignore everything from the session
// until the first onPageStop call.
+ // For the cached session, we may get multiple initial loads. We should specifically look
+ // for an about:blank load, and wait until that has stopped.
+ final boolean lookForAboutBlank = session.equals(sCachedSession);
+
try {
// We cannot detect initial page load without progress delegate.
assertThat("ProgressDelegate cannot be null-delegate when opening session",
GeckoSession.ProgressDelegate.class, not(isIn(mNullDelegates)));
mCallRecordHandler = new CallRecordHandler() {
+ private boolean mIsAboutBlank = !lookForAboutBlank;
+
@Override
public boolean handleCall(final Method method, final Object[] args) {
final boolean matching = DEFAULT_DELEGATES.contains(
method.getDeclaringClass()) && session.equals(args[0]);
- if (matching && sOnPageStop.equals(method)) {
+ if (matching && sOnPageStart.equals(method)) {
+ mIsAboutBlank = "about:blank".equals(args[1]);
+ } else if (matching && mIsAboutBlank && sOnPageStop.equals(method)) {
mCallRecordHandler = null;
}
return matching;
}
};
do {
loopUntilIdle(getDefaultTimeoutMillis());