2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

Add FLAG_SECURE to SearchDialogFragment

This commit is contained in:
Alexandru2909 2023-02-20 11:14:07 +02:00 committed by mergify[bot]
parent 32ed9fd197
commit 1dfb2bd409
2 changed files with 51 additions and 0 deletions

View File

@ -86,6 +86,7 @@ import org.mozilla.fenix.ext.getRectWithScreenLocation
import org.mozilla.fenix.ext.increaseTapArea import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.registerForActivityResult import org.mozilla.fenix.ext.registerForActivityResult
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.secure
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.search.awesomebar.AwesomeBarView import org.mozilla.fenix.search.awesomebar.AwesomeBarView
import org.mozilla.fenix.search.awesomebar.toSearchProviderState import org.mozilla.fenix.search.awesomebar.toSearchProviderState
@ -169,6 +170,10 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
override fun onBackPressed() { override fun onBackPressed() {
this@SearchDialogFragment.onBackPressed() this@SearchDialogFragment.onBackPressed()
} }
}.apply {
if ((requireActivity() as HomeActivity).browsingModeManager.mode.isPrivate) {
this.secure(requireActivity())
}
} }
} }

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.search package org.mozilla.fenix.search
import android.view.WindowManager.LayoutParams
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.NavBackStackEntry import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController import androidx.navigation.NavController
@ -14,20 +15,27 @@ import io.mockk.every
import io.mockk.just import io.mockk.just
import io.mockk.mockk import io.mockk.mockk
import io.mockk.mockkStatic import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkStatic import io.mockk.unmockkStatic
import io.mockk.verify import io.mockk.verify
import mozilla.components.browser.state.search.SearchEngine import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.browser.state.state.SearchState import mozilla.components.browser.state.state.SearchState
import mozilla.components.browser.state.state.searchEngines import mozilla.components.browser.state.state.searchEngines
import mozilla.components.browser.state.state.selectedOrDefaultSearchEngine import mozilla.components.browser.state.state.selectedOrDefaultSearchEngine
import mozilla.components.support.test.robolectric.testContext
import org.junit.After import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Assert.assertSame import org.junit.Assert.assertSame
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.components.Components import org.mozilla.fenix.components.Components
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
internal class SearchDialogFragmentTest { internal class SearchDialogFragmentTest {
private val navController: NavController = mockk() private val navController: NavController = mockk()
private val fragment = SearchDialogFragment() private val fragment = SearchDialogFragment()
@ -153,6 +161,44 @@ internal class SearchDialogFragmentTest {
verify { fragment.interactor wasNot Called } verify { fragment.interactor wasNot Called }
} }
@Test
fun `GIVEN app is in private mode WHEN search dialog is created THEN the dialog is secure`() {
val activity: HomeActivity = mockk(relaxed = true)
val fragment = spyk(SearchDialogFragment())
val layoutParams = LayoutParams()
layoutParams.flags = LayoutParams.FLAG_SECURE
every { activity.browsingModeManager.mode.isPrivate } returns true
every { activity.window } returns mockk(relaxed = true) {
every { attributes } returns LayoutParams().apply { flags = LayoutParams.FLAG_SECURE }
}
every { fragment.requireActivity() } returns activity
every { fragment.requireContext() } returns testContext
val dialog = fragment.onCreateDialog(null)
assertEquals(LayoutParams.FLAG_SECURE, dialog.window?.attributes?.flags!! and LayoutParams.FLAG_SECURE)
}
@Test
fun `GIVEN app is in normal mode WHEN search dialog is created THEN the dialog is not secure`() {
val activity: HomeActivity = mockk(relaxed = true)
val fragment = spyk(SearchDialogFragment())
val layoutParams = LayoutParams()
layoutParams.flags = LayoutParams.FLAG_SECURE
every { activity.browsingModeManager.mode.isPrivate } returns false
every { activity.window } returns mockk(relaxed = true) {
every { attributes } returns LayoutParams().apply { flags = LayoutParams.FLAG_SECURE }
}
every { fragment.requireActivity() } returns activity
every { fragment.requireContext() } returns testContext
val dialog = fragment.onCreateDialog(null)
assertEquals(0, dialog.window?.attributes?.flags!! and LayoutParams.FLAG_SECURE)
}
} }
private val fragmentName = SearchDialogFragment::class.java.canonicalName?.substringAfterLast('.')!! private val fragmentName = SearchDialogFragment::class.java.canonicalName?.substringAfterLast('.')!!