Bug 1442243 - 3. Add ClosedSessionAtStart test annotation; r?snorp
Add an annotation for having a closed session at the start of a test.
MozReview-Commit-ID: 4oMJwhwhKU7
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
@@ -43,16 +43,21 @@ class GeckoSessionTestRuleTest {
fun <T> assertThat(reason: String, v: T, m: Matcher<T>) = errors.checkThat(reason, v, m)
@Test fun getSession() {
assertThat("Can get session", sessionRule.session, notNullValue())
assertThat("Session is open",
sessionRule.session.isOpen, equalTo(true))
}
+ @GeckoSessionTestRule.ClosedSessionAtStart
+ @Test fun getSession_closedSession() {
+ assertThat("Session is closed", sessionRule.session.isOpen, equalTo(false))
+ }
+
@Setting.List(Setting(key = Setting.Key.USE_PRIVATE_MODE, value = "true"),
Setting(key = Setting.Key.DISPLAY_MODE, value = "DISPLAY_MODE_MINIMAL_UI"))
@Setting(key = Setting.Key.USE_TRACKING_PROTECTION, value = "true")
@Test fun settingsApplied() {
assertThat("USE_PRIVATE_MODE should be set",
sessionRule.session.settings.getBoolean(
GeckoSessionSettings.USE_PRIVATE_MODE),
equalTo(true))
--- 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
@@ -85,16 +85,25 @@ public class GeckoSessionTestRule extend
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface WithDisplay {
int width();
int height();
}
/**
+ * Specify that the main session should not be opened at the start of the test.
+ */
+ @Target({ElementType.METHOD, ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface ClosedSessionAtStart {
+ boolean value() default true;
+ }
+
+ /**
* Specify a list of GeckoSession settings to be applied to the GeckoSession object
* under test. Can be used on classes or methods. Note that the settings values must
* be string literals regardless of the type of the settings.
* <p>
* Disable e10s for a particular test:
* <pre>
* @Setting.List(@Setting(key = Setting.Key.USE_MULTIPROCESS,
* value = "false"))
@@ -482,16 +491,17 @@ public class GeckoSessionTestRule extend
protected CallbackDelegates mTestScopeDelegates;
protected int mLastWaitStart;
protected int mLastWaitEnd;
protected MethodCall mCurrentMethodCall;
protected long mTimeoutMillis;
protected SurfaceTexture mDisplayTexture;
protected Surface mDisplaySurface;
protected GeckoDisplay mDisplay;
+ protected boolean mClosedSession;
public GeckoSessionTestRule() {
mDefaultSettings = new GeckoSessionSettings();
}
/**
* Set an ErrorCollector for assertion errors, or null to not use one.
*
@@ -580,16 +590,18 @@ public class GeckoSessionTestRule extend
((Setting) annotation).key().set(settings, ((Setting) annotation).value());
} else if (Setting.List.class.equals(annotation.annotationType())) {
for (final Setting setting : ((Setting.List) annotation).value()) {
setting.key().set(settings, setting.value());
}
} else if (WithDisplay.class.equals(annotation.annotationType())) {
final WithDisplay displaySize = (WithDisplay)annotation;
mDisplaySize = new Point(displaySize.width(), displaySize.height());
+ } else if (ClosedSessionAtStart.class.equals(annotation.annotationType())) {
+ mClosedSession = ((ClosedSessionAtStart) annotation).value();
}
}
}
private static RuntimeException unwrapRuntimeException(Throwable e) {
final Throwable cause = e.getCause();
if (cause != null && cause instanceof RuntimeException) {
return (RuntimeException)cause;
@@ -597,16 +609,17 @@ public class GeckoSessionTestRule extend
return new RuntimeException(cause);
}
protected void prepareSession(final Description description) throws Throwable {
final GeckoSessionSettings settings = new GeckoSessionSettings(mDefaultSettings);
mTimeoutMillis = !env.isDebugging() ? DEFAULT_TIMEOUT_MILLIS
: DEFAULT_DEBUG_TIMEOUT_MILLIS;
+ mClosedSession = false;
applyAnnotations(Arrays.asList(description.getTestClass().getAnnotations()), settings);
applyAnnotations(description.getAnnotations(), settings);
final List<CallRecord> records = new ArrayList<>();
final CallbackDelegates waitDelegates = new CallbackDelegates();
final CallbackDelegates testDelegates = new CallbackDelegates();
mCallRecords = records;
@@ -655,16 +668,20 @@ public class GeckoSessionTestRule extend
}
for (final Class<?> cls : CALLBACK_CLASSES) {
if (cls != null) {
getCallbackSetter(cls).invoke(mSession, mCallbackProxy);
}
}
+ if (mClosedSession) {
+ return;
+ }
+
mSession.openWindow(mInstrumentation.getTargetContext());
if (settings.getBoolean(GeckoSessionSettings.USE_MULTIPROCESS)) {
// Under e10s, we receive an initial about:blank load; don't expose that to the test.
waitForPageStop();
}
}