2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/17724: Wait for tab to be fully created before showing ETP Onboarding if ETP is active

This commit is contained in:
hwinnemo 2021-02-01 21:10:58 +01:00 committed by ekager
parent 478a314f44
commit 36ab8d42cf
2 changed files with 25 additions and 5 deletions

View File

@ -62,9 +62,9 @@ class TrackingProtectionOverlay(
}.ifChanged { tab ->
tab.content.loading
}
.collect { tab ->
onLoadingStateChanged(tab)
}
.collect { tab ->
onLoadingStateChanged(tab)
}
}
}
@ -77,7 +77,10 @@ class TrackingProtectionOverlay(
@VisibleForTesting
internal fun onLoadingStateChanged(tab: SessionState) {
if (!tab.content.loading && shouldShowTrackingProtectionOnboarding(tab)) {
if (shouldShowTrackingProtectionOnboarding(tab) &&
tab.content.progress == FULL_PROGRESS &&
settings.shouldUseTrackingProtection
) {
showTrackingProtectionOnboarding()
}
}
@ -85,7 +88,7 @@ class TrackingProtectionOverlay(
private fun shouldShowTrackingProtectionOnboarding(tab: SessionState) =
tab.trackingProtection.enabled &&
tab.trackingProtection.blockedTrackers.isNotEmpty() &&
settings.shouldShowTrackingProtectionCfr
settings.shouldShowTrackingProtectionCfr
@Suppress("MagicNumber", "InflateParams")
private fun showTrackingProtectionOnboarding() {
@ -184,6 +187,7 @@ class TrackingProtectionOverlay(
}
private companion object {
private const val FULL_PROGRESS = 100
private const val BUTTON_INCREASE_DPS = 12
}
}

View File

@ -156,7 +156,9 @@ class TrackingProtectionOverlayTest {
fun `show onboarding when trackers are blocked`() {
every { toolbar.hasWindowFocus() } returns true
every { settings.shouldShowTrackingProtectionCfr } returns true
every { session.content.progress } returns 100
every { session.content.loading } returns false
every { settings.shouldUseTrackingProtection } returns true
every { session.trackingProtection } returns TrackingProtectionState(
enabled = true,
blockedTrackers = listOf(mockk())
@ -165,6 +167,20 @@ class TrackingProtectionOverlayTest {
verify { settings.incrementTrackingProtectionOnboardingCount() }
}
@Test
fun `no-op when trackers are blocked but not finished loading`() {
every { toolbar.hasWindowFocus() } returns true
every { settings.shouldShowTrackingProtectionCfr } returns true
every { session.content.progress } returns 50
every { session.content.loading } returns false
every { session.trackingProtection } returns TrackingProtectionState(
enabled = true,
blockedTrackers = listOf(mockk())
)
overlay.onLoadingStateChanged(session)
verify(exactly = 0) { settings.incrementTrackingProtectionOnboardingCount() }
}
@Test
fun `no-op when toolbar doesn't have focus`() {
every { toolbar.hasWindowFocus() } returns false