Skip to content

Commit 0d7154a

Browse files
committed
Merge branch 'release/5.68.0' into main
2 parents 13759ea + 6593474 commit 0d7154a

29 files changed

+404
-127
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ import dagger.Lazy
108108
import io.reactivex.Observable
109109
import io.reactivex.Single
110110
import kotlinx.coroutines.ExperimentalCoroutinesApi
111-
import kotlinx.coroutines.flow.emptyFlow
111+
import kotlinx.coroutines.channels.Channel
112+
import kotlinx.coroutines.flow.*
112113
import kotlinx.coroutines.runBlocking
113114
import kotlinx.coroutines.test.runBlockingTest
114115
import org.junit.After
@@ -244,6 +245,8 @@ class BrowserTabViewModelTest {
244245

245246
private val loginEventLiveData = MutableLiveData<LoginDetected>()
246247

248+
private val dismissedCtaDaoChannel = Channel<List<DismissedCta>>()
249+
247250
@Before
248251
fun before() {
249252
MockitoAnnotations.initMocks(this)
@@ -256,7 +259,7 @@ class BrowserTabViewModelTest {
256259

257260
mockAutoCompleteApi = AutoCompleteApi(mockAutoCompleteService, mockBookmarksDao)
258261

259-
whenever(mockDismissedCtaDao.dismissedCtas()).thenReturn(emptyFlow())
262+
whenever(mockDismissedCtaDao.dismissedCtas()).thenReturn(dismissedCtaDaoChannel.consumeAsFlow())
260263

261264
ctaViewModel = CtaViewModel(
262265
mockAppInstallStore,
@@ -327,6 +330,8 @@ class BrowserTabViewModelTest {
327330
@ExperimentalCoroutinesApi
328331
@After
329332
fun after() {
333+
ctaViewModel.forceStopFireButtonPulseAnimation.close()
334+
dismissedCtaDaoChannel.close()
330335
testee.onCleared()
331336
db.close()
332337
testee.command.removeObserver(mockCommandObserver)
@@ -590,6 +595,40 @@ class BrowserTabViewModelTest {
590595
assertEquals("", omnibarViewState().omnibarText)
591596
}
592597

598+
@Test
599+
fun whenUserRedirectedBeforePreviousSiteLoadedAndNewContentDelayedThenWebContentIsBlankedOut() = coroutineRule.runBlocking {
600+
loadUrl("http://duckduckgo.com")
601+
testee.progressChanged(50)
602+
603+
overrideUrl("http://example.com")
604+
advanceTimeBy(2000)
605+
606+
assertCommandIssued<Command.HideWebContent>()
607+
}
608+
609+
@Test
610+
fun whenUserRedirectedAfterSiteLoadedAndNewContentDelayedThenWebContentNotBlankedOut() = coroutineRule.runBlocking {
611+
loadUrl("http://duckduckgo.com")
612+
testee.progressChanged(100)
613+
614+
overrideUrl("http://example.com")
615+
advanceTimeBy(2000)
616+
617+
assertCommandNotIssued<Command.HideWebContent>()
618+
}
619+
620+
@Test
621+
fun whenLoadingProgressReaches50ThenShowWebContent() = coroutineRule.runBlocking {
622+
loadUrl("http://duckduckgo.com")
623+
testee.progressChanged(50)
624+
overrideUrl("http://example.com")
625+
advanceTimeBy(2000)
626+
627+
onProgressChanged(url = "http://example.com", newProgress = 50)
628+
629+
assertCommandIssued<Command.ShowWebContent>()
630+
}
631+
593632
@Test
594633
fun whenViewModelNotifiedThatUrlGotFocusThenViewStateIsUpdated() = coroutineRule.runBlocking {
595634
testee.onOmnibarInputStateChanged("", true, hasQueryChanged = false)
@@ -3028,6 +3067,16 @@ class BrowserTabViewModelTest {
30283067
testee.navigationStateChanged(buildWebNavigation(originalUrl = originalUrl, currentUrl = currentUrl))
30293068
}
30303069

3070+
@Suppress("SameParameterValue")
3071+
private fun onProgressChanged(url: String?, newProgress: Int) {
3072+
testee.navigationStateChanged(buildWebNavigation(originalUrl = url, currentUrl = url, progress = newProgress))
3073+
}
3074+
3075+
private fun overrideUrl(url: String, isBrowserShowing: Boolean = true) {
3076+
setBrowserShowing(isBrowserShowing)
3077+
testee.willOverrideUrl(newUrl = url)
3078+
}
3079+
30313080
private fun setupNavigation(
30323081
skipHome: Boolean = false,
30333082
isBrowsing: Boolean,
@@ -3052,7 +3101,8 @@ class BrowserTabViewModelTest {
30523101
title: String? = null,
30533102
canGoForward: Boolean = false,
30543103
canGoBack: Boolean = false,
3055-
stepsToPreviousPage: Int = 0
3104+
stepsToPreviousPage: Int = 0,
3105+
progress: Int? = null
30563106
): WebNavigationState {
30573107
val nav: WebNavigationState = mock()
30583108
whenever(nav.originalUrl).thenReturn(originalUrl)
@@ -3061,6 +3111,7 @@ class BrowserTabViewModelTest {
30613111
whenever(nav.canGoForward).thenReturn(canGoForward)
30623112
whenever(nav.canGoBack).thenReturn(canGoBack)
30633113
whenever(nav.stepsToPreviousPage).thenReturn(stepsToPreviousPage)
3114+
whenever(nav.progress).thenReturn(progress)
30643115
return nav
30653116
}
30663117

app/src/androidTest/java/com/duckduckgo/app/browser/EmptyNavigationStateTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class EmptyNavigationStateTest {
5050
stepsToPreviousPage = 1,
5151
canGoBack = true,
5252
canGoForward = true,
53-
hasNavigationHistory = true
53+
hasNavigationHistory = true,
54+
progress = null
5455
)
5556
}
5657
}

app/src/androidTest/java/com/duckduckgo/app/browser/TestNavigationState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ data class TestNavigationState(
2323
override val stepsToPreviousPage: Int,
2424
override val canGoBack: Boolean,
2525
override val canGoForward: Boolean,
26-
override val hasNavigationHistory: Boolean
26+
override val hasNavigationHistory: Boolean,
27+
override val progress: Int?
2728
) : WebNavigationState

app/src/androidTest/java/com/duckduckgo/app/browser/WebNavigationStateComparisonTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,16 @@ class WebNavigationStateComparisonTest {
126126
assertEquals(Other, latestState.compare(previousState))
127127
}
128128

129-
private fun buildState(originalUrl: String?, currentUrl: String?, title: String? = null): WebNavigationState {
129+
private fun buildState(originalUrl: String?, currentUrl: String?, title: String? = null, newProgress: Int? = null): WebNavigationState {
130130
return TestNavigationState(
131131
originalUrl = originalUrl,
132132
currentUrl = currentUrl,
133133
title = title,
134134
stepsToPreviousPage = 1,
135135
canGoBack = true,
136136
canGoForward = true,
137-
hasNavigationHistory = true
137+
hasNavigationHistory = true,
138+
progress = newProgress
138139
)
139140
}
140141
}

app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ class CtaTest {
374374
assertTrue(testee.pixelShownParameters().isEmpty())
375375
}
376376

377+
@Test
378+
fun whenTryClearDataCtaShownThenConcatenateJourneyStoredValueInPixel() {
379+
val existingJourney = "s:0-t:1"
380+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn(existingJourney)
381+
whenever(mockAppInstallStore.installTimestamp).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
382+
val testee = DaxFireDialogCta.TryClearDataCta(mockOnboardingStore, mockAppInstallStore)
383+
val expectedValue = "$existingJourney-${testee.ctaPixelParam}:1"
384+
385+
val value = testee.pixelShownParameters()
386+
387+
assertEquals(expectedValue, value[CTA_SHOWN])
388+
}
389+
377390
private fun site(
378391
url: String = "http://www.test.com",
379392
uri: Uri? = Uri.parse(url),

app/src/androidTest/java/com/duckduckgo/app/cta/ui/CtaViewModelTest.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ import com.duckduckgo.app.trackerdetection.model.TrackingEvent
5656
import com.duckduckgo.app.widget.ui.WidgetCapabilities
5757
import com.nhaarman.mockitokotlin2.*
5858
import kotlinx.coroutines.ExperimentalCoroutinesApi
59+
import kotlinx.coroutines.FlowPreview
5960
import kotlinx.coroutines.channels.Channel
60-
import kotlinx.coroutines.flow.collect
61-
import kotlinx.coroutines.flow.consumeAsFlow
62-
import kotlinx.coroutines.flow.first
61+
import kotlinx.coroutines.flow.*
6362
import kotlinx.coroutines.launch
6463
import kotlinx.coroutines.test.runBlockingTest
6564
import org.junit.After
@@ -71,6 +70,7 @@ import org.mockito.Mock
7170
import org.mockito.MockitoAnnotations
7271
import java.util.concurrent.TimeUnit
7372

73+
@FlowPreview
7474
@ExperimentalCoroutinesApi
7575
class CtaViewModelTest {
7676

@@ -583,6 +583,22 @@ class CtaViewModelTest {
583583
assertFalse(testee.showFireButtonPulseAnimation.first())
584584
}
585585

586+
@Test
587+
fun whenUserHasAlreadySeenFireButtonPulseAnimationThenFireButtonAnimationShouldNotShow() = coroutineRule.runBlocking {
588+
givenFireButtonEducationActive()
589+
givenOnboardingActive()
590+
whenever(mockDismissedCtaDao.exists(CtaId.DAX_FIRE_BUTTON_PULSE)).thenReturn(true)
591+
592+
val launch = launch {
593+
testee.showFireButtonPulseAnimation.collect {
594+
assertFalse(it)
595+
}
596+
}
597+
dismissedCtaDaoChannel.send(emptyList())
598+
599+
launch.cancel()
600+
}
601+
586602
@Test
587603
fun whenTipsAndFireOnboardingActiveAndUserSeesAnyTriggerFirePulseAnimationCtaThenFireButtonAnimationShouldShow() = coroutineRule.runBlocking {
588604
givenFireButtonEducationActive()
@@ -601,6 +617,27 @@ class CtaViewModelTest {
601617
launch.cancel()
602618
}
603619

620+
@Test
621+
fun whenFireButtonAnimationShowingAndCallDismissThenFireButtonAnimationShouldNotShow() = coroutineRule.runBlocking {
622+
var lastValueCollected: Boolean? = null
623+
givenFireButtonEducationActive()
624+
givenOnboardingActive()
625+
val willTriggerFirePulseAnimationCtas = listOf(CtaId.DAX_DIALOG_TRACKERS_FOUND, CtaId.DAX_DIALOG_NETWORK, CtaId.DAX_DIALOG_OTHER)
626+
val launch = launch {
627+
testee.showFireButtonPulseAnimation.collect {
628+
lastValueCollected = it
629+
}
630+
}
631+
willTriggerFirePulseAnimationCtas.forEach {
632+
dismissedCtaDaoChannel.send(listOf(DismissedCta(it)))
633+
}
634+
635+
testee.dismissPulseAnimation()
636+
637+
assertFalse(lastValueCollected!!)
638+
launch.cancel()
639+
}
640+
604641
@Test
605642
fun whenTipsAndFireOnboardingActiveAndUserSeesAnyNonTriggerFirePulseAnimationCtaThenFireButtonAnimationShouldNotShow() = coroutineRule.runBlocking {
606643
givenFireButtonEducationActive()

0 commit comments

Comments
 (0)