Skip to content

Commit 56d31bb

Browse files
committed
Merge branch 'release/5.36.1'
2 parents a9ba7db + 3c5fe7e commit 56d31bb

Some content is hidden

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

47 files changed

+314
-69
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ android {
3939
}
4040
buildTypes {
4141
debug {
42+
applicationIdSuffix ".debug"
4243
pseudoLocalesEnabled false
4344
}
4445
release {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,25 @@ class BrowserWebViewClientTest {
3636
private lateinit var testee: BrowserWebViewClient
3737
private lateinit var webView: WebView
3838

39-
private val requestRewriter: RequestRewriter = mock()
4039
private val specialUrlDetector: SpecialUrlDetector = mock()
4140
private val requestInterceptor: RequestInterceptor = mock()
4241
private val listener: WebViewClientListener = mock()
4342
private val offlinePixelCountDataStore: OfflinePixelCountDataStore = mock()
4443
private val uncaughtExceptionRepository: UncaughtExceptionRepository = mock()
44+
private val mainFrameUrlHandler: SpecialUrlHandler = mock()
45+
private val subFrameUrlHandler: SpecialUrlHandler = mock()
4546

4647
@UiThreadTest
4748
@Before
4849
fun setup() {
4950
webView = TestWebView(InstrumentationRegistry.getInstrumentation().targetContext)
5051
testee = BrowserWebViewClient(
51-
requestRewriter,
5252
specialUrlDetector,
5353
requestInterceptor,
5454
offlinePixelCountDataStore,
55-
uncaughtExceptionRepository
55+
uncaughtExceptionRepository,
56+
mainFrameUrlHandler,
57+
subFrameUrlHandler
5658
)
5759
testee.webViewClientListener = listener
5860
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2019 DuckDuckGo
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.duckduckgo.app.browser
18+
19+
import android.content.Intent
20+
import android.webkit.WebView
21+
import androidx.test.annotation.UiThreadTest
22+
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
23+
import com.duckduckgo.app.browser.SpecialUrlDetector.UrlType.*
24+
import com.nhaarman.mockitokotlin2.mock
25+
import org.junit.Assert.assertFalse
26+
import org.junit.Assert.assertTrue
27+
import org.junit.Before
28+
import org.junit.Test
29+
30+
class SubFrameUrlHandlerTest {
31+
32+
private val testee = SubFrameUrlHandler()
33+
private lateinit var webView: WebView
34+
private val mockWebViewClientListener: WebViewClientListener = mock()
35+
36+
@UiThreadTest
37+
@Before
38+
fun setUp() {
39+
webView = WebView(getInstrumentation().targetContext)
40+
}
41+
42+
@Test
43+
fun whenWebTypeUrlThenRequestShouldNotBeOverridden() {
44+
assertFalse(testee.handleUrl(webView, Web(""), mockWebViewClientListener))
45+
}
46+
47+
@Test
48+
fun whenTelephoneTypeUrlThenRequestShouldBeOverridden() {
49+
assertTrue(testee.handleUrl(webView, Telephone(""), mockWebViewClientListener))
50+
}
51+
52+
@Test
53+
fun whenEmailUrlTypeThenRequestShouldBeOverridden() {
54+
assertTrue(testee.handleUrl(webView, Email(""), mockWebViewClientListener))
55+
}
56+
57+
@Test
58+
fun whenSmsUrlTypeThenRequestShouldBeOverridden() {
59+
assertTrue(testee.handleUrl(webView, Sms(""), mockWebViewClientListener))
60+
}
61+
62+
@Test
63+
fun whenSearchQueryUrlTypeThenRequestShouldBeOverridden() {
64+
assertTrue(testee.handleUrl(webView, SearchQuery(""), mockWebViewClientListener))
65+
}
66+
67+
@Test
68+
fun whenIntentUrlTypeThenRequestShouldBeOverridden() {
69+
assertTrue(testee.handleUrl(webView, IntentType("", Intent(), null), mockWebViewClientListener))
70+
}
71+
72+
@Test
73+
fun whenUnknownUrlTypeThenRequestShouldBeOverridden() {
74+
assertTrue(testee.handleUrl(webView, Unknown(""), mockWebViewClientListener))
75+
}
76+
}

app/src/androidTest/java/com/duckduckgo/app/global/api/ApiRequestInterceptorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ApiRequestInterceptorTest {
5353
testee.intercept(mockChain)
5454
verify(mockChain).proceed(captor.capture())
5555

56-
val regex = "ddg_android/.*\\(com.duckduckgo.mobile.android.test; Android API .*\\)".toRegex()
56+
val regex = "ddg_android/.*\\(com.duckduckgo.mobile.android.debug.test; Android API .*\\)".toRegex()
5757
val result = captor.value.header(Header.USER_AGENT)!!
5858
assertTrue(result.matches(regex))
5959
}

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,55 +49,55 @@ class ApiBasedPixelTest {
4949

5050
@Test
5151
fun whenPixelFiredThenPixelServiceCalledWithCorrectAtbAndVariant() {
52-
whenever(mockPixelService.fire(any(), any(), any(), anyOrNull())).thenReturn(Completable.complete())
52+
configurePixelFireIsSuccessful()
5353
whenever(mockStatisticsDataStore.atb).thenReturn(Atb("atb"))
5454
whenever(mockVariantManager.getVariant()).thenReturn(Variant("variant", filterBy = { true }))
5555
whenever(mockDeviceInfo.formFactor()).thenReturn(DeviceInfo.FormFactor.PHONE)
5656

5757
val pixel = ApiBasedPixel(mockPixelService, mockStatisticsDataStore, mockVariantManager, mockDeviceInfo)
5858
pixel.fire(PRIVACY_DASHBOARD_OPENED)
5959

60-
verify(mockPixelService).fire(eq("mp"), eq("phone"), eq("atbvariant"), any())
60+
verify(mockPixelService).fire(eq("mp"), eq("phone"), eq("atbvariant"), any(), any())
6161
}
6262

6363
@Test
6464
fun whenPixelFiredThenPixelServiceCalledWithCorrectAtb() {
65-
whenever(mockPixelService.fire(any(), any(), any(), any())).thenReturn(Completable.complete())
65+
whenever(mockPixelService.fire(any(), any(), any(), any(), any())).thenReturn(Completable.complete())
6666
whenever(mockStatisticsDataStore.atb).thenReturn(Atb("atb"))
6767
whenever(mockVariantManager.getVariant()).thenReturn(VariantManager.DEFAULT_VARIANT)
6868
whenever(mockDeviceInfo.formFactor()).thenReturn(DeviceInfo.FormFactor.PHONE)
6969

7070
val pixel = ApiBasedPixel(mockPixelService, mockStatisticsDataStore, mockVariantManager, mockDeviceInfo)
7171
pixel.fire(FORGET_ALL_EXECUTED)
7272

73-
verify(mockPixelService).fire(eq("mf"), eq("phone"), eq("atb"), any())
73+
verify(mockPixelService).fire(eq("mf"), eq("phone"), eq("atb"), any(), any())
7474
}
7575

7676
@Test
7777
fun whenPixelFiredTabletFormFactorThenPixelServiceCalledWithTabletParameter() {
78-
whenever(mockPixelService.fire(any(), any(), any(), any())).thenReturn(Completable.complete())
78+
whenever(mockPixelService.fire(any(), any(), any(), any(), any())).thenReturn(Completable.complete())
7979
whenever(mockDeviceInfo.formFactor()).thenReturn(DeviceInfo.FormFactor.TABLET)
8080

8181
val pixel = ApiBasedPixel(mockPixelService, mockStatisticsDataStore, mockVariantManager, mockDeviceInfo)
8282
pixel.fire(APP_LAUNCH)
8383

84-
verify(mockPixelService).fire(eq("ml"), eq("tablet"), eq(""), any())
84+
verify(mockPixelService).fire(eq("ml"), eq("tablet"), eq(""), any(), any())
8585
}
8686

8787
@Test
8888
fun whenPixelFiredWithNoAtbThenPixelServiceCalledWithCorrectPixelNameAndNoAtb() {
89-
whenever(mockPixelService.fire(any(), any(), any(), any())).thenReturn(Completable.complete())
89+
whenever(mockPixelService.fire(any(), any(), any(), any(), any())).thenReturn(Completable.complete())
9090
whenever(mockDeviceInfo.formFactor()).thenReturn(DeviceInfo.FormFactor.PHONE)
9191

9292
val pixel = ApiBasedPixel(mockPixelService, mockStatisticsDataStore, mockVariantManager, mockDeviceInfo)
9393
pixel.fire(APP_LAUNCH)
9494

95-
verify(mockPixelService).fire(eq("ml"), eq("phone"), eq(""), any())
95+
verify(mockPixelService).fire(eq("ml"), eq("phone"), eq(""), any(), any())
9696
}
9797

9898
@Test
9999
fun whenPixelFiredWithAdditionalParametersThenPixelServiceCalledWithDefaultAndAdditionalParameters() {
100-
whenever(mockPixelService.fire(any(), any(), any(), any())).thenReturn(Completable.complete())
100+
configurePixelFireIsSuccessful()
101101
whenever(mockStatisticsDataStore.atb).thenReturn(Atb("atb"))
102102
whenever(mockVariantManager.getVariant()).thenReturn(Variant("variant", filterBy = { true }))
103103
whenever(mockDeviceInfo.formFactor()).thenReturn(DeviceInfo.FormFactor.PHONE)
@@ -113,7 +113,7 @@ class ApiBasedPixelTest {
113113

114114
@Test
115115
fun whenPixelFiredWithoutAdditionalParametersThenPixelServiceCalledWithOnlyDefaultParameters() {
116-
whenever(mockPixelService.fire(any(), any(), any(), any())).thenReturn(Completable.complete())
116+
configurePixelFireIsSuccessful()
117117
whenever(mockStatisticsDataStore.atb).thenReturn(Atb("atb"))
118118
whenever(mockVariantManager.getVariant()).thenReturn(Variant("variant", filterBy = { true }))
119119
whenever(mockDeviceInfo.formFactor()).thenReturn(DeviceInfo.FormFactor.PHONE)
@@ -125,4 +125,8 @@ class ApiBasedPixelTest {
125125
val expectedParams = mapOf("appVersion" to "1.0.0")
126126
verify(mockPixelService).fire("mp", "phone", "atbvariant", expectedParams)
127127
}
128+
129+
private fun configurePixelFireIsSuccessful() {
130+
whenever(mockPixelService.fire(any(), any(), any(), anyOrNull(), any())).thenReturn(Completable.complete())
131+
}
128132
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ class VariantManagerTest {
3737
assertEquals(0, variant.features.size)
3838
}
3939

40+
@Test
41+
fun defaultLightThemeExperimentVariantActive() {
42+
val variant = variants.firstOrNull { it.key == "mo" }
43+
assertEqualsDouble(1.0, variant!!.weight)
44+
}
45+
46+
@Test
47+
fun defaultLightThemeExperimentVariantHasExperimentalFeatureForLightTheme() {
48+
val variant = variants.firstOrNull { it.key == "mo" }
49+
assertEquals(1, variant!!.features.size)
50+
assertTrue(variant.hasFeature(VariantManager.VariantFeature.LightThemeExperiment))
51+
}
52+
53+
@Test
54+
fun defaultLightThemeControlGroupVariantActive() {
55+
val variant = variants.firstOrNull { it.key == "mp" }
56+
assertEqualsDouble(1.0, variant!!.weight)
57+
}
58+
59+
@Test
60+
fun defaultLightThemeControlGroupVariantHasNoExperimentFeatures() {
61+
val variant = variants.firstOrNull { it.key == "mp" }
62+
assertEquals(0, variant!!.features.size)
63+
}
64+
4065
@Suppress("SameParameterValue")
4166
private fun assertEqualsDouble(expected: Double, actual: Double) {
4267
val comparison = expected.compareTo(actual)
3.02 KB
Loading
6.16 KB
Loading
2.89 KB
Loading
3.83 KB
Loading

0 commit comments

Comments
 (0)