From a4f2c7f7f0a4843348ef6e523ab81f37cbb7a561 Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Wed, 1 Sep 2021 23:40:33 +0000 Subject: [PATCH] Bug 1676216 - Remove o.m.g.test.util.Callbacks. r=owlish It's a relic of the past when we didn't require default methods for delegates, we don't need it anymore. Differential Revision: https://phabricator.services.mozilla.com/D122506 --- .../geckoview/test/AutocompleteTest.kt | 31 ++- .../geckoview/test/AutofillDelegateTest.kt | 33 ++- .../test/ContentBlockingControllerTest.kt | 16 +- .../geckoview/test/ContentCrashTest.kt | 4 +- .../ContentDelegateMultipleSessionsTest.kt | 8 +- .../geckoview/test/ContentDelegateTest.kt | 54 ++-- .../geckoview/test/DynamicToolbarTest.kt | 8 +- .../test/GeckoSessionTestRuleTest.kt | 237 ++++++++---------- .../geckoview/test/HistoryDelegateTest.kt | 18 +- .../geckoview/test/ImageResourceTest.kt | 11 - .../geckoview/test/InputResultDetailTest.kt | 4 +- .../geckoview/test/MediaDelegateTest.kt | 7 +- .../test/MediaDelegateXOriginTest.kt | 11 +- .../geckoview/test/MediaSessionTest.kt | 11 +- .../geckoview/test/NavigationDelegateTest.kt | 200 ++++++++------- .../mozilla/geckoview/test/OpenWindowTest.kt | 16 +- .../geckoview/test/PanZoomControllerTest.kt | 3 - .../geckoview/test/PermissionDelegateTest.kt | 53 ++-- .../geckoview/test/ProgressDelegateTest.kt | 37 +-- .../geckoview/test/PromptDelegateTest.kt | 61 ++--- .../geckoview/test/RuntimeSettingsTest.kt | 10 +- .../mozilla/geckoview/test/ScreenshotTest.kt | 31 ++- .../test/SelectionActionDelegateTest.kt | 16 +- .../geckoview/test/TextInputDelegateTest.kt | 19 +- .../geckoview/test/VerticalClippingTest.kt | 6 +- .../geckoview/test/WebExtensionTest.kt | 10 +- .../geckoview/test/WebNotificationTest.kt | 4 +- .../org/mozilla/geckoview/test/WebPushTest.kt | 4 +- .../test/rule/GeckoSessionTestRule.java | 81 +++--- .../mozilla/geckoview/test/util/Callbacks.kt | 65 ----- 30 files changed, 497 insertions(+), 572 deletions(-) delete mode 100644 mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/util/Callbacks.kt diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutocompleteTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutocompleteTest.kt index d2770b59e1ef..7c6a4df29295 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutocompleteTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutocompleteTest.kt @@ -32,7 +32,6 @@ import org.mozilla.geckoview.Autocomplete.StorageDelegate import org.mozilla.geckoview.Autocomplete.UsedField import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @@ -165,7 +164,7 @@ class AutocompleteTest : BaseSessionTest() { } }) - mainSession.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + mainSession.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 1) override fun onCreditCardSelect( session: GeckoSession, @@ -286,7 +285,7 @@ class AutocompleteTest : BaseSessionTest() { override fun onAddressSave(address: Address) {} }) - mainSession.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + mainSession.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 1) override fun onAddressSelect( session: GeckoSession, @@ -478,7 +477,7 @@ class AutocompleteTest : BaseSessionTest() { // Submit the form. mainSession.evaluateJS("document.querySelector('#form1').submit()") - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSave( session: GeckoSession, @@ -544,7 +543,7 @@ class AutocompleteTest : BaseSessionTest() { } }) - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSave( session: GeckoSession, @@ -621,7 +620,7 @@ class AutocompleteTest : BaseSessionTest() { } }) - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSave( session: GeckoSession, @@ -737,7 +736,7 @@ class AutocompleteTest : BaseSessionTest() { } }) - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 2) override fun onLoginSave( session: GeckoSession, @@ -867,7 +866,7 @@ class AutocompleteTest : BaseSessionTest() { }) } - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(false) override fun onLoginSave( session: GeckoSession, @@ -943,7 +942,7 @@ class AutocompleteTest : BaseSessionTest() { override fun onLoginUsed(login: LoginEntry, usedFields: Int) {} }) - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(false) override fun onLoginSave( session: GeckoSession, @@ -1121,7 +1120,7 @@ class AutocompleteTest : BaseSessionTest() { mainSession.loadTestPath(FORMS3_HTML_PATH) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PromptDelegate { + mainSession.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSave( session: GeckoSession, @@ -1161,7 +1160,7 @@ class AutocompleteTest : BaseSessionTest() { session2.loadTestPath(FORMS3_HTML_PATH) session2.waitForPageStop() - session2.delegateDuringNextWait(object : Callbacks.PromptDelegate { + session2.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSave( session: GeckoSession, @@ -1199,7 +1198,7 @@ class AutocompleteTest : BaseSessionTest() { // Reload for the last time. val session3 = sessionRule.createOpenSession() - session3.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + session3.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSelect( session: GeckoSession, @@ -1372,7 +1371,7 @@ class AutocompleteTest : BaseSessionTest() { mainSession.loadTestPath(FORMS3_HTML_PATH) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PromptDelegate { + mainSession.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSave( session: GeckoSession, @@ -1412,7 +1411,7 @@ class AutocompleteTest : BaseSessionTest() { session2.loadTestPath(FORMS3_HTML_PATH) session2.waitForPageStop() - session2.delegateDuringNextWait(object : Callbacks.PromptDelegate { + session2.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSave( session: GeckoSession, @@ -1450,7 +1449,7 @@ class AutocompleteTest : BaseSessionTest() { // Reload for the last time. val session3 = sessionRule.createOpenSession() - session3.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + session3.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 1) override fun onLoginSelect( session: GeckoSession, @@ -1586,7 +1585,7 @@ class AutocompleteTest : BaseSessionTest() { mainSession.loadTestPath(FORMS4_HTML_PATH) mainSession.waitForPageStop() - mainSession.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + mainSession.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled override fun onLoginSelect( session: GeckoSession, diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt index 4b0e798b306f..120cd1ba67a8 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt @@ -23,7 +23,6 @@ import org.mozilla.geckoview.GeckoSession import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @@ -37,7 +36,7 @@ class AutofillDelegateTest : BaseSessionTest() { mainSession.loadTestPath(FORMS_HTML_PATH) // Wait for the auto-fill nodes to populate. - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { // For the root document and the iframe document, each has a form group and // a group for inputs outside of forms, so the total count is 4. @AssertCalled(count = 4) @@ -61,7 +60,7 @@ class AutofillDelegateTest : BaseSessionTest() { // Submit the session. mainSession.evaluateJS("document.querySelector('#form1').submit()") - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 5) override fun onAutofill(session: GeckoSession, notification: Int, @@ -101,7 +100,7 @@ class AutofillDelegateTest : BaseSessionTest() { mainSession.loadTestPath(FORMS_ID_VALUE_HTML_PATH) // Wait for the auto-fill nodes to populate. - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 1) override fun onAutofill(session: GeckoSession, notification: Int, @@ -120,7 +119,7 @@ class AutofillDelegateTest : BaseSessionTest() { // Submit the session. mainSession.evaluateJS("document.querySelector('#form1').submit()") - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 2) override fun onAutofill(session: GeckoSession, notification: Int, @@ -149,7 +148,7 @@ class AutofillDelegateTest : BaseSessionTest() { // SessionAccessibility for a11y auto-fill support. mainSession.loadTestPath(FORMS_HTML_PATH) // Wait for the auto-fill nodes to populate. - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { // For the root document and the iframe document, each has a form group and // a group for inputs outside of forms, so the total count is 4. @AssertCalled(count = 4) @@ -251,7 +250,7 @@ class AutofillDelegateTest : BaseSessionTest() { @Test fun autofillNavigation() { // Wait for the accessibility nodes to populate. mainSession.loadTestPath(FORMS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 4) override fun onAutofill(session: GeckoSession, notification: Int, @@ -270,7 +269,7 @@ class AutofillDelegateTest : BaseSessionTest() { // Now wait for the nodes to clear. mainSession.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 1) override fun onAutofill(session: GeckoSession, notification: Int, @@ -287,7 +286,7 @@ class AutofillDelegateTest : BaseSessionTest() { // Now wait for the nodes to reappear. mainSession.waitForPageStop() mainSession.goBack() - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 4) override fun onAutofill(session: GeckoSession, notification: Int, @@ -307,7 +306,7 @@ class AutofillDelegateTest : BaseSessionTest() { mainSession.evaluateJS("document.querySelector('#pass2').focus()") - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 1) override fun onAutofill(session: GeckoSession, notification: Int, @@ -330,7 +329,7 @@ class AutofillDelegateTest : BaseSessionTest() { equalTo(8)) mainSession.evaluateJS("document.querySelector('#pass2').blur()") - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 1) override fun onAutofill(session: GeckoSession, notification: Int, @@ -349,7 +348,7 @@ class AutofillDelegateTest : BaseSessionTest() { @Test fun autofillUserpass() { mainSession.loadTestPath(FORMS2_HTML_PATH) // Wait for the auto-fill nodes to populate. - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 3) override fun onAutofill(session: GeckoSession, notification: Int, @@ -392,7 +391,7 @@ class AutofillDelegateTest : BaseSessionTest() { // inactive. Likewise, we should focus a node once we return. mainSession.loadTestPath(FORMS_HTML_PATH) // Wait for the auto-fill nodes to populate. - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { // For the root document and the iframe document, each has a form group and // a group for inputs outside of forms, so the total count is 4. @AssertCalled(count = 4) @@ -408,7 +407,7 @@ class AutofillDelegateTest : BaseSessionTest() { }) mainSession.evaluateJS("document.querySelector('#pass2').focus()") - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 1) override fun onAutofill(session: GeckoSession, notification: Int, @@ -424,7 +423,7 @@ class AutofillDelegateTest : BaseSessionTest() { // Make sure we get NODE_BLURRED when inactive mainSession.setActive(false) - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 1) override fun onAutofill(session: GeckoSession, notification: Int, @@ -438,7 +437,7 @@ class AutofillDelegateTest : BaseSessionTest() { // Make sure we get NODE_FOCUSED when active once again mainSession.setActive(true) - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 1) override fun onAutofill(session: GeckoSession, notification: Int, @@ -456,7 +455,7 @@ class AutofillDelegateTest : BaseSessionTest() { @WithDisplay(width = 100, height = 100) @Test fun autofillAutocompleteAttribute() { mainSession.loadTestPath(FORMS_AUTOCOMPLETE_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate { + sessionRule.waitUntilCalled(object : Autofill.Delegate { @AssertCalled(count = 3) override fun onAutofill(session: GeckoSession, notification: Int, diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentBlockingControllerTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentBlockingControllerTest.kt index 63bc028713b1..306a59f95bf1 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentBlockingControllerTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentBlockingControllerTest.kt @@ -7,7 +7,6 @@ package org.mozilla.geckoview.test import androidx.test.filters.MediumTest import androidx.test.ext.junit.runners.AndroidJUnit4 import org.hamcrest.Matchers.* -import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.ContentBlocking @@ -17,7 +16,6 @@ import org.mozilla.geckoview.GeckoSession import org.mozilla.geckoview.GeckoSessionSettings import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.util.Callbacks import org.junit.Assume.assumeThat @RunWith(AndroidJUnit4::class) @@ -31,7 +29,7 @@ class ContentBlockingControllerTest : BaseSessionTest() { session1.loadTestPath(TRACKERS_PATH) sessionRule.waitUntilCalled( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @GeckoSessionTestRule.AssertCalled(count=3) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -69,7 +67,7 @@ class ContentBlockingControllerTest : BaseSessionTest() { sessionRule.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @GeckoSessionTestRule.AssertCalled(false) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -87,7 +85,7 @@ class ContentBlockingControllerTest : BaseSessionTest() { session1.reload() sessionRule.waitUntilCalled( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @GeckoSessionTestRule.AssertCalled(count=3) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -236,7 +234,7 @@ class ContentBlockingControllerTest : BaseSessionTest() { sessionRule.session.loadTestPath(TRACKERS_PATH) sessionRule.waitUntilCalled( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @GeckoSessionTestRule.AssertCalled(count=3) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -263,7 +261,7 @@ class ContentBlockingControllerTest : BaseSessionTest() { sessionRule.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @GeckoSessionTestRule.AssertCalled(false) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -280,7 +278,7 @@ class ContentBlockingControllerTest : BaseSessionTest() { sessionRule.session.reload() sessionRule.waitUntilCalled( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @GeckoSessionTestRule.AssertCalled(count=3) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -341,7 +339,7 @@ class ContentBlockingControllerTest : BaseSessionTest() { sessionRule.session.settings.useTrackingProtection = true sessionRule.session.loadTestPath(TRACKERS_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentBlockingDelegate { + sessionRule.waitUntilCalled(object : ContentBlocking.Delegate { @AssertCalled(count = 1) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentCrashTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentCrashTest.kt index 56782226cfa9..c383218d6189 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentCrashTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentCrashTest.kt @@ -12,8 +12,8 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.BuildConfig +import org.mozilla.geckoview.GeckoSession.ContentDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.IgnoreCrash -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @@ -37,7 +37,7 @@ class ContentCrashTest : BaseSessionTest() { assumeThat(sessionRule.env.isIsolatedProcess, Matchers.equalTo(false)) mainSession.loadUri(CONTENT_CRASH_URL) - mainSession.waitUntilCalled(Callbacks.ContentDelegate::class, "onCrash") + mainSession.waitUntilCalled(ContentDelegate::class, "onCrash") // This test is really slow so we allow double the usual timeout var evalResult = client.getEvalResult(env.defaultTimeoutMillis * 2) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateMultipleSessionsTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateMultipleSessionsTest.kt index cdaf9bff272c..67540f51ff1f 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateMultipleSessionsTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateMultipleSessionsTest.kt @@ -4,9 +4,9 @@ package org.mozilla.geckoview.test +import org.mozilla.geckoview.GeckoSession.ContentDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.IgnoreCrash -import org.mozilla.geckoview.test.util.Callbacks import androidx.annotation.AnyThread import androidx.test.filters.MediumTest @@ -37,7 +37,7 @@ class ContentDelegateMultipleSessionsTest : BaseSessionTest() { killAllContentProcesses() if (isMainSessionAlreadyOpen) { - mainSession.waitUntilCalled(object : Callbacks.ContentDelegate { + mainSession.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onKill(session: GeckoSession) { } @@ -108,7 +108,7 @@ class ContentDelegateMultipleSessionsTest : BaseSessionTest() { // ...but we use GeckoResult.allOf for waiting on the aggregated results val allCrashesFound = GeckoResult.allOf(mainSessionCrash, newSessionCrash) - sessionRule.delegateUntilTestEnd(object : Callbacks.ContentDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate { fun reportCrash(session: GeckoSession) { if (session == mainSession) { mainSessionCrash.complete(null) @@ -143,7 +143,7 @@ class ContentDelegateMultipleSessionsTest : BaseSessionTest() { val allKillEventsReceived = GeckoResult.allOf(mainSessionKilled, newSessionKilled) - sessionRule.delegateUntilTestEnd(object : Callbacks.ContentDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate { override fun onKill(session: GeckoSession) { if (session == mainSession) { mainSessionKilled.complete(null) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt index 79f423efb3f6..3d903bf2841e 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt @@ -7,10 +7,12 @@ package org.mozilla.geckoview.test import android.graphics.SurfaceTexture import android.net.Uri import org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest +import org.mozilla.geckoview.GeckoSession.ProgressDelegate +import org.mozilla.geckoview.GeckoSession.ContentDelegate +import org.mozilla.geckoview.GeckoSession.NavigationDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.IgnoreCrash import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay -import org.mozilla.geckoview.test.util.Callbacks import androidx.annotation.AnyThread import androidx.test.filters.MediumTest @@ -31,7 +33,7 @@ class ContentDelegateTest : BaseSessionTest() { @Test fun titleChange() { sessionRule.session.loadTestPath(TITLE_CHANGE_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 2) override fun onTitleChange(session: GeckoSession, title: String?) { assertThat("Title should match", title, @@ -46,7 +48,7 @@ class ContentDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(DOWNLOAD_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.NavigationDelegate, Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : NavigationDelegate, ContentDelegate { @AssertCalled(count = 2) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { @@ -77,7 +79,7 @@ class ContentDelegateTest : BaseSessionTest() { assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) mainSession.loadUri(CONTENT_CRASH_URL) - mainSession.waitUntilCalled(object : Callbacks.ContentDelegate { + mainSession.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onCrash(session: GeckoSession) { assertThat("Session should be closed after a crash", @@ -88,7 +90,7 @@ class ContentDelegateTest : BaseSessionTest() { // Recover immediately mainSession.open() mainSession.loadTestPath(HELLO_HTML_PATH) - mainSession.waitUntilCalled(object: Callbacks.ProgressDelegate { + mainSession.waitUntilCalled(object: ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("Page should load successfully", success, equalTo(true)) @@ -102,7 +104,7 @@ class ContentDelegateTest : BaseSessionTest() { // TODO: bug 1710940 assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) - mainSession.delegateUntilTestEnd(object : Callbacks.ContentDelegate { + mainSession.delegateUntilTestEnd(object : ContentDelegate { override fun onCrash(session: GeckoSession) { mainSession.open() mainSession.loadTestPath(HELLO_HTML_PATH) @@ -129,7 +131,7 @@ class ContentDelegateTest : BaseSessionTest() { @IgnoreCrash @Test fun killContent() { killAllContentProcesses() - mainSession.waitUntilCalled(object : Callbacks.ContentDelegate { + mainSession.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onKill(session: GeckoSession) { assertThat("Session should be closed after being killed", @@ -139,7 +141,7 @@ class ContentDelegateTest : BaseSessionTest() { mainSession.open() mainSession.loadTestPath(HELLO_HTML_PATH) - mainSession.waitUntilCalled(object : Callbacks.ProgressDelegate { + mainSession.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("Page should load successfully", success, equalTo(true)) @@ -152,7 +154,7 @@ class ContentDelegateTest : BaseSessionTest() { mainSession.loadTestPath(FULLSCREEN_PATH) mainSession.waitForPageStop() val promise = mainSession.evaluatePromiseJS("document.querySelector('#fullscreen').requestFullscreen()") - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFullScreen(session: GeckoSession, fullScreen: Boolean) { assertThat("Div went fullscreen", fullScreen, equalTo(true)) @@ -162,7 +164,7 @@ class ContentDelegateTest : BaseSessionTest() { } private fun waitForFullscreenExit() { - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFullScreen(session: GeckoSession, fullScreen: Boolean) { assertThat("Div left fullscreen", fullScreen, equalTo(false)) @@ -190,14 +192,14 @@ class ContentDelegateTest : BaseSessionTest() { val surface = Surface(texture) display.surfaceChanged(surface, 100, 100) mainSession.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstComposite(session: GeckoSession) { } }) display.surfaceDestroyed() display.surfaceChanged(surface, 100, 100) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstComposite(session: GeckoSession) { } @@ -209,7 +211,7 @@ class ContentDelegateTest : BaseSessionTest() { @WithDisplay(width = 10, height = 10) @Test fun firstContentfulPaint() { mainSession.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -242,7 +244,7 @@ class ContentDelegateTest : BaseSessionTest() { @Test fun webAppManifest() { mainSession.loadTestPath(HELLO_HTML_PATH) - mainSession.waitUntilCalled(object : Callbacks.All { + mainSession.waitUntilCalled(object : ContentDelegate, ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("Page load should succeed", success, equalTo(true)) @@ -273,7 +275,7 @@ class ContentDelegateTest : BaseSessionTest() { @Test fun viewportFit() { mainSession.loadTestPath(VIEWPORT_PATH) - mainSession.waitUntilCalled(object : Callbacks.All { + mainSession.waitUntilCalled(object : ContentDelegate, ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("Page load should succeed", success, equalTo(true)) @@ -286,7 +288,7 @@ class ContentDelegateTest : BaseSessionTest() { }) mainSession.loadTestPath(HELLO_HTML_PATH) - mainSession.waitUntilCalled(object : Callbacks.All { + mainSession.waitUntilCalled(object : ContentDelegate, ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("Page load should succeed", success, equalTo(true)) @@ -308,7 +310,7 @@ class ContentDelegateTest : BaseSessionTest() { mainSession.waitForPageStop() mainSession.evaluateJS("window.close()") - mainSession.waitUntilCalled(object : Callbacks.ContentDelegate { + mainSession.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onCloseRequest(session: GeckoSession) { } @@ -322,7 +324,7 @@ class ContentDelegateTest : BaseSessionTest() { mainSession.waitForPageStop() val newSession = sessionRule.createClosedSession() - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onNewSession(session: GeckoSession, uri: String): GeckoResult? { return GeckoResult.fromValue(newSession) @@ -331,7 +333,7 @@ class ContentDelegateTest : BaseSessionTest() { mainSession.evaluateJS("const w = window.open('about:blank'); w.close()") - newSession.waitUntilCalled(object : Callbacks.All { + newSession.waitUntilCalled(object : ContentDelegate, ProgressDelegate { @AssertCalled(count = 1) override fun onCloseRequest(session: GeckoSession) { } @@ -358,11 +360,11 @@ class ContentDelegateTest : BaseSessionTest() { /** * With no delegate set, the default behaviour is to stop hung scripts. */ - @NullDelegate(GeckoSession.ContentDelegate::class) + @NullDelegate(ContentDelegate::class) @Test fun stopHungProcessDefault() { setHangReportTestPrefs() mainSession.loadTestPath(HUNG_SCRIPT) - sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("The script did not complete.", @@ -379,7 +381,7 @@ class ContentDelegateTest : BaseSessionTest() { */ @Test fun stopHungProcessNull() { setHangReportTestPrefs() - sessionRule.delegateUntilTestEnd(object : GeckoSession.ContentDelegate, Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate, ProgressDelegate { // default onSlowScript returns null @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { @@ -398,7 +400,7 @@ class ContentDelegateTest : BaseSessionTest() { @Test fun stopHungProcessDoNothing() { setHangReportTestPrefs() var scriptHungReportCount = 0 - sessionRule.delegateUntilTestEnd(object : GeckoSession.ContentDelegate, Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate, ProgressDelegate { @AssertCalled() override fun onSlowScript(geckoSession: GeckoSession, scriptFileName: String): GeckoResult { scriptHungReportCount += 1; @@ -421,7 +423,7 @@ class ContentDelegateTest : BaseSessionTest() { */ @Test fun stopHungProcess() { setHangReportTestPrefs() - sessionRule.delegateUntilTestEnd(object : GeckoSession.ContentDelegate, Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate, ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onSlowScript(geckoSession: GeckoSession, scriptFileName: String): GeckoResult { return GeckoResult.fromValue(SlowScriptResponse.STOP) @@ -442,7 +444,7 @@ class ContentDelegateTest : BaseSessionTest() { */ @Test fun stopHungProcessWait() { setHangReportTestPrefs() - sessionRule.delegateUntilTestEnd(object : GeckoSession.ContentDelegate, Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate, ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onSlowScript(geckoSession: GeckoSession, scriptFileName: String): GeckoResult { return GeckoResult.fromValue(SlowScriptResponse.CONTINUE) @@ -464,7 +466,7 @@ class ContentDelegateTest : BaseSessionTest() { @Test fun stopHungProcessWaitThenStop() { setHangReportTestPrefs(500) var scriptWaited = false - sessionRule.delegateUntilTestEnd(object : GeckoSession.ContentDelegate, Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate, ProgressDelegate { @AssertCalled(count = 2, order = [1, 2]) override fun onSlowScript(geckoSession: GeckoSession, scriptFileName: String): GeckoResult { return if (!scriptWaited) { diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/DynamicToolbarTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/DynamicToolbarTest.kt index e400b89b8420..adf4677ee026 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/DynamicToolbarTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/DynamicToolbarTest.kt @@ -11,12 +11,12 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import android.util.Base64 import java.io.ByteArrayOutputStream import org.hamcrest.Matchers.* -import org.junit.Assert.fail import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession -import org.mozilla.geckoview.test.util.Callbacks +import org.mozilla.geckoview.GeckoSession.ContentDelegate +import org.mozilla.geckoview.GeckoSession.ScrollDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay import org.hamcrest.Matchers.closeTo @@ -326,7 +326,7 @@ class DynamicToolbarTest : BaseSessionTest() { mainSession.loadTestPath(SHOW_DYNAMIC_TOOLBAR_HTML_PATH) mainSession.waitForPageStop() mainSession.evaluateJS("window.scrollTo(0, " + dynamicToolbarMaxHeight + ")") - mainSession.waitUntilCalled(object : Callbacks.ScrollDelegate { + mainSession.waitUntilCalled(object : ScrollDelegate { @AssertCalled(count = 1) override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -337,7 +337,7 @@ class DynamicToolbarTest : BaseSessionTest() { mainSession.synthesizeTap(5, 25) - mainSession.waitUntilCalled(object : Callbacks.ContentDelegate { + mainSession.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onShowDynamicToolbar(session: GeckoSession) { } diff --git 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 index fbb590035094..4cb642b2d6a9 100644 --- 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 @@ -8,9 +8,15 @@ import android.os.Handler import android.os.Looper import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.SessionState +import org.mozilla.geckoview.GeckoSession.ContentDelegate +import org.mozilla.geckoview.GeckoSession.NavigationDelegate +import org.mozilla.geckoview.GeckoSession.ScrollDelegate +import org.mozilla.geckoview.GeckoSession.PromptDelegate +import org.mozilla.geckoview.GeckoSession.ProgressDelegate +import org.mozilla.geckoview.GeckoSession.HistoryDelegate import org.mozilla.geckoview.GeckoSessionSettings import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.* -import org.mozilla.geckoview.test.util.Callbacks import org.mozilla.geckoview.test.util.UiThreadUtils import androidx.test.filters.MediumTest @@ -66,32 +72,22 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @TimeoutMillis(2000) fun noPendingCallbacks() { // Make sure we don't have unexpected pending callbacks at the start of a test. - sessionRule.waitUntilCalled(object : Callbacks.All { + sessionRule.waitUntilCalled(object : ProgressDelegate, HistoryDelegate { // There may be extraneous onSessionStateChange and onHistoryStateChange calls // after a test, so ignore the first received. @AssertCalled(count = 2) - override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) { + override fun onSessionStateChange(session: GeckoSession, state: SessionState) { } @AssertCalled(count = 2) - override fun onHistoryStateChange(session: GeckoSession, historyList: GeckoSession.HistoryDelegate.HistoryList) { + override fun onHistoryStateChange(session: GeckoSession, historyList: HistoryDelegate.HistoryList) { } }) } - @Test fun includesAllCallbacks() { - for (ifce in GeckoSession::class.java.classes) { - if (!ifce.isInterface || !ifce.simpleName.endsWith("Delegate")) { - continue - } - assertThat("Callbacks.All should include interface " + ifce.simpleName, - ifce.isInstance(Callbacks.Default), equalTo(true)) - } - } - - @NullDelegate.List(NullDelegate(GeckoSession.ContentDelegate::class), - NullDelegate(Callbacks.NavigationDelegate::class)) - @NullDelegate(Callbacks.ScrollDelegate::class) + @NullDelegate.List(NullDelegate(ContentDelegate::class), + NullDelegate(NavigationDelegate::class)) + @NullDelegate(ScrollDelegate::class) @Test fun nullDelegate() { assertThat("Content delegate should be null", sessionRule.session.contentDelegate, nullValue()) @@ -104,7 +100,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.progressDelegate, notNullValue()) } - @NullDelegate(GeckoSession.ProgressDelegate::class) + @NullDelegate(ProgressDelegate::class) @ClosedSessionAtStart @Test fun nullDelegate_closed() { assertThat("Progress delegate should be null", @@ -112,7 +108,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } @Test(expected = AssertionError::class) - @NullDelegate(GeckoSession.ProgressDelegate::class) + @NullDelegate(ProgressDelegate::class) @ClosedSessionAtStart fun nullDelegate_requireProgressOnOpen() { assertThat("Progress delegate should be null", @@ -127,7 +123,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } @@ -136,13 +132,6 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { assertThat("Callback count should be correct", counter, equalTo(1)) } - @Test(expected = AssertionError::class) - fun waitForPageStop_throwOnChangedCallback() { - sessionRule.session.progressDelegate = Callbacks.Default - sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitForPageStop() - } - @Test fun waitForPageStops() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.session.reload() @@ -150,7 +139,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } @@ -160,7 +149,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } @Test(expected = AssertionError::class) - @NullDelegate(GeckoSession.ProgressDelegate::class) + @NullDelegate(ProgressDelegate::class) @ClosedSessionAtStart fun waitForPageStops_throwOnNullDelegate() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) @@ -175,11 +164,11 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { // TODO: Bug 1673953 assumeThat(sessionRule.env.isFission, equalTo(false)) sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(GeckoSession.ProgressDelegate::class) + sessionRule.waitUntilCalled(ProgressDelegate::class) var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { override fun onPageStart(session: GeckoSession, url: String) { counter++ } @@ -189,7 +178,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } override fun onSecurityChange(session: GeckoSession, - securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) { + securityInfo: ProgressDelegate.SecurityInformation) { counter++ } @@ -197,7 +186,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { counter++ } - override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) { + override fun onSessionStateChange(session: GeckoSession, state: SessionState) { counter++ } }) @@ -207,12 +196,12 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test fun waitUntilCalled_specificInterfaceMethod() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(GeckoSession.ProgressDelegate::class, + sessionRule.waitUntilCalled(ProgressDelegate::class, "onPageStart", "onPageStop") var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { override fun onPageStart(session: GeckoSession, url: String) { counter++ } @@ -233,26 +222,16 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { fun waitUntilCalled_notThrowOnCallbackInterface() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(Callbacks.ProgressDelegate::class) + sessionRule.waitUntilCalled(ProgressDelegate::class) } - @Test(expected = AssertionError::class) - @NullDelegate(GeckoSession.ScrollDelegate::class) - fun waitUntilCalled_throwOnNullDelegateInterface() { - sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitForPageStop() - - sessionRule.session.reload() - sessionRule.session.waitUntilCalled(Callbacks.All::class) - } - - @NullDelegate(GeckoSession.ScrollDelegate::class) + @NullDelegate(ScrollDelegate::class) @Test fun waitUntilCalled_notThrowOnNonNullDelegateMethod() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() sessionRule.session.reload() - sessionRule.session.waitUntilCalled(Callbacks.All::class, "onPageStop") + sessionRule.session.waitUntilCalled(ProgressDelegate::class, "onPageStop") } @Test fun waitUntilCalled_anyObjectMethod() { @@ -262,7 +241,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { override fun onPageStart(session: GeckoSession, url: String) { counter++ } @@ -272,7 +251,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } override fun onSecurityChange(session: GeckoSession, - securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) { + securityInfo: ProgressDelegate.SecurityInformation) { counter++ } @@ -280,7 +259,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { counter++ } - override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) { + override fun onSessionStateChange(session: GeckoSession, state: SessionState) { counter++ } }) @@ -293,7 +272,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -309,26 +288,26 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } @Test(expected = AssertionError::class) - @NullDelegate(GeckoSession.ScrollDelegate::class) + @NullDelegate(ScrollDelegate::class) fun waitUntilCalled_throwOnNullDelegateObject() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() sessionRule.session.reload() - sessionRule.session.waitUntilCalled(object : Callbacks.All { + sessionRule.session.waitUntilCalled(object : ScrollDelegate { @AssertCalled override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } }) } - @NullDelegate(GeckoSession.ScrollDelegate::class) + @NullDelegate(ScrollDelegate::class) @Test fun waitUntilCalled_notThrowOnNonNullDelegateObject() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() sessionRule.session.reload() - sessionRule.session.waitUntilCalled(object : Callbacks.All { + sessionRule.session.waitUntilCalled(object : ProgressDelegate { @AssertCalled override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -341,7 +320,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 2) override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -362,7 +341,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 2, order = [1, 2]) override fun onPageStop(session: GeckoSession, success: Boolean) { val info = sessionRule.currentCall @@ -381,7 +360,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test(expected = IllegalStateException::class) fun waitUntilCalled_passThroughExceptions() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled override fun onPageStop(session: GeckoSession, success: Boolean) { throw IllegalStateException() @@ -392,7 +371,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test fun waitUntilCalled_zeroCount() { // Support having @AssertCalled(count = 0) annotations for waitUntilCalled calls. sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate, Callbacks.ScrollDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate, ScrollDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -411,7 +390,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } @@ -425,7 +404,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : GeckoSession.ScrollDelegate {}) + sessionRule.forCallbacksDuringWait(object : ScrollDelegate {}) } @Test fun forCallbacksDuringWait_specificMethod() { @@ -434,7 +413,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -456,7 +435,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -476,7 +455,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : GeckoSession.ScrollDelegate { + sessionRule.forCallbacksDuringWait(object : ScrollDelegate { @AssertCalled override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -490,7 +469,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 2) override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -511,7 +490,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.reload() sessionRule.waitForPageStops(2) - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStart(session: GeckoSession, url: String) { } @@ -526,7 +505,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(order = [1]) override fun onPageStart(session: GeckoSession, url: String) { } @@ -542,7 +521,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(order = [2]) override fun onPageStart(session: GeckoSession, url: String) { } @@ -558,7 +537,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.reload() sessionRule.waitForPageStops(2) - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(order = [1, 3, 1]) override fun onPageStart(session: GeckoSession, url: String) { } @@ -575,7 +554,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.reload() sessionRule.waitForPageStops(2) - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(order = [1, 2, 1]) override fun onPageStart(session: GeckoSession, url: String) { } @@ -590,7 +569,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : GeckoSession.ScrollDelegate { + sessionRule.forCallbacksDuringWait(object : ScrollDelegate { @AssertCalled(false) override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -602,7 +581,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(false) override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -613,7 +592,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : GeckoSession.ScrollDelegate { + sessionRule.forCallbacksDuringWait(object : ScrollDelegate { @AssertCalled(count = 0) override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -625,7 +604,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 0) override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -647,7 +626,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 // assert should only apply to callbacks within range (loadUri, first reload]. - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -666,7 +645,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { val info = sessionRule.currentCall @@ -684,7 +663,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled override fun onPageStop(session: GeckoSession, success: Boolean) { throw IllegalStateException() @@ -693,39 +672,39 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } @Test(expected = AssertionError::class) - @NullDelegate(GeckoSession.ScrollDelegate::class) + @NullDelegate(ScrollDelegate::class) fun forCallbacksDuringWait_throwOnAnyNullDelegate() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() sessionRule.session.reload() sessionRule.session.waitForPageStop() - sessionRule.session.forCallbacksDuringWait(object : Callbacks.All {}) + sessionRule.session.forCallbacksDuringWait(object : NavigationDelegate, ScrollDelegate {}) } @Test(expected = AssertionError::class) - @NullDelegate(GeckoSession.ScrollDelegate::class) + @NullDelegate(ScrollDelegate::class) fun forCallbacksDuringWait_throwOnSpecificNullDelegate() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() sessionRule.session.reload() sessionRule.session.waitForPageStop() - sessionRule.session.forCallbacksDuringWait(object : Callbacks.All { + sessionRule.session.forCallbacksDuringWait(object : ScrollDelegate { @AssertCalled override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } }) } - @NullDelegate(GeckoSession.ScrollDelegate::class) + @NullDelegate(ScrollDelegate::class) @Test fun forCallbacksDuringWait_notThrowOnNonNullDelegate() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() sessionRule.session.reload() sessionRule.session.waitForPageStop() - sessionRule.session.forCallbacksDuringWait(object : Callbacks.All { + sessionRule.session.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -740,7 +719,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test fun delegateUntilTestEnd() { var counter = 0 - sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -759,7 +738,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } @Test fun delegateUntilTestEnd_notCalled() { - sessionRule.delegateUntilTestEnd(object : GeckoSession.ScrollDelegate { + sessionRule.delegateUntilTestEnd(object : ScrollDelegate { @AssertCalled(false) override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -768,7 +747,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test(expected = AssertionError::class) fun delegateUntilTestEnd_throwOnNotCalled() { - sessionRule.delegateUntilTestEnd(object : GeckoSession.ScrollDelegate { + sessionRule.delegateUntilTestEnd(object : ScrollDelegate { @AssertCalled(count = 1) override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -778,7 +757,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test(expected = AssertionError::class) fun delegateUntilTestEnd_throwOnCallingNoCall() { - sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(false) override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -790,7 +769,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test(expected = AssertionError::class) fun delegateUntilTestEnd_throwOnWrongOrder() { - sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(count = 1, order = [2]) override fun onPageStart(session: GeckoSession, url: String) { } @@ -805,7 +784,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } @Test fun delegateUntilTestEnd_currentCall() { - sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { val info = sessionRule.currentCall @@ -826,7 +805,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.waitForPageStop() var counter = 0 - sessionRule.delegateDuringNextWait(object : Callbacks.ProgressDelegate { + sessionRule.delegateDuringNextWait(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { counter++ @@ -851,7 +830,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test(expected = AssertionError::class) fun delegateDuringNextWait_throwOnNotCalled() { - sessionRule.delegateDuringNextWait(object : GeckoSession.ScrollDelegate { + sessionRule.delegateDuringNextWait(object : ScrollDelegate { @AssertCalled(count = 1) override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -862,7 +841,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test(expected = AssertionError::class) fun delegateDuringNextWait_throwOnNotCalledAtTestEnd() { - sessionRule.delegateDuringNextWait(object : GeckoSession.ScrollDelegate { + sessionRule.delegateDuringNextWait(object : ScrollDelegate { @AssertCalled(count = 1) override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) { } @@ -874,8 +853,8 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var testCounter = 0 var waitCounter = 0 - sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate, - Callbacks.NavigationDelegate { + sessionRule.delegateUntilTestEnd(object : ProgressDelegate, + NavigationDelegate { @AssertCalled(count = 1, order = [2]) override fun onPageStart(session: GeckoSession, url: String) { testCounter++ @@ -897,7 +876,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } }) - sessionRule.delegateDuringNextWait(object : Callbacks.ProgressDelegate { + sessionRule.delegateDuringNextWait(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { waitCounter++ @@ -925,7 +904,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test(expected = IllegalStateException::class) fun delegateDuringNextWait_passThroughExceptions() { - sessionRule.delegateDuringNextWait(object : Callbacks.ProgressDelegate { + sessionRule.delegateDuringNextWait(object : ProgressDelegate { @AssertCalled override fun onPageStop(session: GeckoSession, success: Boolean) { throw IllegalStateException() @@ -937,9 +916,9 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { } @Test(expected = AssertionError::class) - @NullDelegate(GeckoSession.NavigationDelegate::class) + @NullDelegate(NavigationDelegate::class) fun delegateDuringNextWait_throwOnNullDelegate() { - sessionRule.session.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateDuringNextWait(object : NavigationDelegate { override fun onLocationChange(session: GeckoSession, url: String?) { } }) @@ -980,13 +959,13 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStops(2) - newSession.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + newSession.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(false) override fun onPageStop(session: GeckoSession, success: Boolean) { } }) - sessionRule.session.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.session.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 2) override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -1014,15 +993,15 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { fun noPendingCallbacks_withSpecificSession() { sessionRule.createOpenSession() // Make sure we don't have unexpected pending callbacks after opening a session. - sessionRule.waitUntilCalled(object : Callbacks.All { + sessionRule.waitUntilCalled(object : HistoryDelegate, ProgressDelegate { // There may be extraneous onSessionStateChange and onHistoryStateChange calls // after a test, so ignore the first received. @AssertCalled(count = 2) - override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) { + override fun onSessionStateChange(session: GeckoSession, state: SessionState) { } @AssertCalled(count = 2) - override fun onHistoryStateChange(session: GeckoSession, historyList: GeckoSession.HistoryDelegate.HistoryList) { + override fun onHistoryStateChange(session: GeckoSession, historyList: HistoryDelegate.HistoryList) { } }) } @@ -1072,19 +1051,19 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test fun waitUntilCalled_interfaceWithSpecificSession() { val newSession = sessionRule.createOpenSession() newSession.loadTestPath(HELLO_HTML_PATH) - newSession.waitUntilCalled(Callbacks.ProgressDelegate::class, "onPageStop") + newSession.waitUntilCalled(ProgressDelegate::class, "onPageStop") } @Test fun waitUntilCalled_interfaceWithAllSessions() { val newSession = sessionRule.createOpenSession() newSession.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(Callbacks.ProgressDelegate::class, "onPageStop") + sessionRule.waitUntilCalled(ProgressDelegate::class, "onPageStop") } @Test fun waitUntilCalled_callbackWithSpecificSession() { val newSession = sessionRule.createOpenSession() newSession.loadTestPath(HELLO_HTML_PATH) - newSession.waitUntilCalled(object : Callbacks.ProgressDelegate { + newSession.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -1095,7 +1074,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { val newSession = sessionRule.createOpenSession() newSession.loadTestPath(HELLO_HTML_PATH) sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 2) override fun onPageStop(session: GeckoSession, success: Boolean) { } @@ -1109,14 +1088,14 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - newSession.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + newSession.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } }) - sessionRule.session.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.session.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(false) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ @@ -1134,7 +1113,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 2) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ @@ -1156,21 +1135,21 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { // forCallbacksDuringWait calls strictly apply to the last wait, session-specific or not. var counter = 0 - sessionRule.session.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.session.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(false) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } }) - newSession.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + newSession.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } }) - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ @@ -1185,14 +1164,14 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { var counter = 0 - newSession.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + newSession.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } }) - sessionRule.session.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + sessionRule.session.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(false) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ @@ -1208,7 +1187,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @Test fun delegateUntilTestEnd_withAllSessions() { var counter = 0 - sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ @@ -1226,14 +1205,14 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { val newSession = sessionRule.createOpenSession() var counter = 0 - newSession.delegateDuringNextWait(object : Callbacks.ProgressDelegate { + newSession.delegateDuringNextWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } }) - newSession.delegateUntilTestEnd(object : Callbacks.ProgressDelegate { + newSession.delegateUntilTestEnd(object : ProgressDelegate { @AssertCalled(false) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ @@ -1251,14 +1230,14 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { val newSession = sessionRule.createOpenSession() var counter = 0 - newSession.delegateDuringNextWait(object : Callbacks.ProgressDelegate { + newSession.delegateDuringNextWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ } }) - sessionRule.delegateDuringNextWait(object : Callbacks.ProgressDelegate { + sessionRule.delegateDuringNextWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { counter++ @@ -1416,10 +1395,10 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { fun evaluateJS_canTimeout() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.session.waitForPageStop() - sessionRule.session.delegateUntilTestEnd(object : Callbacks.PromptDelegate { - override fun onAlertPrompt(session: GeckoSession, prompt: GeckoSession.PromptDelegate.AlertPrompt): GeckoResult { + sessionRule.session.delegateUntilTestEnd(object : PromptDelegate { + override fun onAlertPrompt(session: GeckoSession, prompt: PromptDelegate.AlertPrompt): GeckoResult { // Return a GeckoResult that we will never complete, so it hangs. - val res = GeckoResult() + val res = GeckoResult() return res } }) @@ -1558,9 +1537,9 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.session.waitForJS("alert(), 'foo'") as String, equalTo("foo")) - sessionRule.session.forCallbacksDuringWait(object : Callbacks.PromptDelegate { + sessionRule.session.forCallbacksDuringWait(object : PromptDelegate { @AssertCalled(count = 1) - override fun onAlertPrompt(session: GeckoSession, prompt: GeckoSession.PromptDelegate.AlertPrompt): GeckoResult? { + override fun onAlertPrompt(session: GeckoSession, prompt: PromptDelegate.AlertPrompt): GeckoResult? { return null; } }) @@ -1579,8 +1558,8 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { sessionRule.waitForPageStop() var count = 0 - sessionRule.session.delegateDuringNextWait(object : Callbacks.PromptDelegate { - override fun onAlertPrompt(session: GeckoSession, prompt: GeckoSession.PromptDelegate.AlertPrompt): GeckoResult { + sessionRule.session.delegateDuringNextWait(object : PromptDelegate { + override fun onAlertPrompt(session: GeckoSession, prompt: PromptDelegate.AlertPrompt): GeckoResult { count++ return GeckoResult.fromValue(prompt.dismiss()) } @@ -1696,7 +1675,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) mainSession.loadUri(CONTENT_CRASH_URL) - mainSession.waitUntilCalled(object : Callbacks.ContentDelegate { + mainSession.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onCrash(session: GeckoSession) = Unit }) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/HistoryDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/HistoryDelegateTest.kt index 28e3661f70d0..c0372fa519f1 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/HistoryDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/HistoryDelegateTest.kt @@ -6,6 +6,7 @@ package org.mozilla.geckoview.test import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.HistoryDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled @@ -15,7 +16,6 @@ import org.hamcrest.Matchers.* import org.junit.Assume.assumeThat import org.junit.Test import org.junit.runner.RunWith -import org.mozilla.geckoview.test.util.Callbacks import org.junit.Ignore import org.mozilla.geckoview.test.util.UiThreadUtils @@ -99,7 +99,7 @@ class HistoryDelegateTest : BaseSessionTest() { @Test fun onHistoryStateChange() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have one entry", state.size, @@ -113,7 +113,7 @@ class HistoryDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO2_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have two entries", state.size, @@ -127,7 +127,7 @@ class HistoryDelegateTest : BaseSessionTest() { sessionRule.session.goBack() - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have two entries", state.size, @@ -141,7 +141,7 @@ class HistoryDelegateTest : BaseSessionTest() { sessionRule.session.goForward() - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have two entries", state.size, @@ -155,7 +155,7 @@ class HistoryDelegateTest : BaseSessionTest() { sessionRule.session.gotoHistoryIndex(0) - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have two entries", state.size, @@ -169,7 +169,7 @@ class HistoryDelegateTest : BaseSessionTest() { sessionRule.session.gotoHistoryIndex(1) - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have two entries", state.size, @@ -189,7 +189,7 @@ class HistoryDelegateTest : BaseSessionTest() { // This is a smaller version of the above test, in the hopes to minimize race conditions sessionRule.session.loadTestPath(HELLO_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have one entry", state.size, @@ -203,7 +203,7 @@ class HistoryDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO2_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate { + sessionRule.waitUntilCalled(object : HistoryDelegate { @AssertCalled(count = 1) override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { assertThat("History should have two entries", state.size, diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ImageResourceTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ImageResourceTest.kt index 1c203e859608..4ea76a3e72f9 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ImageResourceTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ImageResourceTest.kt @@ -6,21 +6,10 @@ package org.mozilla.geckoview.test import androidx.test.filters.MediumTest import androidx.test.ext.junit.runners.AndroidJUnit4 -import android.util.Log import org.hamcrest.Matchers.* -import org.json.JSONObject -import org.junit.After -import org.junit.Before -import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assume.assumeThat -import org.junit.Assume.assumeTrue - -import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.rule.GeckoSessionTestRule -import org.mozilla.geckoview.test.util.Callbacks import org.mozilla.geckoview.GeckoResult import org.mozilla.gecko.util.ImageResource diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/InputResultDetailTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/InputResultDetailTest.kt index 9330db72f031..6ae02dd62999 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/InputResultDetailTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/InputResultDetailTest.kt @@ -11,10 +11,10 @@ import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.ContentDelegate import org.mozilla.geckoview.PanZoomController import org.mozilla.geckoview.PanZoomController.InputResultDetail import org.mozilla.geckoview.test.rule.GeckoSessionTestRule -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @MediumTest @@ -23,7 +23,7 @@ class InputResultDetailTest : BaseSessionTest() { private fun setupDocument(documentPath: String) { sessionRule.session.loadTestPath(documentPath) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @GeckoSessionTestRule.AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateTest.kt index 8f1048bbc078..f9a61861a33d 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateTest.kt @@ -13,8 +13,9 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.Assume.assumeThat import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.MediaDelegate +import org.mozilla.geckoview.GeckoSession.PermissionDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @MediumTest @@ -23,7 +24,7 @@ class MediaDelegateTest : BaseSessionTest() { private fun requestRecordingPermission(allowAudio: Boolean, allowCamera: Boolean) { - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @GeckoSessionTestRule.AssertCalled(count = 1) override fun onMediaPermissionRequest( session: GeckoSession, uri: String, @@ -55,7 +56,7 @@ class MediaDelegateTest : BaseSessionTest() { } }) - mainSession.delegateDuringNextWait(object : Callbacks.MediaDelegate { + mainSession.delegateDuringNextWait(object : MediaDelegate { @GeckoSessionTestRule.AssertCalled(count = 1) override fun onRecordingStatusChanged(session: GeckoSession, devices: Array) { diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateXOriginTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateXOriginTest.kt index 90c9f785b28e..47a4384a4f8b 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateXOriginTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaDelegateXOriginTest.kt @@ -13,8 +13,9 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.Assume.assumeThat import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.MediaDelegate +import org.mozilla.geckoview.GeckoSession.PermissionDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @MediumTest @@ -23,7 +24,7 @@ class MediaDelegateXOriginTest : BaseSessionTest() { private fun requestRecordingPermission(allowAudio: Boolean, allowCamera: Boolean) { - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @GeckoSessionTestRule.AssertCalled(count = 1) override fun onMediaPermissionRequest( session: GeckoSession, uri: String, @@ -55,7 +56,7 @@ class MediaDelegateXOriginTest : BaseSessionTest() { } }) - mainSession.delegateDuringNextWait(object : Callbacks.MediaDelegate { + mainSession.delegateDuringNextWait(object : MediaDelegate { @GeckoSessionTestRule.AssertCalled(count = 1) override fun onRecordingStatusChanged(session: GeckoSession, devices: Array) { @@ -102,7 +103,7 @@ class MediaDelegateXOriginTest : BaseSessionTest() { private fun requestRecordingPermissionNoAllow(allowAudio: Boolean, allowCamera: Boolean) { - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @GeckoSessionTestRule.AssertCalled(count = 0) override fun onMediaPermissionRequest( session: GeckoSession, uri: String, @@ -120,7 +121,7 @@ class MediaDelegateXOriginTest : BaseSessionTest() { } }) - mainSession.delegateDuringNextWait(object : Callbacks.MediaDelegate { + mainSession.delegateDuringNextWait(object : MediaDelegate { @GeckoSessionTestRule.AssertCalled(count = 0) override fun onRecordingStatusChanged(session: GeckoSession, devices: Array) {} diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaSessionTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaSessionTest.kt index d2eea235d511..c1a34689a7be 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaSessionTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/MediaSessionTest.kt @@ -14,7 +14,6 @@ import org.junit.runner.RunWith import org.junit.Assume.assumeThat import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.util.Callbacks import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession @@ -164,7 +163,7 @@ class MediaSessionTest : BaseSessionTest() { // 1. session1.loadTestPath(path) - session1.delegateUntilTestEnd(object : Callbacks.MediaSessionDelegate { + session1.delegateUntilTestEnd(object : MediaSession.Delegate { @AssertCalled(count = 1, order = [1]) override fun onActivated( session: GeckoSession, @@ -355,7 +354,7 @@ class MediaSessionTest : BaseSessionTest() { // 1. session1.loadTestPath(path) - session1.delegateUntilTestEnd(object : Callbacks.MediaSessionDelegate { + session1.delegateUntilTestEnd(object : MediaSession.Delegate { @AssertCalled(count = 1, order = [1]) override fun onActivated( session: GeckoSession, @@ -490,7 +489,7 @@ class MediaSessionTest : BaseSessionTest() { var mediaSession1 : MediaSession? = null var mediaSession2 : MediaSession? = null - session1.delegateUntilTestEnd(object : Callbacks.MediaSessionDelegate { + session1.delegateUntilTestEnd(object : MediaSession.Delegate { @AssertCalled(count = 1) override fun onActivated( session: GeckoSession, @@ -596,7 +595,7 @@ class MediaSessionTest : BaseSessionTest() { } }) - session2.delegateUntilTestEnd(object : Callbacks.MediaSessionDelegate { + session2.delegateUntilTestEnd(object : MediaSession.Delegate { @AssertCalled(count = 1) override fun onActivated( session: GeckoSession, @@ -725,7 +724,7 @@ class MediaSessionTest : BaseSessionTest() { val path = VIDEO_WEBM_PATH val session1 = sessionRule.createOpenSession() - session1.delegateUntilTestEnd(object : Callbacks.MediaSessionDelegate { + session1.delegateUntilTestEnd(object : MediaSession.Delegate { @AssertCalled(count = 1, order = [1]) override fun onActivated( session: GeckoSession, diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt index 7bd84164d7f5..e29d4e9a1c49 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt @@ -19,11 +19,17 @@ import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.* -import org.mozilla.geckoview.GeckoSession.* +import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.ContentDelegate +import org.mozilla.geckoview.GeckoSession.HistoryDelegate +import org.mozilla.geckoview.GeckoSession.Loader +import org.mozilla.geckoview.GeckoSession.NavigationDelegate import org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest +import org.mozilla.geckoview.GeckoSession.PermissionDelegate +import org.mozilla.geckoview.GeckoSession.ProgressDelegate +import org.mozilla.geckoview.GeckoSession.TextInputDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.* -import org.mozilla.geckoview.test.util.Callbacks import org.mozilla.geckoview.test.util.UiThreadUtils @RunWith(AndroidJUnit4::class) @@ -51,7 +57,7 @@ class NavigationDelegateTest : BaseSessionTest() { expectedError: Int, errorPageUrl: String?) { sessionRule.delegateDuringNextWait( - object : Callbacks.ProgressDelegate, Callbacks.NavigationDelegate, Callbacks.ContentDelegate { + object : ProgressDelegate, NavigationDelegate, ContentDelegate { @AssertCalled(count = 1, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -89,7 +95,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.waitForPageStop() if (errorPageUrl != null) { - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate, Callbacks.NavigationDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("URL should match", url, equalTo(testLoader.getUri())) @@ -120,7 +126,7 @@ class NavigationDelegateTest : BaseSessionTest() { expectedError: Int, errorPageUrl: String?) { sessionRule.delegateDuringNextWait( - object : Callbacks.ProgressDelegate, Callbacks.NavigationDelegate, Callbacks.ContentDelegate { + object : ProgressDelegate, NavigationDelegate, ContentDelegate { @AssertCalled(false) override fun onPageStart(session: GeckoSession, url: String) { @@ -143,10 +149,10 @@ class NavigationDelegateTest : BaseSessionTest() { }) sessionRule.session.loadUri(testUri) - sessionRule.waitUntilCalled(Callbacks.NavigationDelegate::class, "onLoadError") + sessionRule.waitUntilCalled(NavigationDelegate::class, "onLoadError") if (errorPageUrl != null) { - sessionRule.waitUntilCalled(object: Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object: ContentDelegate { @AssertCalled(count = 1) override fun onTitleChange(session: GeckoSession, title: String?) { assertThat("Title should not be empty", title, not(isEmptyOrNullString())) @@ -203,13 +209,19 @@ class NavigationDelegateTest : BaseSessionTest() { // TODO: bug 1710943 assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) - testLoadExpectError(TestLoader().uri("file:///").flags(LOAD_FLAGS_EXTERNAL), + testLoadExpectError(TestLoader() + .uri("file:///") + .flags(GeckoSession.LOAD_FLAGS_EXTERNAL), WebRequestError.ERROR_CATEGORY_UNKNOWN, WebRequestError.ERROR_UNKNOWN) - testLoadExpectError(TestLoader().uri("resource://gre/").flags(LOAD_FLAGS_EXTERNAL), + testLoadExpectError(TestLoader() + .uri("resource://gre/") + .flags(GeckoSession.LOAD_FLAGS_EXTERNAL), WebRequestError.ERROR_CATEGORY_UNKNOWN, WebRequestError.ERROR_UNKNOWN) - testLoadExpectError(TestLoader().uri("about:about").flags(LOAD_FLAGS_EXTERNAL), + testLoadExpectError(TestLoader() + .uri("about:about") + .flags(GeckoSession.LOAD_FLAGS_EXTERNAL), WebRequestError.ERROR_CATEGORY_UNKNOWN, WebRequestError.ERROR_UNKNOWN) } @@ -247,7 +259,7 @@ class NavigationDelegateTest : BaseSessionTest() { mainSession.waitForJS("document.addCertException(false)") mainSession.delegateDuringNextWait( - object : Callbacks.ProgressDelegate, Callbacks.NavigationDelegate, Callbacks.ContentDelegate { + object : ProgressDelegate, NavigationDelegate, ContentDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URI should be " + uri, url, equalTo(uri)) @@ -255,7 +267,7 @@ class NavigationDelegateTest : BaseSessionTest() { @AssertCalled(count = 1, order = [2]) override fun onSecurityChange(session: GeckoSession, - securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) { + securityInfo: ProgressDelegate.SecurityInformation) { assertThat("Should be exception", securityInfo.isException, equalTo(true)) assertThat("Should not be secure", securityInfo.isSecure, equalTo(false)) } @@ -292,7 +304,7 @@ class NavigationDelegateTest : BaseSessionTest() { WebRequestError.ERROR_CATEGORY_SECURITY, WebRequestError.ERROR_SECURITY_SSL) - mainSession.delegateDuringNextWait(object : Callbacks.ProgressDelegate, Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : ProgressDelegate, NavigationDelegate { @AssertCalled(count = 0) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { return null @@ -327,7 +339,7 @@ class NavigationDelegateTest : BaseSessionTest() { mainSession.loadUri(insecureUri) mainSession.waitForPageStop() - mainSession.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + mainSession.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { assertThat("categories should match", error.category, equalTo(WebRequestError.ERROR_CATEGORY_SECURITY)) @@ -341,7 +353,7 @@ class NavigationDelegateTest : BaseSessionTest() { mainSession.loadUri(secureUri) mainSession.waitForPageStop() - mainSession.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + mainSession.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 0) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { return null @@ -362,7 +374,7 @@ class NavigationDelegateTest : BaseSessionTest() { privateSession.waitForPageStop() var onLoadCalledCounter = 0 - privateSession.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + privateSession.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 0) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { return null @@ -389,7 +401,7 @@ class NavigationDelegateTest : BaseSessionTest() { privateSession.loadUri(insecureUri) privateSession.waitForPageStop() - privateSession.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + privateSession.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { assertThat("categories should match", error.category, equalTo(WebRequestError.ERROR_CATEGORY_SECURITY)) @@ -401,7 +413,7 @@ class NavigationDelegateTest : BaseSessionTest() { mainSession.loadUri(secureUri) mainSession.waitForPageStop() - mainSession.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + mainSession.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 0) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { return null @@ -432,7 +444,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(IFRAME_UNKNOWN_PROTOCOL) sessionRule.session.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLoadRequest(session: GeckoSession, request: LoadRequest) : GeckoResult? { assertThat("URI should not be null", request.uri, notNullValue()) @@ -459,7 +471,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(TRACKERS_PATH) sessionRule.waitUntilCalled( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @AssertCalled(count = 3) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -481,7 +493,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.ContentBlockingDelegate { + object : ContentBlocking.Delegate { @AssertCalled(false) override fun onContentBlocked(session: GeckoSession, event: ContentBlocking.BlockEvent) { @@ -516,7 +528,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadUri(uri) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 2, order = [1, 2]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -531,7 +543,7 @@ class NavigationDelegateTest : BaseSessionTest() { equalTo(forEachCall(true, false))) assertThat("Target should not be null", request.target, notNullValue()) assertThat("Target should match", request.target, - equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) + equalTo(NavigationDelegate.TARGET_WINDOW_CURRENT)) assertThat("Redirect flag is set", request.isRedirect, equalTo(forEachCall(false, true))) return null @@ -553,7 +565,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.waitForPageStop() // We shouldn't be firing onLoadRequest for iframes, including redirects. - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -599,7 +611,7 @@ class NavigationDelegateTest : BaseSessionTest() { } sessionRule.delegateDuringNextWait( - object : Callbacks.NavigationDelegate { + object : NavigationDelegate { @AssertCalled(count = 2, order = [1, 2]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -614,7 +626,7 @@ class NavigationDelegateTest : BaseSessionTest() { equalTo(forEachCall(true, false))) assertThat("Target should not be null", request.target, notNullValue()) assertThat("Target should match", request.target, - equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) + equalTo(NavigationDelegate.TARGET_WINDOW_CURRENT)) assertThat("Redirect flag is set", request.isRedirect, equalTo(forEachCall(false, true))) @@ -626,7 +638,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.ProgressDelegate { + object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URL should match", url, equalTo(uri)) @@ -648,7 +660,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadUri(uri) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 2, order = [1, 2]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -677,7 +689,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.NavigationDelegate { + object : NavigationDelegate { @AssertCalled(false) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { @@ -709,7 +721,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.NavigationDelegate { + object : NavigationDelegate { @AssertCalled(false) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { @@ -740,7 +752,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.NavigationDelegate { + object : NavigationDelegate { @AssertCalled(false) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { @@ -767,7 +779,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.NavigationDelegate { + object : NavigationDelegate { @AssertCalled(false) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { @@ -798,7 +810,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() sessionRule.forCallbacksDuringWait( - object : Callbacks.NavigationDelegate { + object : NavigationDelegate { @AssertCalled(false) override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { @@ -929,7 +941,7 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("User agent should now be reported as VR", getUserAgent(), containsString(vrSubStr)) - sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.delegateDuringNextWait(object : NavigationDelegate { override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { sessionRule.session.settings.userAgentOverride = overrideUserAgent return null @@ -942,7 +954,7 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("User agent should be reported as override after being set in onLoadRequest", getUserAgent(), equalTo(overrideUserAgent)) - sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.delegateDuringNextWait(object : NavigationDelegate { override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { sessionRule.session.settings.userAgentOverride = null return null @@ -1000,7 +1012,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadUri("$TEST_ENDPOINT$HELLO_HTML_PATH") sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -1014,7 +1026,7 @@ class NavigationDelegateTest : BaseSessionTest() { equalTo(true)) assertThat("Target should not be null", request.target, notNullValue()) assertThat("Target should match", request.target, - equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) + equalTo(NavigationDelegate.TARGET_WINDOW_CURRENT)) assertThat("Redirect flag is not set", request.isRedirect, equalTo(false)) assertThat("Should not have a user gesture", request.hasUserGesture, equalTo(false)) return null @@ -1054,7 +1066,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadUri(dataUrl) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate, ProgressDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("URL should match the provided data URL", url, equalTo(dataUrl)) @@ -1067,7 +1079,7 @@ class NavigationDelegateTest : BaseSessionTest() { }) } - @NullDelegate(GeckoSession.NavigationDelegate::class) + @NullDelegate(NavigationDelegate::class) @Test fun load_withoutNavigationDelegate() { // TODO: bug 1710943 assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) @@ -1080,14 +1092,14 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() } - @NullDelegate(GeckoSession.NavigationDelegate::class) + @NullDelegate(NavigationDelegate::class) @Test fun load_canUnsetNavigationDelegate() { // TODO: bug 1710943 assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) // Test that if we unset the navigation delegate during a load, the load still proceeds. var onLocationCount = 0 - sessionRule.session.navigationDelegate = object : Callbacks.NavigationDelegate { + sessionRule.session.navigationDelegate = object : NavigationDelegate { override fun onLocationChange(session: GeckoSession, url: String?) { onLocationCount++ } @@ -1115,7 +1127,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.load(Loader().data(dataString, mimeType)) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate, Callbacks.ContentDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate, ProgressDelegate, ContentDelegate { @AssertCalled override fun onTitleChange(session: GeckoSession, title: String?) { assertThat("Title should match", title, equalTo("TheTitle")) @@ -1138,7 +1150,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.load(Loader().data("Hello, World!", null)) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate, ProgressDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("URL should be a data URL", url, startsWith("data:")) @@ -1161,7 +1173,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.load(Loader().data(bytes, "text/html")) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate, Callbacks.ContentDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate, ProgressDelegate, ContentDelegate { @AssertCalled(count = 1) override fun onTitleChange(session: GeckoSession, title: String?) { assertThat("Title should match", title, equalTo("Hello, world!")) @@ -1197,7 +1209,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.load(Loader().data(bytes, mimeType)) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate, ProgressDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("URL should match", url, equalTo(createDataUri(bytes, mimeType))) @@ -1229,7 +1241,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.reload() sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -1238,7 +1250,7 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("Trigger URL should be null", request.triggerUri, nullValue()) assertThat("Target should match", request.target, - equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_CURRENT)) + equalTo(NavigationDelegate.TARGET_WINDOW_CURRENT)) assertThat("Load should not be direct", request.isDirectNavigation, equalTo(false)) return null @@ -1276,9 +1288,9 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadUri("$TEST_ENDPOINT$HELLO2_HTML_PATH") sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { + override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("URL should match", url, endsWith(HELLO2_HTML_PATH)) } }) @@ -1286,7 +1298,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.goBack() sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 0, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -1297,7 +1309,7 @@ class NavigationDelegateTest : BaseSessionTest() { } @AssertCalled(count = 1, order = [2]) - override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { + override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("URL should match", url, endsWith(HELLO_HTML_PATH)) } @@ -1320,7 +1332,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.goForward() sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 0, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -1331,7 +1343,7 @@ class NavigationDelegateTest : BaseSessionTest() { } @AssertCalled(count = 1, order = [2]) - override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { + override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("URL should match", url, endsWith(HELLO2_HTML_PATH)) } @@ -1356,7 +1368,7 @@ class NavigationDelegateTest : BaseSessionTest() { // TODO: bug 1710943 assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) - sessionRule.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 2) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -1373,7 +1385,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO2_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URL should match", url, endsWith(HELLO2_HTML_PATH)) @@ -1398,7 +1410,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS("window.open('newSession_child.html', '_blank')") - sessionRule.session.waitUntilCalled(object : Callbacks.NavigationDelegate { + sessionRule.session.waitUntilCalled(object : NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -1407,7 +1419,7 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("Trigger URL should match", request.triggerUri, endsWith(NEW_SESSION_HTML_PATH)) assertThat("Target should be correct", request.target, - equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_NEW)) + equalTo(NavigationDelegate.TARGET_WINDOW_NEW)) assertThat("Load should not be direct", request.isDirectNavigation, equalTo(false)) return null @@ -1444,7 +1456,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS("document.querySelector('#targetBlankLink').click()") - sessionRule.session.waitUntilCalled(object : Callbacks.NavigationDelegate { + sessionRule.session.waitUntilCalled(object : NavigationDelegate { // We get two onLoadRequest calls for the link click, // one when loading the URL and one when opening a new window. @AssertCalled(count = 1, order = [1]) @@ -1455,7 +1467,7 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("Trigger URL should be null", request.triggerUri, endsWith(NEW_SESSION_HTML_PATH)) assertThat("Target should be correct", request.target, - equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_NEW)) + equalTo(NavigationDelegate.TARGET_WINDOW_NEW)) return null } @@ -1470,7 +1482,7 @@ class NavigationDelegateTest : BaseSessionTest() { private fun delegateNewSession(settings: GeckoSessionSettings = mainSession.settings): GeckoSession { val newSession = sessionRule.createClosedSession(settings) - sessionRule.session.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onNewSession(session: GeckoSession, uri: String): GeckoResult { return GeckoResult.fromValue(newSession) @@ -1497,7 +1509,7 @@ class NavigationDelegateTest : BaseSessionTest() { // NEW_SESSION_CHILD_HTML_PATH newSession.waitForPageStop() - newSession.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + newSession.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URL should match", url, endsWith(NEW_SESSION_CHILD_HTML_PATH)) @@ -1558,7 +1570,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(NEW_SESSION_HTML_PATH) sessionRule.session.waitForPageStop() - sessionRule.session.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateDuringNextWait(object : NavigationDelegate { override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { @@ -1577,7 +1589,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.waitForPageStop() // Assert that onNewSession was not called for the link click. - sessionRule.session.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.session.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled(count = 2) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -1606,7 +1618,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS(""" document.querySelector('input[type=text]').focus() """) - sessionRule.session.waitUntilCalled(GeckoSession.TextInputDelegate::class, + sessionRule.session.waitUntilCalled(TextInputDelegate::class, "restartInput") val time = SystemClock.uptimeMillis() @@ -1616,7 +1628,7 @@ class NavigationDelegateTest : BaseSessionTest() { KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_UP)) - sessionRule.session.waitUntilCalled(object : Callbacks.NavigationDelegate { + sessionRule.session.waitUntilCalled(object : NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { @@ -1625,7 +1637,7 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("Trigger URL should match", request.triggerUri, endsWith("form_blank.html")) assertThat("Target should be correct", request.target, - equalTo(GeckoSession.NavigationDelegate.TARGET_WINDOW_NEW)) + equalTo(NavigationDelegate.TARGET_WINDOW_NEW)) return null } @@ -1693,7 +1705,7 @@ class NavigationDelegateTest : BaseSessionTest() { .uri(uri) .referrer(sessionRule.session) .flags(GeckoSession.LOAD_FLAGS_NONE)) - newSession.waitUntilCalled(object : Callbacks.NavigationDelegate { + newSession.waitUntilCalled(object : NavigationDelegate { @AssertCalled override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { return null @@ -1754,22 +1766,22 @@ class NavigationDelegateTest : BaseSessionTest() { testLoaderEquals( Loader().uri("http://test-uri-equals.com") - .flags(LOAD_FLAGS_BYPASS_CLASSIFIER) - .headerFilter(HEADER_FILTER_UNRESTRICTED_UNSAFE) + .flags(GeckoSession.LOAD_FLAGS_BYPASS_CLASSIFIER) + .headerFilter(GeckoSession.HEADER_FILTER_UNRESTRICTED_UNSAFE) .referrer("test-referrer"), Loader().uri("http://test-uri-equals.com") - .flags(LOAD_FLAGS_BYPASS_CLASSIFIER) - .headerFilter(HEADER_FILTER_UNRESTRICTED_UNSAFE) + .flags(GeckoSession.LOAD_FLAGS_BYPASS_CLASSIFIER) + .headerFilter(GeckoSession.HEADER_FILTER_UNRESTRICTED_UNSAFE) .referrer("test-referrer"), true) testLoaderEquals( Loader().uri("http://test-uri-equals.com") - .flags(LOAD_FLAGS_BYPASS_CLASSIFIER) - .headerFilter(HEADER_FILTER_UNRESTRICTED_UNSAFE) + .flags(GeckoSession.LOAD_FLAGS_BYPASS_CLASSIFIER) + .headerFilter(GeckoSession.HEADER_FILTER_UNRESTRICTED_UNSAFE) .referrer(sessionRule.session), Loader().uri("http://test-uri-equals.com") - .flags(LOAD_FLAGS_BYPASS_CLASSIFIER) - .headerFilter(HEADER_FILTER_UNRESTRICTED_UNSAFE) + .flags(GeckoSession.LOAD_FLAGS_BYPASS_CLASSIFIER) + .headerFilter(GeckoSession.HEADER_FILTER_UNRESTRICTED_UNSAFE) .referrer("test-referrer"), false) @@ -1955,7 +1967,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(NEW_SESSION_HTML_PATH) sessionRule.session.waitForPageStop() - sessionRule.session.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onNewSession(session: GeckoSession, uri: String): GeckoResult { return GeckoResult.fromValue(sessionRule.createOpenSession()) @@ -1964,7 +1976,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS("document.querySelector('#targetBlankLink').click()") - sessionRule.session.waitUntilCalled(GeckoSession.NavigationDelegate::class, + sessionRule.session.waitUntilCalled(NavigationDelegate::class, "onNewSession") UiThreadUtils.loopUntilIdle(sessionRule.env.defaultTimeoutMillis) } @@ -2018,7 +2030,7 @@ class NavigationDelegateTest : BaseSessionTest() { settings.aboutConfigEnabled = true var currentUrl: String? = null - mainSession.delegateUntilTestEnd(object: GeckoSession.NavigationDelegate { + mainSession.delegateUntilTestEnd(object: NavigationDelegate { override fun onLocationChange(session: GeckoSession, url: String?) { currentUrl = url } @@ -2089,7 +2101,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS("location.hash = 'test1';") - sessionRule.session.waitUntilCalled(object : Callbacks.NavigationDelegate { + sessionRule.session.waitUntilCalled(object : NavigationDelegate { @AssertCalled(count = 0) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -2100,14 +2112,14 @@ class NavigationDelegateTest : BaseSessionTest() { } @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { + override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("URI should match", url, endsWith("#test1")) } }) sessionRule.session.evaluateJS("location.hash = 'test2';") - sessionRule.session.waitUntilCalled(object : Callbacks.NavigationDelegate { + sessionRule.session.waitUntilCalled(object : NavigationDelegate { @AssertCalled(count = 0) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): @@ -2116,7 +2128,7 @@ class NavigationDelegateTest : BaseSessionTest() { } @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { + override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("URI should match", url, endsWith("#test2")) } }) @@ -2130,7 +2142,7 @@ class NavigationDelegateTest : BaseSessionTest() { assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) sessionRule.session.loadUri("$TEST_ENDPOINT$HELLO_HTML_PATH") - sessionRule.waitUntilCalled(object : Callbacks.NavigationDelegate { + sessionRule.waitUntilCalled(object : NavigationDelegate { @AssertCalled(count = 1) override fun onCanGoBack(session: GeckoSession, canGoBack: Boolean) { assertThat("Session should not be null", session, notNullValue()) @@ -2144,7 +2156,7 @@ class NavigationDelegateTest : BaseSessionTest() { } }) sessionRule.session.loadUri("$TEST_ENDPOINT$HELLO2_HTML_PATH") - sessionRule.waitUntilCalled(object : Callbacks.All { + sessionRule.waitUntilCalled(object : HistoryDelegate, NavigationDelegate { @AssertCalled(count = 1) override fun onCanGoBack(session: GeckoSession, canGoBack: Boolean) { assertThat("Session should not be null", session, notNullValue()) @@ -2156,14 +2168,14 @@ class NavigationDelegateTest : BaseSessionTest() { assertThat("Cannot go forward", canGoForward, equalTo(false)) } @AssertCalled(count = 1) - override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { + override fun onHistoryStateChange(session: GeckoSession, state: HistoryDelegate.HistoryList) { assertThat("History should have two entries", state.size, equalTo(2)) } }) sessionRule.session.purgeHistory() - sessionRule.waitUntilCalled(object : Callbacks.All { + sessionRule.waitUntilCalled(object : HistoryDelegate, NavigationDelegate { @AssertCalled(count = 1) - override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) { + override fun onHistoryStateChange(session: GeckoSession, state: HistoryDelegate.HistoryList) { assertThat("History should have one entry", state.size, equalTo(1)) } @AssertCalled(count = 1) @@ -2190,7 +2202,7 @@ class NavigationDelegateTest : BaseSessionTest() { mainSession.synthesizeTap(50, 50) - sessionRule.waitUntilCalled(object : Callbacks.NavigationDelegate { + sessionRule.waitUntilCalled(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { assertThat("Should have a user gesture", request.hasUserGesture, equalTo(true)) @@ -2208,7 +2220,7 @@ class NavigationDelegateTest : BaseSessionTest() { // TODO: bug 1710943 assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) - sessionRule.session.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 2) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { assertThat("URLs should match", request.uri, endsWith(forEachCall(HELLO_HTML_PATH, HELLO2_HTML_PATH))) @@ -2227,7 +2239,7 @@ class NavigationDelegateTest : BaseSessionTest() { val expectedUri = createDataUri(dataBytes, "*/*") val loader = Loader().data(dataBytes, "*/*") - sessionRule.session.delegateUntilTestEnd(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateUntilTestEnd(object : NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { assertThat("URLs should match", request.uri, equalTo(expectedUri)) @@ -2247,7 +2259,7 @@ class NavigationDelegateTest : BaseSessionTest() { }) sessionRule.session.load(loader) - sessionRule.waitUntilCalled(Callbacks.NavigationDelegate::class, "onLoadError") + sessionRule.waitUntilCalled(NavigationDelegate::class, "onLoadError") } @Test @@ -2261,7 +2273,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(DATA_URI_PATH) sessionRule.session.waitForPageStop() - sessionRule.session.delegateUntilTestEnd(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateUntilTestEnd(object : NavigationDelegate { @AssertCalled(false) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { return GeckoResult.deny() @@ -2275,7 +2287,7 @@ class NavigationDelegateTest : BaseSessionTest() { @Test fun loadShortDataUriToplevelIndirect() { - sessionRule.session.delegateUntilTestEnd(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateUntilTestEnd(object : NavigationDelegate { @AssertCalled(count = 2) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { return GeckoResult.allow() @@ -2326,7 +2338,7 @@ class NavigationDelegateTest : BaseSessionTest() { fun loadLongDataUriNonToplevel() { val dataUri = createLargeHighEntropyImageDataUri() - sessionRule.session.delegateUntilTestEnd(object : Callbacks.NavigationDelegate { + sessionRule.session.delegateUntilTestEnd(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult? { return GeckoResult.allow() diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/OpenWindowTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/OpenWindowTest.kt index 3bd12174c442..fe2d0a808214 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/OpenWindowTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/OpenWindowTest.kt @@ -9,10 +9,12 @@ import org.junit.Test import org.junit.runner.RunWith import org.mozilla.gecko.util.ThreadUtils import org.mozilla.geckoview.* +import org.mozilla.geckoview.GeckoSession.ContentDelegate +import org.mozilla.geckoview.GeckoSession.PermissionDelegate +import org.mozilla.geckoview.GeckoSession.NavigationDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.TimeoutMillis import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.util.Callbacks import org.mozilla.geckoview.test.util.UiThreadUtils @RunWith(AndroidJUnit4::class) @@ -24,7 +26,7 @@ class OpenWindowTest : BaseSessionTest() { sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false)) // Grant "desktop notification" permission - mainSession.delegateUntilTestEnd(object : Callbacks.PermissionDelegate { + mainSession.delegateUntilTestEnd(object : PermissionDelegate { override fun onContentPermissionRequest(session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): GeckoResult? { assertThat("Should grant DESKTOP_NOTIFICATIONS permission", perm.permission, equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION)) return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW); @@ -60,7 +62,7 @@ class OpenWindowTest : BaseSessionTest() { @Test fun openWindowNullDelegate() { - sessionRule.delegateUntilTestEnd(object : Callbacks.ContentDelegate, Callbacks.NavigationDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate, NavigationDelegate { override fun onLocationChange(session: GeckoSession, url: String?) { // we should not open the target url assertThat("URL should notmatch", url, not(createTestUrl(OPEN_WINDOW_TARGET_PATH))) @@ -79,7 +81,7 @@ class OpenWindowTest : BaseSessionTest() { return GeckoResult.fromValue(null) } }) - sessionRule.delegateUntilTestEnd(object : Callbacks.ContentDelegate, Callbacks.NavigationDelegate { + sessionRule.delegateUntilTestEnd(object : ContentDelegate, NavigationDelegate { override fun onLocationChange(session: GeckoSession, url: String?) { // we should not open the target url assertThat("URL should notmatch", url, not(createTestUrl(OPEN_WINDOW_TARGET_PATH))) @@ -99,7 +101,7 @@ class OpenWindowTest : BaseSessionTest() { } }) openPageClickNotification() - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate, Callbacks.NavigationDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("Should be on the main session", session, equalTo(mainSession)) @@ -126,7 +128,7 @@ class OpenWindowTest : BaseSessionTest() { } }) openPageClickNotification() - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate, Callbacks.NavigationDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { @AssertCalled(count = 1, order = [1]) override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("Should be on the target session", session, equalTo(targetSession)) @@ -140,4 +142,4 @@ class OpenWindowTest : BaseSessionTest() { } }) } -} \ No newline at end of file +} diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PanZoomControllerTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PanZoomControllerTest.kt index 24cf65953389..816b3d42d957 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PanZoomControllerTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PanZoomControllerTest.kt @@ -11,11 +11,8 @@ import org.hamcrest.Matchers.* import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.GeckoResult -import org.mozilla.geckoview.GeckoSession import org.junit.Assume.assumeTrue import org.mozilla.geckoview.PanZoomController -import org.mozilla.geckoview.test.rule.GeckoSessionTestRule -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @MediumTest diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt index 8f842259a18f..6f24c2b525e3 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt @@ -6,9 +6,10 @@ package org.mozilla.geckoview.test import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.NavigationDelegate +import org.mozilla.geckoview.GeckoSession.PermissionDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.RejectedPromiseException -import org.mozilla.geckoview.test.util.Callbacks import android.Manifest import android.content.pm.PackageManager @@ -75,7 +76,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Device list should contain microphone device", hasAudio, equalTo(true)) - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onMediaPermissionRequest( session: GeckoSession, uri: String, @@ -123,7 +124,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Stream should be active and id should not be empty.", isActive, equalTo(true)); // Now test rejecting the request. - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onMediaPermissionRequest( session: GeckoSession, uri: String, @@ -158,7 +159,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { // Ensure the content permission is asked first, before the Android permission. @AssertCalled(count = 1, order = [1]) override fun onContentPermissionRequest( @@ -207,7 +208,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Geolocation permission should be set to allow", permFound, equalTo(true)) - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2 : Boolean = false @@ -229,7 +230,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -265,7 +266,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Geolocation permission should be set to allow", permFound, equalTo(true)) - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2 : Boolean = false @@ -288,7 +289,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -318,7 +319,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Notification permission should be set to allow", permFound, equalTo(true)) - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2 : Boolean = false @@ -346,7 +347,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -373,7 +374,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Notification permission should be set to allow", permFound, equalTo(true)) - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2 : Boolean = false @@ -398,7 +399,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadTestPath(AUTOPLAY_PATH) - mainSession.waitUntilCalled(object : Callbacks.PermissionDelegate { + mainSession.waitUntilCalled(object : PermissionDelegate { @AssertCalled(count = 2) override fun onContentPermissionRequest(session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): GeckoResult? { @@ -416,7 +417,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -447,7 +448,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Notification permission should be set to allow", permFound, equalTo(true)) - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2: Boolean = false @@ -471,7 +472,7 @@ class PermissionDelegateTest : BaseSessionTest() { session2.loadUri(url) session2.waitForPageStop() - session2.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + session2.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -503,7 +504,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertThat("Notification permission should be set to allow", permFound, equalTo(true)) - session2.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + session2.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2: Boolean = false @@ -527,7 +528,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -558,7 +559,7 @@ class PermissionDelegateTest : BaseSessionTest() { sessionRule.runtime.storageController.setPermission(notificationPerm!!, GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2 : Boolean = false @@ -586,7 +587,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -621,7 +622,7 @@ class PermissionDelegateTest : BaseSessionTest() { sessionRule.runtime.storageController.setPermission(notificationPerm!!, GeckoSession.PermissionDelegate.ContentPermission.VALUE_DENY) - mainSession.delegateDuringNextWait(object : Callbacks.NavigationDelegate { + mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList) { var permFound2 : Boolean = false @@ -649,7 +650,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -684,7 +685,7 @@ class PermissionDelegateTest : BaseSessionTest() { sessionRule.runtime.storageController.setPermission(notificationPerm!!, GeckoSession.PermissionDelegate.ContentPermission.VALUE_PROMPT) - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -705,7 +706,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.loadUri(url) mainSession.waitForPageStop() - mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + mainSession.delegateDuringNextWait(object : PermissionDelegate { @AssertCalled(count = 1) override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): @@ -755,7 +756,7 @@ class PermissionDelegateTest : BaseSessionTest() { // mainSession.waitForPageStop() // // Persistent storage can be rejected - // mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + // mainSession.delegateDuringNextWait(object : PermissionDelegate { // @AssertCalled(count = 1) // override fun onContentPermissionRequest( // session: GeckoSession, uri: String?, type: Int, @@ -770,7 +771,7 @@ class PermissionDelegateTest : BaseSessionTest() { // success as Boolean, equalTo(false)) // // Persistent storage can be granted - // mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + // mainSession.delegateDuringNextWait(object : PermissionDelegate { // // Ensure the content permission is asked first, before the Android permission. // @AssertCalled(count = 1, order = [1]) // override fun onContentPermissionRequest( @@ -790,7 +791,7 @@ class PermissionDelegateTest : BaseSessionTest() { // equalTo(true)) // // after permission granted further requests will always return true, regardless of response - // mainSession.delegateDuringNextWait(object : Callbacks.PermissionDelegate { + // mainSession.delegateDuringNextWait(object : PermissionDelegate { // @AssertCalled(count = 1) // override fun onContentPermissionRequest( // session: GeckoSession, uri: String?, type: Int, diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt index cf3d84fe145d..07700932fab8 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProgressDelegateTest.kt @@ -13,8 +13,9 @@ import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.NavigationDelegate +import org.mozilla.geckoview.GeckoSession.ProgressDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.* -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @MediumTest @@ -27,8 +28,8 @@ class ProgressDelegateTest : BaseSessionTest() { var counter = 0 var lastProgress = -1 - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate, - Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate, + NavigationDelegate { @AssertCalled override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("LocationChange is called", url, endsWith(path)) @@ -70,7 +71,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("Session should not be null", session, notNullValue()) @@ -101,7 +102,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStops(2) - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 2, order = [1, 3]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URL should match", url, @@ -125,7 +126,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.reload() sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URL should match", url, endsWith(HELLO_HTML_PATH)) @@ -152,7 +153,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.goBack() sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URL should match", url, endsWith(HELLO_HTML_PATH)) @@ -172,7 +173,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.goForward() sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1, order = [1]) override fun onPageStart(session: GeckoSession, url: String) { assertThat("URL should match", url, endsWith(HELLO2_HTML_PATH)) @@ -196,7 +197,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.loadUri("https://example.com") sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onSecurityChange(session: GeckoSession, securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) { @@ -236,7 +237,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.loadUri("https://mozilla-modern.badssl.com") sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onSecurityChange(session: GeckoSession, securityInfo: GeckoSession.ProgressDelegate.SecurityInformation) { @@ -277,7 +278,7 @@ class ProgressDelegateTest : BaseSessionTest() { "https://expired.badssl.com") sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate { + sessionRule.forCallbacksDuringWait(object : ProgressDelegate { @AssertCalled(count = 1) override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("Load should fail", success, equalTo(false)) @@ -327,7 +328,7 @@ class ProgressDelegateTest : BaseSessionTest() { waitForVerticalScroll(100.0, sessionRule.env.defaultTimeoutMillis.toDouble()) var savedState : GeckoSession.SessionState? = null - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count=1) override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) { savedState = state @@ -357,7 +358,7 @@ class ProgressDelegateTest : BaseSessionTest() { session.restoreState(savedState) session.waitForPageStop() - session.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + session.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("URI should match", url, equalTo(startUri)) @@ -376,7 +377,7 @@ class ProgressDelegateTest : BaseSessionTest() { session.goBack() - session.waitUntilCalled(object: Callbacks.NavigationDelegate { + session.waitUntilCalled(object: NavigationDelegate { override fun onLocationChange(session: GeckoSession, url: String?, perms : MutableList) { assertThat("History should be preserved", url, equalTo(helloUri)) } @@ -396,7 +397,7 @@ class ProgressDelegateTest : BaseSessionTest() { mainSession.restoreState(savedState) sessionRule.waitForPageStop() - sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate { + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("URI should match", url, equalTo(startUri)) @@ -424,7 +425,7 @@ class ProgressDelegateTest : BaseSessionTest() { var oldState : GeckoSession.SessionState? = null - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 1) override fun onSessionStateChange(session: GeckoSession, sessionState: GeckoSession.SessionState) { oldState = sessionState @@ -435,7 +436,7 @@ class ProgressDelegateTest : BaseSessionTest() { mainSession.setActive(false) - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 1) override fun onSessionStateChange(session: GeckoSession, sessionState: GeckoSession.SessionState) { assertThat("Old session state and new should match", sessionState, equalTo(oldState)) @@ -456,7 +457,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 1) override fun onSessionStateChange(session: GeckoSession, sessionState: GeckoSession.SessionState) { } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PromptDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PromptDelegateTest.kt index 45d988fc72da..8c67a91c1c4f 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PromptDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PromptDelegateTest.kt @@ -3,11 +3,12 @@ package org.mozilla.geckoview.test import org.mozilla.geckoview.AllowOrDeny import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.NavigationDelegate import org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest +import org.mozilla.geckoview.GeckoSession.ProgressDelegate import org.mozilla.geckoview.GeckoSession.PromptDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.util.Callbacks import androidx.test.filters.MediumTest import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -24,7 +25,7 @@ class PromptDelegateTest : BaseSessionTest() { // Ensure popup blocking is enabled for this test. sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to true)) - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate, Callbacks.NavigationDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate, NavigationDelegate { @AssertCalled(count = 1) override fun onPopupPrompt(session: GeckoSession, prompt: PromptDelegate.PopupPrompt) : GeckoResult? { @@ -52,14 +53,14 @@ class PromptDelegateTest : BaseSessionTest() { }) sessionRule.session.loadTestPath(POPUP_HTML_PATH) - sessionRule.waitUntilCalled(Callbacks.NavigationDelegate::class, "onNewSession") + sessionRule.waitUntilCalled(NavigationDelegate::class, "onNewSession") } @Test fun popupTestBlock() { // Ensure popup blocking is enabled for this test. sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to true)) - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate, Callbacks.NavigationDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate, NavigationDelegate { @AssertCalled(count = 1) override fun onPopupPrompt(session: GeckoSession, prompt: PromptDelegate.PopupPrompt) : GeckoResult? { @@ -93,7 +94,7 @@ class PromptDelegateTest : BaseSessionTest() { @Test fun alertTest() { sessionRule.session.evaluateJS("alert('Alert!');") - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onAlertPrompt(session: GeckoSession, prompt: PromptDelegate.AlertPrompt): GeckoResult { assertThat("Message should match", "Alert!", equalTo(prompt.message)) @@ -103,7 +104,7 @@ class PromptDelegateTest : BaseSessionTest() { } @Test fun dismissAuthTest() { - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 2) override fun onAuthPrompt(session: GeckoSession, prompt: PromptDelegate.AuthPrompt): GeckoResult? { //TODO: Figure out some better testing here. @@ -122,7 +123,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.waitForPageStop() - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onButtonPrompt(session: GeckoSession, prompt: PromptDelegate.ButtonPrompt): GeckoResult { assertThat("Message should match", "Confirm?", equalTo(prompt.message)) @@ -134,7 +135,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.session.waitForJS("confirm('Confirm?')") as Boolean, equalTo(true)) - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onButtonPrompt(session: GeckoSession, prompt: PromptDelegate.ButtonPrompt): GeckoResult { assertThat("Message should match", "Confirm?", equalTo(prompt.message)) @@ -161,7 +162,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.waitForPageStop() val result = GeckoResult() - sessionRule.delegateUntilTestEnd(object: Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object: ProgressDelegate { override fun onPageStart(session: GeckoSession, url: String) { assertThat("Only HELLO_HTML_PATH should load", url, endsWith(HELLO_HTML_PATH)) result.complete(null) @@ -171,7 +172,7 @@ class PromptDelegateTest : BaseSessionTest() { val promptResult = GeckoResult() val promptResult2 = GeckoResult() - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 2) override fun onRepostConfirmPrompt(session: GeckoSession, prompt: PromptDelegate.RepostConfirmPrompt): GeckoResult? { // We have to return something here because otherwise the delegate will be invoked @@ -183,7 +184,7 @@ class PromptDelegateTest : BaseSessionTest() { // This should trigger a confirm resubmit prompt sessionRule.session.reload(); - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onRepostConfirmPrompt(session: GeckoSession, prompt: PromptDelegate.RepostConfirmPrompt): GeckoResult? { promptResult.complete(prompt.confirm(AllowOrDeny.DENY)) @@ -195,7 +196,7 @@ class PromptDelegateTest : BaseSessionTest() { // Trigger it again, this time the load should go through sessionRule.session.reload(); - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onRepostConfirmPrompt(session: GeckoSession, prompt: PromptDelegate.RepostConfirmPrompt): GeckoResult? { promptResult2.complete(prompt.confirm(AllowOrDeny.ALLOW)) @@ -216,7 +217,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.waitForPageStop() val result = GeckoResult() - sessionRule.delegateUntilTestEnd(object: Callbacks.ProgressDelegate { + sessionRule.delegateUntilTestEnd(object: ProgressDelegate { override fun onPageStart(session: GeckoSession, url: String) { assertThat("Only HELLO2_HTML_PATH should load", url, endsWith(HELLO2_HTML_PATH)) result.complete(null) @@ -226,7 +227,7 @@ class PromptDelegateTest : BaseSessionTest() { val promptResult = GeckoResult() val promptResult2 = GeckoResult() - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 2) override fun onBeforeUnloadPrompt(session: GeckoSession, prompt: PromptDelegate.BeforeUnloadPrompt): GeckoResult? { // We have to return something here because otherwise the delegate will be invoked @@ -238,7 +239,7 @@ class PromptDelegateTest : BaseSessionTest() { // This will try to load "hello.html" but will be denied, if the request // goes through anyway the onLoadRequest delegate above will throw an exception sessionRule.session.evaluateJS("document.querySelector('#navigateAway').click()") - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onBeforeUnloadPrompt(session: GeckoSession, prompt: PromptDelegate.BeforeUnloadPrompt): GeckoResult? { promptResult.complete(prompt.confirm(AllowOrDeny.DENY)) @@ -251,7 +252,7 @@ class PromptDelegateTest : BaseSessionTest() { // This request will go through and end the test. Doing the negative case first will // ensure that if either of this tests fail the test will fail. sessionRule.session.evaluateJS("document.querySelector('#navigateAway2').click()") - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onBeforeUnloadPrompt(session: GeckoSession, prompt: PromptDelegate.BeforeUnloadPrompt): GeckoResult? { promptResult2.complete(prompt.confirm(AllowOrDeny.ALLOW)) @@ -267,7 +268,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(HELLO_HTML_PATH) sessionRule.session.waitForPageStop() - sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate { + sessionRule.delegateUntilTestEnd(object : PromptDelegate { @AssertCalled(count = 1) override fun onTextPrompt(session: GeckoSession, prompt: PromptDelegate.TextPrompt): GeckoResult { assertThat("Message should match", "Prompt:", equalTo(prompt.message)) @@ -290,7 +291,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS("document.getElementById('selectexample').click();") - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onChoicePrompt(session: GeckoSession, prompt: PromptDelegate.ChoicePrompt): GeckoResult { return GeckoResult.fromValue(prompt.dismiss()) @@ -304,7 +305,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.session.loadTestPath(PROMPT_HTML_PATH) sessionRule.session.waitForPageStop() - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onColorPrompt(session: GeckoSession, prompt: PromptDelegate.ColorPrompt): GeckoResult { assertThat("Value should match", "#ffffff", equalTo(prompt.defaultValue)) @@ -341,7 +342,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS("document.getElementById('dateexample').click();") - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onDateTimePrompt(session: GeckoSession, prompt: PromptDelegate.DateTimePrompt): GeckoResult { return GeckoResult.fromValue(prompt.dismiss()) @@ -357,7 +358,7 @@ class PromptDelegateTest : BaseSessionTest() { sessionRule.session.evaluateJS("document.getElementById('fileexample').click();") - sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate { + sessionRule.waitUntilCalled(object : PromptDelegate { @AssertCalled(count = 1) override fun onFilePrompt(session: GeckoSession, prompt: PromptDelegate.FilePrompt): GeckoResult { assertThat("Length of mimeTypes should match", 2, equalTo(prompt.mimeTypes!!.size)) @@ -376,7 +377,7 @@ class PromptDelegateTest : BaseSessionTest() { val shareText = "Example share text" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { assertThat("Text field is not null", prompt.text, notNullValue()) @@ -401,7 +402,7 @@ class PromptDelegateTest : BaseSessionTest() { val shareUrl = "https://example.com/" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { assertThat("Text field is null", prompt.text, nullValue()) @@ -426,7 +427,7 @@ class PromptDelegateTest : BaseSessionTest() { val shareTitle = "Title!" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { assertThat("Text field is null", prompt.text, nullValue()) @@ -451,7 +452,7 @@ class PromptDelegateTest : BaseSessionTest() { val shareUrl = "https://www.example.com" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { return GeckoResult.fromValue(prompt.confirm(PromptDelegate.SharePrompt.Result.FAILURE)) @@ -474,7 +475,7 @@ class PromptDelegateTest : BaseSessionTest() { val shareUrl = "https://www.example.com" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { return GeckoResult.fromValue(prompt.confirm(PromptDelegate.SharePrompt.Result.ABORT)) @@ -497,7 +498,7 @@ class PromptDelegateTest : BaseSessionTest() { val shareUrl = "https://www.example.com" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 1) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { return GeckoResult.fromValue(prompt.dismiss()) @@ -518,7 +519,7 @@ class PromptDelegateTest : BaseSessionTest() { mainSession.loadTestPath(HELLO_HTML_PATH) mainSession.waitForPageStop() - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 0) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { return GeckoResult.fromValue(prompt.dismiss()) @@ -542,7 +543,7 @@ class PromptDelegateTest : BaseSessionTest() { // Invalid port should cause URL parser to fail. val shareUrl = "http://www.example.com:123456" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 0) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { return GeckoResult.fromValue(prompt.dismiss()) @@ -565,7 +566,7 @@ class PromptDelegateTest : BaseSessionTest() { val shareUrl = "https://www.example.com" - sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate { + sessionRule.delegateDuringNextWait(object : PromptDelegate { @AssertCalled(count = 0) override fun onSharePrompt(session: GeckoSession, prompt: PromptDelegate.SharePrompt): GeckoResult? { return GeckoResult.fromValue(prompt.dismiss()) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt index 928e3b5f5e60..833601b857dc 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/RuntimeSettingsTest.kt @@ -8,19 +8,17 @@ import android.provider.Settings import androidx.test.platform.app.InstrumentationRegistry import androidx.test.filters.MediumTest import androidx.test.ext.junit.runners.AndroidJUnit4 -import android.util.Log import org.hamcrest.Matchers.* import org.junit.Assume.assumeThat import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.GeckoResult -import kotlin.math.roundToInt import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.NavigationDelegate +import org.mozilla.geckoview.GeckoSession.ProgressDelegate import org.mozilla.geckoview.WebRequestError import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.util.Callbacks -import java.util.concurrent.atomic.AtomicBoolean @RunWith(AndroidJUnit4::class) @MediumTest @@ -158,7 +156,7 @@ class RuntimeSettingsTest : BaseSessionTest() { settings.aboutConfigEnabled, equalTo(false)) mainSession.loadUri("about:config") - mainSession.waitUntilCalled(object : Callbacks.NavigationDelegate { + mainSession.waitUntilCalled(object : NavigationDelegate { @AssertCalled override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult? { @@ -169,7 +167,7 @@ class RuntimeSettingsTest : BaseSessionTest() { settings.aboutConfigEnabled = true - mainSession.delegateDuringNextWait(object : Callbacks.ProgressDelegate { + mainSession.delegateDuringNextWait(object : ProgressDelegate { @AssertCalled override fun onPageStop(session: GeckoSession, success: Boolean) { assertThat("about:config load should succeed", success, equalTo(true)) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ScreenshotTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ScreenshotTest.kt index 9293eba31046..fc85d9585feb 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ScreenshotTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ScreenshotTest.kt @@ -19,9 +19,10 @@ import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoResult.OnExceptionListener import org.mozilla.geckoview.GeckoResult.fromException import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.ProgressDelegate +import org.mozilla.geckoview.GeckoSession.ContentDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay -import org.mozilla.geckoview.test.util.Callbacks import kotlin.math.absoluteValue import kotlin.math.max import android.graphics.BitmapFactory @@ -29,8 +30,6 @@ import android.graphics.Bitmap import androidx.test.platform.app.InstrumentationRegistry import org.junit.Assume.assumeThat import java.lang.IllegalStateException -import java.lang.NullPointerException - private const val SCREEN_HEIGHT = 800 private const val SCREEN_WIDTH = 800 @@ -96,7 +95,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH, SCREEN_HEIGHT) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -113,7 +112,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH, SCREEN_HEIGHT) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -209,7 +208,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH, SCREEN_HEIGHT) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -218,7 +217,7 @@ class ScreenshotTest : BaseSessionTest() { sessionRule.session.setActive(false) // Deactivating the session should trigger a flush state change - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count = 1) override fun onSessionStateChange(session: GeckoSession, sessionState: GeckoSession.SessionState) {} @@ -235,7 +234,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH, SCREEN_HEIGHT) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -252,7 +251,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH/2, SCREEN_HEIGHT/2) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -269,7 +268,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH/2, SCREEN_HEIGHT/2) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -286,7 +285,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH/2, SCREEN_HEIGHT/2) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -303,7 +302,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH, SCREEN_HEIGHT) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -325,7 +324,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH, SCREEN_HEIGHT) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -342,7 +341,7 @@ class ScreenshotTest : BaseSessionTest() { val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH/2, SCREEN_HEIGHT/2) sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -361,7 +360,7 @@ class ScreenshotTest : BaseSessionTest() { fun screenshotQuarters() { val res = InstrumentationRegistry.getInstrumentation().targetContext.resources sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -384,7 +383,7 @@ class ScreenshotTest : BaseSessionTest() { fun screenshotQuartersScaled() { val res = InstrumentationRegistry.getInstrumentation().targetContext.resources sessionRule.session.loadTestPath(COLORS_HTML_PATH) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/SelectionActionDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/SelectionActionDelegateTest.kt index 588617e27b33..04ab2f24662b 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/SelectionActionDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/SelectionActionDelegateTest.kt @@ -4,11 +4,11 @@ package org.mozilla.geckoview.test +import org.mozilla.geckoview.GeckoSession.SelectionActionDelegate import org.mozilla.geckoview.GeckoSession.SelectionActionDelegate.* import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay -import org.mozilla.geckoview.test.util.Callbacks import android.content.ClipData import android.content.ClipboardManager @@ -172,7 +172,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { @NullDelegate(GeckoSession.SelectionActionDelegate::class) @Test fun clearDelegate() { var counter = 0 - mainSession.selectionActionDelegate = object : Callbacks.SelectionActionDelegate { + mainSession.selectionActionDelegate = object : SelectionActionDelegate { override fun onHideAction(session: GeckoSession, reason: Int) { counter++ } @@ -224,14 +224,14 @@ class SelectionActionDelegateTest : BaseSessionTest() { "geckoview.selection_action.show_on_focus" to true, "layout.accessiblecaret.script_change_update_mode" to 2)) - mainSession.delegateDuringNextWait(object : Callbacks.SelectionActionDelegate { + mainSession.delegateDuringNextWait(object : SelectionActionDelegate { override fun onShowActionRequest(session: GeckoSession, selection: GeckoSession.SelectionActionDelegate.Selection) { respondingWith(selection) } }) content.select() - mainSession.waitUntilCalled(object : Callbacks.SelectionActionDelegate { + mainSession.waitUntilCalled(object : SelectionActionDelegate { @AssertCalled(count = 1) override fun onShowActionRequest(session: GeckoSession, selection: Selection) { assertThat("Initial content should match", @@ -266,7 +266,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { var clientRect = RectF() content.select() - mainSession.waitUntilCalled(object : Callbacks.SelectionActionDelegate { + mainSession.waitUntilCalled(object : SelectionActionDelegate { @AssertCalled(count = 1) override fun onShowActionRequest(session: GeckoSession, selection: Selection) { clientRect = selection.clientRect!! @@ -436,7 +436,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { private fun hasShowActionRequest(expectedFlags: Int, expectedActions: Array) = { it: SelectedContent -> - mainSession.forCallbacksDuringWait(object : Callbacks.SelectionActionDelegate { + mainSession.forCallbacksDuringWait(object : SelectionActionDelegate { @AssertCalled(count = 1) override fun onShowActionRequest(session: GeckoSession, selection: GeckoSession.SelectionActionDelegate.Selection) { assertThat("Selection text should be valid", @@ -462,7 +462,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { private fun changesSelectionTo(text: String) = changesSelectionTo(equalTo(text)) private fun changesSelectionTo(matcher: Matcher) = { _: SelectedContent -> - sessionRule.waitUntilCalled(object : Callbacks.SelectionActionDelegate { + sessionRule.waitUntilCalled(object : SelectionActionDelegate { @AssertCalled(count = 1) override fun onShowActionRequest(session: GeckoSession, selection: Selection) { assertThat("New selection text should match", selection.text, matcher) @@ -471,7 +471,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { } private fun clearsSelection() = { _: SelectedContent -> - sessionRule.waitUntilCalled(object : Callbacks.SelectionActionDelegate { + sessionRule.waitUntilCalled(object : SelectionActionDelegate { @AssertCalled(count = 1) override fun onHideAction(session: GeckoSession, reason: Int) { assertThat("Hide reason should be correct", diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TextInputDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TextInputDelegateTest.kt index b2b0aeb613b6..14c5f69d3483 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TextInputDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TextInputDelegateTest.kt @@ -8,9 +8,9 @@ import android.os.SystemClock import androidx.test.platform.app.InstrumentationRegistry import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.TextInputDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay -import org.mozilla.geckoview.test.util.Callbacks import androidx.test.filters.MediumTest import android.os.Handler; @@ -29,9 +29,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized import org.junit.runners.Parameterized.Parameter -import org.mozilla.geckoview.test.util.UiThreadUtils -import java.util.* -import java.util.concurrent.atomic.AtomicBoolean @MediumTest @RunWith(Parameterized::class) @@ -199,7 +196,7 @@ class TextInputDelegateTest : BaseSessionTest() { mainSession.waitForPageStop() mainSession.evaluateJS("document.querySelector('$id').focus()") - mainSession.waitUntilCalled(object : Callbacks.TextInputDelegate { + mainSession.waitUntilCalled(object : TextInputDelegate { @AssertCalled(count = 1) override fun restartInput(session: GeckoSession, reason: Int) { assertThat("Reason should be correct", @@ -208,7 +205,7 @@ class TextInputDelegateTest : BaseSessionTest() { }) mainSession.evaluateJS("document.querySelector('$id').blur()") - mainSession.waitUntilCalled(object : Callbacks.TextInputDelegate { + mainSession.waitUntilCalled(object : TextInputDelegate { @AssertCalled(count = 1) override fun restartInput(session: GeckoSession, reason: Int) { assertThat("Reason should be correct", @@ -243,7 +240,7 @@ class TextInputDelegateTest : BaseSessionTest() { mainSession.pressKey(KeyEvent.KEYCODE_CTRL_LEFT) mainSession.evaluateJS("document.querySelector('$id').focus()") - mainSession.waitUntilCalled(object : Callbacks.TextInputDelegate { + mainSession.waitUntilCalled(object : TextInputDelegate { @AssertCalled(count = 1, order = [1]) override fun restartInput(session: GeckoSession, reason: Int) { assertThat("Reason should be correct", @@ -252,12 +249,10 @@ class TextInputDelegateTest : BaseSessionTest() { @AssertCalled(count = 1, order = [2]) override fun showSoftInput(session: GeckoSession) { - super.showSoftInput(session) } @AssertCalled(count = 0) override fun hideSoftInput(session: GeckoSession) { - super.hideSoftInput(session) } }) } @@ -279,7 +274,7 @@ class TextInputDelegateTest : BaseSessionTest() { // but only one showSoftInput call and no hideSoftInput call. mainSession.evaluateJS("document.querySelector('$id').blur(); document.querySelector('$id').focus()") - mainSession.waitUntilCalled(object : Callbacks.TextInputDelegate { + mainSession.waitUntilCalled(object : TextInputDelegate { @AssertCalled(count = 2, order = [1]) override fun restartInput(session: GeckoSession, reason: Int) { assertThat("Reason should be correct", reason, equalTo(forEachCall( @@ -308,7 +303,7 @@ class TextInputDelegateTest : BaseSessionTest() { mainSession.pressKey(KeyEvent.KEYCODE_CTRL_LEFT) mainSession.evaluateJS("document.querySelector('$id').focus()") - mainSession.waitUntilCalled(object : Callbacks.TextInputDelegate { + mainSession.waitUntilCalled(object : TextInputDelegate { @AssertCalled(count = 1, order = [1]) override fun restartInput(session: GeckoSession, reason: Int) { } @@ -323,7 +318,7 @@ class TextInputDelegateTest : BaseSessionTest() { }) mainSession.evaluateJS("document.querySelector('$id').blur()") - mainSession.waitUntilCalled(object : Callbacks.TextInputDelegate { + mainSession.waitUntilCalled(object : TextInputDelegate { @AssertCalled(count = 1, order = [1]) override fun restartInput(session: GeckoSession, reason: Int) { } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VerticalClippingTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VerticalClippingTest.kt index c2a428466945..504d71f4271e 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VerticalClippingTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VerticalClippingTest.kt @@ -17,8 +17,8 @@ import android.graphics.Bitmap import org.hamcrest.Matchers import org.hamcrest.Matchers.equalTo import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.ContentDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled -import org.mozilla.geckoview.test.util.Callbacks private const val SCREEN_HEIGHT = 800 @@ -67,7 +67,7 @@ class VerticalClippingTest : BaseSessionTest() { assumeThat(sessionRule.env.isWebrender, equalTo(false)) sessionRule.display?.setVerticalClipping(45) sessionRule.session.loadTestPath(FIXED_BOTTOM) - sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate { + sessionRule.waitUntilCalled(object : ContentDelegate { @AssertCalled(count = 1) override fun onFirstContentfulPaint(session: GeckoSession) { } @@ -78,4 +78,4 @@ class VerticalClippingTest : BaseSessionTest() { } } -} \ No newline at end of file +} diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebExtensionTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebExtensionTest.kt index 2471fd04deac..b2625dd60940 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebExtensionTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebExtensionTest.kt @@ -14,8 +14,9 @@ import org.junit.Assume.assumeThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mozilla.gecko.EventDispatcher import org.mozilla.geckoview.* +import org.mozilla.geckoview.GeckoSession.NavigationDelegate +import org.mozilla.geckoview.GeckoSession.ProgressDelegate import org.mozilla.geckoview.WebExtension.* import org.mozilla.geckoview.WebExtension.BrowsingDataDelegate.Type.* import org.mozilla.geckoview.WebExtensionController.EnableSource @@ -23,7 +24,6 @@ import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.Setting import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.RejectedPromiseException -import org.mozilla.geckoview.test.util.Callbacks import org.mozilla.geckoview.test.util.RuntimeCreator import org.mozilla.geckoview.test.util.UiThreadUtils import java.nio.charset.Charset @@ -1191,7 +1191,7 @@ class WebExtensionTest : BaseSessionTest() { sessionRule.waitForPageStop() var savedState : GeckoSession.SessionState? = null - sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate { + sessionRule.waitUntilCalled(object : ProgressDelegate { @AssertCalled(count=1) override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) { savedState = state @@ -1635,7 +1635,7 @@ class WebExtensionTest : BaseSessionTest() { mainSession.loadUri("http://example.com") - mainSession.waitUntilCalled(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate { + mainSession.waitUntilCalled(object : NavigationDelegate, ProgressDelegate { @GeckoSessionTestRule.AssertCalled(count = 1) override fun onLocationChange(session: GeckoSession, url: String?) { assertThat("Url should load example.com first", @@ -1653,7 +1653,7 @@ class WebExtensionTest : BaseSessionTest() { var page: String? = null val pageStop = GeckoResult() - mainSession.delegateUntilTestEnd(object : Callbacks.NavigationDelegate, Callbacks.ProgressDelegate { + mainSession.delegateUntilTestEnd(object : NavigationDelegate, ProgressDelegate { override fun onLocationChange(session: GeckoSession, url: String?) { page = url } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebNotificationTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebNotificationTest.kt index 4603fb3f2cd5..bdb962dbcb8d 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebNotificationTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebNotificationTest.kt @@ -8,10 +8,10 @@ import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.GeckoResult import org.mozilla.geckoview.GeckoSession +import org.mozilla.geckoview.GeckoSession.PermissionDelegate import org.mozilla.geckoview.WebNotification import org.mozilla.geckoview.WebNotificationDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule -import org.mozilla.geckoview.test.util.Callbacks @RunWith(AndroidJUnit4::class) @MediumTest @@ -24,7 +24,7 @@ class WebNotificationTest : BaseSessionTest() { sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false)) // Grant "desktop notification" permission - mainSession.delegateUntilTestEnd(object : Callbacks.PermissionDelegate { + mainSession.delegateUntilTestEnd(object : PermissionDelegate { override fun onContentPermissionRequest(session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): GeckoResult? { assertThat("Should grant DESKTOP_NOTIFICATIONS permission", perm.permission, equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION)) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebPushTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebPushTest.kt index a1680acfd4d4..23bd75803539 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebPushTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/WebPushTest.kt @@ -16,9 +16,9 @@ import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mozilla.geckoview.* +import org.mozilla.geckoview.GeckoSession.PermissionDelegate import org.mozilla.geckoview.test.rule.GeckoSessionTestRule import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.RejectedPromiseException -import org.mozilla.geckoview.test.util.Callbacks import java.security.KeyPair import java.security.KeyPairGenerator import java.security.SecureRandom @@ -59,7 +59,7 @@ class WebPushTest : BaseSessionTest() { fun setup() { sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false)) // Grant "desktop notification" permission - mainSession.delegateUntilTestEnd(object : Callbacks.PermissionDelegate { + mainSession.delegateUntilTestEnd(object : PermissionDelegate { override fun onContentPermissionRequest(session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): GeckoResult? { assertThat("Should grant DESKTOP_NOTIFICATIONS permission", perm.permission, equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION)) diff --git 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 index 5c128e1d08be..4d7539b66d02 100644 --- 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 @@ -13,6 +13,16 @@ import org.mozilla.geckoview.GeckoDisplay; import org.mozilla.geckoview.GeckoResult; import org.mozilla.geckoview.GeckoRuntime; import org.mozilla.geckoview.GeckoSession; +import org.mozilla.geckoview.GeckoSession.ContentDelegate; +import org.mozilla.geckoview.GeckoSession.HistoryDelegate; +import org.mozilla.geckoview.GeckoSession.MediaDelegate; +import org.mozilla.geckoview.GeckoSession.NavigationDelegate; +import org.mozilla.geckoview.GeckoSession.PermissionDelegate; +import org.mozilla.geckoview.GeckoSession.ProgressDelegate; +import org.mozilla.geckoview.GeckoSession.PromptDelegate; +import org.mozilla.geckoview.GeckoSession.ScrollDelegate; +import org.mozilla.geckoview.GeckoSession.SelectionActionDelegate; +import org.mozilla.geckoview.GeckoSession.TextInputDelegate; import org.mozilla.geckoview.GeckoSessionSettings; import org.mozilla.geckoview.MediaSession; import org.mozilla.geckoview.RuntimeTelemetry; @@ -23,7 +33,6 @@ import org.mozilla.geckoview.test.util.TestServer; import org.mozilla.geckoview.test.util.RuntimeCreator; import org.mozilla.geckoview.test.util.Environment; import org.mozilla.geckoview.test.util.UiThreadUtils; -import org.mozilla.geckoview.test.util.Callbacks; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; @@ -729,29 +738,40 @@ public class GeckoSessionTestRule implements TestRule { } } - private static void addCallbackClasses(final List> list, final Class ifce) { - if (!Callbacks.class.equals(ifce.getDeclaringClass())) { - list.add(ifce); - return; - } - final Class[] superIfces = ifce.getInterfaces(); - for (final Class superIfce : superIfces) { - addCallbackClasses(list, superIfce); - } + private static final Set> DEFAULT_DELEGATES = new HashSet<>(); + static { + DEFAULT_DELEGATES.add(Autofill.Delegate.class); + DEFAULT_DELEGATES.add(ContentBlocking.Delegate.class); + DEFAULT_DELEGATES.add(ContentDelegate.class); + DEFAULT_DELEGATES.add(HistoryDelegate.class); + DEFAULT_DELEGATES.add(MediaDelegate.class); + DEFAULT_DELEGATES.add(MediaSession.Delegate.class); + DEFAULT_DELEGATES.add(NavigationDelegate.class); + DEFAULT_DELEGATES.add(PermissionDelegate.class); + DEFAULT_DELEGATES.add(ProgressDelegate.class); + DEFAULT_DELEGATES.add(PromptDelegate.class); + DEFAULT_DELEGATES.add(ScrollDelegate.class); + DEFAULT_DELEGATES.add(SelectionActionDelegate.class); + DEFAULT_DELEGATES.add(TextInputDelegate.class); } - private static Set> getDefaultDelegates() { - final Class[] ifces = Callbacks.class.getDeclaredClasses(); - final List> list = new ArrayList<>(ifces.length); + private static class DefaultImpl implements + Autofill.Delegate, + ContentBlocking.Delegate, + ContentDelegate, + HistoryDelegate, + MediaDelegate, + MediaSession.Delegate, + NavigationDelegate, + PermissionDelegate, + ProgressDelegate, + PromptDelegate, + ScrollDelegate, + SelectionActionDelegate, + TextInputDelegate + {} - for (final Class ifce : ifces) { - addCallbackClasses(list, ifce); - } - - return new HashSet<>(list); - } - - private static final Set> DEFAULT_DELEGATES = getDefaultDelegates(); + private static final DefaultImpl DEFAULT_IMPL = new DefaultImpl(); public final Environment env = new Environment(); @@ -953,15 +973,9 @@ public class GeckoSessionTestRule implements TestRule { } private void addNullDelegate(final Class delegate) { - if (!Callbacks.class.equals(delegate.getDeclaringClass())) { - assertThat("Null-delegate must be valid interface class", - delegate, isIn(DEFAULT_DELEGATES)); - mNullDelegates.add(delegate); - return; - } - for (final Class ifce : delegate.getInterfaces()) { - addNullDelegate(ifce); - } + assertThat("Null-delegate must be valid interface class", + delegate, isIn(DEFAULT_DELEGATES)); + mNullDelegates.add(delegate); } protected void applyAnnotations(final Collection annotations, @@ -1088,8 +1102,11 @@ public class GeckoSessionTestRule implements TestRule { Object returnValue = null; try { mCurrentMethodCall = call; - returnValue = method.invoke((call != null) ? call.target - : Callbacks.Default.INSTANCE, args); + if (call != null && call.target != null) { + returnValue = method.invoke(call.target, args); + } else { + returnValue = method.invoke(DEFAULT_IMPL, args); + } } catch (final IllegalAccessException | InvocationTargetException e) { throw unwrapRuntimeException(e); } finally { diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/util/Callbacks.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/util/Callbacks.kt deleted file mode 100644 index 8f5a7a5658b8..000000000000 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/util/Callbacks.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.mozilla.geckoview.test.util - -import org.mozilla.geckoview.AllowOrDeny -import org.mozilla.geckoview.Autofill -import org.mozilla.geckoview.ContentBlocking -import org.mozilla.geckoview.GeckoResult -import org.mozilla.geckoview.GeckoSession -import org.mozilla.geckoview.GeckoSession.ContentDelegate.ContextElement -import org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest -import org.mozilla.geckoview.MediaSession -import org.mozilla.geckoview.WebRequestError - -import android.view.inputmethod.CursorAnchorInfo -import android.view.inputmethod.ExtractedText -import android.view.inputmethod.ExtractedTextRequest -import org.json.JSONObject - -class Callbacks private constructor() { - object Default : All - - interface All : AutofillDelegate, ContentBlockingDelegate, ContentDelegate, - HistoryDelegate, MediaDelegate, MediaSessionDelegate, - NavigationDelegate, PermissionDelegate, ProgressDelegate, - PromptDelegate, ScrollDelegate, SelectionActionDelegate, - TextInputDelegate - - interface AutofillDelegate : Autofill.Delegate {} - interface ContentDelegate : GeckoSession.ContentDelegate {} - interface NavigationDelegate : GeckoSession.NavigationDelegate {} - interface PermissionDelegate : GeckoSession.PermissionDelegate {} - interface ProgressDelegate : GeckoSession.ProgressDelegate {} - interface PromptDelegate : GeckoSession.PromptDelegate {} - interface ScrollDelegate : GeckoSession.ScrollDelegate {} - interface ContentBlockingDelegate : ContentBlocking.Delegate {} - interface SelectionActionDelegate : GeckoSession.SelectionActionDelegate {} - @Suppress("DEPRECATION") - interface MediaDelegate: GeckoSession.MediaDelegate {} - interface HistoryDelegate : GeckoSession.HistoryDelegate {} - interface MediaSessionDelegate: MediaSession.Delegate {} - - interface TextInputDelegate : GeckoSession.TextInputDelegate { - override fun restartInput(session: GeckoSession, reason: Int) { - } - - override fun showSoftInput(session: GeckoSession) { - } - - override fun hideSoftInput(session: GeckoSession) { - } - - override fun updateSelection(session: GeckoSession, selStart: Int, selEnd: Int, compositionStart: Int, compositionEnd: Int) { - } - - override fun updateExtractedText(session: GeckoSession, request: ExtractedTextRequest, text: ExtractedText) { - } - - override fun updateCursorAnchorInfo(session: GeckoSession, info: CursorAnchorInfo) { - } - } -}