|
|
|
@ -4,6 +4,7 @@
|
|
|
|
|
|
|
|
|
|
package org.mozilla.fenix.search
|
|
|
|
|
|
|
|
|
|
import android.view.WindowManager.LayoutParams
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import androidx.navigation.NavBackStackEntry
|
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
@ -14,20 +15,27 @@ import io.mockk.every
|
|
|
|
|
import io.mockk.just
|
|
|
|
|
import io.mockk.mockk
|
|
|
|
|
import io.mockk.mockkStatic
|
|
|
|
|
import io.mockk.spyk
|
|
|
|
|
import io.mockk.unmockkStatic
|
|
|
|
|
import io.mockk.verify
|
|
|
|
|
import mozilla.components.browser.state.search.SearchEngine
|
|
|
|
|
import mozilla.components.browser.state.state.SearchState
|
|
|
|
|
import mozilla.components.browser.state.state.searchEngines
|
|
|
|
|
import mozilla.components.browser.state.state.selectedOrDefaultSearchEngine
|
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
|
import org.junit.After
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
import org.junit.Assert.assertNull
|
|
|
|
|
import org.junit.Assert.assertSame
|
|
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
import org.mozilla.fenix.HomeActivity
|
|
|
|
|
import org.mozilla.fenix.components.Components
|
|
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
|
|
|
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
|
|
|
|
|
|
|
|
|
@RunWith(FenixRobolectricTestRunner::class)
|
|
|
|
|
internal class SearchDialogFragmentTest {
|
|
|
|
|
private val navController: NavController = mockk()
|
|
|
|
|
private val fragment = SearchDialogFragment()
|
|
|
|
@ -153,6 +161,44 @@ internal class SearchDialogFragmentTest {
|
|
|
|
|
|
|
|
|
|
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('.')!!
|
|
|
|
|