mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/19135 - Set different offsets for expanded trays
As in the previous version of tabs tray when tray is expanded while in portrait it should have a 40dp offset and when the tray is expanded while in landscape it should have a 0dp offset - effectively making it fullscreen. These values were set in code, always overriding the xml set value so I removed that xml declaration.
This commit is contained in:
parent
74a14fe91c
commit
65f75412cd
@ -5,11 +5,16 @@
|
||||
package org.mozilla.fenix.tabstray
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.View
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN
|
||||
import mozilla.components.support.ktx.android.util.dpToPx
|
||||
|
||||
@VisibleForTesting internal const val EXPANDED_OFFSET_IN_LANDSCAPE_DP = 0
|
||||
@VisibleForTesting internal const val EXPANDED_OFFSET_IN_PORTRAIT_DP = 40
|
||||
|
||||
/**
|
||||
* Helper class for updating how the tray looks and behaves depending on app state / internal tray state.
|
||||
@ -19,13 +24,15 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN
|
||||
* @param maxNumberOfTabs highest number of tabs in each tray page.
|
||||
* @param numberForExpandingTray limit depending on which the tray should be collapsed or expanded.
|
||||
* @param navigationInteractor [NavigationInteractor] used for tray updates / navigation.
|
||||
* @param displayMetrics [DisplayMetrics] used for adapting resources to the current display.
|
||||
*/
|
||||
internal class TabSheetBehaviorManager(
|
||||
private val behavior: BottomSheetBehavior<ConstraintLayout>,
|
||||
orientation: Int,
|
||||
private val maxNumberOfTabs: Int,
|
||||
private val numberForExpandingTray: Int,
|
||||
navigationInteractor: NavigationInteractor
|
||||
navigationInteractor: NavigationInteractor,
|
||||
private val displayMetrics: DisplayMetrics
|
||||
) {
|
||||
@VisibleForTesting
|
||||
internal var currentOrientation = orientation
|
||||
@ -35,7 +42,9 @@ internal class TabSheetBehaviorManager(
|
||||
TraySheetBehaviorCallback(behavior, navigationInteractor)
|
||||
)
|
||||
|
||||
updateBehaviorState(isLandscape(orientation))
|
||||
val isInLandscape = isLandscape(orientation)
|
||||
updateBehaviorExpandedOffset(isInLandscape)
|
||||
updateBehaviorState(isInLandscape)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,6 +55,7 @@ internal class TabSheetBehaviorManager(
|
||||
currentOrientation = newOrientation
|
||||
|
||||
val isInLandscape = isLandscape(newOrientation)
|
||||
updateBehaviorExpandedOffset(isInLandscape)
|
||||
updateBehaviorState(isInLandscape)
|
||||
}
|
||||
}
|
||||
@ -59,6 +69,15 @@ internal class TabSheetBehaviorManager(
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun updateBehaviorExpandedOffset(isLandscape: Boolean) {
|
||||
behavior.expandedOffset = if (isLandscape) {
|
||||
EXPANDED_OFFSET_IN_LANDSCAPE_DP.dpToPx(displayMetrics)
|
||||
} else {
|
||||
EXPANDED_OFFSET_IN_PORTRAIT_DP.dpToPx(displayMetrics)
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun isLandscape(orientation: Int) = Configuration.ORIENTATION_LANDSCAPE == orientation
|
||||
}
|
||||
|
@ -170,7 +170,8 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
||||
} else {
|
||||
EXPAND_AT_LIST_SIZE
|
||||
},
|
||||
navigationInteractor = navigationInteractor
|
||||
navigationInteractor = navigationInteractor,
|
||||
displayMetrics = requireContext().resources.displayMetrics
|
||||
)
|
||||
|
||||
tabsTrayCtaBinding.set(
|
||||
|
@ -623,7 +623,6 @@
|
||||
<style name="BottomSheetModal" parent="Widget.Design.BottomSheet.Modal">
|
||||
<item name="shapeAppearance">@style/BottomSheetShapeAppearance</item>
|
||||
<item name="behavior_fitToContents">false</item>
|
||||
<item name="behavior_expandedOffset">80dp</item>
|
||||
<item name="behavior_skipCollapsed">false</item>
|
||||
<!-- Effectively disable STATE_HALF_EXPANDED by having the tray have a minuscule height in this state -->
|
||||
<item name="behavior_halfExpandedRatio">0.001</item>
|
||||
|
@ -5,8 +5,8 @@
|
||||
package org.mozilla.fenix.tabstray
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.util.DisplayMetrics
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.paging.Config
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_DRAGGING
|
||||
@ -15,11 +15,14 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HALF_EX
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_SETTLING
|
||||
import io.mockk.Called
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.slot
|
||||
import io.mockk.spyk
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import mozilla.components.support.ktx.android.util.dpToPx
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertSame
|
||||
@ -69,7 +72,7 @@ class TabSheetBehaviorManagerTest {
|
||||
val navigationInteractor: NavigationInteractor = mockk()
|
||||
val callbackCaptor = slot<TraySheetBehaviorCallback>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 2, 2, navigationInteractor)
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 2, 2, navigationInteractor, mockk())
|
||||
|
||||
verify { behavior.addBottomSheetCallback(capture(callbackCaptor)) }
|
||||
assertSame(behavior, callbackCaptor.captured.behavior)
|
||||
@ -78,13 +81,13 @@ class TabSheetBehaviorManagerTest {
|
||||
|
||||
@Test
|
||||
fun `WHEN TabSheetBehaviorManager is initialized THEN it caches the orientation parameter value`() {
|
||||
val manager0 = TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk())
|
||||
val manager0 = TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk(), mockk())
|
||||
assertEquals(Configuration.ORIENTATION_UNDEFINED, manager0.currentOrientation)
|
||||
|
||||
val manager1 = TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 5, 4, mockk(relaxed = true))
|
||||
val manager1 = TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 5, 4, mockk(relaxed = true), mockk())
|
||||
assertEquals(Configuration.ORIENTATION_PORTRAIT, manager1.currentOrientation)
|
||||
|
||||
val manager2 = TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_LANDSCAPE, 5, 4, mockk())
|
||||
val manager2 = TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_LANDSCAPE, 5, 4, mockk(), mockk())
|
||||
assertEquals(Configuration.ORIENTATION_LANDSCAPE, manager2.currentOrientation)
|
||||
}
|
||||
|
||||
@ -92,7 +95,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN more tabs opened than the expanding limit and portrait orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_PORTRAIT, 5, 4, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_PORTRAIT, 5, 4, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_EXPANDED, behavior.state)
|
||||
}
|
||||
@ -101,7 +104,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN the number of tabs opened is exactly the expanding limit and portrait orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_PORTRAIT, 5, 5, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_PORTRAIT, 5, 5, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_EXPANDED, behavior.state)
|
||||
}
|
||||
@ -110,7 +113,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN fewer tabs opened than the expanding limit and portrait orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as collapsed`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_COLLAPSED, behavior.state)
|
||||
}
|
||||
@ -119,7 +122,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN more tabs opened than the expanding limit and undefined orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_EXPANDED, behavior.state)
|
||||
}
|
||||
@ -128,7 +131,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN the number of tabs opened is exactly the expanding limit and undefined orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 5, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 5, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_EXPANDED, behavior.state)
|
||||
}
|
||||
@ -137,7 +140,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN fewer tabs opened than the expanding limit and undefined orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as collapsed`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 4, 5, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 4, 5, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_COLLAPSED, behavior.state)
|
||||
}
|
||||
@ -146,7 +149,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN more tabs opened than the expanding limit and landscape orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 5, 4, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 5, 4, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_EXPANDED, behavior.state)
|
||||
}
|
||||
@ -155,7 +158,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN the number of tabs opened is exactly the expanding limit and landscape orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 5, 5, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 5, 5, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_EXPANDED, behavior.state)
|
||||
}
|
||||
@ -164,7 +167,7 @@ class TabSheetBehaviorManagerTest {
|
||||
fun `GIVEN fewer tabs opened than the expanding limit and landscape orientation WHEN TabSheetBehaviorManager is initialized THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 4, 5, mockk())
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 4, 5, mockk(), mockk())
|
||||
|
||||
assertEquals(STATE_EXPANDED, behavior.state)
|
||||
}
|
||||
@ -172,7 +175,7 @@ class TabSheetBehaviorManagerTest {
|
||||
@Test
|
||||
fun `GIVEN more tabs opened than the expanding limit and not landscape orientation WHEN updateBehaviorState is called THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk())
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk(), mockk())
|
||||
|
||||
manager.updateBehaviorState(false)
|
||||
|
||||
@ -182,7 +185,7 @@ class TabSheetBehaviorManagerTest {
|
||||
@Test
|
||||
fun `GIVEN the number of tabs opened is exactly the expanding limit and portrait orientation WHEN updateBehaviorState is called THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 5, mockk())
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 5, mockk(), mockk())
|
||||
|
||||
manager.updateBehaviorState(false)
|
||||
|
||||
@ -192,7 +195,7 @@ class TabSheetBehaviorManagerTest {
|
||||
@Test
|
||||
fun `GIVEN fewer tabs opened than the expanding limit and portrait orientation WHEN updateBehaviorState is called THEN the behavior is set as collapsed`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 4, 5, mockk())
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 4, 5, mockk(), mockk())
|
||||
|
||||
manager.updateBehaviorState(false)
|
||||
|
||||
@ -202,7 +205,7 @@ class TabSheetBehaviorManagerTest {
|
||||
@Test
|
||||
fun `GIVEN more tabs opened than the expanding limit and landscape orientation WHEN updateBehaviorState is called THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk())
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk(), mockk())
|
||||
|
||||
manager.updateBehaviorState(true)
|
||||
|
||||
@ -212,7 +215,7 @@ class TabSheetBehaviorManagerTest {
|
||||
@Test
|
||||
fun `GIVEN the number of tabs opened is exactly the expanding limit and landscape orientation WHEN updateBehaviorState is called THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 5, mockk())
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 5, mockk(), mockk())
|
||||
|
||||
manager.updateBehaviorState(true)
|
||||
|
||||
@ -222,7 +225,7 @@ class TabSheetBehaviorManagerTest {
|
||||
@Test
|
||||
fun `GIVEN fewer tabs opened than the expanding limit and landscape orientation WHEN updateBehaviorState is called THEN the behavior is set as expanded`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 4, 5, mockk())
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 4, 5, mockk(), mockk())
|
||||
|
||||
manager.updateBehaviorState(true)
|
||||
|
||||
@ -231,45 +234,165 @@ class TabSheetBehaviorManagerTest {
|
||||
|
||||
@Test
|
||||
fun `WHEN updateDependingOnOrientation is called with the same orientation as the current one THEN nothing happens`() {
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk()))
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk(), mockk()))
|
||||
|
||||
manager.updateDependingOnOrientation(Configuration.ORIENTATION_PORTRAIT)
|
||||
|
||||
verify(exactly = 0) { manager.currentOrientation = any() }
|
||||
verify(exactly = 0) { manager.updateBehaviorExpandedOffset(any()) }
|
||||
verify(exactly = 0) { manager.updateBehaviorState(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN updateDependingOnOrientation is called with a new orientation THEN this is cached and updateBehaviorState is called`() {
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk()))
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk(), mockk()))
|
||||
|
||||
manager.updateDependingOnOrientation(Configuration.ORIENTATION_UNDEFINED)
|
||||
assertEquals(Configuration.ORIENTATION_UNDEFINED, manager.currentOrientation)
|
||||
verify { manager.updateBehaviorExpandedOffset(any()) }
|
||||
verify { manager.updateBehaviorState(any()) }
|
||||
|
||||
manager.updateDependingOnOrientation(Configuration.ORIENTATION_LANDSCAPE)
|
||||
assertEquals(Configuration.ORIENTATION_LANDSCAPE, manager.currentOrientation)
|
||||
verify(exactly = 2) { manager.updateBehaviorExpandedOffset(any()) }
|
||||
verify(exactly = 2) { manager.updateBehaviorState(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN isLandscape is called with Configuration#ORIENTATION_LANDSCAPE THEN it returns true`() {
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk()))
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk(), mockk()))
|
||||
|
||||
assertTrue(manager.isLandscape(Configuration.ORIENTATION_LANDSCAPE))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN isLandscape is called with Configuration#ORIENTATION_PORTRAIT THEN it returns false`() {
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk()))
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk(), mockk()))
|
||||
|
||||
assertFalse(manager.isLandscape(Configuration.ORIENTATION_PORTRAIT))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN isLandscape is called with Configuration#ORIENTATION_UNDEFINED THEN it returns false`() {
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk()))
|
||||
val manager = spyk(TabSheetBehaviorManager(mockk(relaxed = true), Configuration.ORIENTATION_PORTRAIT, 4, 5, mockk(), mockk()))
|
||||
|
||||
assertFalse(manager.isLandscape(Configuration.ORIENTATION_UNDEFINED))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a behavior and landscape orientation WHEN TabSheetBehaviorManager is initialized THEN it sets the behavior expandedOffset to 0`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
// expandedOffset is only used if isFitToContents == false
|
||||
behavior.isFitToContents = false
|
||||
val displayMetrics: DisplayMetrics = mockk()
|
||||
|
||||
try {
|
||||
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
every { EXPANDED_OFFSET_IN_LANDSCAPE_DP.dpToPx(displayMetrics) } returns EXPANDED_OFFSET_IN_LANDSCAPE_DP
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 5, 4, mockk(), displayMetrics)
|
||||
} finally {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
}
|
||||
|
||||
assertEquals(0, behavior.expandedOffset)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a behavior and portrait orientation WHEN TabSheetBehaviorManager is initialized THEN it sets the behavior expandedOffset to 40`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
// expandedOffset is only used if isFitToContents == false
|
||||
behavior.isFitToContents = false
|
||||
val displayMetrics: DisplayMetrics = mockk()
|
||||
|
||||
try {
|
||||
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
every { EXPANDED_OFFSET_IN_PORTRAIT_DP.dpToPx(displayMetrics) } returns EXPANDED_OFFSET_IN_PORTRAIT_DP
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_PORTRAIT, 5, 4, mockk(), displayMetrics)
|
||||
} finally {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
}
|
||||
|
||||
assertEquals(40, behavior.expandedOffset)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN a behavior and undefined orientation WHEN TabSheetBehaviorManager is initialized THEN it sets the behavior expandedOffset to 40`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
// expandedOffset is only used if isFitToContents == false
|
||||
behavior.isFitToContents = false
|
||||
val displayMetrics: DisplayMetrics = mockk()
|
||||
|
||||
try {
|
||||
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
every { EXPANDED_OFFSET_IN_PORTRAIT_DP.dpToPx(displayMetrics) } returns EXPANDED_OFFSET_IN_PORTRAIT_DP
|
||||
|
||||
TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk(), displayMetrics)
|
||||
} finally {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
}
|
||||
|
||||
assertEquals(40, behavior.expandedOffset)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN updateBehaviorExpandedOffset is called with a portrait parameter THEN it sets expandedOffset to be 40 dp`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
// expandedOffset is only used if isFitToContents == false
|
||||
behavior.isFitToContents = false
|
||||
val displayMetrics: DisplayMetrics = mockk()
|
||||
|
||||
try {
|
||||
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
every { EXPANDED_OFFSET_IN_PORTRAIT_DP.dpToPx(displayMetrics) } returns EXPANDED_OFFSET_IN_PORTRAIT_DP
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 5, 4, mockk(), displayMetrics)
|
||||
|
||||
manager.updateDependingOnOrientation(Configuration.ORIENTATION_PORTRAIT)
|
||||
} finally {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
}
|
||||
|
||||
assertEquals(40, behavior.expandedOffset)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN updateBehaviorExpandedOffset is called with a undefined parameter THEN it sets expandedOffset to be 40 dp`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
// expandedOffset is only used if isFitToContents == false
|
||||
behavior.isFitToContents = false
|
||||
val displayMetrics: DisplayMetrics = mockk()
|
||||
|
||||
try {
|
||||
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
every { EXPANDED_OFFSET_IN_PORTRAIT_DP.dpToPx(displayMetrics) } returns EXPANDED_OFFSET_IN_PORTRAIT_DP
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_LANDSCAPE, 5, 4, mockk(), displayMetrics)
|
||||
|
||||
manager.updateDependingOnOrientation(Configuration.ORIENTATION_UNDEFINED)
|
||||
} finally {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
}
|
||||
|
||||
assertEquals(40, behavior.expandedOffset)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN updateBehaviorExpandedOffset is called with a landscape parameter THEN it sets expandedOffset to be 0 dp`() {
|
||||
val behavior = BottomSheetBehavior<ConstraintLayout>()
|
||||
// expandedOffset is only used if isFitToContents == false
|
||||
behavior.isFitToContents = false
|
||||
val displayMetrics: DisplayMetrics = mockk()
|
||||
|
||||
try {
|
||||
mockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
every { EXPANDED_OFFSET_IN_LANDSCAPE_DP.dpToPx(displayMetrics) } returns EXPANDED_OFFSET_IN_LANDSCAPE_DP
|
||||
val manager = TabSheetBehaviorManager(behavior, Configuration.ORIENTATION_UNDEFINED, 5, 4, mockk(), displayMetrics)
|
||||
|
||||
manager.updateDependingOnOrientation(Configuration.ORIENTATION_LANDSCAPE)
|
||||
} finally {
|
||||
unmockkStatic("mozilla.components.support.ktx.android.util.DisplayMetricsKt")
|
||||
}
|
||||
|
||||
assertEquals(0, behavior.expandedOffset)
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package org.mozilla.fenix.tabstray
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.ImageButton
|
||||
@ -16,6 +17,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import io.mockk.Runs
|
||||
@ -35,6 +37,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import mozilla.components.browser.menu.BrowserMenu
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Before
|
||||
@ -356,4 +359,15 @@ class TabsTrayFragmentTest {
|
||||
|
||||
verify { trayBehaviorManager.updateDependingOnOrientation(newConfiguration.orientation) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN the tabs tray is declared in XML THEN certain options are set for the behavior`() {
|
||||
val view: View = LayoutInflater.from(testContext)
|
||||
.inflate(R.layout.component_tabstray2, CoordinatorLayout(testContext), true)
|
||||
val behavior = BottomSheetBehavior.from(view.tab_wrapper)
|
||||
|
||||
Assert.assertFalse(behavior.isFitToContents)
|
||||
Assert.assertFalse(behavior.skipCollapsed)
|
||||
assert(behavior.halfExpandedRatio <= 0.001f)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user