Commit 3e31742d authored by Grisha Kruglov's avatar Grisha Kruglov Committed by Grisha Kruglov
Browse files

Part 5: Do not emit 'logged-out' event on "no account present"

The change here is to only emit the "logged out" event when a logout
action takes place. Before we were emitting it as part of the
"i'm initializing, and there is no account present" flow.
That complicates a sync manager implementation, as it'll have to
distinguish the two states. By dropping this event, we allow
consumers assume that initial state is always "logged out",
and the correct event observers will fire otherwise.
parent 9186ba75
......@@ -331,8 +331,6 @@ open class FxaAccountManager(
Event.AccountNotFound -> {
account = createAccount(config)
notifyObservers { onLoggedOut() }
null
}
Event.Authenticate -> {
......
......@@ -121,13 +121,11 @@ class FxaAccountManagerTest {
accountStorage
)
var onLoggedOutCalled = false
var onErrorCalled = false
val accountObserver = object : AccountObserver {
override fun onLoggedOut() {
assertFalse(onLoggedOutCalled)
onLoggedOutCalled = true
fail()
}
override fun onAuthenticated(account: OAuthAccount) {
......@@ -153,7 +151,6 @@ class FxaAccountManagerTest {
}
assertTrue(onErrorCalled)
assertTrue(onLoggedOutCalled)
}
@Test
......@@ -177,7 +174,7 @@ class FxaAccountManagerTest {
verify(accountObserver, never()).onError(any())
verify(accountObserver, never()).onAuthenticated(any())
verify(accountObserver, never()).onProfileUpdated(any())
verify(accountObserver, times(1)).onLoggedOut()
verify(accountObserver, never()).onLoggedOut()
verify(accountStorage, times(1)).read()
verify(accountStorage, never()).write(any())
......@@ -284,8 +281,9 @@ class FxaAccountManagerTest {
manager.initAsync().await()
}
// We start off as logged-out.
verify(accountObserver, times(1)).onLoggedOut()
// We start off as logged-out, but the event won't be called (initial default state is assumed).
verify(accountObserver, never()).onLoggedOut()
verify(accountObserver, never()).onAuthenticated(any())
reset(accountObserver)
runBlocking {
......@@ -358,8 +356,9 @@ class FxaAccountManagerTest {
manager.initAsync().await()
}
// We start off as logged-out.
verify(accountObserver, times(1)).onLoggedOut()
// We start off as logged-out, but the event won't be called (initial default state is assumed).
verify(accountObserver, never()).onLoggedOut()
verify(accountObserver, never()).onAuthenticated(any())
reset(accountObserver)
runBlocking {
......@@ -445,8 +444,9 @@ class FxaAccountManagerTest {
manager.initAsync().await()
}
// We start off as logged-out.
verify(accountObserver, times(1)).onLoggedOut()
// We start off as logged-out, but the event won't be called (initial default state is assumed).
verify(accountObserver, never()).onLoggedOut()
verify(accountObserver, never()).onAuthenticated(any())
reset(accountObserver)
runBlocking {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment