Skip to content

Commit 5272de9

Browse files
committed
Merge branch 'release/5.51.0'
2 parents f765023 + 7c6e862 commit 5272de9

File tree

172 files changed

+1692
-693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+1692
-693
lines changed

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

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,6 @@ class BrowserTabViewModelTest {
13371337

13381338
@Test
13391339
fun whenScheduledSurveyChangesAndInstalledDaysDontMatchThenCtaIsNull() {
1340-
setCovidCtaShown()
13411340
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 2, status = Survey.Status.SCHEDULED))
13421341
assertNull(testee.ctaViewState.value!!.cta)
13431342
}
@@ -1359,7 +1358,6 @@ class BrowserTabViewModelTest {
13591358

13601359
@Test
13611360
fun whenCtaRefreshedAndAutoAddSupportedAndWidgetAlreadyInstalledThenCtaIsNull() = coroutineRule.runBlocking {
1362-
setCovidCtaShown()
13631361
whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(true)
13641362
whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(true)
13651363
whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(true)
@@ -1376,7 +1374,6 @@ class BrowserTabViewModelTest {
13761374

13771375
@Test
13781376
fun whenCtaRefreshedAndOnlyStandardAddSupportedAndWidgetAlreadyInstalledThenCtaIsNull() = coroutineRule.runBlocking {
1379-
setCovidCtaShown()
13801377
whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(true)
13811378
whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(false)
13821379
whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(true)
@@ -1386,7 +1383,6 @@ class BrowserTabViewModelTest {
13861383

13871384
@Test
13881385
fun whenCtaRefreshedAndStandardAddNotSupportedAndWidgetNotInstalledThenCtaIsNull() = coroutineRule.runBlocking {
1389-
setCovidCtaShown()
13901386
whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(false)
13911387
whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(false)
13921388
whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(false)
@@ -1396,7 +1392,6 @@ class BrowserTabViewModelTest {
13961392

13971393
@Test
13981394
fun whenCtaRefreshedAndStandardAddNotSupportedAndWidgetAlreadyInstalledThenCtaIsNull() = coroutineRule.runBlocking {
1399-
setCovidCtaShown()
14001395
whenever(mockWidgetCapabilities.supportsStandardWidgetAdd).thenReturn(false)
14011396
whenever(mockWidgetCapabilities.supportsAutomaticWidgetAdd).thenReturn(false)
14021397
whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(true)
@@ -1443,45 +1438,41 @@ class BrowserTabViewModelTest {
14431438
@Test
14441439
fun whenUserClickedCtaButtonThenFirePixel() {
14451440
val cta = DaxBubbleCta.DaxIntroCta(mockOnboardingStore, mockAppInstallStore)
1446-
testee.onUserClickCtaOkButton(cta)
1441+
setCta(cta)
1442+
testee.onUserClickCtaOkButton()
14471443
verify(mockPixel).fire(cta.okPixel!!, cta.pixelOkParameters())
14481444
}
14491445

14501446
@Test
14511447
fun whenUserClickedSurveyCtaButtonThenLaunchSurveyCommand() {
14521448
val cta = HomePanelCta.Survey(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1453-
testee.onUserClickCtaOkButton(cta)
1449+
setCta(cta)
1450+
testee.onUserClickCtaOkButton()
14541451
assertCommandIssued<Command.LaunchSurvey>()
14551452
}
14561453

14571454
@Test
14581455
fun whenUserClickedAddWidgetCtaButtonThenLaunchAddWidgetCommand() {
14591456
val cta = HomePanelCta.AddWidgetAuto
1460-
testee.onUserClickCtaOkButton(cta)
1457+
setCta(cta)
1458+
testee.onUserClickCtaOkButton()
14611459
assertCommandIssued<Command.LaunchAddWidget>()
14621460
}
14631461

14641462
@Test
14651463
fun whenUserClickedLegacyAddWidgetCtaButtonThenLaunchLegacyAddWidgetCommand() {
14661464
val cta = HomePanelCta.AddWidgetInstructions
1467-
testee.onUserClickCtaOkButton(cta)
1465+
setCta(cta)
1466+
testee.onUserClickCtaOkButton()
14681467
assertCommandIssued<Command.LaunchLegacyAddWidget>()
14691468
}
14701469

14711470
@Test
14721471
fun whenSurveyCtaDismissedAndNoOtherCtaPossibleCtaIsNull() = coroutineRule.runBlocking {
1473-
givenShownCtas(CtaId.DAX_INTRO, CtaId.DAX_END, CtaId.COVID)
1474-
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1475-
testee.onUserDismissedCta(testee.ctaViewState.value!!.cta!!)
1476-
assertNull(testee.ctaViewState.value!!.cta)
1477-
}
1478-
1479-
@Test
1480-
fun whenSurveyCtaDismissedAndWidgetNotCompatibleAndCovidCtaNotShownThenCtaIsCovid() = coroutineRule.runBlocking {
14811472
givenShownCtas(CtaId.DAX_INTRO, CtaId.DAX_END)
14821473
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1483-
testee.onUserDismissedCta(testee.ctaViewState.value!!.cta!!)
1484-
assertEquals(HomeTopPanelCta.CovidCta(), testee.ctaViewState.value!!.cta)
1474+
testee.onUserDismissedCta()
1475+
assertNull(testee.ctaViewState.value!!.cta)
14851476
}
14861477

14871478
@Test
@@ -1491,46 +1482,68 @@ class BrowserTabViewModelTest {
14911482
whenever(mockWidgetCapabilities.hasInstalledWidgets).thenReturn(false)
14921483

14931484
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1494-
testee.onUserDismissedCta(testee.ctaViewState.value!!.cta!!)
1485+
testee.onUserDismissedCta()
14951486
assertEquals(HomePanelCta.AddWidgetAuto, testee.ctaViewState.value!!.cta)
14961487
}
14971488

14981489
@Test
14991490
fun whenUserDismissedCtaThenFirePixel() = coroutineRule.runBlocking {
15001491
val cta = HomePanelCta.Survey(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1501-
testee.onUserDismissedCta(cta)
1492+
setCta(cta)
1493+
testee.onUserDismissedCta()
15021494
verify(mockPixel).fire(cta.cancelPixel!!, cta.pixelCancelParameters())
15031495
}
15041496

1497+
@Test
1498+
fun whenUserClickedHideDaxDialogThenHideDaxDialogCommandSent() {
1499+
val cta = DaxDialogCta.DaxSerpCta(mockOnboardingStore, mockAppInstallStore)
1500+
setCta(cta)
1501+
testee.onUserHideDaxDialog()
1502+
val command = captureCommands().lastValue
1503+
assertTrue(command is Command.DaxCommand.HideDaxDialog)
1504+
}
1505+
1506+
@Test
1507+
fun whenUserDismissDaxTrackersBlockedDialogThenFinishTrackerAnimationCommandSent() {
1508+
val cta = DaxDialogCta.DaxTrackersBlockedCta(mockOnboardingStore, mockAppInstallStore, emptyList(), "")
1509+
setCta(cta)
1510+
testee.onDaxDialogDismissed()
1511+
val command = captureCommands().lastValue
1512+
assertTrue(command is Command.DaxCommand.FinishTrackerAnimation)
1513+
}
1514+
1515+
@Test
1516+
fun whenUserDismissDifferentThanDaxTrackersBlockedDialogThenFinishTrackerAnimationCommandNotSent() {
1517+
val cta = DaxDialogCta.DaxSerpCta(mockOnboardingStore, mockAppInstallStore)
1518+
setCta(cta)
1519+
testee.onDaxDialogDismissed()
1520+
verify(mockCommandObserver, never()).onChanged(commandCaptor.capture())
1521+
}
1522+
15051523
@Test
15061524
fun whenUserDismissedCtaThenRegisterInDatabase() = coroutineRule.runBlocking {
15071525
val cta = HomePanelCta.AddWidgetAuto
1508-
testee.onUserDismissedCta(cta)
1526+
setCta(cta)
1527+
testee.onUserDismissedCta()
15091528
verify(mockDismissedCtaDao).insert(DismissedCta(cta.ctaId))
15101529
}
15111530

15121531
@Test
15131532
fun whenUserDismissedSurveyCtaThenDoNotRegisterInDatabase() = coroutineRule.runBlocking {
15141533
val cta = HomePanelCta.Survey(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1515-
testee.onUserDismissedCta(cta)
1534+
setCta(cta)
1535+
testee.onUserDismissedCta()
15161536
verify(mockDismissedCtaDao, never()).insert(DismissedCta(cta.ctaId))
15171537
}
15181538

15191539
@Test
15201540
fun whenUserDismissedSurveyCtaThenCancelScheduledSurveys() = coroutineRule.runBlocking {
15211541
val cta = HomePanelCta.Survey(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1522-
testee.onUserDismissedCta(cta)
1542+
setCta(cta)
1543+
testee.onUserDismissedCta()
15231544
verify(mockSurveyDao).cancelScheduledSurveys()
15241545
}
15251546

1526-
1527-
@Test
1528-
fun whenUserDismissedHomeTopPanelCtaThenReturnEmptyCta() {
1529-
val cta = HomeTopPanelCta.CovidCta()
1530-
testee.onUserDismissedCta(cta)
1531-
assertNull(testee.ctaViewState.value!!.cta)
1532-
}
1533-
15341547
@Test
15351548
fun whenSurrogateDetectedThenSiteUpdated() {
15361549
givenOneActiveTabSelected()
@@ -1665,13 +1678,6 @@ class BrowserTabViewModelTest {
16651678
assertEquals("surrogate.com", brokenSiteFeedback.surrogates)
16661679
}
16671680

1668-
@Test
1669-
fun whenUserClickedTopCtaButtonAndCtaIsCovidCtaThenSubmitQuery() {
1670-
val cta = HomeTopPanelCta.CovidCta()
1671-
testee.onUserClickTopCta(cta)
1672-
assertEquals(cta.searchTerm, omnibarViewState().omnibarText)
1673-
}
1674-
16751681
private inline fun <reified T : Command> assertCommandIssued(instanceAssertions: T.() -> Unit = {}) {
16761682
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
16771683
val issuedCommand = commandCaptor.allValues.find { it is T }
@@ -1710,6 +1716,10 @@ class BrowserTabViewModelTest {
17101716
testee.browserViewState.value = browserViewState().copy(browserShowing = isBrowsing)
17111717
}
17121718

1719+
private fun setCta(cta: Cta) {
1720+
testee.ctaViewState.value = ctaViewState().copy(cta = cta)
1721+
}
1722+
17131723
private fun loadUrl(url: String?, title: String? = null, isBrowserShowing: Boolean = true) {
17141724
setBrowserShowing(isBrowserShowing)
17151725
testee.navigationStateChanged(buildWebNavigation(originalUrl = url, currentUrl = url, title = title))
@@ -1721,10 +1731,6 @@ class BrowserTabViewModelTest {
17211731
testee.navigationStateChanged(buildWebNavigation(originalUrl = originalUrl, currentUrl = currentUrl))
17221732
}
17231733

1724-
private fun setCovidCtaShown() {
1725-
whenever(mockDismissedCtaDao.exists(CtaId.COVID)).thenReturn(true)
1726-
}
1727-
17281734
private fun setupNavigation(
17291735
skipHome: Boolean = false,
17301736
isBrowsing: Boolean,
@@ -1761,6 +1767,7 @@ class BrowserTabViewModelTest {
17611767
return nav
17621768
}
17631769

1770+
private fun ctaViewState() = testee.ctaViewState.value!!
17641771
private fun browserViewState() = testee.browserViewState.value!!
17651772
private fun omnibarViewState() = testee.omnibarViewState.value!!
17661773
private fun loadingViewState() = testee.loadingViewState.value!!

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

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@
1717
package com.duckduckgo.app.cta.ui
1818

1919
import android.content.res.Resources
20+
import android.net.Uri
2021
import androidx.fragment.app.FragmentActivity
2122
import com.duckduckgo.app.global.install.AppInstallStore
23+
import com.duckduckgo.app.global.model.Site
24+
import com.duckduckgo.app.global.model.orderedTrackingEntities
2225
import com.duckduckgo.app.onboarding.store.OnboardingStore
26+
import com.duckduckgo.app.privacy.model.HttpsStatus
27+
import com.duckduckgo.app.privacy.model.PrivacyGrade
28+
import com.duckduckgo.app.privacy.model.PrivacyPractices
2329
import com.duckduckgo.app.privacy.model.TestEntity
2430
import com.duckduckgo.app.statistics.pixels.Pixel.PixelParameter.CTA_SHOWN
2531
import com.duckduckgo.app.survey.model.Survey
32+
import com.duckduckgo.app.trackerdetection.model.Entity
2633
import com.duckduckgo.app.trackerdetection.model.TrackingEvent
2734
import com.nhaarman.mockitokotlin2.any
35+
import com.nhaarman.mockitokotlin2.mock
2836
import com.nhaarman.mockitokotlin2.whenever
2937
import org.junit.Assert.*
3038
import org.junit.Before
@@ -52,7 +60,7 @@ class CtaTest {
5260
MockitoAnnotations.initMocks(this)
5361

5462
whenever(mockActivity.resources).thenReturn(mockResources)
55-
whenever(mockResources.getString(any())).thenReturn("withZero")
63+
whenever(mockResources.getQuantityString(any(), any())).thenReturn("withZero")
5664
whenever(mockResources.getQuantityString(any(), any(), any())).thenReturn("withMultiple")
5765
}
5866

@@ -209,7 +217,7 @@ class CtaTest {
209217

210218
@Test
211219
fun whenCanSendPixelAndCtaIsPartOfHistoryThenReturnFalse() {
212-
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn("e:0")
220+
whenever(mockOnboardingStore.onboardingDialogJourney).thenReturn("i:0-e:0-s:0")
213221

214222
val testee = DaxBubbleCta.DaxEndCta(mockOnboardingStore, mockAppInstallStore)
215223
assertFalse(testee.canSendShownPixel())
@@ -261,11 +269,11 @@ class CtaTest {
261269
}
262270

263271
@Test
264-
fun whenMoreThanTwoMajorTrackersBlockedReturnFirstTwoWithMultipleString() {
272+
fun whenMoreThanTwoTrackersBlockedReturnFirstTwoWithMultipleString() {
265273
val trackers = listOf(
266-
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 9.0), categories = null),
267-
TrackingEvent("other.com", "other.com", blocked = true, entity = TestEntity("Other", "Other", 9.0), categories = null),
268-
TrackingEvent("amazon.com", "amazon.com", blocked = true, entity = TestEntity("Amazon", "Amazon", 9.0), categories = null)
274+
TestEntity("Facebook", "Facebook", 9.0),
275+
TestEntity("Other", "Other", 9.0),
276+
TestEntity("Amazon", "Amazon", 9.0)
269277
)
270278

271279
val testee = DaxDialogCta.DaxTrackersBlockedCta(mockOnboardingStore, mockAppInstallStore, trackers, "http://www.trackers.com")
@@ -275,10 +283,10 @@ class CtaTest {
275283
}
276284

277285
@Test
278-
fun whenTwoMajorTrackersBlockedReturnThemWithZeroString() {
286+
fun whenTwoTrackersBlockedReturnThemWithZeroString() {
279287
val trackers = listOf(
280-
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 9.0), categories = null),
281-
TrackingEvent("other.com", "other.com", blocked = true, entity = TestEntity("Other", "Other", 9.0), categories = null)
288+
TestEntity("Facebook", "Facebook", 9.0),
289+
TestEntity("Other", "Other", 9.0)
282290
)
283291

284292
val testee = DaxDialogCta.DaxTrackersBlockedCta(mockOnboardingStore, mockAppInstallStore, trackers, "http://www.trackers.com")
@@ -288,29 +296,58 @@ class CtaTest {
288296
}
289297

290298
@Test
291-
fun whenOneMajorTrackersBlockedReturnItWithMultipleString() {
299+
fun whenTrackersBlockedReturnThemSortingByPrevalence() {
292300
val trackers = listOf(
293-
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 9.0), categories = null),
294-
TrackingEvent("other.com", "other.com", blocked = true, entity = TestEntity("Other", "Other", 3.0), categories = null)
301+
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 3.0), categories = null),
302+
TrackingEvent("other.com", "other.com", blocked = true, entity = TestEntity("Other", "Other", 9.0), categories = null)
295303
)
304+
val site = site(events = trackers)
296305

297-
val testee = DaxDialogCta.DaxTrackersBlockedCta(mockOnboardingStore, mockAppInstallStore, trackers, "http://www.trackers.com")
306+
val testee =
307+
DaxDialogCta.DaxTrackersBlockedCta(mockOnboardingStore, mockAppInstallStore, site.orderedTrackingEntities(), "http://www.trackers.com")
298308
val value = testee.getDaxText(mockActivity)
299309

300-
assertEquals("<b>Facebook</b>withMultiple", value)
310+
assertEquals("<b>Other, Facebook</b>withZero", value)
301311
}
302312

303313
@Test
304-
fun whenMultipleTrackersFromSameNetworkBlockedReturnOnlyOneWithMultipleString() {
314+
fun whenMultipleTrackersFromSameNetworkBlockedReturnOnlyOneWithZeroString() {
305315
val trackers = listOf(
306-
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 9.0), categories = null),
307-
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 9.0), categories = null),
308-
TrackingEvent("facebook.com", "facebook.com", blocked = true, entity = TestEntity("Facebook", "Facebook", 9.0), categories = null)
316+
TestEntity("Facebook", "Facebook", 9.0),
317+
TestEntity("Facebook", "Facebook", 9.0),
318+
TestEntity("Facebook", "Facebook", 9.0)
309319
)
310320

311321
val testee = DaxDialogCta.DaxTrackersBlockedCta(mockOnboardingStore, mockAppInstallStore, trackers, "http://www.trackers.com")
312322
val value = testee.getDaxText(mockActivity)
313323

314-
assertEquals("<b>Facebook</b>withMultiple", value)
324+
assertEquals("<b>Facebook</b>withZero", value)
325+
}
326+
327+
private fun site(
328+
url: String = "http://www.test.com",
329+
uri: Uri? = Uri.parse(url),
330+
https: HttpsStatus = HttpsStatus.SECURE,
331+
trackerCount: Int = 0,
332+
events: List<TrackingEvent> = emptyList(),
333+
majorNetworkCount: Int = 0,
334+
allTrackersBlocked: Boolean = true,
335+
privacyPractices: PrivacyPractices.Practices = PrivacyPractices.UNKNOWN,
336+
entity: Entity? = null,
337+
grade: PrivacyGrade = PrivacyGrade.UNKNOWN,
338+
improvedGrade: PrivacyGrade = PrivacyGrade.UNKNOWN
339+
): Site {
340+
val site: Site = mock()
341+
whenever(site.url).thenReturn(url)
342+
whenever(site.uri).thenReturn(uri)
343+
whenever(site.https).thenReturn(https)
344+
whenever(site.entity).thenReturn(entity)
345+
whenever(site.trackingEvents).thenReturn(events)
346+
whenever(site.trackerCount).thenReturn(trackerCount)
347+
whenever(site.majorNetworkCount).thenReturn(majorNetworkCount)
348+
whenever(site.allTrackersBlocked).thenReturn(allTrackersBlocked)
349+
whenever(site.privacyPractices).thenReturn(privacyPractices)
350+
whenever(site.calculateGrades()).thenReturn(Site.SiteGrades(grade, improvedGrade))
351+
return site
315352
}
316353
}

0 commit comments

Comments
 (0)