@ -7,12 +7,15 @@ package org.mozilla.fenix.ext
import android.app.Activity
import android.app.Activity
import android.view.View
import android.view.View
import android.view.WindowManager
import android.view.WindowManager
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org. robolectric.Robolectric
import org. mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.robolectric.Robolectric
import org.robolectric.Shadows.shadowOf
import org.robolectric.Shadows.shadowOf
@RunWith ( FenixRobolectricTestRunner :: class )
@RunWith ( FenixRobolectricTestRunner :: class )
@ -39,4 +42,67 @@ class ActivityTest {
for ( f in flags ) assertEquals ( f , window . decorView . systemUiVisibility and f )
for ( f in flags ) assertEquals ( f , window . decorView . systemUiVisibility and f )
assertTrue ( shadowOf ( window ) . getFlag ( WindowManager . LayoutParams . FLAG _KEEP _SCREEN _ON ) )
assertTrue ( shadowOf ( window ) . getFlag ( WindowManager . LayoutParams . FLAG _KEEP _SCREEN _ON ) )
}
}
@Test
fun `testCheckAndUpdateScreenshotPermission adds flag in private mode when screenshots are not allowed ` ( ) {
// given
val activity = Robolectric . buildActivity ( Activity :: class . java ) . create ( ) . get ( )
val window = activity . window
testContext . settings ( ) . lastKnownMode = BrowsingMode . Private
testContext . settings ( ) . allowScreenshotsInPrivateMode = false
// when
activity . checkAndUpdateScreenshotPermission ( activity . settings ( ) )
// then
assertTrue ( shadowOf ( window ) . getFlag ( WindowManager . LayoutParams . FLAG _SECURE ) )
}
@Test
fun `testCheckAndUpdateScreenshotPermission removes flag in private mode when screenshots are allowed ` ( ) {
// given
val activity = Robolectric . buildActivity ( Activity :: class . java ) . create ( ) . get ( )
val window = activity . window
window . addFlags ( WindowManager . LayoutParams . FLAG _SECURE )
testContext . settings ( ) . lastKnownMode = BrowsingMode . Private
testContext . settings ( ) . allowScreenshotsInPrivateMode = true
// when
activity . checkAndUpdateScreenshotPermission ( activity . settings ( ) )
// then
assertFalse ( shadowOf ( window ) . getFlag ( WindowManager . LayoutParams . FLAG _SECURE ) )
}
@Test
fun `testCheckAndUpdateScreenshotPermission removes flag in normal mode when screenshots are allowed ` ( ) {
// given
val activity = Robolectric . buildActivity ( Activity :: class . java ) . create ( ) . get ( )
val window = activity . window
window . addFlags ( WindowManager . LayoutParams . FLAG _SECURE )
testContext . settings ( ) . lastKnownMode = BrowsingMode . Normal
testContext . settings ( ) . allowScreenshotsInPrivateMode = true
// when
activity . checkAndUpdateScreenshotPermission ( activity . settings ( ) )
// then
assertFalse ( shadowOf ( window ) . getFlag ( WindowManager . LayoutParams . FLAG _SECURE ) )
}
@Test
fun `testCheckAndUpdateScreenshotPermission removes flag when in normal mode screenshots are not allowed ` ( ) {
// given
val activity = Robolectric . buildActivity ( Activity :: class . java ) . create ( ) . get ( )
val window = activity . window
window . addFlags ( WindowManager . LayoutParams . FLAG _SECURE )
testContext . settings ( ) . lastKnownMode = BrowsingMode . Normal
testContext . settings ( ) . allowScreenshotsInPrivateMode = false
// when
activity . checkAndUpdateScreenshotPermission ( activity . settings ( ) )
// then
assertFalse ( shadowOf ( window ) . getFlag ( WindowManager . LayoutParams . FLAG _SECURE ) )
}
}
}