2
0
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/20250 - Adds FLAG_SECURE to TabsTray dialog

This commit is contained in:
codrut.topliceanu 2021-07-06 09:20:28 +03:00 committed by mergify[bot]
parent c805dd3320
commit ae19555d25
3 changed files with 26 additions and 6 deletions

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.tabstray
import android.view.WindowManager
import androidx.fragment.app.Fragment
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
@ -22,7 +23,8 @@ import org.mozilla.fenix.utils.Settings
class SecureTabsTrayBinding(
store: TabsTrayStore,
private val settings: Settings,
private val fragment: Fragment
private val fragment: Fragment,
private val dialog: TabsTrayDialog
) : AbstractBinding<TabsTrayState>(store) {
override suspend fun onState(flow: Flow<TabsTrayState>) {
@ -36,8 +38,10 @@ class SecureTabsTrayBinding(
if (state.selectedPage == Page.PrivateTabs &&
!settings.allowScreenshotsInPrivateMode) {
fragment.secure()
dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else if (!settings.lastKnownMode.isPrivate) {
fragment.removeSecure()
dialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
}

View File

@ -278,7 +278,8 @@ class TabsTrayFragment : AppCompatDialogFragment() {
feature = SecureTabsTrayBinding(
store = tabsTrayStore,
settings = requireComponents.settings,
fragment = this
fragment = this,
dialog = dialog as TabsTrayDialog
),
owner = this,
view = view

View File

@ -4,6 +4,8 @@
package org.mozilla.fenix.tabstray
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.content.res.AppCompatResources
import androidx.fragment.app.Fragment
import io.mockk.Runs
@ -31,6 +33,8 @@ class SecureTabsTrayBindingTest {
private val settings: Settings = mockk(relaxed = true)
private val fragment: Fragment = mockk(relaxed = true)
private val dialog: TabsTrayDialog = mockk(relaxed = true)
private val window: Window = mockk(relaxed = true)
@Before
fun setup() {
@ -38,6 +42,9 @@ class SecureTabsTrayBindingTest {
every { AppCompatResources.getDrawable(any(), any()) } returns mockk(relaxed = true)
every { fragment.secure() } just Runs
every { fragment.removeSecure() } just Runs
every { dialog.window } returns window
every { window.addFlags(any()) } just Runs
every { window.clearFlags(any()) } just Runs
}
@Test
@ -46,7 +53,8 @@ class SecureTabsTrayBindingTest {
val secureTabsTrayBinding = SecureTabsTrayBinding(
store = tabsTrayStore,
settings = settings,
fragment = fragment
fragment = fragment,
dialog = dialog
)
secureTabsTrayBinding.start()
@ -54,6 +62,7 @@ class SecureTabsTrayBindingTest {
tabsTrayStore.waitUntilIdle()
verify { fragment.secure() }
verify { window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) }
}
@Test
@ -62,7 +71,8 @@ class SecureTabsTrayBindingTest {
val secureTabsTrayBinding = SecureTabsTrayBinding(
store = tabsTrayStore,
settings = settings,
fragment = fragment
fragment = fragment,
dialog = dialog
)
every { settings.allowScreenshotsInPrivateMode } returns true
@ -71,6 +81,7 @@ class SecureTabsTrayBindingTest {
tabsTrayStore.waitUntilIdle()
verify { fragment.removeSecure() }
verify { window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }
}
@Test
@ -80,7 +91,8 @@ class SecureTabsTrayBindingTest {
val secureTabsTrayBinding = SecureTabsTrayBinding(
store = tabsTrayStore,
settings = settings,
fragment = fragment
fragment = fragment,
dialog = dialog
)
secureTabsTrayBinding.start()
@ -88,6 +100,7 @@ class SecureTabsTrayBindingTest {
tabsTrayStore.waitUntilIdle()
verify { fragment.removeSecure() }
verify { window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }
}
@Test
@ -97,7 +110,8 @@ class SecureTabsTrayBindingTest {
val secureTabsTrayBinding = SecureTabsTrayBinding(
store = tabsTrayStore,
settings = settings,
fragment = fragment
fragment = fragment,
dialog = dialog
)
secureTabsTrayBinding.start()
@ -105,5 +119,6 @@ class SecureTabsTrayBindingTest {
tabsTrayStore.waitUntilIdle()
verify(exactly = 0) { fragment.removeSecure() }
verify(exactly = 0) { window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }
}
}