mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/19738 - Adds tests for SecureTabsTrayBinding.kt
This commit is contained in:
parent
d113daa53f
commit
3b5e51d2ee
@ -4,6 +4,7 @@
|
||||
|
||||
package org.mozilla.fenix.tabstray
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
@ -21,7 +22,7 @@ import org.mozilla.fenix.utils.Settings
|
||||
class SecureTabsTrayBinding(
|
||||
store: TabsTrayStore,
|
||||
private val settings: Settings,
|
||||
private val tabsTrayFragment: TabsTrayFragment
|
||||
private val fragment: Fragment
|
||||
) : AbstractBinding<TabsTrayState>(store) {
|
||||
|
||||
override suspend fun onState(flow: Flow<TabsTrayState>) {
|
||||
@ -33,9 +34,9 @@ class SecureTabsTrayBinding(
|
||||
}
|
||||
.collect { state ->
|
||||
if (state.selectedPage == Page.PrivateTabs) {
|
||||
tabsTrayFragment.secure()
|
||||
fragment.secure()
|
||||
} else if (!settings.lastKnownMode.isPrivate) {
|
||||
tabsTrayFragment.removeSecure()
|
||||
fragment.removeSecure()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ class TabsTrayFragment : AppCompatDialogFragment() {
|
||||
feature = SecureTabsTrayBinding(
|
||||
store = tabsTrayStore,
|
||||
settings = requireComponents.settings,
|
||||
tabsTrayFragment = this
|
||||
fragment = this
|
||||
),
|
||||
owner = this,
|
||||
view = view
|
||||
|
@ -0,0 +1,92 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.tabstray
|
||||
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.fragment.app.Fragment
|
||||
import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||
import mozilla.components.support.test.libstate.ext.waitUntilIdle
|
||||
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.ext.removeSecure
|
||||
import org.mozilla.fenix.ext.secure
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
class SecureTabsTrayBindingTest {
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@get:Rule
|
||||
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
|
||||
|
||||
private val settings: Settings = mockk(relaxed = true)
|
||||
private val fragment: Fragment = mockk(relaxed = true)
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockkStatic(AppCompatResources::class)
|
||||
every { AppCompatResources.getDrawable(any(), any()) } returns mockk(relaxed = true)
|
||||
every { fragment.secure() } just Runs
|
||||
every { fragment.removeSecure() } just Runs
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `WHEN tab selected page switches to private THEN set fragment to secure`() {
|
||||
val tabsTrayStore = TabsTrayStore(TabsTrayState())
|
||||
val secureTabsTrayBinding = SecureTabsTrayBinding(
|
||||
store = tabsTrayStore,
|
||||
settings = settings,
|
||||
fragment = fragment
|
||||
)
|
||||
|
||||
secureTabsTrayBinding.start()
|
||||
tabsTrayStore.dispatch(TabsTrayAction.PageSelected(Page.positionToPage(Page.PrivateTabs.ordinal)))
|
||||
tabsTrayStore.waitUntilIdle()
|
||||
|
||||
verify { fragment.secure() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN not in private mode WHEN tab selected page switches to normal tabs from private THEN set fragment to un-secure`() {
|
||||
every { settings.lastKnownMode.isPrivate } returns false
|
||||
val tabsTrayStore = TabsTrayStore(TabsTrayState())
|
||||
val secureTabsTrayBinding = SecureTabsTrayBinding(
|
||||
store = tabsTrayStore,
|
||||
settings = settings,
|
||||
fragment = fragment
|
||||
)
|
||||
|
||||
secureTabsTrayBinding.start()
|
||||
tabsTrayStore.dispatch(TabsTrayAction.PageSelected(Page.positionToPage(Page.NormalTabs.ordinal)))
|
||||
tabsTrayStore.waitUntilIdle()
|
||||
|
||||
verify { fragment.removeSecure() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN private mode WHEN tab selected page switches to normal tabs from private THEN do nothing`() {
|
||||
every { settings.lastKnownMode.isPrivate } returns true
|
||||
val tabsTrayStore = TabsTrayStore(TabsTrayState())
|
||||
val secureTabsTrayBinding = SecureTabsTrayBinding(
|
||||
store = tabsTrayStore,
|
||||
settings = settings,
|
||||
fragment = fragment
|
||||
)
|
||||
|
||||
secureTabsTrayBinding.start()
|
||||
tabsTrayStore.dispatch(TabsTrayAction.PageSelected(Page.positionToPage(Page.NormalTabs.ordinal)))
|
||||
tabsTrayStore.waitUntilIdle()
|
||||
|
||||
verify(exactly = 0) { fragment.removeSecure() }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user