Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

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 #3579
... but we actually need it for the UIs!
  • Loading branch information
Grisha Kruglov authored and grigoryk committed Jul 26, 2019
1 parent 0860133 commit 6460296
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ open class FxaAccountManager(
Unit
}

/**
* Indicates if sync is currently running.
*/
fun isSyncActive() = syncManager?.isSyncActive() ?: 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,11 @@ 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() = syncDispatcher?.isSyncActive() ?: false

internal fun registerSyncStatusObserver(observer: SyncStatusObserver) {
syncStatusObserverRegistry.register(observer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,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 @@ -312,6 +315,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 @@ -401,6 +405,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 @@ -426,6 +431,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 @@ -43,6 +43,9 @@ permalink: /changelog/
* **browser-icons**
* Changed the maximum size for decoded icons. Icons are now scaled to the target size to save memory.

* **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 6460296

Please sign in to comment.