Bug 1442243 - 2. Allow Callbacks interfaces for waitUntilCalled(Class<?>); r=me
Allow calls like `waitUntilCalled(Callbacks.NavigationListener::class)`
in addition to `waitUntilCalled(GeckoSession.NavigationListener::class)`.
MozReview-Commit-ID: CZHYnjGlxtT
--- 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
@@ -166,16 +166,21 @@ class GeckoSessionTestRuleTest {
}
@Test(expected = AssertionError::class)
fun waitUntilCalled_throwOnNotGeckoSessionInterface() {
sessionRule.session.loadTestPath(HELLO_HTML_PATH)
sessionRule.waitUntilCalled(CharSequence::class)
}
+ fun waitUntilCalled_notThrowOnCallbackInterface() {
+ sessionRule.session.loadTestPath(HELLO_HTML_PATH)
+ sessionRule.waitUntilCalled(Callbacks.ProgressDelegate::class)
+ }
+
@Test fun waitUntilCalled_anyObjectMethod() {
sessionRule.session.loadTestPath(HELLO_HTML_PATH)
var counter = 0
sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate {
override fun onPageStart(session: GeckoSession, url: String) {
counter++
--- 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
@@ -840,35 +840,44 @@ public class GeckoSessionTestRule extend
* Wait until the specified methods have been called on the specified callback
* interface. If no methods are specified, wait until any method has been called.
*
* @param callback Target callback interface; must be an interface under GeckoSession.
* @param methods List of methods to wait on; use empty or null or wait on any method.
*/
public void waitUntilCalled(final @NonNull Class<?> callback,
final @Nullable String... methods) {
- assertThat("Class should be a GeckoSession interface",
- callback, isIn(CALLBACK_CLASSES));
-
final int length = (methods != null) ? methods.length : 0;
final Pattern[] patterns = new Pattern[length];
for (int i = 0; i < length; i++) {
patterns[i] = Pattern.compile(methods[i]);
}
final List<MethodCall> waitMethods = new ArrayList<>();
+ boolean isSessionCallback = false;
- for (final Method method : callback.getDeclaredMethods()) {
- for (final Pattern pattern : patterns) {
- if (pattern.matcher(method.getName()).matches()) {
+ for (final Class<?> ifce : CALLBACK_CLASSES) {
+ if (!ifce.isAssignableFrom(callback)) {
+ continue;
+ }
+ for (final Method method : ifce.getMethods()) {
+ for (final Pattern pattern : patterns) {
+ if (!pattern.matcher(method.getName()).matches()) {
+ continue;
+ }
waitMethods.add(new MethodCall(method, /* requirement */ null));
+ break;
}
}
+ isSessionCallback = true;
}
+ assertThat("Class should be a GeckoSession interface",
+ isSessionCallback, equalTo(true));
+
waitUntilCalled(callback, waitMethods);
}
/**
* Wait until the specified methods have been called on the specified object,
* as specified by any {@link AssertCalled @AssertCalled} annotations. If no
* {@link AssertCalled @AssertCalled} annotations are found, wait until any method
* has been called. Only methods belonging to a GeckoSession callback are supported.