Skip to content

Commit

Permalink
No issue: add isSyncActive method to FxaAccountManager
Browse files Browse the repository at this point in the history
This got removed as part of mozilla-mobile#3579
... but we actually need it for the UIs!
  • Loading branch information
Grisha Kruglov committed Jul 26, 2019
1 parent f671192 commit c206fef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ open class FxaAccountManager(
Unit
}

/**
* Indicates if sync is currently running.
*/
fun isSyncActive(): Boolean {
syncManager?.let { return it.isSyncActive() }
return false
}

/**
* Call this after registering your observers, and before interacting with this class.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ abstract class SyncManager(
// Currently the interfaces are the same, hence the name "pass-through".
private val dispatcherStatusObserver = PassThroughSyncStatusObserver(syncStatusObserverRegistry)

/**
* Indicates if sync is currently running.
*/
internal fun isSyncActive(): Boolean {
syncDispatcher?.let { return it.isSyncActive() }
return false
}

internal fun registerSyncStatusObserver(observer: SyncStatusObserver) {
syncStatusObserverRegistry.register(observer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ class FxaAccountManagerTest {

manager.initAsync().await()

// Can check if sync is running (it's not!), even if we don't have sync configured.
assertFalse(manager.isSyncActive())

val syncStatusObserver = TestSyncStatusObserver()
val lifecycleOwner: LifecycleOwner = mock()
val lifecycle: Lifecycle = mock()
Expand Down Expand Up @@ -300,6 +303,7 @@ class FxaAccountManagerTest {
verify(latestSyncManager!!.dispatcher.inner, times(1)).syncNow(anyBoolean())

// Make sure sync status listeners are working.
// TODO fix these tests.
// // Test dispatcher -> sync manager -> account manager -> our test observer.
// latestSyncManager!!.dispatcherRegistry.notifyObservers { onStarted() }
// assertEquals(1, syncStatusObserver.onStartedCount)
Expand Down Expand Up @@ -389,6 +393,7 @@ class FxaAccountManagerTest {
manager.syncNowAsync(startup = true).await()
verify(latestSyncManager!!.dispatcher.inner, times(3)).syncNow(anyBoolean())

// TODO fix these tests
// assertEquals(0, syncStatusObserver.onStartedCount)
// assertEquals(0, syncStatusObserver.onIdleCount)
// assertEquals(0, syncStatusObserver.onErrorCount)
Expand All @@ -414,6 +419,14 @@ class FxaAccountManagerTest {
verify(latestSyncManager!!.dispatcher.inner, times(2)).syncNow(anyBoolean())
manager.syncNowAsync(startup = true).await()
verify(latestSyncManager!!.dispatcher.inner, times(3)).syncNow(anyBoolean())

// Pretend sync is running.
`when`(latestSyncManager!!.dispatcher.inner.isSyncActive()).thenReturn(true)
assertTrue(manager.isSyncActive())

// Pretend sync is not running.
`when`(latestSyncManager!!.dispatcher.inner.isSyncActive()).thenReturn(false)
assertFalse(manager.isSyncActive())
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ permalink: /changelog/
* **lib-push-amazon**
* 🆕 Added a new component for Amazon Device Messaging push support.

* **service-firefox-account**
* Added `isSyncActive(): Boolean` method to `FxaAccountManager`

# 5.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v4.0.0...v5.0.0)
Expand Down

0 comments on commit c206fef

Please sign in to comment.