8000 Merge branch 'release/5.64.0' into main · githublucas420/Android@7e37e70 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e37e70

Browse files
committed
Merge branch 'release/5.64.0' into main
2 parents 28dfd2a + e96bb0f commit 7e37e70

Some content is hidden

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

49 files changed

+1763
-2003
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/shortcut/ShortcutReceiverTest.kt

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -17,70 +17,27 @@
1717
package com.duckduckgo.app.browser.shortcut
1818

1919
import android.content.Intent
20-
import com.duckduckgo.app.CoroutineTestRule
21-
import com.duckduckgo.app.global.events.db.UserEventKey
2220
import com.duckduckgo.app.global.events.db.UserEventsStore
2321
import com.duckduckgo.app.global.useourapp.UseOurAppDetector
24-
import com.duckduckgo.app.runBlocking
25-
import com.duckduckgo.app.statistics.Variant
26-
import com.duckduckgo.app.statistics.VariantManager
2722
import com.duckduckgo.app.statistics.pixels.Pixel
2823
import com.nhaarman.mockitokotlin2.mock
29-
import com.nhaarman.mockitokotlin2.never
3024
import com.nhaarman.mockitokotlin2.verify
31-
import com.nhaarman.mockitokotlin2.whenever
32-
import kotlinx.coroutines.ExperimentalCoroutinesApi
3325
import org.junit.Before
34-
import org.junit.Rule
3526
import org.junit.Test
3627

37-
@ExperimentalCoroutinesApi
3828
class ShortcutReceiverTest {
3929

40-
@get:Rule
41-
var coroutinesTestRule = CoroutineTestRule()
42-
4330
private val mockUserEventsStore: UserEventsStore = mock()
4431
private val mockPixel: Pixel = mock()
45-
private val mockVariantManager: VariantManager = mock()
4632
private lateinit var testee: ShortcutReceiver
4733

4834
@Before
4935
fun before() {
50-
testee = ShortcutReceiver(
51-
mockUserEventsStore,
52-
coroutinesTestRule.testDispatcherProvider,
53-
UseOurAppDetector(mockUserEventsStore),
54-
mockVariantManager,
55-
mockPixel
56-
)
57-
}
58-
59-
@Test
60-
fun whenIntentReceivedIfUrlIsFromUseOurAppDomainAndVariantIsInAppUsageThenRegisterTimestamp() = coroutinesTestRule.runBlocking {
61-
setInAppUsageVariant()
62-
val intent = Intent()
63-
intent.putExtra(ShortcutBuilder.SHORTCUT_URL_ARG, "https://facebook.com")
64-
intent.putExtra(ShortcutBuilder.SHORTCUT_TITLE_ARG, "Title")
65-
testee.onReceive(null, intent)
66-
67-
verify(mockUserEventsStore).registerUserEvent(UserEventKey.USE_OUR_APP_SHORTCUT_ADDED)
68-
}
69-
70-
@Test
71-
fun whenIntentReceivedIfUrlIsFromUseOurAppDomainAndVariantIsNotInAppUsageThenDoNotRegisterTimestamp() = coroutinesTestRule.runBlocking {
72-
setDefaultVariant()
73-
val intent = Intent()
74-
intent.putExtra(ShortcutBuilder.SHORTCUT_URL_ARG, "https://facebook.com")
75-
intent.putExtra(ShortcutBuilder.SHORTCUT_TITLE_ARG, "Title")
76-
testee.onReceive(null, intent)
77-
78-
verify(mockUserEventsStore, never()).registerUserEvent(UserEventKey.USE_OUR_APP_SHORTCUT_ADDED)
36+
testee = ShortcutReceiver(UseOurAppDetector(mockUserEventsStore), mockPixel)
7937
}
8038

8139
@Test
8240
fun whenIntentReceivedIfUrlContainsUseOurAppDomainThenFirePixel() {
83-
setDefaultVariant()
8441
val intent = Intent()
8542
intent.putExtra(ShortcutBuilder.SHORTCUT_URL_ARG, "https://facebook.com")
8643
intent.putExtra(ShortcutBuilder.SHORTCUT_TITLE_ARG, "Title")
@@ -89,20 +46,8 @@ class ShortcutReceiverTest {
8946
verify(mockPixel).fire(Pixel.PixelName.USE_OUR_APP_SHORTCUT_ADDED)
9047
}
9148

92-
@Test
93-
fun whenIntentReceivedIfUrlIsNotFromUseOurAppDomainThenDoNotRegisterEvent() = coroutinesTestRule.runBlocking {
94-
setDefaultVariant()
95-
val intent = Intent()
96-
intent.putExtra(ShortcutBuilder.SHORTCUT_URL_ARG, "www.example.com")
97-
intent.putExtra(ShortcutBuilder.SHORTCUT_TITLE_ARG, "Title")
98-
testee.onReceive(null, intent)
99-
100-
verify(mockUserEventsStore, never()).registerUserEvent(UserEventKey.USE_OUR_APP_SHORTCUT_ADDED)
101-
}
102-
10349
@Test
10450
fun whenIntentReceivedIfUrlIsNotFromUseOurAppDomainThenFireShortcutAddedPixel() {
105-
setDefaultVariant()
10651
val intent = Intent()
10752
intent.putExtra(ShortcutBuilder.SHORTCUT_URL_ARG, "www.example.com")
10853
intent.putExtra(ShortcutBuilder.SHORTCUT_TITLE_ARG, "Title")
@@ -111,20 +56,4 @@ class ShortcutReceiverTest {
11156
verify(mockPixel).fire(Pixel.PixelName.SHORTCUT_ADDED)
11257
}
11358

114-
private fun setDefaultVariant() {
115-
whenever(mockVariantManager.getVariant()).thenReturn(VariantManager.DEFAULT_VARIANT)
116-
}
117-
118-
private fun setInAppUsageVariant() {
119-
whenever(mockVariantManager.getVariant()).thenReturn(
120-
Variant(
121-
"test",
122-
features = listOf(
123-
VariantManager.VariantFeature.InAppUsage,
124-
VariantManager.VariantFeature.RemoveDay1AndDay3Notifications,
125-
VariantManager.VariantFeature.KillOnboarding
126-
),
127-
filterBy = { true })
128-
)
129-
}
13059
}

app/src/androidTest/java/com/duckduckgo/app/notification/AndroidNotificationSchedulerTest.kt

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ import androidx.work.testing.WorkManagerTestInitHelper
2828
import com.duckduckgo.app.CoroutineTestRule
2929
import com.duckduckgo.app.notification.NotificationScheduler.ClearDataNotificationWorker
3030
import com.duckduckgo.app.notification.NotificationScheduler.PrivacyNotificationWorker
31-
import com.duckduckgo.app.notification.NotificationScheduler.UseOurAppNotificationWorker
3231
import com.duckduckgo.app.notification.model.SchedulableNotification
33-
import com.duckduckgo.app.statistics.Variant
34-
import com.duckduckgo.app.statistics.VariantManager
35-
import com.duckduckgo.app.statistics.VariantManager.Companion.DEFAULT_VARIANT
3632
import com.nhaarman.mockitokotlin2.mock
3733
import com.nhaarman.mockitokotlin2.whenever
3834
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -49,10 +45,8 @@ class AndroidNotificationSchedulerTest {
4945
@get:Rule
5046
var coroutinesTestRule = CoroutineTestRule()
5147

52-
private val variantManager: VariantManager = mock()
5348
private val clearNotification: SchedulableNotification = mock()
5449
private val privacyNotification: SchedulableNotification = mock()
55-
private val useOurAppNotification: SchedulableNotification = mock()
5650

5751
private val context = InstrumentationRegistry.getInstrumentation().targetContext
5852
private lateinit var workManager: WorkManager
@@ -65,9 +59,7 @@ class AndroidNotificationSchedulerTest {
6559
testee = NotificationScheduler(
6660
workManager,
6761
clearNotification,
68-
privacyNotification,
69-
useOurAppNotification,
70-
variantManager
62+
privacyNotification
7163
)
7264
}
7365

@@ -84,7 +76,6 @@ class AndroidNotificationSchedulerTest {
8476

8577
@Test
8678
fun whenPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled() = runBlocking<Unit> {
87-
setDefaultVariant()
8879
whenever(privacyNotification.canShow()).thenReturn(true)
8980
whenever(clearNotification.canShow()).thenReturn(true)
9081
testee.scheduleNextNotification()
@@ -94,7 +85,6 @@ class AndroidNotificationSchedulerTest {
9485

9586
@Test
9687
fun whenPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled() = runBlocking<Unit> {
97-
setDefaultVariant()
9888
whenever(privacyNotification.canShow()).thenReturn(true)
9989
whenever(clearNotification.canShow()).thenReturn(false)
10090
testee.scheduleNextNotification()
@@ -104,7 +94,6 @@ class AndroidNotificationSchedulerTest {
10494

10595
@Test
10696
fun whenPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationIsScheduled() = runBlocking<Unit> {
107-
setDefaultVariant()
10897
whenever(privacyNotification.canShow()).thenReturn(false)
10998
whenever(clearNotification.canShow()).thenReturn(true)
11099
testee.scheduleNextNotification()
@@ -114,135 +103,13 @@ class AndroidNotificationSchedulerTest {
114103

115104
@Test
116105
fun whenPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled() = runBlocking<Unit> {
117-
setDefaultVariant()
118106
whenever(privacyNotification.canShow()).thenReturn(false)
119107
whenever(clearNotification.canShow()).thenReturn(false)
120108
testee.scheduleNextNotification()
121109

122110
assertNoNotificationScheduled()
123111
}
124112

125-
@Test
126-
fun whenInAppUsageVariantAndUseOurAppNotificationCanShowThenNotificationScheduled() = runBlocking {
127-
givenNoInactiveUserNotifications()
128-
setInAppUsageVariant()
129-
whenever(useOurAppNotification.canShow()).thenReturn(true)
130-
131-
testee.scheduleNextNotification()
132-
133-
assertNotificationScheduled(UseOurAppNotificationWorker::class.jvmName, NotificationScheduler.USE_OUR_APP_WORK_REQUEST_TAG)
134-
}
135-
136-
@Test
137-
fun whenInAppUsageVariantUseOurAppNotificationCannotShowThenNoNotificationScheduled() = runBlocking {
138-
givenNoInactiveUserNotifications()
139-
setInAppUsageVariant()
140-
whenever(useOurAppNotification.canShow()).thenReturn(false)
141-
142-
testee.scheduleNextNotification()
143-
144-
assertNoNotificationScheduled(NotificationScheduler.USE_OUR_APP_WORK_REQUEST_TAG)
145-
}
146-
147-
@Test
148-
fun whenInAppUsageSecondControlVariantThenNoNotificationScheduled() = runBlocking<Unit> {
149-
setInAppUsageSecondControlVariant()
150-
whenever(useOurAppNotification.canShow()).thenReturn(true)
151-
152-
testee.scheduleNextNotification()
153-
154-
assertNoNotificationScheduled(NotificationScheduler.USE_OUR_APP_WORK_REQUEST_TAG)
155-
}
156-
157-
@Test
158-
fun whenInAppUsageControlVariantThenNoNotificationScheduled() = runBlocking<Unit> {
159-
givenNoInactiveUserNotifications()
160-
setInAppUsageControlVariant()
161-
whenever(useOurAppNotification.canShow()).thenReturn(true)
162-
163-
testee.scheduleNextNotification()
164-
165-
assertNoNotificationScheduled(NotificationScheduler.USE_OUR_APP_WORK_REQUEST_TAG)
166-
}
167-
168-
@Test
169-
fun whenInAppUsageControlVariantAndPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled() = runBlocking<Unit> {
170-
setInAppUsageControlVariant()
171-
whenever(privacyNotification.canShow()).thenReturn(true)
172-
whenever(clearNotification.canShow()).thenReturn(true)
173-
testee.scheduleNextNotification()
174-
175-
assertNotificationScheduled(PrivacyNotificationWorker::class.jvmName)
176-
}
177-
178-
@Test
179-
fun whenInAppUsageControlVariantAndPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled() = runBlocking<Unit> {
180-
setInAppUsageControlVariant()
181-
whenever(privacyNotification.canShow()).thenReturn(true)
182-
whenever(clearNotification.canShow()).thenReturn(false)
183-
testee.scheduleNextNotification()
184-
185-
assertNotificationScheduled(PrivacyNotificationWorker::class.jvmName)
186-
}
187-
188-
@Test
189-
fun whenInAppUsageControlVariantAndPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationScheduled() = runBlocking<Unit> {
190-
setInAppUsageControlVariant()
191-
whenever(privacyNotification.canShow()).thenReturn(false)
192-
whenever(clearNotification.canShow()).thenReturn(true)
193-
testee.scheduleNextNotification()
194-
195-
assertNotificationScheduled(ClearDataNotificationWorker::class.jvmName)
196-
}
197-
198-
@Test
199-
fun whenInAppUsageControlVariantAndPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled() = runBlocking<Unit> {
200-
setDefaultVariant()
201-
whenever(privacyNotification.canShow()).thenReturn(false)
202-
whenever(clearNotification.canShow()).thenReturn(false)
203-
testee.scheduleNextNotification()
204-
205-
assertNoNotificationScheduled()
206-
}
207-
208-
private suspend fun givenNoInactiveUserNotifications() {
209-
whenever(privacyNotification.canShow()).thenReturn(false)
210-
whenever(clearNotification.canShow()).thenReturn(false)
211-
}
212-
213-
private fun setInAppUsageVariant() {
214-
whenever(variantManager.getVariant()).thenReturn(
215-
Variant(
216-
"test",
217-
features = listOf(
218-
VariantManager.VariantFeature.InAppUsage,
219-
VariantManager.VariantFeature.RemoveDay1AndDay3Notifications,
220-
VariantManager.VariantFeature.KillOnboarding
221-
),
222-
filterBy = { true })
223-
)
224-
}
225-
226-
private fun setInAppUsageSecondControlVariant() {
227-
whenever(variantManager.getVariant()).thenReturn(
228-
Variant(
229-
"test",
230-
features = listOf(
231-
VariantManager.VariantFeature.RemoveDay1AndDay3Notifications,
232-
VariantManager.VariantFeature.KillOnboarding
233-
),
234-
filterBy = { true })
235-
)
236-
}
237-
238-
private fun setInAppUsageControlVariant() {
239-
whenever(variantManager.getVariant()).thenReturn(Variant("test", features = emptyList(), filterBy = { true }))
240-
}
241-
242-
private fun setDefaultVariant() {
243-
whenever(variantManager.getVariant()).thenReturn(DEFAULT_VARIANT)
244-
}
245-
246113
private fun assertNotificationScheduled(workerName: String, tag: String = NotificationScheduler.UNUSED_APP_WORK_REQUEST_TAG) {
247114
assertTrue(getScheduledWorkers(tag).any { it.tags.contains(workerName) })
248115
}

app/src/androidTest/java/com/duckduckgo/app/notification/model/AppFeatureNotificationTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.duckduckgo.app.notification.model
2020

2121
import androidx.test.platform.app.InstrumentationRegistry
22+
import com.duckduckgo.app.browser.R
2223
import com.duckduckgo.app.notification.db.NotificationDao
2324
import com.nhaarman.mockitokotlin2.any
2425
import com.nhaarman.mockitokotlin2.mock
@@ -38,7 +39,7 @@ class AppFeatureNotificationTest {
3839

3940
@Before
4041
fun before() {
41-
testee = AppFeatureNotification(context, notificationsDao, TITLE, DESCRIPTION, PIXEL)
42+
testee = AppFeatureNotification(context, notificationsDao, R.string.yes, R.string.no, PIXEL)
4243
}
4344

4445
@Test
@@ -61,7 +62,5 @@ class AppFeatureNotificationTest {
6162

6263
companion object {
6364
private const val PIXEL = "pixel"
64-
private const val TITLE = AppFeatureNotification.DRIP_B_1_TITLE
65-
private const val DESCRIPTION = AppFeatureNotification.DRIP_B_1_DESCRIPTION
6665
}
6766
}

app/src/androidTest/java/com/duckduckgo/app/notification/model/WebsiteNotificationTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.duckduckgo.app.notification.model
2020

2121
import androidx.test.platform.app.InstrumentationRegistry
22+
import com.duckduckgo.app.browser.R
2223
import com.duckduckgo.app.notification.db.NotificationDao
2324
import com.nhaarman.mockitokotlin2.any
2425
import com.nhaarman.mockitokotlin2.mock
@@ -39,7 +40,7 @@ class WebsiteNotificationTest {
3940

4041
@Before
4142
fun before() {
42-
testee = WebsiteNotification(context, notificationsDao, URL, TITLE, DESCRIPTION, PIXEL)
43+
testee = WebsiteNotification(context, notificationsDao, URL, R.string.yes, R.string.no, PIXEL)
4344
}
4445

4546
@Test
@@ -69,7 +70,5 @@ class WebsiteNotificationTest {
6970
companion object {
7071
private const val URL = "test"
7172
private const val PIXEL = "pixel"
72-
private const val TITLE = WebsiteNotification.DRIP_A_1_TITLE
73-
private const val DESCRIPTION = WebsiteNotification.DRIP_A_1_DESCRIPTION
7473
}
7574
}

0 commit comments

Comments
 (0)
0