Skip to content

Commit 2db6f0e

Browse files
committed
Merge branch 'release/5.69.0' into main
2 parents 0d7154a + ccae981 commit 2db6f0e

File tree

67 files changed

+2827
-480
lines changed

Some content is hidden

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

67 files changed

+2827
-480
lines changed

app/schemas/com.duckduckgo.app.global.db.AppDatabase/26.json

Lines changed: 796 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ import org.mockito.ArgumentMatchers.anyString
122122
import org.mockito.Mockito.never
123123
import org.mockito.Mockito.verify
124124
import java.io.File
125+
import java.util.*
125126
import java.util.concurrent.TimeUnit
126127

127128
@ExperimentalCoroutinesApi
@@ -250,7 +251,6 @@ class BrowserTabViewModelTest {
250251
@Before
251252
fun before() {
252253
MockitoAnnotations.initMocks(this)
253-
254254
db = Room.inMemoryDatabaseBuilder(getInstrumentation().targetContext, AppDatabase::class.java)
255255
.allowMainThreadQueries()
256256
.build()
@@ -1634,13 +1634,13 @@ class BrowserTabViewModelTest {
16341634

16351635
@Test
16361636
fun whenScheduledSurveyChangesAndInstalledDaysMatchThenCtaIsSurvey() {
1637-
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
1637+
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED), Locale.US)
16381638
assertTrue(testee.ctaViewState.value!!.cta is HomePanelCta.Survey)
16391639
}
16401640

16411641
@Test
16421642
fun whenScheduledSurveyChangesAndInstalledDaysDontMatchThenCtaIsNull() {
1643-
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 2, status = Survey.Status.SCHEDULED))
1643+
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 2, status = Survey.Status.SCHEDULED), Locale.US)
16441644
assertNull(testee.ctaViewState.value!!.cta)
16451645
}
16461646

@@ -2668,6 +2668,39 @@ class BrowserTabViewModelTest {
26682668
assertCommandNotIssued<Command.ShowDomainHasPermissionMessage>()
26692669
}
26702670

2671+
@Test
2672+
fun whenUserRefreshesASiteLocationMessageIsNotShownAgain() = coroutineRule.runBlocking {
2673+
val domain = "https://www.example.com/"
2674+
2675+
givenUserAlreadySelectedPermissionForDomain(domain, LocationPermissionType.ALLOW_ALWAYS)
2676+
givenCurrentSite(domain)
2677+
givenDeviceLocationSharingIsEnabled(true)
2678+
givenLocationPermissionIsEnabled(true)
2679+
2680+
loadUrl("https://www.example.com", isBrowserShowing = true)
2681+
2682+
assertCommandIssued<Command.ShowDomainHasPermissionMessage>()
2683+
2684+
loadUrl("https://www.example.com", isBrowserShowing = true)
2685+
2686+
assertCommandIssuedTimes<Command.ShowDomainHasPermissionMessage>(1)
2687+
}
2688+
2689+
@Test
2690+
fun whenUserSelectsPermissionAndRefreshesPageThenLocationMessageIsNotShown() = coroutineRule.runBlocking {
2691+
val domain = "http://example.com"
2692+
2693+
givenCurrentSite(domain)
2694+
givenDeviceLocationSharingIsEnabled(true)
2695+
givenLocationPermissionIsEnabled(true)
2696+
2697+
testee.onSiteLocationPermissionSelected(domain, LocationPermissionType.ALLOW_ALWAYS)
2698+
2699+
loadUrl(domain, isBrowserShowing = true)
2700+
2701+
assertCommandNotIssued<Command.ShowDomainHasPermissionMessage>()
2702+
}
2703+
26712704
@Test
26722705
fun whenSystemLocationPermissionIsDeniedThenSiteLocationPermissionIsAlwaysDenied() = coroutineRule.runBlocking {
26732706
val domain = "https://www.example.com/"
@@ -2983,6 +3016,11 @@ class BrowserTabViewModelTest {
29833016
assertNull(issuedCommand)
29843017
}
29853018

3019+
private inline fun <reified T : Command> assertCommandIssuedTimes(times: Int) {
3020+
val timesIssued = commandCaptor.allValues.count { it is T }
3021+
assertEquals(times, timesIssued)
3022+
}
3023+
29863024
private fun pixelParams(showedBookmarks: Boolean, bookmarkCapable: Boolean) = mapOf(
29873025
Pixel.PixelParameter.SHOWED_BOOKMARKS to showedBookmarks.toString(),
29883026
Pixel.PixelParameter.BOOKMARK_CAPABLE to bookmarkCapable.toString()

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import org.junit.Rule
6868
import org.junit.Test
6969
import org.mockito.Mock
7070
import org.mockito.MockitoAnnotations
71+
import java.util.*
7172
import java.util.concurrent.TimeUnit
7273

7374
@FlowPreview
@@ -145,7 +146,6 @@ class CtaViewModelTest {
145146
@Before
146147
fun before() {
147148
MockitoAnnotations.initMocks(this)
148-
149149
val context = InstrumentationRegistry.getInstrumentation().targetContext
150150
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
151151
.allowMainThreadQueries()
@@ -180,16 +180,43 @@ class CtaViewModelTest {
180180
}
181181

182182
@Test
183-
fun whenScheduledSurveyChangesAndInstalledDaysMatchThenCtaIsSurvey() {
184-
val survey = Survey("abc", "http://example.com", 1, SCHEDULED)
183+
fun whenScheduledSurveyChangesAndInstalledDaysMatchAndLocaleIsUsThenCtaIsSurvey() = coroutineRule.runBlocking {
184+
testee.onSurveyChanged(Survey("abc", "http://example.com", 1, SCHEDULED))
185+
val value = testee.refreshCta(coroutineRule.testDispatcher, isBrowserShowing = false, site = null, locale = Locale.US)
186+
assertTrue(value is HomePanelCta.Survey)
187+
}
188+
189+
@Test
190+
fun whenScheduledSurveyChangesAndInstalledDaysMatchButLocaleIsNotUsThenCtaIsNotSurvey() = coroutineRule.runBlocking {
191+
testee.onSurveyChanged(Survey("abc", "http://example.com", 1, SCHEDULED))
192+
val value = testee.refreshCta(coroutineRule.testDispatcher, isBrowserShowing = false, site = null, locale = Locale.CANADA)
193+
assertFalse(value is HomePanelCta.Survey)
194+
}
195+
196+
@Test
197+
fun whenScheduledSurveyIsNullThenCtaIsNotSurvey() = coroutineRule.runBlocking {
198+
val value = testee.refreshCta(coroutineRule.testDispatcher, isBrowserShowing = false, site = null, locale = Locale.US)
199+
assertFalse(value is HomePanelCta.Survey)
200+
}
201+
202+
@Test
203+
fun whenScheduledSurveyChangesFromNullToNullThenClearedIsFalse() {
204+
val value = testee.onSurveyChanged(null)
205+
assertFalse(value)
206+
}
207+
208+
@Test
209+
fun whenScheduledSurveyChangesFromNullToASurveyThenClearedIsFalse() {
210+
testee.onSurveyChanged(null)
185211
val value = testee.onSurveyChanged(Survey("abc", "http://example.com", 1, SCHEDULED))
186-
assertEquals(survey, value)
212+
assertFalse(value)
187213
}
188214

189215
@Test
190-
fun whenScheduledSurveyIsNullThenCtaIsNotSurvey() {
216+
fun whenScheduledSurveyChangesFromASurveyToNullThenClearedIsTrue() {
217+
testee.onSurveyChanged(Survey("abc", "http://example.com", 1, SCHEDULED))
191218
val value = testee.onSurveyChanged(null)
192-
assertNull(value)
219+
assertTrue(value)
193220
}
194221

195222
@Test

app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/HttpsUpgraderTest.kt

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,24 @@
1717
package com.duckduckgo.app.httpsupgrade
1818

1919
import android.net.Uri
20-
import com.duckduckgo.app.httpsupgrade.api.HttpsBloomFilterFactory
21-
import com.duckduckgo.app.httpsupgrade.api.HttpsUpgradeService
22-
import com.duckduckgo.app.httpsupgrade.db.HttpsWhitelistDao
20+
import com.duckduckgo.app.httpsupgrade.store.HttpsFalsePositivesDao
2321
import com.duckduckgo.app.privacy.db.UserWhitelistDao
2422
import com.duckduckgo.app.statistics.pixels.Pixel
25-
import com.nhaarman.mockitokotlin2.any
2623
import com.nhaarman.mockitokotlin2.mock
2724
import com.nhaarman.mockitokotlin2.whenever
28-
import okhttp3.ResponseBody
2925
import org.junit.Assert.assertFalse
3026
import org.junit.Assert.assertTrue
3127
import org.junit.Before
3228
import org.junit.Test
3329
import retrofit2.Call
34-
import retrofit2.Response
3530

3631
class HttpsUpgraderTest {
3732

3833
lateinit var testee: HttpsUpgrader
3934

4035
private var mockHttpsBloomFilterFactory: HttpsBloomFilterFactory = mock()
41-
private var mockWhitelistDao: HttpsWhitelistDao = mock()
42-
private var mockUserWhitelistDao: UserWhitelistDao = mock()
43-
private var mockUpgradeService: HttpsUpgradeService = mock()
36+
private var mockBloomFalsePositiveListDao: HttpsFalsePositivesDao = mock()
37+
private var mockUserAllowlistDao: UserWhitelistDao = mock()
4438
private var mockServiceCall: Call<List<String>> = mock()
4539

4640
private var mockPixel: Pixel = mock()
@@ -49,84 +43,43 @@ class HttpsUpgraderTest {
4943
@Before
5044
fun before() {
5145
whenever(mockHttpsBloomFilterFactory.create()).thenReturn(bloomFilter)
52-
testee = HttpsUpgraderImpl(mockWhitelistDao, mockUserWhitelistDao, mockHttpsBloomFilterFactory, mockUpgradeService, mockPixel)
46+
testee = HttpsUpgraderImpl(mockHttpsBloomFilterFactory, mockBloomFalsePositiveListDao, mockUserAllowlistDao, mockPixel)
5347
testee.reloadData()
5448
}
5549

5650
@Test
57-
fun whenHttpUriIsInLocalListThenShouldUpgrade() {
51+
fun whenHttpUriIsInBloomThenShouldUpgrade() {
5852
bloomFilter.add("www.local.url")
5953
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.local.url")))
54+
mockPixel.fire(Pixel.PixelName.HTTPS_LOCAL_UPGRADE)
55+
}
56+
57+
@Test
58+
fun whenHttpUriIsNotInBloomThenShouldNotUpgrade() {
59+
bloomFilter.add("www.local.url")
60+
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.differentlocal.url")))
61+
mockPixel.fire(Pixel.PixelName.HTTPS_NO_UPGRADE)
6062
}
6163

6264
@Test
6365
fun whenHttpsUriThenShouldNotUpgrade() {
66+
bloomFilter.add("www.local.url")
6467
assertFalse(testee.shouldUpgrade(Uri.parse("https://www.local.url")))
68+
mockPixel.fire(Pixel.PixelName.HTTPS_NO_UPGRADE)
6569
}
6670

6771
@Test
6872
fun whenHttpUriHasOnlyPartDomainInLocalListThenShouldNotUpgrade() {
6973
bloomFilter.add("local.url")
7074
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.local.url")))
71-
}
72-
73-
@Test
74-
fun whenHttpDomainIsUserWhitelistedThenShouldNotUpgradeAndNoLookupPixelIsSet() {
75-
whenever(mockUserWhitelistDao.contains("www.local.url")).thenReturn(true)
76-
bloomFilter.add("www.local.url")
77-
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.local.url")))
7875
mockPixel.fire(Pixel.PixelName.HTTPS_NO_LOOKUP)
7976
}
8077

8178
@Test
82-
fun whenHttpUriIsInLocalListAndInWhitelistThenShouldNotUpgrade() {
79+
fun whenHttpDomainIsUserWhitelistedThenShouldNotUpgrade() {
8380
bloomFilter.add("www.local.url")
84-
whenever(mockWhitelistDao.contains("www.local.url")).thenReturn(true)
81+
whenever(mockUserAllowlistDao.contains("www.local.url")).thenReturn(true)
8582
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.local.url")))
86-
}
87-
88-
@Test
89-
fun whenHttpUriIsNotInLocalListButCanBeUpgradedByServiceThenShouldUpgrade() {
90-
whenever(mockServiceCall.execute()).thenReturn(Response.success(serviceResponse()))
91-
whenever(mockUpgradeService.upgradeListForPartialHost(any())).thenReturn(mockServiceCall)
92-
assertTrue(testee.shouldUpgrade(Uri.parse("http://service.url")))
93-
}
94-
95-
@Test
96-
fun whenHttpUriIsNotInLocalListAndCannotBeUpgradedByServiceThenShouldNotUpgrade() {
97-
whenever(mockServiceCall.execute()).thenReturn(Response.success(serviceResponse()))
98-
whenever(mockUpgradeService.upgradeListForPartialHost(any())).thenReturn(mockServiceCall)
99-
assertFalse(testee.shouldUpgrade(Uri.parse("http://unknown.com")))
100-
}
101-
102-
@Test
103-
fun whenHttpUriIsNotInLocalListAndServiceRequestFailsThenShouldNotUpgrade() {
104-
whenever(mockServiceCall.execute()).thenReturn(Response.error(500, ResponseBody.create(null, "")))
105-
whenever(mockUpgradeService.upgradeListForPartialHost(any())).thenReturn(mockServiceCall)
106-
assertFalse(testee.shouldUpgrade(Uri.parse("http://service.url")))
107-
}
108-
109-
@Test
110-
fun whenBloomFilterIsNotLoadedAndUrlIsInServiceListThenShouldUpgrade() {
111-
whenever(mockHttpsBloomFilterFactory.create()).thenReturn(null)
112-
whenever(mockServiceCall.execute()).thenReturn(Response.success(serviceResponse()))
113-
whenever(mockUpgradeService.upgradeListForPartialHost(any())).thenReturn(mockServiceCall)
114-
assertTrue(testee.shouldUpgrade(Uri.parse("http://service.url")))
115-
}
116-
117-
@Test
118-
fun testWhenBloomFilterIsNotLoadedAndUrlNotInServiceListThenShouldNotUpgrade() {
119-
whenever(mockHttpsBloomFilterFactory.create()).thenReturn(null)
120-
whenever(mockServiceCall.execute()).thenReturn(Response.success(serviceResponse()))
121-
whenever(mockUpgradeService.upgradeListForPartialHost(any())).thenReturn(mockServiceCall)
122-
assertFalse(testee.shouldUpgrade(Uri.parse("http://unknown.com")))
123-
}
124-
125-
private fun serviceResponse(): List<String> {
126-
return arrayListOf(
127-
"cfb1a171724ad0b8f108526d6a201667f74691e4",
128-
"cfb10e3da9ae3bc2ba7e4641c911987da63aa0a7",
129-
"cfb18efe21acd63556dd75bcae7003a2fff90752"
130-
)
83+
mockPixel.fire(Pixel.PixelName.HTTPS_NO_LOOKUP)
13184
}
13285
}

app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/api/HttpsWhitelistJsonTest.kt renamed to app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/api/HttpsFalsePositivesJsonTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
package com.duckduckgo.app.httpsupgrade.api
1818

19-
import com.duckduckgo.app.httpsupgrade.model.HttpsWhitelistedDomain
19+
import com.duckduckgo.app.httpsupgrade.model.HttpsFalsePositiveDomain
2020
import com.squareup.moshi.JsonAdapter
2121
import com.squareup.moshi.Moshi
2222
import com.squareup.moshi.Types
2323
import org.junit.Assert.assertEquals
2424
import org.junit.Test
2525

26-
class HttpsWhitelistJsonTest {
26+
class HttpsFalsePositivesJsonTest {
2727

2828
@Test
2929
fun whenGivenValidJsonThenParsesCorrectly() {
3030

31-
val moshi = Moshi.Builder().add(HttpsWhitelistJsonAdapter()).build()
32-
val type = Types.newParameterizedType(List::class.java, HttpsWhitelistedDomain::class.java)
33-
val jsonAdapter: JsonAdapter<List<HttpsWhitelistedDomain>> = moshi.adapter(type)
31+
val moshi = Moshi.Builder().add(HttpsFalsePositivesJsonAdapter()).build()
32+
val type = Types.newParameterizedType(List::class.java, HttpsFalsePositiveDomain::class.java)
33+
val jsonAdapter: JsonAdapter<List<HttpsFalsePositiveDomain>> = moshi.adapter(type)
3434

3535
val list = jsonAdapter.fromJson(json())!!
3636
assertEquals(7, list.count())

app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/db/HttpsBloomFilterSpecDaoTest.kt renamed to app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/store/HttpsBloomFilterSpecDaoTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.duckduckgo.app.httpsupgrade.db
17+
package com.duckduckgo.app.httpsupgrade.store
1818

1919
import androidx.room.Room
2020
import androidx.test.platform.app.InstrumentationRegistry
@@ -48,17 +48,18 @@ class HttpsBloomFilterSpecDaoTest {
4848

4949
@Test
5050
fun whenModelIsInsertedThenGetIsNotNull() {
51-
dao.insert(HttpsBloomFilterSpec(errorRate = 0.1, totalEntries = 55, sha256 = "abc"))
51+
dao.insert(HttpsBloomFilterSpec(errorRate = 0.1, bitCount = 1000, totalEntries = 55, sha256 = "abc"))
5252
assertNotNull(dao.get())
5353
}
5454

5555
@Test
5656
fun whenNewModelIsInsertedThenGetIsNotNullAndDetailsUpdates() {
57-
dao.insert(HttpsBloomFilterSpec(errorRate = 0.1, totalEntries = 55, sha256 = "abc"))
58-
dao.insert(HttpsBloomFilterSpec(errorRate = 0.2, totalEntries = 60, sha256 = "xyz"))
57+
dao.insert(HttpsBloomFilterSpec(bitCount = 1000, errorRate = 0.1, totalEntries = 55, sha256 = "abc"))
58+
dao.insert(HttpsBloomFilterSpec(bitCount = 2000, errorRate = 0.2, totalEntries = 60, sha256 = "xyz"))
5959

6060
val specification = dao.get()
6161
assertNotNull(specification)
62+
assertEquals(2000, specification!!.bitCount)
6263
assertEquals(0.2, specification!!.errorRate, 0.01)
6364
assertEquals(60, specification.totalEntries)
6465
assertEquals("xyz", specification.sha256)

0 commit comments

Comments
 (0)