Skip to content

Commit 504086d

Browse files
committed
Merge branch 'release/5.43.0'
2 parents a8480fb + 01739f8 commit 504086d

19 files changed

+152
-72
lines changed

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

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

1919
import android.net.Uri
2020
import com.duckduckgo.app.global.AppUrl.ParamKey
21+
import com.duckduckgo.app.referral.AppReferrerDataStore
2122
import com.duckduckgo.app.statistics.VariantManager
2223
import com.duckduckgo.app.statistics.model.Atb
2324
import com.duckduckgo.app.statistics.store.StatisticsDataStore
@@ -30,14 +31,16 @@ import org.junit.Test
3031
class DuckDuckGoRequestRewriterTest {
3132

3233
private lateinit var testee: DuckDuckGoRequestRewriter
33-
private var mockStatisticsStore: StatisticsDataStore = mock()
34-
private var mockVariantManager: VariantManager = mock()
34+
private val mockStatisticsStore: StatisticsDataStore = mock()
35+
private val mockVariantManager: VariantManager = mock()
36+
private val mockAppReferrerDataStore: AppReferrerDataStore = mock()
3537
private lateinit var builder: Uri.Builder
3638

3739
@Before
3840
fun before() {
3941
whenever(mockVariantManager.getVariant()).thenReturn(VariantManager.DEFAULT_VARIANT)
40-
testee = DuckDuckGoRequestRewriter(DuckDuckGoUrlDetector(), mockStatisticsStore, mockVariantManager)
42+
whenever(mockAppReferrerDataStore.installedFromEuAuction).thenReturn(false)
43+
testee = DuckDuckGoRequestRewriter(DuckDuckGoUrlDetector(), mockStatisticsStore, mockVariantManager, mockAppReferrerDataStore)
4144
builder = Uri.Builder()
4245
}
4346

@@ -49,6 +52,15 @@ class DuckDuckGoRequestRewriterTest {
4952
assertEquals("ddg_android", uri.getQueryParameter(ParamKey.SOURCE))
5053
}
5154

55+
@Test
56+
fun whenAddingCustomParamsAndUserSourcedFromEuAuctionThenEuSourceParameterIsAdded() {
57+
whenever(mockAppReferrerDataStore.installedFromEuAuction).thenReturn(true)
58+
testee.addCustomQueryParams(builder)
59+
val uri = builder.build()
60+
assertTrue(uri.queryParameterNames.contains(ParamKey.SOURCE))
61+
assertEquals("ddg_androideu", uri.getQueryParameter(ParamKey.SOURCE))
62+
}
63+
5264
@Test
5365
fun whenAddingCustomParamsIfStoreContainsAtbIsAdded() {
5466
whenever(mockStatisticsStore.atb).thenReturn(Atb("v105-2ma"))

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.duckduckgo.app.browser
1818

1919
import android.net.Uri
2020
import com.duckduckgo.app.browser.omnibar.QueryUrlConverter
21+
import com.duckduckgo.app.referral.AppReferrerDataStore
2122
import com.duckduckgo.app.statistics.VariantManager
2223
import com.duckduckgo.app.statistics.store.StatisticsDataStore
2324
import com.nhaarman.mockitokotlin2.mock
@@ -28,7 +29,8 @@ class QueryUrlConverterTest {
2829

2930
private var mockStatisticsStore: StatisticsDataStore = mock()
3031
private val variantManager: VariantManager = mock()
31-
private val requestRewriter = DuckDuckGoRequestRewriter(DuckDuckGoUrlDetector(), mockStatisticsStore, variantManager)
32+
private val mockAppReferrerDataStore: AppReferrerDataStore = mock()
33+
private val requestRewriter = DuckDuckGoRequestRewriter(DuckDuckGoUrlDetector(), mockStatisticsStore, variantManager, mockAppReferrerDataStore)
3234
private val testee: QueryUrlConverter = QueryUrlConverter(requestRewriter)
3335

3436
@Test

app/src/androidTest/java/com/duckduckgo/app/launch/LaunchViewModelTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class LaunchViewModelTest {
120120
override suspend fun waitForReferrerCode(): ParsedReferrerResult {
121121
if (mockDelayMs > 0) delay(mockDelayMs)
122122

123-
return ParsedReferrerResult.ReferrerFound(referrer)
123+
return ParsedReferrerResult.CampaignReferrerFound(referrer)
124124
}
125125

126126
override fun initialiseReferralRetrieval() {

app/src/androidTest/java/com/duckduckgo/app/referral/QueryParamReferrerParserTest.kt

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@
1616

1717
package com.duckduckgo.app.referral
1818

19-
import com.duckduckgo.app.referral.ParsedReferrerResult.ReferrerFound
20-
import com.duckduckgo.app.statistics.pixels.Pixel
21-
import com.nhaarman.mockitokotlin2.mock
19+
import com.duckduckgo.app.referral.ParsedReferrerResult.CampaignReferrerFound
20+
import com.duckduckgo.app.referral.ParsedReferrerResult.EuAuctionReferrerFound
2221
import org.junit.Assert.assertEquals
2322
import org.junit.Assert.assertTrue
2423
import org.junit.Test
2524

2625
class QueryParamReferrerParserTest {
2726

28-
private val pixel: Pixel = mock()
29-
30-
private val testee: QueryParamReferrerParser = QueryParamReferrerParser(pixel)
27+
private val testee: QueryParamReferrerParser = QueryParamReferrerParser()
3128

3229
@Test
3330
fun whenReferrerDoesNotContainTargetThenNoReferrerFound() {
@@ -37,13 +34,13 @@ class QueryParamReferrerParserTest {
3734
@Test
3835
fun whenReferrerContainsTargetAndLongSuffixThenShortenedReferrerFound() {
3936
val result = testee.parse("DDGRAABC")
40-
verifyReferrerFound("AB", result)
37+
verifyCampaignReferrerFound("AB", result)
4138
}
4239

4340
@Test
4441
fun whenReferrerContainsTargetAndTwoCharSuffixThenReferrerFound() {
4542
val result = testee.parse("DDGRAXY")
46-
verifyReferrerFound("XY", result)
43+
verifyCampaignReferrerFound("XY", result)
4744
}
4845

4946
@Test
@@ -66,13 +63,13 @@ class QueryParamReferrerParserTest {
6663
@Test
6764
fun whenReferrerContainsTargetAsFirstParamThenReferrerFound() {
6865
val result = testee.parse("key1=DDGRAAB&key2=foo&key3=bar")
69-
verifyReferrerFound("AB", result)
66+
verifyCampaignReferrerFound("AB", result)
7067
}
7168

7269
@Test
7370
fun whenReferrerContainsTargetAsLastParamThenReferrerFound() {
7471
val result = testee.parse("key1=foo&key2=bar&key3=DDGRAAB")
75-
verifyReferrerFound("AB", result)
72+
verifyCampaignReferrerFound("AB", result)
7673
}
7774

7875
@Test
@@ -81,17 +78,42 @@ class QueryParamReferrerParserTest {
8178
}
8279

8380
@Test
84-
fun whenTypeAReferrerNotFoundButTypeBFoundThenReferrerFound() {
85-
verifyReferrerFound("AB", testee.parse("key1=foo&key2=bar&key3=DDGRBAB"))
81+
fun whenReferrerContainsEuAuctionDataThenEuActionReferrerFound() {
82+
val result = testee.parse("$INSTALLATION_SOURCE_KEY=$INSTALLATION_SOURCE_EU_AUCTION_VALUE")
83+
assertTrue(result is EuAuctionReferrerFound)
84+
}
85+
86+
@Test
87+
fun whenReferrerContainsBothEuAuctionAndCampaignReferrerDataThenEuActionReferrerFound() {
88+
val result = testee.parse("key1=DDGRAAB&key2=foo&key3=bar&$INSTALLATION_SOURCE_KEY=$INSTALLATION_SOURCE_EU_AUCTION_VALUE")
89+
assertTrue(result is EuAuctionReferrerFound)
90+
}
91+
92+
@Test
93+
fun whenReferrerContainsInstallationSourceKeyButNotMatchingValueThenNoReferrerFound() {
94+
val result = testee.parse("$INSTALLATION_SOURCE_KEY=bar")
95+
verifyReferrerNotFound(result)
96+
}
97+
98+
@Test
99+
fun whenReferrerContainsInstallationSourceKeyAndNoEuAuctionValueButHasCampaignReferrerDataThenCampaignReferrerFound() {
100+
val result = testee.parse("key1=DDGRAAB&key2=foo&key3=bar&$INSTALLATION_SOURCE_KEY=bar")
101+
verifyCampaignReferrerFound("AB", result)
86102
}
87103

88-
private fun verifyReferrerFound(expectedReferrer: String, result: ParsedReferrerResult) {
89-
assertTrue(result is ReferrerFound)
90-
val value = (result as ReferrerFound).campaignSuffix
104+
private fun verifyCampaignReferrerFound(expectedReferrer: String, result: ParsedReferrerResult) {
105+
assertTrue(result is CampaignReferrerFound)
106+
val value = (result as CampaignReferrerFound).campaignSuffix
91107
assertEquals(expectedReferrer, value)
92108
}
93109

94110
private fun verifyReferrerNotFound(result: ParsedReferrerResult) {
95111
assertTrue(result is ParsedReferrerResult.ReferrerNotFound)
96112
}
113+
114+
companion object {
115+
private const val INSTALLATION_SOURCE_KEY = "utm_source"
116+
private const val INSTALLATION_SOURCE_EU_AUCTION_VALUE = "eea-search-choice"
117+
}
118+
97119
}

app/src/androidTest/java/com/duckduckgo/app/statistics/AtbInitializerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ class AtbInitializerTest {
8888

8989
private suspend fun referrerAnswer(delayMs: Long): Answer<ParsedReferrerResult> {
9090
delay(delayMs)
91-
return Answer { ParsedReferrerResult.ReferrerFound("") }
91+
return Answer { ParsedReferrerResult.CampaignReferrerFound("") }
9292
}
9393
}

app/src/androidTest/java/com/duckduckgo/app/statistics/VariantManagerTest.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package com.duckduckgo.app.statistics
1818

1919
import com.duckduckgo.app.statistics.VariantManager.VariantFeature.*
20-
import org.junit.Assert.assertEquals
21-
import org.junit.Assert.assertTrue
22-
import org.junit.Assert.fail
20+
import org.junit.Assert.*
2321
import org.junit.Test
2422

2523
class VariantManagerTest {
@@ -131,6 +129,17 @@ class VariantManagerTest {
131129
assertTrue(variant.hasFeature(ConceptTest))
132130
}
133131

132+
@Test
133+
fun verifyNoDuplicateVariantNames() {
134+
val existingNames = mutableSetOf<String>()
135+
variants.forEach {
136+
if (!existingNames.add(it.key)) {
137+
fail("Duplicate variant name found: ${it.key}")
138+
}
139+
}
140+
}
141+
142+
134143
@Suppress("SameParameterValue")
135144
private fun assertEqualsDouble(expected: Double, actual: Double) {
136145
val comparison = expected.compareTo(actual)

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class BrowserTabFragment : Fragment(), FindListener, CoroutineScope {
512512
}
513513
is Command.DownloadImage -> requestImageDownload(it.url)
514514
is Command.FindInPageCommand -> webView?.findAllAsync(it.searchTerm)
515-
is Command.DismissFindInPage -> webView?.findAllAsync(null)
515+
is Command.DismissFindInPage -> webView?.findAllAsync("")
516516
is Command.ShareLink -> launchSharePageChooser(it.url)
517517
is Command.CopyLink -> {
518518
clipboardManager.primaryClip = ClipData.newPlainText(null, it.url)
@@ -1010,6 +1010,7 @@ class BrowserTabFragment : Fragment(), FindListener, CoroutineScope {
10101010
url = url,
10111011
contentDisposition = contentDisposition,
10121012
mimeType = mimeType,
1013+
userAgent = userAgentProvider.getUserAgent(),
10131014
subfolder = Environment.DIRECTORY_DOWNLOADS
10141015
)
10151016

@@ -1019,6 +1020,7 @@ class BrowserTabFragment : Fragment(), FindListener, CoroutineScope {
10191020
private fun requestImageDownload(url: String) {
10201021
pendingFileDownload = PendingFileDownload(
10211022
url = url,
1023+
userAgent = userAgentProvider.getUserAgent(),
10221024
subfolder = Environment.DIRECTORY_PICTURES
10231025
)
10241026

app/src/main/java/com/duckduckgo/app/browser/DuckDuckGoRequestRewriter.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.duckduckgo.app.browser
1919
import android.net.Uri
2020
import com.duckduckgo.app.global.AppUrl.ParamKey
2121
import com.duckduckgo.app.global.AppUrl.ParamValue
22+
import com.duckduckgo.app.referral.AppReferrerDataStore
2223
import com.duckduckgo.app.statistics.VariantManager
2324
import com.duckduckgo.app.statistics.store.StatisticsDataStore
2425
import timber.log.Timber
@@ -32,7 +33,8 @@ interface RequestRewriter {
3233
class DuckDuckGoRequestRewriter(
3334
private val duckDuckGoUrlDetector: DuckDuckGoUrlDetector,
3435
private val statisticsStore: StatisticsDataStore,
35-
private val variantManager: VariantManager
36+
private val variantManager: VariantManager,
37+
private val appReferrerDataStore: AppReferrerDataStore
3638
) : RequestRewriter {
3739

3840
override fun rewriteRequestWithCustomQueryParams(request: Uri): Uri {
@@ -67,6 +69,8 @@ class DuckDuckGoRequestRewriter(
6769
if (atb != null) {
6870
builder.appendQueryParameter(ParamKey.ATB, atb.formatWithVariant(variantManager.getVariant()))
6971
}
70-
builder.appendQueryParameter(ParamKey.SOURCE, ParamValue.SOURCE)
72+
73+
val sourceValue = if (appReferrerDataStore.installedFromEuAuction) ParamValue.SOURCE_EU_AUCTION else ParamValue.SOURCE
74+
builder.appendQueryParameter(ParamKey.SOURCE, sourceValue)
7175
}
7276
}

app/src/main/java/com/duckduckgo/app/browser/di/BrowserModule.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.duckduckgo.app.global.file.FileDeleter
3939
import com.duckduckgo.app.global.install.AppInstallStore
4040
import com.duckduckgo.app.httpsupgrade.HttpsUpgrader
4141
import com.duckduckgo.app.privacy.db.PrivacyProtectionCountDao
42+
import com.duckduckgo.app.referral.AppReferrerDataStore
4243
import com.duckduckgo.app.statistics.VariantManager
4344
import com.duckduckgo.app.statistics.pixels.Pixel
4445
import com.duckduckgo.app.statistics.store.OfflinePixelCountDataStore
@@ -57,9 +58,10 @@ class BrowserModule {
5758
fun duckDuckGoRequestRewriter(
5859
urlDetector: DuckDuckGoUrlDetector,
5960
statisticsStore: StatisticsDataStore,
60-
variantManager: VariantManager
61+
variantManager: VariantManager,
62+
appReferrerDataStore: AppReferrerDataStore
6163
): RequestRewriter {
62-
return DuckDuckGoRequestRewriter(urlDetector, statisticsStore, variantManager)
64+
return DuckDuckGoRequestRewriter(urlDetector, statisticsStore, variantManager, appReferrerDataStore)
6365
}
6466

6567
@Provides

app/src/main/java/com/duckduckgo/app/browser/downloader/FileDownloader.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class FileDownloader @Inject constructor(
4646
val contentDisposition: String? = null,
4747
val mimeType: String? = null,
4848
val subfolder: String,
49+
val userAgent: String,
4950
val directory: File = Environment.getExternalStoragePublicDirectory(subfolder)
5051
)
5152

0 commit comments

Comments
 (0)