@ -17,6 +17,9 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Assert.fail
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org.mozilla.fenix.StrictModeManager
import org.mozilla.fenix.helpers.TestStrictModeManager
import kotlin.coroutines.CoroutineContext
@RunWith ( FenixRobolectricTestRunner :: class )
@RunWith ( FenixRobolectricTestRunner :: class )
class AccountAbnormalitiesTest {
class AccountAbnormalitiesTest {
@ -25,7 +28,7 @@ class AccountAbnormalitiesTest {
val crashReporter : CrashReporter = mockk ( )
val crashReporter : CrashReporter = mockk ( )
// no account present
// no account present
val accountAbnormalities = AccountAbnormalities( testContext, crashReporter, mockk ( relaxed = true ) )
val accountAbnormalities = new AccountAbnormalities( crashReporter)
try {
try {
accountAbnormalities . userRequestedLogout ( )
accountAbnormalities . userRequestedLogout ( )
@ -52,7 +55,7 @@ class AccountAbnormalitiesTest {
val crashReporter : CrashReporter = mockk ( relaxed = true )
val crashReporter : CrashReporter = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountAbnormalities = AccountAbnormalities( testContext, crashReporter, mockk ( relaxed = true ) , this . coroutineContext )
val accountAbnormalities = new AccountAbnormalities( crashReporter, this . coroutineContext )
accountAbnormalities . accountManagerStarted ( accountManager )
accountAbnormalities . accountManagerStarted ( accountManager )
// Logout action must be preceded by auth.
// Logout action must be preceded by auth.
@ -65,7 +68,7 @@ class AccountAbnormalitiesTest {
val crashReporter : CrashReporter = mockk ( relaxed = true )
val crashReporter : CrashReporter = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountAbnormalities = AccountAbnormalities( testContext, crashReporter, mockk ( relaxed = true ) , this . coroutineContext )
val accountAbnormalities = new AccountAbnormalities( crashReporter, this . coroutineContext )
accountAbnormalities . accountManagerStarted ( accountManager )
accountAbnormalities . accountManagerStarted ( accountManager )
accountAbnormalities . onAuthenticated ( mockk ( ) , mockk ( ) )
accountAbnormalities . onAuthenticated ( mockk ( ) , mockk ( ) )
@ -83,7 +86,7 @@ class AccountAbnormalitiesTest {
val crashReporter : CrashReporter = mockk ( relaxed = true )
val crashReporter : CrashReporter = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountAbnormalities = AccountAbnormalities( testContext, crashReporter, mockk ( relaxed = true ) , this . coroutineContext )
val accountAbnormalities = new AccountAbnormalities( crashReporter, this . coroutineContext )
accountAbnormalities . accountManagerStarted ( accountManager )
accountAbnormalities . accountManagerStarted ( accountManager )
// User didn't request this logout.
// User didn't request this logout.
@ -96,7 +99,7 @@ class AccountAbnormalitiesTest {
val crashReporter : CrashReporter = mockk ( relaxed = true )
val crashReporter : CrashReporter = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountAbnormalities = AccountAbnormalities( testContext, crashReporter, mockk ( relaxed = true ) , this . coroutineContext )
val accountAbnormalities = new AccountAbnormalities( crashReporter, this . coroutineContext )
accountAbnormalities . accountManagerStarted ( accountManager )
accountAbnormalities . accountManagerStarted ( accountManager )
accountAbnormalities . onAuthenticated ( mockk ( ) , mockk ( ) )
accountAbnormalities . onAuthenticated ( mockk ( ) , mockk ( ) )
@ -104,7 +107,7 @@ class AccountAbnormalitiesTest {
every { accountManager . authenticatedAccount ( ) } returns null
every { accountManager . authenticatedAccount ( ) } returns null
// Pretend we restart, and instantiate a new middleware instance.
// Pretend we restart, and instantiate a new middleware instance.
val accountAbnormalities2 = AccountAbnormalities( testContext, crashReporter, mockk ( relaxed = true ) , this . coroutineContext )
val accountAbnormalities2 = new AccountAbnormalities( crashReporter, this . coroutineContext )
// mock accountManager doesn't have an account, but we expect it to have one since we
// mock accountManager doesn't have an account, but we expect it to have one since we
// were authenticated before our "restart".
// were authenticated before our "restart".
accountAbnormalities2 . accountManagerStarted ( accountManager )
accountAbnormalities2 . accountManagerStarted ( accountManager )
@ -117,7 +120,7 @@ class AccountAbnormalitiesTest {
val crashReporter : CrashReporter = mockk ( )
val crashReporter : CrashReporter = mockk ( )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountManager : FxaAccountManager = mockk ( relaxed = true )
val accountAbnormalities = AccountAbnormalities( testContext, crashReporter, mockk ( relaxed = true ) , this . coroutineContext )
val accountAbnormalities = new AccountAbnormalities( crashReporter, coroutineContext )
accountAbnormalities . accountManagerStarted ( accountManager )
accountAbnormalities . accountManagerStarted ( accountManager )
// We saw an auth event, then user requested a logout.
// We saw an auth event, then user requested a logout.
@ -131,4 +134,13 @@ class AccountAbnormalitiesTest {
crashReporter . submitCaughtException ( any < T > ( ) )
crashReporter . submitCaughtException ( any < T > ( ) )
}
}
}
}
private fun newAccountAbnormalities (
crashReporter : CrashReporter ,
coroutineContext : CoroutineContext ? = null
) : AccountAbnormalities = if ( coroutineContext != null ) {
AccountAbnormalities ( testContext , crashReporter , TestStrictModeManager ( ) as StrictModeManager , coroutineContext )
} else {
AccountAbnormalities ( testContext , crashReporter , TestStrictModeManager ( ) as StrictModeManager )
}
}
}