diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /mobile/android/geckoview/src/androidTest/java | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-upstream/125.0.1.tar.xz firefox-upstream/125.0.1.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/geckoview/src/androidTest/java')
23 files changed, 500 insertions, 121 deletions
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 fbfe2fe46d..dddba77768 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 @@ -2407,7 +2407,7 @@ class AutocompleteTest : BaseSessionTest() { "Hint should match", option.hint, equalTo(LoginSaveOption.Hint.GENERATED)) - */ + */ assertThat( "Password should not be empty", diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt index 655db7248f..d57cd8f157 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt @@ -36,6 +36,7 @@ open class BaseSessionTest( const val RESUBMIT_CONFIRM = "/assets/www/resubmit.html" const val BEFORE_UNLOAD = "/assets/www/beforeunload.html" const val CLICK_TO_RELOAD_HTML_PATH = "/assets/www/clickToReload.html" + const val CLICK_TO_REPLACE_HTML_PATH = "/assets/www/clickToReplace.html" const val CLIPBOARD_READ_HTML_PATH = "/assets/www/clipboard_read.html" const val CONTENT_CRASH_URL = "about:crashcontent" const val DND_HTML_PATH = "/assets/www/dnd.html" diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoAppShellTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoAppShellTest.kt index c05820012d..75204a2f5d 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoAppShellTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoAppShellTest.kt @@ -86,6 +86,7 @@ class GeckoAppShellTest : BaseSessionTest() { // This is waiting and holding the test harness open while Android Lifecycle events complete mainSession.waitUntilCalled(object : GeckoSession.ContentDelegate, GeckoSession.NavigationDelegate { @GeckoSessionTestRule.AssertCalled(count = 2) + @Suppress("OVERRIDE_DEPRECATION") override fun onLocationChange( session: GeckoSession, url: String?, 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 d6380bf5bf..2ec305f913 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 @@ -1115,6 +1115,7 @@ class GeckoSessionTestRuleTest : BaseSessionTest(noErrorCollector = true) { @NullDelegate(NavigationDelegate::class) fun delegateDuringNextWait_throwOnNullDelegate() { mainSession.delegateDuringNextWait(object : NavigationDelegate { + @Suppress("OVERRIDE_DEPRECATION") override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>) { } }) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeolocationTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeolocationTest.kt index 1bb568123c..4deac5fb66 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeolocationTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeolocationTest.kt @@ -72,8 +72,7 @@ class GeolocationTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) } override fun onAndroidPermissionsRequest( 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 370594a93f..2d2f4bb4af 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 @@ -250,6 +250,11 @@ class HistoryDelegateTest : BaseSessionTest() { } @Test fun onHistoryStateChangeSavingState() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt index 69deac1c89..608681d7d9 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/LocaleTest.kt @@ -40,4 +40,16 @@ class LocaleTest : BaseSessionTest() { equalTo(listOf("en-GB", "en-US", "en-FR")), ) } + + @Test + fun acceptLangaugeFormat() { + // No way to override default language settings from unit test. + // So we only test this on current settings. + + val intlAcceptLanauge = "intl.accept_languages" + val prefValue = (sessionRule.getPrefs(intlAcceptLanauge)[0] as String).split(",") + for (value in prefValue) { + assertThat("Accept-Lanauge format should be language or language-region", value.filter { it == '-' }.count(), lessThanOrEqualTo(1)) + } + } } 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 aab32cd01d..839ac4b468 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 @@ -67,8 +67,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "URI should be " + testLoader.getUri(), request.uri, @@ -123,6 +122,7 @@ class NavigationDelegateTest : BaseSessionTest() { if (errorPageUrl != null) { sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { @AssertCalled(count = 1, order = [1]) + @Suppress("OVERRIDE_DEPRECATION") override fun onLocationChange( session: GeckoSession, url: String?, @@ -492,8 +492,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("The URLs must match", request.uri, equalTo(forEachCall(uri, httpsUri))) return null } @@ -552,8 +551,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("The URLs must match", request.uri, equalTo(forEachCall(uri, httpsUri))) return null } @@ -593,6 +591,7 @@ class NavigationDelegateTest : BaseSessionTest() { sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { @AssertCalled(count = 1, order = [1]) + @Suppress("OVERRIDE_DEPRECATION") override fun onLocationChange( session: GeckoSession, url: String?, @@ -611,8 +610,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("The URLs must match", request.uri, equalTo(forEachCall(uri, httpsUri))) return null } @@ -646,6 +644,7 @@ class NavigationDelegateTest : BaseSessionTest() { // No good way to wait for loading about:blank error page. Use onLocaitonChange etc. sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { + @Suppress("OVERRIDE_DEPRECATION") override fun onLocationChange( session: GeckoSession, url: String?, @@ -665,8 +664,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { // We set http scheme only in case it's not iFrame assertThat("The URLs must match", request.uri, equalTo(uri)) return null @@ -717,8 +715,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "URI should be HTTP then redirected to HTTPS", request.uri, @@ -774,8 +771,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onSubframeLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("URI should not be null", request.uri, notNullValue()) assertThat("URI should match", request.uri, endsWith(iframeUri)) return null @@ -862,8 +858,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("Session should not be null", session, notNullValue()) assertThat("URI should not be null", request.uri, notNullValue()) assertThat( @@ -913,8 +908,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("Session should not be null", session, notNullValue()) assertThat("App requested this load", request.isDirectNavigation, equalTo(true)) assertThat("URI should not be null", request.uri, notNullValue()) @@ -927,8 +921,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onSubframeLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("Session should not be null", session, notNullValue()) assertThat("App did not request this load", request.isDirectNavigation, equalTo(false)) assertThat("URI should not be null", request.uri, notNullValue()) @@ -960,8 +953,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("Session should not be null", session, notNullValue()) assertThat("URI should not be null", request.uri, notNullValue()) assertThat( @@ -1023,8 +1015,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("URL should match", request.uri, equalTo(forEachCall(uri, redirectUri))) assertThat( "From app should be correct", @@ -1447,8 +1438,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("Session should not be null", session, notNullValue()) assertThat("URI should not be null", request.uri, notNullValue()) assertThat("URI should match", request.uri, endsWith(HELLO_HTML_PATH)) @@ -1478,10 +1468,12 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("Session should not be null", session, notNullValue()) assertThat("URL should not be null", url, notNullValue()) assertThat("URL should match", url, endsWith(HELLO_HTML_PATH)) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1, order = [2]) @@ -1514,8 +1506,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should match the provided data URL", url, equalTo(dataUrl)) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1) @@ -1542,6 +1536,7 @@ class NavigationDelegateTest : BaseSessionTest() { // Test that if we unset the navigation delegate during a load, the load still proceeds. var onLocationCount = 0 mainSession.navigationDelegate = object : NavigationDelegate { + @Suppress("OVERRIDE_DEPRECATION") override fun onLocationChange( session: GeckoSession, url: String?, @@ -1587,12 +1582,14 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat( "URL should be a data URL", url, equalTo(createDataUri(dataString, mimeType)), ) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1) @@ -1612,8 +1609,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should be a data URL", url, startsWith("data:")) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1) @@ -1641,8 +1640,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should match", url, equalTo(createDataUri(bytes, "text/html"))) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1) @@ -1683,8 +1684,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should match", url, equalTo(createDataUri(bytes, mimeType))) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1) @@ -1714,8 +1717,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("URI should match", request.uri, endsWith(HELLO_HTML_PATH)) assertThat( "Trigger URL should be null", @@ -1740,8 +1742,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should match", url, endsWith(HELLO_HTML_PATH)) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1, order = [2]) @@ -1774,8 +1778,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should match", url, endsWith(HELLO2_HTML_PATH)) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } }) @@ -1787,8 +1793,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "Load should not be direct", request.isDirectNavigation, @@ -1802,8 +1807,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should match", url, endsWith(HELLO_HTML_PATH)) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1, order = [2]) @@ -1830,8 +1837,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "Load should not be direct", request.isDirectNavigation, @@ -1845,8 +1851,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URL should match", url, endsWith(HELLO2_HTML_PATH)) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } @AssertCalled(count = 1, order = [2]) @@ -1872,8 +1880,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { if (request.uri.endsWith(HELLO_HTML_PATH)) { return GeckoResult.deny() } else { @@ -1913,8 +1920,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("URI should be correct", request.uri, endsWith(NEW_SESSION_CHILD_HTML_PATH)) assertThat( "Trigger URL should match", @@ -1969,8 +1975,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat("URI should be correct", request.uri, endsWith(NEW_SESSION_CHILD_HTML_PATH)) assertThat( "Trigger URL should be null", @@ -2080,8 +2085,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { // Pretend we handled the target="_blank" link click. if (request.uri.endsWith(NEW_SESSION_CHILD_HTML_PATH)) { return GeckoResult.deny() @@ -2102,8 +2106,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "URI must match", request.uri, @@ -2151,8 +2154,7 @@ class NavigationDelegateTest : BaseSessionTest() { mainSession.waitUntilCalled(object : NavigationDelegate { @AssertCalled(count = 1, order = [1]) - override fun onLoadRequest(session: GeckoSession, request: LoadRequest): - GeckoResult<AllowOrDeny>? { + override fun onLoadRequest(session: GeckoSession, request: LoadRequest): GeckoResult<AllowOrDeny>? { assertThat( "URL should be correct", request.uri, @@ -2172,8 +2174,7 @@ class NavigationDelegateTest : BaseSessionTest() { } @AssertCalled(count = 1, order = [2]) - override fun onNewSession(session: GeckoSession, uri: String): - GeckoResult<GeckoSession>? { + override fun onNewSession(session: GeckoSession, uri: String): GeckoResult<GeckoSession>? { assertThat("URL should be correct", uri, endsWith("form_blank.html?")) return null } @@ -2621,6 +2622,7 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { currentUrl = url } @@ -2702,8 +2704,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "Load should not be direct", request.isDirectNavigation, @@ -2717,8 +2718,10 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URI should match", url, endsWith("#test1")) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } }) @@ -2729,8 +2732,7 @@ class NavigationDelegateTest : BaseSessionTest() { override fun onLoadRequest( session: GeckoSession, request: LoadRequest, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { return null } @@ -2739,13 +2741,20 @@ class NavigationDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URI should match", url, endsWith("#test2")) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) } }) } @Test fun purgeHistory() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) @@ -2830,6 +2839,54 @@ class NavigationDelegateTest : BaseSessionTest() { }) } + @WithDisplay(width = 100, height = 100) + @Test + fun locationReplaceOnUserGesture() { + mainSession.loadUri("$TEST_ENDPOINT$CLICK_TO_REPLACE_HTML_PATH") + mainSession.waitForPageStop() + + mainSession.synthesizeTap(50, 50) + + sessionRule.waitUntilCalled(object : NavigationDelegate { + @AssertCalled(count = 1) + override fun onLocationChange( + session: GeckoSession, + url: String?, + perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, + ) { + assertThat("Should have a user gesture", hasUserGesture, equalTo(true)) + assertThat( + "Location should be replaced to replacedUrl", + url, + equalTo("replacedUrl"), + ) + } + }) + } + + @WithDisplay(width = 100, height = 100) + @Test + fun locationNotReplaceOnNoUserGesture() { + mainSession.loadUri("$TEST_ENDPOINT$HELLO_HTML_PATH") + sessionRule.waitForPageStop() + + sessionRule.forCallbacksDuringWait(object : NavigationDelegate { + @AssertCalled(count = 1, order = [2]) + override fun onLocationChange( + session: GeckoSession, + url: String?, + perms: MutableList<PermissionDelegate.ContentPermission>, + hasUserGesture: Boolean, + ) { + assertThat("Session should not be null", session, notNullValue()) + assertThat("URL should not be null", url, notNullValue()) + assertThat("URL should match", url, endsWith(HELLO_HTML_PATH)) + assertThat("Should not have user gesture", hasUserGesture, equalTo(false)) + } + }) + } + @Test fun loadAfterLoad() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 2) @@ -3078,6 +3135,11 @@ class NavigationDelegateTest : BaseSessionTest() { } @Test fun goBackFromHistory() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) @@ -3119,6 +3181,7 @@ class NavigationDelegateTest : BaseSessionTest() { var lastTitle: String? = "" sessionRule.delegateDuringNextWait(object : NavigationDelegate, ContentDelegate { @AssertCalled(count = 1) + @Suppress("OVERRIDE_DEPRECATION") override fun onLocationChange( session: GeckoSession, url: String?, 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 335535bbb4..b7aed020b4 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 @@ -64,7 +64,7 @@ class OpenWindowTest : BaseSessionTest() { @NullDelegate(ServiceWorkerDelegate::class) fun openWindowNullDelegate() { sessionRule.delegateUntilTestEnd(object : ContentDelegate, NavigationDelegate { - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, hasUserGesture: Boolean) { // we should not open the target url assertThat("URL should notmatch", url, not(createTestUrl(OPEN_WINDOW_TARGET_PATH))) } @@ -76,7 +76,7 @@ class OpenWindowTest : BaseSessionTest() { @Test fun openWindowNullResult() { sessionRule.delegateUntilTestEnd(object : ContentDelegate, NavigationDelegate { - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, hasUserGesture: Boolean) { // we should not open the target url assertThat("URL should notmatch", url, not(createTestUrl(OPEN_WINDOW_TARGET_PATH))) } @@ -103,7 +103,7 @@ class OpenWindowTest : BaseSessionTest() { openPageClickNotification() sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { @AssertCalled(count = 1, order = [1]) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, hasUserGesture: Boolean) { assertThat("Should be on the main session", session, equalTo(mainSession)) assertThat("URL should match", url, equalTo(createTestUrl(OPEN_WINDOW_TARGET_PATH))) } @@ -130,7 +130,7 @@ class OpenWindowTest : BaseSessionTest() { openPageClickNotification() sessionRule.waitUntilCalled(object : ContentDelegate, NavigationDelegate { @AssertCalled(count = 1, order = [1]) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, hasUserGesture: Boolean) { assertThat("Should be on the target session", session, equalTo(targetSession)) assertThat("URL should match", url, equalTo(createTestUrl(OPEN_WINDOW_TARGET_PATH))) } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PdfCreationTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PdfCreationTest.kt index 627c076fc4..de9f282484 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PdfCreationTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PdfCreationTest.kt @@ -177,4 +177,16 @@ class PdfCreationTest : BaseSessionTest() { } } } + + @NullDelegate(Autofill.Delegate::class) + @Test + fun dontTryToOpenNullContent() { + // Bug 1881927. + assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false)) + activityRule.scenario.onActivity { + TestContentProvider.setNullTestData("application/pdf") + mainSession.loadUri("content://org.mozilla.geckoview.test.provider/pdf") + mainSession.waitForPageStop() + } + } } 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 9ab2d2515f..6b39d410eb 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 @@ -214,8 +214,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", @@ -275,7 +274,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_GEOLOCATION && @@ -302,8 +301,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { return GeckoResult.fromValue(ContentPermission.VALUE_DENY) } @@ -342,7 +340,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_GEOLOCATION && @@ -462,6 +460,7 @@ class PermissionDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, + hasUserGesture: Boolean, ) { for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_TRACKING) { @@ -501,6 +500,7 @@ class PermissionDelegateTest : BaseSessionTest() { assertTrackingProtectionPermission(null) mainSession.loadTestPath(HELLO_HTML_PATH) + mainSession.waitForPageStop() assertTrackingProtectionPermission(ContentPermission.VALUE_DENY) } @@ -515,8 +515,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", @@ -551,7 +550,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION && @@ -587,8 +586,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { return GeckoResult.fromValue(ContentPermission.VALUE_DENY) } }) @@ -617,7 +615,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION && @@ -649,8 +647,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.waitUntilCalled(object : PermissionDelegate { @AssertCalled(count = 2) - override fun onContentPermissionRequest(session: GeckoSession, perm: ContentPermission): - GeckoResult<Int> { + override fun onContentPermissionRequest(session: GeckoSession, perm: ContentPermission): GeckoResult<Int> { val expectedType = if (sessionRule.currentCall.counter == 1) PermissionDelegate.PERMISSION_AUTOPLAY_AUDIBLE else PermissionDelegate.PERMISSION_AUTOPLAY_INAUDIBLE assertThat("Type should match", perm.permission, equalTo(expectedType)) return GeckoResult.fromValue(ContentPermission.VALUE_DENY) @@ -670,8 +667,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", @@ -707,7 +703,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION && @@ -736,8 +732,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", @@ -777,7 +772,7 @@ class PermissionDelegateTest : BaseSessionTest() { session2.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION && @@ -805,8 +800,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", @@ -841,7 +835,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION && @@ -876,8 +870,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", @@ -919,7 +912,7 @@ class PermissionDelegateTest : BaseSessionTest() { mainSession.delegateDuringNextWait(object : NavigationDelegate { @AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { var permFound2 = false for (perm in perms) { if (perm.permission == PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION && @@ -954,8 +947,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", @@ -1000,8 +992,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { return GeckoResult.fromValue(ContentPermission.VALUE_PROMPT) } }) @@ -1026,8 +1017,7 @@ class PermissionDelegateTest : BaseSessionTest() { override fun onContentPermissionRequest( session: GeckoSession, perm: ContentPermission, - ): - GeckoResult<Int> { + ): GeckoResult<Int> { assertThat("URI should match", perm.uri, endsWith(url)) assertThat( "Type should match", 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 3097452da8..f8046ed2ed 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 @@ -33,7 +33,7 @@ class ProgressDelegateTest : BaseSessionTest() { ProgressDelegate, NavigationDelegate { @AssertCalled - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { assertThat("LocationChange is called", url, endsWith(path)) } @@ -448,6 +448,11 @@ class ProgressDelegateTest : BaseSessionTest() { @WithDisplay(width = 400, height = 400) @Test fun saveAndRestoreStateNewSession() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) val helloUri = createTestUrl(HELLO_HTML_PATH) @@ -467,6 +472,7 @@ class ProgressDelegateTest : BaseSessionTest() { session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, + hasUserGesture: Boolean, ) { assertThat("URI should match", url, equalTo(startUri)) } @@ -487,7 +493,7 @@ class ProgressDelegateTest : BaseSessionTest() { session.goBack() session.waitUntilCalled(object : NavigationDelegate { - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { assertThat("History should be preserved", url, equalTo(helloUri)) } }) @@ -511,7 +517,7 @@ class ProgressDelegateTest : BaseSessionTest() { sessionRule.forCallbacksDuringWait(object : NavigationDelegate { @AssertCalled - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<ContentPermission>, hasUserGesture: Boolean) { assertThat("URI should match", url, equalTo(startUri)) } }) @@ -532,6 +538,11 @@ class ProgressDelegateTest : BaseSessionTest() { @WithDisplay(width = 400, height = 400) @Test fun flushSessionState() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) val startUri = createTestUrl(SAVE_STATE_PATH) @@ -568,6 +579,11 @@ class ProgressDelegateTest : BaseSessionTest() { @NullDelegate(GeckoSession.HistoryDelegate::class) @Test fun noHistoryDelegateOnSessionStateChange() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) mainSession.loadTestPath(HELLO_HTML_PATH) 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 6504af8a4c..2b690726f3 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 @@ -277,8 +277,7 @@ class RuntimeSettingsTest : BaseSessionTest() { mainSession.loadUri("about:config") mainSession.waitUntilCalled(object : NavigationDelegate { @AssertCalled - override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): - GeckoResult<String>? { + override fun onLoadError(session: GeckoSession, uri: String?, error: WebRequestError): GeckoResult<String>? { assertThat("about:config should not load.", uri, equalTo("about:config")) return null } 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 cee16f3f4c..f3141c661c 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 @@ -203,6 +203,11 @@ class ScreenshotTest : BaseSessionTest() { @WithDisplay(height = SCREEN_HEIGHT, width = SCREEN_WIDTH) @Test fun capturePixelsWhileSessionDeactivated() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) val screenshotFile = getComparisonScreenshot(SCREEN_WIDTH, SCREEN_HEIGHT) 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 e5e8ec6ce2..d3e52cda6a 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 @@ -393,8 +393,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { override fun onShowClipboardPermissionRequest( session: GeckoSession, perm: ClipboardPermission, - ): - GeckoResult<AllowOrDeny> { + ): GeckoResult<AllowOrDeny> { assertThat( "Type should match", perm.type, @@ -408,8 +407,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { override fun onAlertPrompt( session: GeckoSession, prompt: PromptDelegate.AlertPrompt, - ): - GeckoResult<PromptDelegate.PromptResponse> { + ): GeckoResult<PromptDelegate.PromptResponse> { assertThat("Message should match", "allow", equalTo(prompt.message)) result.complete(null) return GeckoResult.fromValue(prompt.dismiss()) @@ -440,8 +438,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { override fun onShowClipboardPermissionRequest( session: GeckoSession, perm: ClipboardPermission, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "Type should match", perm.type, @@ -454,8 +451,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { override fun onAlertPrompt( session: GeckoSession, prompt: PromptDelegate.AlertPrompt, - ): - GeckoResult<PromptDelegate.PromptResponse> { + ): GeckoResult<PromptDelegate.PromptResponse> { assertThat("Message should match", "deny", equalTo(prompt.message)) result.complete(null) return GeckoResult.fromValue(prompt.dismiss()) @@ -486,8 +482,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { override fun onShowClipboardPermissionRequest( session: GeckoSession, perm: ClipboardPermission, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "Type should match", perm.type, @@ -533,8 +528,7 @@ class SelectionActionDelegateTest : BaseSessionTest() { override fun onShowClipboardPermissionRequest( session: GeckoSession, perm: ClipboardPermission, - ): - GeckoResult<AllowOrDeny>? { + ): GeckoResult<AllowOrDeny>? { assertThat( "Type should match", perm.type, diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TestContentProvider.java b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TestContentProvider.java index 787448a859..b0591b693e 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TestContentProvider.java +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TestContentProvider.java @@ -18,6 +18,7 @@ public class TestContentProvider extends ContentProvider { private static final String LOGTAG = "TestContentProvider"; private static byte[] sTestData; private static String sMimeType; + private static boolean sAllowNullData = false; @Override public boolean onCreate() { @@ -62,7 +63,10 @@ public class TestContentProvider extends ContentProvider { public ParcelFileDescriptor openFile(final Uri uri, final String mode) throws FileNotFoundException { if (sTestData == null) { - throw new FileNotFoundException("No test data for: " + uri); + if (!sAllowNullData) { + throw new FileNotFoundException("No test data for: " + uri); + } + return null; } ParcelFileDescriptor[] pipe = null; @@ -98,6 +102,19 @@ public class TestContentProvider extends ContentProvider { */ public static void setTestData(final byte[] data, final String mimeType) { sTestData = data; + sAllowNullData = false; + sMimeType = mimeType; + } + + /** + * Set null that is used from content resolver but don't throw when calling openFile. + * + * @param data test data + * @param mimeType A mime type of test data. + */ + public static void setNullTestData(final String mimeType) { + sTestData = null; + sAllowNullData = true; sMimeType = mimeType; } } 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 7e4015a246..ca21d0a61d 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 @@ -537,7 +537,8 @@ class TextInputDelegateTest : BaseSessionTest() { "Can commit text (select before)", ic, "foobarfoo", - 5, /* checkGecko */ + 5, + /* checkGecko */ false, ) } @@ -641,7 +642,8 @@ class TextInputDelegateTest : BaseSessionTest() { "Can set new composing region text", ic, "frabar", - 6, /* checkGecko */ + 6, + /* checkGecko */ false, ) @@ -826,7 +828,13 @@ class TextInputDelegateTest : BaseSessionTest() { }.joinToString("") setupContent(content) val ic = mainSession.textInput.onCreateInputConnection(EditorInfo())!! - assertText("Can set large initial text", ic, content, /* checkGecko */ false) + assertText( + "Can set large initial text", + ic, + content, + /* checkGecko */ + false, + ) } @SdkSuppress(minSdkVersion = Build.VERSION_CODES.N_MR1) @@ -1279,6 +1287,25 @@ class TextInputDelegateTest : BaseSessionTest() { assertText("commit abc", ic, "abc") } + // Bug 1837931 - When 2nd commitText uses -1 as newCursorPosition into batch mode, text + // cannot insert correct position. + @WithDisplay(width = 512, height = 512) + // Child process updates require having a display. + @Test + fun inputConnection_multiple_commitText_into_batchEdit() { + setupContent("") + val ic = mainSession.textInput.onCreateInputConnection(EditorInfo())!! + + // Emulate GBoard's InputConnection API calls + ic.beginBatchEdit() + ic.commitText("( ", 1) + ic.commitText(")", -1) + ic.endBatchEdit() + processChildEvents() + + assertText("commit ()", ic, "( )") + } + // Bug 1593683 - Cursor is jumping when using the arrow keys in input field on GBoard @WithDisplay(width = 512, height = 512) // Child process updates require having a display. @@ -1294,7 +1321,14 @@ class TextInputDelegateTest : BaseSessionTest() { pressKey(ic, KeyEvent.KEYCODE_DPAD_LEFT) pressKey(ic, KeyEvent.KEYCODE_DPAD_LEFT) pressKey(ic, KeyEvent.KEYCODE_DPAD_LEFT) - assertSelection("IME caret is moved to top", ic, 0, 0, /* checkGecko */ false) + assertSelection( + "IME caret is moved to top", + ic, + 0, + 0, + /* checkGecko */ + false, + ) setComposingText(ic, "bar", 1) finishComposingText(ic) diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TrackingPermissionService.java b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TrackingPermissionService.java index 141849589e..4b7bcabee5 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TrackingPermissionService.java +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TrackingPermissionService.java @@ -36,7 +36,8 @@ public class TrackingPermissionService extends TestRuntimeService { public void onLocationChange( final @NonNull GeckoSession session, final @Nullable String url, - final @NonNull List<ContentPermission> perms) { + final @NonNull List<ContentPermission> perms, + final @NonNull Boolean hasUserGesture) { for (ContentPermission perm : perms) { if (perm.permission == PermissionDelegate.PERMISSION_TRACKING) { mContentPermission = perm; diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VideoCaptureTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VideoCaptureTest.kt new file mode 100644 index 0000000000..7e1f8b1275 --- /dev/null +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VideoCaptureTest.kt @@ -0,0 +1,58 @@ +package org.mozilla.geckoview.test + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.webrtc.CameraEnumerationAndroid.CaptureFormat +import org.webrtc.CameraEnumerator +import org.webrtc.CameraVideoCapturer +import org.webrtc.CameraVideoCapturer.CameraEventsHandler +import org.webrtc.videoengine.VideoCaptureAndroid + +@RunWith(AndroidJUnit4::class) +@SmallTest +class VideoCaptureTest { + // Always throw exception. + class BadCameraEnumerator : CameraEnumerator { + override fun getDeviceNames(): Array<String?>? { + throw java.lang.RuntimeException("") + } + + override fun isFrontFacing(deviceName: String?): Boolean { + throw java.lang.RuntimeException("") + } + + override fun isBackFacing(deviceName: String?): Boolean { + throw java.lang.RuntimeException("") + } + + override fun isInfrared(deviceName: String?): Boolean { + throw java.lang.RuntimeException("") + } + + override fun getSupportedFormats(deviceName: String?): List<CaptureFormat?>? { + throw java.lang.RuntimeException("") + } + + override fun createCapturer( + deviceName: String?, + eventsHandler: CameraEventsHandler?, + ): CameraVideoCapturer? { + throw java.lang.RuntimeException("") + } + } + + @Test + fun constructWithBadEnumerator() { + val ctr = VideoCaptureAndroid::class.java.getDeclaredConstructors()[0].apply { isAccessible = true } + val capture = ctr.newInstance( + InstrumentationRegistry.getInstrumentation().targetContext, + "my camera", + BadCameraEnumerator(), + ) as VideoCaptureAndroid + assertEquals(false, capture.canCapture()) + } +} 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 126e52da34..702ba4d23b 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 @@ -7,6 +7,7 @@ package org.mozilla.geckoview.test import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers import org.hamcrest.Matchers.greaterThan import org.hamcrest.core.IsEqual.equalTo import org.hamcrest.core.StringEndsWith.endsWith @@ -90,6 +91,14 @@ class WebExtensionTest : BaseSessionTest() { assertTrue(borderify.isBuiltIn) + assertArrayEquals( + arrayOf("*://developer.mozilla.org/*"), + borderify.metaData.optionalOrigins, + ) + assertArrayEquals( + arrayOf("clipboardRead"), + borderify.metaData.optionalPermissions, + ) mainSession.reload() sessionRule.waitForPageStop() @@ -109,6 +118,156 @@ class WebExtensionTest : BaseSessionTest() { assertBodyBorderEqualTo("") } + @Test + fun verifyOptionalAndOriginsPermissionsMV3() { + mainSession.loadUri("https://example.com") + sessionRule.waitForPageStop() + + // First let's check that the color of the border is empty before loading + // the WebExtension + assertBodyBorderEqualTo("") + + // Load the WebExtension that will add a border to the body + val borderify = sessionRule.waitForResult( + controller.installBuiltIn( + "resource://android/assets/web_extensions/borderify-mv3/", + ), + ) + + assertArrayEquals( + arrayOf("clipboardRead"), + borderify.metaData.optionalPermissions, + ) + + val expectedOptionalOrigins = arrayOf( + "*://*.example.com/*", + "*://opt-host-perm.example.com/*", + "*://host-perm.example.com/*", + ) + + expectedOptionalOrigins.sort() + borderify.metaData.optionalOrigins.sort() + + assertArrayEquals( + expectedOptionalOrigins, + borderify.metaData.optionalOrigins, + ) + + mainSession.reload() + sessionRule.waitForPageStop() + + // Check that the WebExtension was applied by checking the border color + assertBodyBorderEqualTo("red") + + // Uninstall WebExtension and check again + sessionRule.waitForResult(controller.uninstall(borderify)) + + mainSession.reload() + sessionRule.waitForPageStop() + + // Check that the WebExtension was not applied after being uninstalled + assertBodyBorderEqualTo("") + } + + @WithDisplay(width = 100, height = 100) + @Test + fun grantedOptionalPermissions() { + sessionRule.setPrefsUntilTestEnd( + mapOf( + "xpinstall.signatures.required" to false, + "extensions.install.requireBuiltInCerts" to false, + "extensions.update.requireBuiltInCerts" to false, + ), + ) + + val extension = sessionRule.waitForResult( + controller.ensureBuiltIn( + "resource://android/assets/web_extensions/optional-permission-request/", + "optional-permission-request@example.com", + ), + ) + + assertEquals("optional-permission-request@example.com", extension.id) + + mainSession.loadUri("${extension.metaData.baseUrl}clickToRequestPermission.html") + sessionRule.waitForPageStop() + + var grantedOptionalPermissions = extension.metaData.grantedOptionalPermissions + var grantedOptionalOrigins = extension.metaData.grantedOptionalOrigins + + assertThat( + "grantedOptionalPermissions must be 0.", + grantedOptionalPermissions.size, + equalTo(0), + ) + assertThat("grantedOptionalOrigins must be 0.", grantedOptionalOrigins.size, equalTo(0)) + + // click triggers permissions.request + mainSession.synthesizeTap(50, 50) + + sessionRule.delegateUntilTestEnd(object : WebExtensionController.PromptDelegate { + override fun onOptionalPrompt( + extension: WebExtension, + permissions: Array<String>, + origins: Array<String>, + ): GeckoResult<AllowOrDeny> { + return GeckoResult.allow() + } + }) + + var result = GeckoResult<String>() + mainSession.webExtensionController.setMessageDelegate( + extension, + object : WebExtension.MessageDelegate { + override fun onMessage( + nativeApp: String, + message: Any, + sender: WebExtension.MessageSender, + ): GeckoResult<Any>? { + result.complete(message as String) + return null + } + }, + "browser", + ) + + result = GeckoResult<String>() + val message = sessionRule.waitForResult(result) + assertThat("Permission request should be accepted.", message, equalTo("true")) + + val updatedExtension = sessionRule.waitForResult( + // Adds "internal:privateBrowsingAllowed" + controller.setAllowedInPrivateBrowsing(extension, true), + ) + + grantedOptionalPermissions = updatedExtension.metaData.grantedOptionalPermissions + grantedOptionalOrigins = updatedExtension.metaData.grantedOptionalOrigins + + assertThat( + "grantedOptionalPermissions must be 1.", + grantedOptionalPermissions.size, + equalTo(1), + ) + assertThat("grantedOptionalOrigins must be 1.", grantedOptionalOrigins.size, equalTo(1)) + assertThat( + "grantedOptionalOrigins must be *://example.com/*.", + grantedOptionalOrigins.first(), + equalTo("*://example.com/*"), + ) + + // geolocation is part of the manifest but not requested/granted. + assertFalse(grantedOptionalPermissions.contains("geolocation")) + + // "internal:privateBrowsingAllowed" must not be part of grantedOptionalPermissions. + assertThat( + "grantedOptionalPermissions must be activeTab.", + grantedOptionalPermissions.first(), + equalTo("activeTab"), + ) + + sessionRule.waitForResult(controller.uninstall(extension)) + } + private fun assertBodyBorderEqualTo(expected: String) { val color = mainSession.evaluateJS("document.body.style.borderColor") assertThat( @@ -1618,6 +1777,11 @@ class WebExtensionTest : BaseSessionTest() { // - verifies that the messages are received when restoring the tab in a fresh session @Test fun testRestoringExtensionPagePreservesMessages() { + // TODO: Bug 1884334 + val geckoPrefs = sessionRule.getPrefs( + "fission.disableSessionHistoryInParent", + ) + assumeThat(geckoPrefs[0] as Boolean, Matchers.equalTo(true)) // TODO: Bug 1837551 assumeThat(sessionRule.env.isFission, equalTo(false)) @@ -2138,7 +2302,7 @@ class WebExtensionTest : BaseSessionTest() { mainSession.waitUntilCalled(object : NavigationDelegate, ProgressDelegate { @GeckoSessionTestRule.AssertCalled(count = 1) - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, hasUserGesture: Boolean) { assertThat( "Url should load example.com first", url, @@ -2160,7 +2324,7 @@ class WebExtensionTest : BaseSessionTest() { val pageStop = GeckoResult<Boolean>() mainSession.delegateUntilTestEnd(object : NavigationDelegate, ProgressDelegate { - override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>) { + override fun onLocationChange(session: GeckoSession, url: String?, perms: MutableList<PermissionDelegate.ContentPermission>, hasUserGesture: Boolean) { 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 469fd049ce..358134313a 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 @@ -31,8 +31,7 @@ class WebNotificationTest : BaseSessionTest() { // Grant "desktop notification" permission mainSession.delegateUntilTestEnd(object : PermissionDelegate { - override fun onContentPermissionRequest(session: GeckoSession, perm: PermissionDelegate.ContentPermission): - GeckoResult<Int>? { + override fun onContentPermissionRequest(session: GeckoSession, perm: PermissionDelegate.ContentPermission): GeckoResult<Int>? { assertThat("Should grant DESKTOP_NOTIFICATIONS permission", perm.permission, equalTo(PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION)) return GeckoResult.fromValue(PermissionDelegate.ContentPermission.VALUE_ALLOW) } @@ -336,7 +335,11 @@ class WebNotificationTest : BaseSessionTest() { // Test that we can serialize a notification val parcel = Parcel.obtain() - notification.writeToParcel(parcel, /* ignored */ -1) + notification.writeToParcel( + parcel, + /* ignored */ + -1, + ) assertThat("Promise should have been resolved.", promiseResult.value as Double, equalTo(1.0)) } @@ -375,7 +378,11 @@ class WebNotificationTest : BaseSessionTest() { // Test that we can serialize a notification with an imageUrl.length >= 150 val parcel = Parcel.obtain() - notification.writeToParcel(parcel, /* ignored */ -1) + notification.writeToParcel( + parcel, + /* ignored */ + -1, + ) parcel.setDataPosition(0) val serializedNotification = WebNotification.CREATOR.createFromParcel(parcel) 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 a2e6d58f3a..609275526c 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 @@ -60,8 +60,7 @@ class WebPushTest : BaseSessionTest() { sessionRule.setPrefsUntilTestEnd(mapOf("dom.webnotifications.requireuserinteraction" to false)) // Grant "desktop notification" permission mainSession.delegateUntilTestEnd(object : PermissionDelegate { - override fun onContentPermissionRequest(session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): - GeckoResult<Int>? { + override fun onContentPermissionRequest(session: GeckoSession, perm: GeckoSession.PermissionDelegate.ContentPermission): GeckoResult<Int>? { assertThat("Should grant DESKTOP_NOTIFICATIONS permission", perm.permission, equalTo(GeckoSession.PermissionDelegate.PERMISSION_DESKTOP_NOTIFICATION)) return GeckoResult.fromValue(GeckoSession.PermissionDelegate.ContentPermission.VALUE_ALLOW) } 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 9c9a9d6188..727f403931 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 @@ -831,7 +831,8 @@ public class GeckoSessionTestRule implements TestRule { public void onLocationChange( @NonNull GeckoSession session, @Nullable String url, - @NonNull List<ContentPermission> perms) {} + @NonNull List<ContentPermission> perms, + @NonNull Boolean hasUserGesture) {} @Override public void onShutdown() {} |