Skip to content

Commit 9b66e7c

Browse files
committed
Merge branch 'release/5.92.0' into main
2 parents 5f3574e + e3d8c69 commit 9b66e7c

File tree

80 files changed

+848
-713
lines changed

Some content is hidden

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

80 files changed

+848
-713
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ import com.duckduckgo.app.location.data.LocationPermissionEntity
8888
import com.duckduckgo.app.location.data.LocationPermissionType
8989
import com.duckduckgo.app.location.data.LocationPermissionsDao
9090
import com.duckduckgo.app.location.data.LocationPermissionsRepository
91-
import com.duckduckgo.app.notification.db.NotificationDao
9291
import com.duckduckgo.app.onboarding.store.AppStage
9392
import com.duckduckgo.app.onboarding.store.OnboardingStore
9493
import com.duckduckgo.app.onboarding.store.UserStageStore
@@ -101,8 +100,6 @@ import com.duckduckgo.app.privacy.model.TestEntity
101100
import com.duckduckgo.app.privacy.model.UserWhitelistedDomain
102101
import com.duckduckgo.app.runBlocking
103102
import com.duckduckgo.app.settings.db.SettingsDataStore
104-
import com.duckduckgo.app.statistics.VariantManager
105-
import com.duckduckgo.app.statistics.VariantManager.Companion.DEFAULT_VARIANT
106103
import com.duckduckgo.app.statistics.api.StatisticsUpdater
107104
import com.duckduckgo.app.statistics.pixels.Pixel
108105
import com.duckduckgo.app.surrogates.SurrogateResponse
@@ -220,9 +217,6 @@ class BrowserTabViewModelTest {
220217
@Mock
221218
private lateinit var mockAppInstallStore: AppInstallStore
222219

223-
@Mock
224-
private lateinit var mockVariantManager: VariantManager
225-
226220
@Mock
227221
private lateinit var mockPixel: Pixel
228222

@@ -250,9 +244,6 @@ class BrowserTabViewModelTest {
250244
@Mock
251245
private lateinit var mockUserEventsStore: UserEventsStore
252246

253-
@Mock
254-
private lateinit var mockNotificationDao: NotificationDao
255-
256247
@Mock
257248
private lateinit var mockFileDownloader: FileDownloader
258249

@@ -342,7 +333,6 @@ class BrowserTabViewModelTest {
342333
val siteFactory = SiteFactory(mockPrivacyPractices, mockEntityLookup)
343334

344335
whenever(mockOmnibarConverter.convertQueryToUrl(any(), any(), any())).thenReturn("duckduckgo.com")
345-
whenever(mockVariantManager.getVariant()).thenReturn(DEFAULT_VARIANT)
346336
whenever(mockTabRepository.liveSelectedTab).thenReturn(selectedTabLiveData)
347337
whenever(mockNavigationAwareLoginDetector.loginEventLiveData).thenReturn(loginEventLiveData)
348338
whenever(mockTabRepository.retrieveSiteData(any())).thenReturn(MutableLiveData())
@@ -382,8 +372,6 @@ class BrowserTabViewModelTest {
382372
geoLocationPermissions = geoLocationPermissions,
383373
navigationAwareLoginDetector = mockNavigationAwareLoginDetector,
384374
userEventsStore = mockUserEventsStore,
385-
notificationDao = mockNotificationDao,
386-
variantManager = mockVariantManager,
387375
fileDownloader = mockFileDownloader,
388376
globalPrivacyControl = GlobalPrivacyControlManager(mockSettingsStore),
389377
fireproofDialogsEventHandler = fireproofDialogsEventHandler,
@@ -2832,7 +2820,6 @@ class BrowserTabViewModelTest {
28322820

28332821
testee.iconReceived("https://notexample.com", bitmap)
28342822

2835-
verify(mockPixel).enqueueFire(AppPixelName.FAVICON_WRONG_URL_ERROR)
28362823
verify(mockTabRepository, never()).updateTabFavicon("TAB_ID", file.name)
28372824
}
28382825

@@ -2875,7 +2862,6 @@ class BrowserTabViewModelTest {
28752862

28762863
testee.iconReceived("https://notexample.com", "https://example.com/favicon.png")
28772864

2878-
verify(mockPixel).enqueueFire(AppPixelName.FAVICON_WRONG_URL_ERROR)
28792865
verify(mockFaviconManager, never()).storeFavicon(any(), any())
28802866
}
28812867

@@ -3155,19 +3141,21 @@ class BrowserTabViewModelTest {
31553141
@Test
31563142
fun whenConsumeAliasThenPixelSent() {
31573143
whenever(mockEmailManager.getAlias()).thenReturn("alias")
3144+
whenever(mockEmailManager.getCohort()).thenReturn("cohort")
31583145

31593146
testee.consumeAlias()
31603147

3161-
verify(mockPixel).enqueueFire(AppPixelName.EMAIL_USE_ALIAS)
3148+
verify(mockPixel).enqueueFire(AppPixelName.EMAIL_USE_ALIAS, mapOf(Pixel.PixelParameter.COHORT to "cohort"))
31623149
}
31633150

31643151
@Test
31653152
fun whenCancelAutofillTooltipThenPixelSent() {
31663153
whenever(mockEmailManager.getAlias()).thenReturn("alias")
3154+
whenever(mockEmailManager.getCohort()).thenReturn("cohort")
31673155

31683156
testee.cancelAutofillTooltip()
31693157

3170-
verify(mockPixel).enqueueFire(AppPixelName.EMAIL_TOOLTIP_DISMISSED)
3158+
verify(mockPixel).enqueueFire(AppPixelName.EMAIL_TOOLTIP_DISMISSED, mapOf(Pixel.PixelParameter.COHORT to "cohort"))
31713159
}
31723160

31733161
@Test
@@ -3184,10 +3172,11 @@ class BrowserTabViewModelTest {
31843172
@Test
31853173
fun whenUseAddressThenPixelSent() {
31863174
whenever(mockEmailManager.getEmailAddress()).thenReturn("address")
3175+
whenever(mockEmailManager.getCohort()).thenReturn("cohort")
31873176

31883177
testee.useAddress()
31893178

3190-
verify(mockPixel).enqueueFire(AppPixelName.EMAIL_USE_ADDRESS)
3179+
verify(mockPixel).enqueueFire(AppPixelName.EMAIL_USE_ADDRESS, mapOf(Pixel.PixelParameter.COHORT to "cohort"))
31913180
}
31923181

31933182
@Test

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,6 @@ class BrowserWebViewClientTest {
217217
verify(listener, never()).prefetchFavicon(any())
218218
}
219219

220-
@UiThreadTest
221-
@Test
222-
fun whenOnPageFinishedCalledThenInjectEmailAutofillJsCalled() {
223-
testee.onPageFinished(webView, null)
224-
verify(emailInjector).injectEmailAutofillJs(webView, null)
225-
}
226-
227220
@UiThreadTest
228221
@Test
229222
fun whenOnPageFinishedCalledThenFlushCookies() {
@@ -243,9 +236,9 @@ class BrowserWebViewClientTest {
243236

244237
@UiThreadTest
245238
@Test
246-
fun whenOnPageStartedCalledThenResetInjectedJsFlagCalled() {
239+
fun whenOnPageStartedCalledThenInjectEmailAutofillJsCalled() {
247240
testee.onPageStarted(webView, null, null)
248-
verify(emailInjector).resetInjectedJsFlag()
241+
verify(emailInjector).injectEmailAutofillJs(webView, null)
249242
}
250243

251244
@Test

app/src/androidTest/java/com/duckduckgo/app/browser/downloader/BlobConverterInjectorJsTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.duckduckgo.app.browser.downloader
1818

1919
import android.webkit.WebView
2020
import androidx.test.annotation.UiThreadTest
21+
import androidx.test.filters.SdkSuppress
2122
import androidx.test.platform.app.InstrumentationRegistry
2223
import com.duckduckgo.app.browser.R
2324
import com.nhaarman.mockitokotlin2.spy
@@ -37,6 +38,7 @@ class BlobConverterInjectorJsTest {
3738

3839
@UiThreadTest
3940
@Test
41+
@SdkSuppress(minSdkVersion = 24)
4042
fun whenConvertBlobIntoDataUriAndDownloadThenInjectJsCode() {
4143
val jsToEvaluate = getJsToEvaluate().replace("%blobUrl%", blobUrl).replace("%contentType%", contentType)
4244
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))

app/src/androidTest/java/com/duckduckgo/app/browser/logindetection/JsLoginDetectorTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.net.Uri
2020
import android.webkit.WebResourceRequest
2121
import android.webkit.WebView
2222
import androidx.test.annotation.UiThreadTest
23+
import androidx.test.filters.SdkSuppress
2324
import androidx.test.platform.app.InstrumentationRegistry
2425
import com.duckduckgo.app.CoroutineTestRule
2526
import com.duckduckgo.app.browser.logindetection.LoginDetectionJavascriptInterface.Companion.JAVASCRIPT_INTERFACE_NAME
@@ -42,6 +43,7 @@ class JsLoginDetectorTest {
4243

4344
@UiThreadTest
4445
@Test
46+
@SdkSuppress(minSdkVersion = 24)
4547
fun whenAddLoginDetectionThenJSInterfaceAdded() = coroutinesTestRule.runBlocking {
4648
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
4749
testee.addLoginDetection(webView) {}
@@ -50,6 +52,7 @@ class JsLoginDetectorTest {
5052

5153
@UiThreadTest
5254
@Test
55+
@SdkSuppress(minSdkVersion = 24)
5356
fun whenLoginDetectionDisabledAndPageStartedEventThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
5457
whenever(settingsDataStore.appLoginDetection).thenReturn(false)
5558
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -59,6 +62,7 @@ class JsLoginDetectorTest {
5962

6063
@UiThreadTest
6164
@Test
65+
@SdkSuppress(minSdkVersion = 24)
6266
fun whenLoginDetectionDisabledAndInterceptRequestEventThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
6367
whenever(settingsDataStore.appLoginDetection).thenReturn(false)
6468
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -69,6 +73,7 @@ class JsLoginDetectorTest {
6973

7074
@UiThreadTest
7175
@Test
76+
@SdkSuppress(minSdkVersion = 24)
7277
fun whenLoginDetectionEnabledAndPageStartedEventThenJSLoginDetectionInjected() = coroutinesTestRule.runBlocking {
7378
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
7479
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -78,6 +83,7 @@ class JsLoginDetectorTest {
7883

7984
@UiThreadTest
8085
@Test
86+
@SdkSuppress(minSdkVersion = 24)
8187
fun whenLoginDetectionEnabledAndLoginPostRequestCapturedThenJSLoginDetectionInjected() = coroutinesTestRule.runBlocking {
8288
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
8389
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -88,6 +94,7 @@ class JsLoginDetectorTest {
8894

8995
@UiThreadTest
9096
@Test
97+
@SdkSuppress(minSdkVersion = 24)
9198
fun whenLoginDetectionEnabledAndNoLoginPostRequestCapturedThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
9299
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
93100
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -98,6 +105,7 @@ class JsLoginDetectorTest {
98105

99106
@UiThreadTest
100107
@Test
108+
@SdkSuppress(minSdkVersion = 24)
101109
fun whenLoginDetectionEnabledAndGetRequestCapturedThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
102110
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
103111
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))

app/src/androidTest/java/com/duckduckgo/app/email/AppEmailManagerTest.kt

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
2020
import com.duckduckgo.app.CoroutineTestRule
2121
import com.duckduckgo.app.email.AppEmailManager.WaitlistState.*
2222
import com.duckduckgo.app.email.AppEmailManager.Companion.DUCK_EMAIL_DOMAIN
23+
import com.duckduckgo.app.email.AppEmailManager.Companion.UNKNOWN_COHORT
2324
import com.duckduckgo.app.email.api.EmailAlias
2425
import com.duckduckgo.app.email.api.EmailInviteCodeResponse
2526
import com.duckduckgo.app.email.api.EmailService
@@ -134,32 +135,33 @@ class AppEmailManagerTest {
134135
whenever(mockEmailDataStore.emailToken).thenReturn("token")
135136
whenever(mockEmailService.newAlias(any())).thenReturn(EmailAlias(""))
136137

137-
testee.storeCredentials("token", "username")
138+
testee.storeCredentials("token", "username", "cohort")
138139

139140
verify(mockEmailService).newAlias(any())
140141
}
141142

142143
@Test
143144
fun whenStoreCredentialsThenCredentialsAreStoredInDataStore() {
144-
testee.storeCredentials("token", "username")
145+
testee.storeCredentials("token", "username", "cohort")
145146

146147
verify(mockEmailDataStore).emailUsername = "username"
147148
verify(mockEmailDataStore).emailToken = "token"
149+
verify(mockEmailDataStore).cohort = "cohort"
148150
}
149151

150152
@Test
151153
fun whenStoreCredentialsIfCredentialsWereCorrectlyStoredThenIsSignedInChannelSendsTrue() = coroutineRule.runBlocking {
152154
whenever(mockEmailDataStore.emailToken).thenReturn("token")
153155
whenever(mockEmailDataStore.emailUsername).thenReturn("username")
154156

155-
testee.storeCredentials("token", "username")
157+
testee.storeCredentials("token", "username", "cohort")
156158

157159
assertTrue(testee.signedInFlow().first())
158160
}
159161

160162
@Test
161163
fun whenStoreCredentialsIfCredentialsWereNotCorrectlyStoredThenIsSignedInChannelSendsFalse() = coroutineRule.runBlocking {
162-
testee.storeCredentials("token", "username")
164+
testee.storeCredentials("token", "username", "cohort")
163165

164166
assertFalse(testee.signedInFlow().first())
165167
}
@@ -332,6 +334,27 @@ class AppEmailManagerTest {
332334
verify(mockEmailDataStore).sendNotification = true
333335
}
334336

337+
@Test
338+
fun whenGetCohortThenReturnCohort() {
339+
whenever(mockEmailDataStore.cohort).thenReturn("cohort")
340+
341+
assertEquals("cohort", testee.getCohort())
342+
}
343+
344+
@Test
345+
fun whenGetCohortIfCohortIsNullThenReturnUnknown() {
346+
whenever(mockEmailDataStore.cohort).thenReturn(null)
347+
348+
assertEquals(UNKNOWN_COHORT, testee.getCohort())
349+
}
350+
351+
@Test
352+
fun whenGetCohortIfCohortIsEmtpyThenReturnUnknown() {
353+
whenever(mockEmailDataStore.cohort).thenReturn("")
354+
355+
assertEquals(UNKNOWN_COHORT, testee.getCohort())
356+
}
357+
335358
private fun givenUserIsInWaitlist() {
336359
whenever(mockEmailDataStore.waitlistTimestamp).thenReturn(1234)
337360
whenever(mockEmailDataStore.waitlistToken).thenReturn("token")

app/src/androidTest/java/com/duckduckgo/app/email/EmailInjectorJsTest.kt

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.duckduckgo.app.email
1818

1919
import android.webkit.WebView
2020
import androidx.test.annotation.UiThreadTest
21+
import androidx.test.filters.SdkSuppress
2122
import androidx.test.platform.app.InstrumentationRegistry
2223
import com.duckduckgo.app.browser.DuckDuckGoUrlDetector
2324
import com.duckduckgo.app.browser.R
@@ -38,6 +39,7 @@ class EmailInjectorJsTest {
3839

3940
@UiThreadTest
4041
@Test
42+
@SdkSuppress(minSdkVersion = 24)
4143
fun whenInjectEmailAutofillJsAndUrlIsFromDuckDuckGoDomainThenInjectJsCode() {
4244
val jsToEvaluate = getJsToEvaluate()
4345
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -49,6 +51,7 @@ class EmailInjectorJsTest {
4951

5052
@UiThreadTest
5153
@Test
54+
@SdkSuppress(minSdkVersion = 24)
5255
fun whenInjectEmailAutofillJsAndUrlIsFromDuckDuckGoSubdomainThenInjectJsCode() {
5356
val jsToEvaluate = getJsToEvaluate()
5457
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -60,6 +63,7 @@ class EmailInjectorJsTest {
6063

6164
@UiThreadTest
6265
@Test
66+
@SdkSuppress(minSdkVersion = 24)
6367
fun whenInjectEmailAutofillJsAndUrlIsNotFromDuckDuckGoAndEmailIsSignedInThenInjectJsCode() {
6468
whenever(mockEmailManager.isSignedIn()).thenReturn(true)
6569
val jsToEvaluate = getJsToEvaluate()
@@ -72,6 +76,7 @@ class EmailInjectorJsTest {
7276

7377
@UiThreadTest
7478
@Test
79+
@SdkSuppress(minSdkVersion = 24)
7580
fun whenInjectEmailAutofillJsAndUrlIsNotFromDuckDuckGoAndEmailIsNotSignedInThenDoNotInjectJsCode() {
7681
whenever(mockEmailManager.isSignedIn()).thenReturn(false)
7782
val jsToEvaluate = getJsToEvaluate()
@@ -84,33 +89,7 @@ class EmailInjectorJsTest {
8489

8590
@UiThreadTest
8691
@Test
87-
fun whenInjectEmailAutofillJsTwiceThenDoNotInjectJsCodeTwice() {
88-
whenever(mockEmailManager.isSignedIn()).thenReturn(true)
89-
val jsToEvaluate = getJsToEvaluate()
90-
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
91-
92-
testee.injectEmailAutofillJs(webView, "https://example.com")
93-
testee.injectEmailAutofillJs(webView, "https://example.com")
94-
95-
verify(webView, times(1)).evaluateJavascript(jsToEvaluate, null)
96-
}
97-
98-
@UiThreadTest
99-
@Test
100-
fun whenResetInjectedFlagCalledBetweenTwoInjectEmailJsCallsThenInjectJsCodeTwice() {
101-
whenever(mockEmailManager.isSignedIn()).thenReturn(true)
102-
val jsToEvaluate = getJsToEvaluate()
103-
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
104-
105-
testee.injectEmailAutofillJs(webView, "https://example.com")
106-
testee.resetInjectedJsFlag()
107-
testee.injectEmailAutofillJs(webView, "https://example.com")
108-
109-
verify(webView, times(2)).evaluateJavascript(jsToEvaluate, null)
110-
}
111-
112-
@UiThreadTest
113-
@Test
92+
@SdkSuppress(minSdkVersion = 24)
11493
fun whenInjectAddressThenInjectJsCodeReplacingTheAlias() {
11594
val address = "address"
11695
val jsToEvaluate = getAliasJsToEvaluate().replace("%s", address)

app/src/androidTest/java/com/duckduckgo/app/email/EmailJavascriptInterfaceTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class EmailJavascriptInterfaceTest {
6666

6767
@Test
6868
fun whenStoreCredentialsThenStoreCredentialsCalledWithCorrectParameters() {
69-
testee.storeCredentials("token", "username")
69+
testee.storeCredentials("token", "username", "cohort")
7070

71-
verify(mockEmailManager).storeCredentials("token", "username")
71+
verify(mockEmailManager).storeCredentials("token", "username", "cohort")
7272
}
7373

7474
@Test

app/src/androidTest/java/com/duckduckgo/app/globalprivacycontrol/GlobalPrivacyControlManagerTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.duckduckgo.app.globalprivacycontrol
1919
import android.webkit.WebView
2020
import androidx.core.net.toUri
2121
import androidx.test.annotation.UiThreadTest
22+
import androidx.test.filters.SdkSuppress
2223
import androidx.test.platform.app.InstrumentationRegistry
2324
import com.duckduckgo.app.browser.R
2425
import com.duckduckgo.app.globalprivacycontrol.GlobalPrivacyControlManager.Companion.GPC_HEADER
@@ -47,6 +48,7 @@ class GlobalPrivacyControlManagerTest {
4748

4849
@UiThreadTest
4950
@Test
51+
@SdkSuppress(minSdkVersion = 24)
5052
fun whenInjectDoNotSellToDomAndGcpIsEnabledThenInjectToDom() {
5153
val jsToEvaluate = getJsToEvaluate()
5254
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
@@ -59,6 +61,7 @@ class GlobalPrivacyControlManagerTest {
5961

6062
@UiThreadTest
6163
@Test
64+
@SdkSuppress(minSdkVersion = 24)
6265
fun whenInjectDoNotSellToDomAndGcpIsNotEnabledThenDoNotInjectToDom() {
6366
val jsToEvaluate = getJsToEvaluate()
6467
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))

0 commit comments

Comments
 (0)