summaryrefslogtreecommitdiffstats
path: root/mobile/android/focus-android/app/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/focus-android/app/src/test')
-rw-r--r--mobile/android/focus-android/app/src/test/java/org/mozilla/focus/TestFocusApplication.kt11
-rw-r--r--mobile/android/focus-android/app/src/test/java/org/mozilla/focus/browser/integration/FullScreenIntegrationTest.kt134
-rw-r--r--mobile/android/focus-android/app/src/test/resources/robolectric.properties2
3 files changed, 142 insertions, 5 deletions
diff --git a/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/TestFocusApplication.kt b/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/TestFocusApplication.kt
index 7892c347b6..94f2410913 100644
--- a/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/TestFocusApplication.kt
+++ b/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/TestFocusApplication.kt
@@ -32,6 +32,10 @@ class TestFocusApplication : FocusApplication() {
}
override fun initializeNimbus() = Unit
+ override fun initializeTelemetry() = Unit
+ override fun finishSetupMegazord() = Unit
+
+ override fun initializeWebExtensionSupport() = Unit
}
/**
@@ -50,6 +54,13 @@ class FakeEngine : Engine {
override val version: EngineVersion
get() = throw NotImplementedError("Not needed for test")
+ override fun isTranslationsEngineSupported(
+ onSuccess: (Boolean) -> Unit,
+ onError: (Throwable) -> Unit,
+ ) {
+ // do nothing
+ }
+
override fun createView(context: Context, attrs: AttributeSet?): EngineView =
throw UnsupportedOperationException()
diff --git a/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/browser/integration/FullScreenIntegrationTest.kt b/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/browser/integration/FullScreenIntegrationTest.kt
index 3f9d9270c4..69b7a031b4 100644
--- a/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/browser/integration/FullScreenIntegrationTest.kt
+++ b/mobile/android/focus-android/app/src/test/java/org/mozilla/focus/browser/integration/FullScreenIntegrationTest.kt
@@ -8,7 +8,9 @@ import android.app.Activity
import android.content.res.Resources
import android.view.View
import android.view.Window
+import android.view.WindowInsetsController
import android.view.WindowManager
+import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import mozilla.components.browser.engine.gecko.GeckoEngineView
import mozilla.components.browser.toolbar.BrowserToolbar
@@ -33,6 +35,7 @@ import org.mozilla.focus.ext.showAsFixed
import org.mozilla.focus.utils.Settings
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
internal class FullScreenIntegrationTest {
@@ -128,7 +131,8 @@ internal class FullScreenIntegrationTest {
@Test
@Suppress("DEPRECATION")
- fun `WHEN entering immersive mode THEN hide all system bars`() {
+ @Config(sdk = [28])
+ fun `WHEN entering immersive mode THEN hide all system bars in SDK 28`() {
val decorView: View = mock()
val activityWindow: Window = mock()
val activity: Activity = mock()
@@ -159,8 +163,50 @@ internal class FullScreenIntegrationTest {
}
@Test
+ fun `WHEN entering immersive mode THEN hide all system bars`() {
+ val decorView: View = mock()
+ val activityWindow: Window = mock()
+ val activity: Activity = mock()
+ val layoutParams = WindowManager.LayoutParams()
+ val insetsController: WindowInsetsController = mock()
+
+ doReturn(activityWindow).`when`(activity).window
+ doReturn(decorView).`when`(activityWindow).decorView
+ doReturn(layoutParams).`when`(activityWindow).attributes
+ doReturn(insetsController).`when`(activityWindow).insetsController
+
+ val integration = FullScreenIntegration(
+ activity,
+ mock(),
+ null,
+ mock(),
+ mock(),
+ mock(),
+ mock(),
+ mock(),
+ mock(),
+ )
+
+ integration.switchToImmersiveMode()
+
+ // verify hiding system bars
+ verify(insetsController).hide(WindowInsetsCompat.Type.systemBars())
+
+ verify(activityWindow).setFlags(
+ WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
+ WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
+ )
+
+ assertEquals(
+ WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES,
+ layoutParams.layoutInDisplayCutoutMode,
+ )
+ }
+
+ @Test
@Suppress("DEPRECATION")
- fun `GIVEN immersive mode WHEN exitImmersiveModeIfNeeded is called THEN show the system bars`() {
+ @Config(sdk = [28])
+ fun `GIVEN immersive mode WHEN exitImmersiveModeIfNeeded is called THEN show the system bars on SDK 28`() {
val decorView: View = mock()
val activityWindow: Window = mock()
val activity: Activity = mock()
@@ -189,6 +235,43 @@ internal class FullScreenIntegrationTest {
}
@Test
+ fun `GIVEN immersive mode WHEN exitImmersiveModeIfNeeded is called THEN show the system bars`() {
+ val decorView: View = mock()
+ val activityWindow: Window = mock()
+ val activity: Activity = mock()
+ val layoutParams = WindowManager.LayoutParams()
+ val insetsController: WindowInsetsController = mock()
+
+ doReturn(activityWindow).`when`(activity).window
+ doReturn(decorView).`when`(activityWindow).decorView
+ doReturn(layoutParams).`when`(activityWindow).attributes
+ doReturn(insetsController).`when`(activityWindow).insetsController
+
+ val integration = FullScreenIntegration(
+ activity,
+ mock(),
+ null,
+ mock(),
+ mock(),
+ mock(),
+ mock(),
+ mock(),
+ mock(),
+ )
+
+ integration.exitImmersiveMode()
+
+ verify(insetsController).show(WindowInsetsCompat.Type.systemBars())
+ verify(decorView).setOnApplyWindowInsetsListener(null)
+ verify(activityWindow).clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
+
+ assertEquals(
+ WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT,
+ layoutParams.layoutInDisplayCutoutMode,
+ )
+ }
+
+ @Test
fun `GIVEN a11y is enabled WHEN enterBrowserFullscreen THEN hide the toolbar`() {
val toolbar: BrowserToolbar = mock()
val engineView: GeckoEngineView = mock()
@@ -335,7 +418,8 @@ internal class FullScreenIntegrationTest {
}
@Test
- fun `WHEN exiting fullscreen THEN put browser in fullscreen, hide system bars and enter immersive mode`() {
+ @Config(sdk = [28])
+ fun `WHEN exiting fullscreen THEN put browser in fullscreen, hide system bars and enter immersive mode in SDK 28`() {
val toolbar: BrowserToolbar = mock()
val engineView: GeckoEngineView = mock()
doReturn(mock<View>()).`when`(engineView).asView()
@@ -371,4 +455,48 @@ internal class FullScreenIntegrationTest {
verify(integration).exitImmersiveMode()
verify(statusBar).isVisible = true
}
+
+ @Test
+ fun `WHEN exiting fullscreen THEN put browser in fullscreen, hide system bars and enter immersive mode in`() {
+ val toolbar: BrowserToolbar = mock()
+ val engineView: GeckoEngineView = mock()
+ doReturn(mock<View>()).`when`(engineView).asView()
+
+ val settings: Settings = mock()
+ doReturn(false).`when`(settings).isAccessibilityEnabled()
+
+ val resources: Resources = mock()
+ val activityWindow: Window = mock()
+ val decorView: View = mock()
+ val windowAttributes = WindowManager.LayoutParams()
+ val activity: Activity = mock()
+ val insetsController: WindowInsetsController = mock()
+
+ doReturn(activityWindow).`when`(activity).window
+ doReturn(decorView).`when`(activityWindow).decorView
+ doReturn(windowAttributes).`when`(activityWindow).attributes
+ doReturn(resources).`when`(activity).resources
+ doReturn(insetsController).`when`(activityWindow).insetsController
+
+ val statusBar: View = mock()
+ val integration = spy(
+ FullScreenIntegration(
+ activity,
+ mock(),
+ null,
+ mock(),
+ settings,
+ toolbar,
+ statusBar,
+ engineView,
+ mock(),
+ ),
+ )
+
+ integration.fullScreenChanged(false)
+
+ verify(integration).exitBrowserFullscreen()
+ verify(integration).exitImmersiveMode()
+ verify(statusBar).isVisible = true
+ }
}
diff --git a/mobile/android/focus-android/app/src/test/resources/robolectric.properties b/mobile/android/focus-android/app/src/test/resources/robolectric.properties
index 4359826c57..05f43c0edf 100644
--- a/mobile/android/focus-android/app/src/test/resources/robolectric.properties
+++ b/mobile/android/focus-android/app/src/test/resources/robolectric.properties
@@ -1,3 +1 @@
-# Needed until Robolectric supports SDK 29+
-sdk=28
application=org.mozilla.focus.EmptyFocusApplication