Skip to content

Commit 3697a95

Browse files
committed
Merge branch 'release/0.10.0'
2 parents 69926fe + e1c824e commit 3697a95

File tree

66 files changed

+1302
-132
lines changed

Some content is hidden

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

66 files changed

+1302
-132
lines changed

app/build.gradle

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
66
apply from: '../versioning.gradle'
77

88
ext {
9-
VERSION_NAME = "0.9.0"
9+
VERSION_NAME = "0.10.0"
1010
}
1111

1212
android {
@@ -52,18 +52,6 @@ android {
5252
testOptions {
5353
unitTests.returnDefaultValues = true
5454
}
55-
sourceSets {
56-
String sharedTestJavaDir = 'src/sharedTest/java'
57-
String sharedTestResourcesDir = 'src/sharedTest/resources'
58-
test {
59-
java.srcDir sharedTestJavaDir
60-
resources.srcDir sharedTestResourcesDir
61-
}
62-
androidTest {
63-
java.srcDir sharedTestJavaDir
64-
resources.srcDir sharedTestResourcesDir
65-
}
66-
}
6755

6856
def staticConfigPath = "${System.getenv('HOME')}/jenkins_static/com.duckduckgo.mobile.android"
6957
def propertiesPath = "${staticConfigPath}/ddg_android_build.properties"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 5,
5+
"identityHash": "df2202389ba5b11018b57a417457b11b",
6+
"entities": [
7+
{
8+
"tableName": "https_upgrade_domain",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`domain` TEXT NOT NULL, PRIMARY KEY(`domain`))",
10+
"fields": [
11+
{
12+
"fieldPath": "domain",
13+
"columnName": "domain",
14+
"affinity": "TEXT",
15+
"notNull": true
16+
}
17+
],
18+
"primaryKey": {
19+
"columnNames": [
20+
"domain"
21+
],
22+
"autoGenerate": false
23+
},
24+
"indices": [],
25+
"foreignKeys": []
26+
},
27+
{
28+
"tableName": "disconnect_tracker",
29+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`url` TEXT NOT NULL, `category` TEXT NOT NULL, `networkName` TEXT NOT NULL, `networkUrl` TEXT NOT NULL, PRIMARY KEY(`url`))",
30+
"fields": [
31+
{
32+
"fieldPath": "url",
33+
"columnName": "url",
34+
"affinity": "TEXT",
35+
"notNull": true
36+
},
37+
{
38+
"fieldPath": "category",
39+
"columnName": "category",
40+
"affinity": "TEXT",
41+
"notNull": true
42+
},
43+
{
44+
"fieldPath": "networkName",
45+
"columnName": "networkName",
46+
"affinity": "TEXT",
47+
"notNull": true
48+
},
49+
{
50+
"fieldPath": "networkUrl",
51+
"columnName": "networkUrl",
52+
"affinity": "TEXT",
53+
"notNull": true
54+
}
55+
],
56+
"primaryKey": {
57+
"columnNames": [
58+
"url"
59+
],
60+
"autoGenerate": false
61+
},
62+
"indices": [],
63+
"foreignKeys": []
64+
},
65+
{
66+
"tableName": "network_leaderboard",
67+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`networkName` TEXT NOT NULL, `domainVisited` TEXT NOT NULL, PRIMARY KEY(`networkName`, `domainVisited`))",
68+
"fields": [
69+
{
70+
"fieldPath": "networkName",
71+
"columnName": "networkName",
72+
"affinity": "TEXT",
73+
"notNull": true
74+
},
75+
{
76+
"fieldPath": "domainVisited",
77+
"columnName": "domainVisited",
78+
"affinity": "TEXT",
79+
"notNull": true
80+
}
81+
],
82+
"primaryKey": {
83+
"columnNames": [
84+
"networkName",
85+
"domainVisited"
86+
],
87+
"autoGenerate": false
88+
},
89+
"indices": [],
90+
"foreignKeys": []
91+
},
92+
{
93+
"tableName": "app_configuration",
94+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `appConfigurationDownloaded` INTEGER NOT NULL, PRIMARY KEY(`key`))",
95+
"fields": [
96+
{
97+
"fieldPath": "key",
98+
"columnName": "key",
99+
"affinity": "TEXT",
100+
"notNull": true
101+
},
102+
{
103+
"fieldPath": "appConfigurationDownloaded",
104+
"columnName": "appConfigurationDownloaded",
105+
"affinity": "INTEGER",
106+
"notNull": true
107+
}
108+
],
109+
"primaryKey": {
110+
"columnNames": [
111+
"key"
112+
],
113+
"autoGenerate": false
114+
},
115+
"indices": [],
116+
"foreignKeys": []
117+
}
118+
],
119+
"setupQueries": [
120+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
121+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"df2202389ba5b11018b57a417457b11b\")"
122+
]
123+
}
124+
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ class BrowserViewModelTest {
5959

6060
private var lastEntry: NetworkLeaderboardEntry? = null
6161

62-
private val testStringResolver: StringResolver = object : StringResolver {
63-
override fun getString(stringId: Int): String = ""
64-
override fun getString(stringId: Int, vararg formatArgs: Any): String = ""
65-
}
62+
private val testStringResolver: StringResolver = object : StringResolver {}
6663

6764
private val testNetworkLeaderboardDao: NetworkLeaderboardDao = object : NetworkLeaderboardDao {
6865
override fun insert(leaderboardEntry: NetworkLeaderboardEntry) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2018 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.global.view
18+
19+
import android.graphics.Color
20+
import org.junit.Assert.assertEquals
21+
import org.junit.Test
22+
23+
class ColorCombinerTest {
24+
25+
private val testee = ColorCombiner()
26+
27+
@Test
28+
fun whenColorsCombineWithZeroRatioThenCombinedColorIsFirstColor() {
29+
val from = Color.argb(200, 200, 200, 200)
30+
val to = Color.argb(100, 100, 100, 100)
31+
assertEquals(from, testee.combine(from, to, 0.toFloat()))
32+
}
33+
34+
@Test
35+
fun whenColorsCombineWithFullRatioThenCombinedColorIsSecondColor() {
36+
val from = Color.argb(200, 200, 200, 200)
37+
val to = Color.argb(100, 100, 100, 100)
38+
assertEquals(to, testee.combine(from, to, 1.toFloat()))
39+
}
40+
41+
@Test
42+
fun whenColorsCombinedWithHalfRatioThenCombinedColorIsMixed() {
43+
val from = Color.argb(200, 200, 200, 200)
44+
val to = Color.argb(100, 100, 100, 100)
45+
val expected = Color.argb(150, 150, 150, 150)
46+
val actual = testee.combine(from, to, 0.5.toFloat())
47+
assertEquals(expected, actual)
48+
}
49+
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.duckduckgo.app.httpsupgrade
1919
import android.net.Uri
2020
import com.duckduckgo.app.httpsupgrade.db.HttpsUpgradeDomainDao
2121
import com.nhaarman.mockito_kotlin.mock
22+
import com.nhaarman.mockito_kotlin.verify
2223
import com.nhaarman.mockito_kotlin.whenever
2324
import org.junit.Assert.*
2425
import org.junit.Before
@@ -35,16 +36,38 @@ class HttpsUpgraderTest {
3536
testee = HttpsUpgrader(mockDao)
3637
}
3738

39+
@Test
40+
fun whenMixedCaseDomainIsASubdominOfAWildCardInTheDatabaseThenShouldUpgrade() {
41+
whenever(mockDao.hasDomain("www.example.com")).thenReturn(false)
42+
whenever(mockDao.hasDomain("*.example.com")).thenReturn(true)
43+
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.EXAMPLE.com")))
44+
verify(mockDao).hasDomain("*.example.com")
45+
}
46+
47+
@Test
48+
fun whenMixedCaseUriIsHttpAndInUpgradeListThenShouldUpgrade() {
49+
whenever(mockDao.hasDomain("www.example.com")).thenReturn(true)
50+
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.EXAMPLE.com")))
51+
}
52+
3853
@Test
3954
fun whenGivenUriItIsUpgradedToHttps() {
4055
val input = Uri.parse("http://www.example.com/some/path/to/a/file.txt")
4156
val expected = Uri.parse("https://www.example.com/some/path/to/a/file.txt")
4257
assertEquals(expected, testee.upgrade(input))
4358
}
4459

60+
@Test
61+
fun whenDomainIsASubdominOfAWildCardInTheDatabaseThenShouldUpgrade() {
62+
whenever(mockDao.hasDomain("www.example.com")).thenReturn(false)
63+
whenever(mockDao.hasDomain("*.example.com")).thenReturn(true)
64+
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.example.com")))
65+
verify(mockDao).hasDomain("*.example.com")
66+
}
67+
4568
@Test
4669
fun whenUriIsHttpAndInUpgradeListThenShouldUpgrade() {
47-
whenever(mockDao.contains("www.example.com")).thenReturn(true)
70+
whenever(mockDao.hasDomain("www.example.com")).thenReturn(true)
4871
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.example.com")))
4972
}
5073

app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/api/HttpsUpgradeJsonTest.kt

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

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

19+
import com.duckduckgo.app.httpsupgrade.db.HttpsUpgradeDomain
20+
import com.squareup.moshi.JsonAdapter
1921
import com.squareup.moshi.Moshi
22+
import com.squareup.moshi.Types
2023
import org.junit.Assert.assertEquals
2124
import org.junit.Test
2225

23-
2426
class HttpsUpgradeJsonTest {
2527

2628
@Test
2729
fun whenGivenValidJsonThenParsesCorrectly() {
2830
val moshi = Moshi.Builder().add(HttpsUpgradeDomainFromStringAdapter()).build()
29-
val adapter = moshi.adapter(HttpsUpgradeJson::class.java)
31+
val type = Types.newParameterizedType(List::class.java, HttpsUpgradeDomain::class.java)
32+
val adapter: JsonAdapter<List<HttpsUpgradeDomain>> = moshi.adapter(type)
33+
3034
val list = adapter.fromJson(json())
31-
assertEquals(5, list.simpleUpgrade.top500.count())
35+
assertEquals(5, list.count())
3236
}
3337

3438
private fun json() : String = """
35-
{ "simpleUpgrade" : { "top500": [
39+
[
3640
"1337x.to",
3741
"1688.com",
3842
"2ch.net",
3943
"adobe.com",
4044
"alibaba.com"
41-
]}}
45+
]
4246
"""
4347

4448
}

app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/db/HttpsUpgradeDomainDAOTest.kt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import android.arch.persistence.room.Room
2020
import android.support.test.InstrumentationRegistry
2121
import com.duckduckgo.app.global.db.AppDatabase
2222
import org.junit.After
23-
import org.junit.Assert.assertFalse
24-
import org.junit.Assert.assertTrue
23+
import org.junit.Assert.*
2524
import org.junit.Before
2625
import org.junit.Test
2726

@@ -54,48 +53,59 @@ class HttpsUpgradeDomainDaoTest {
5453
fun whenExactMatchDomainAddedAndThenAllDeletedThenDoesNotContainExactMatchDomain() {
5554
dao.insertAll(HttpsUpgradeDomain(exactMatchDomain))
5655
dao.deleteAll()
57-
assertFalse(dao.contains(exactMatchDomain))
56+
assertFalse(dao.hasDomain(exactMatchDomain))
5857
}
5958

6059
@Test
6160
fun whenWildcardDomainInsertedModelThenDoesNotContainParentOfWildcardDomain() {
6261
dao.insertAll(HttpsUpgradeDomain(wildcardDomain))
63-
assertFalse(dao.contains(parentOfWildcardDomain))
62+
assertFalse(dao.hasDomain(parentOfWildcardDomain))
6463
}
6564

6665
@Test
6766
fun whenOtherWildcardDomainInsertedThenModelDoesNotContainExampleWildcardDomain() {
6867
dao.insertAll(HttpsUpgradeDomain(otherWildcardDomain))
69-
assertFalse(dao.contains(exampleWildcardDomain))
68+
assertFalse(dao.hasDomain(exampleWildcardDomain))
7069
}
7170

7271
@Test
7372
fun whenWildcardDomainInsertedThenModelDoesNotContainExactMatchDomain() {
7473
dao.insertAll(HttpsUpgradeDomain(wildcardDomain))
75-
assertFalse(dao.contains(exactMatchDomain))
74+
assertFalse(dao.hasDomain(exactMatchDomain))
7675
}
7776

7877
@Test
7978
fun whenWildcardDomainInsertedThenModelContainsExampleWildcardDomain() {
8079
dao.insertAll(HttpsUpgradeDomain(wildcardDomain))
81-
assertTrue(dao.contains(exampleWildcardDomain))
80+
assertTrue(dao.hasDomain("*.$parentOfWildcardDomain"))
8281
}
8382

8483
@Test
8584
fun whenExactMatchDomainInsertedThenModelDoesNotContainOtherDomain() {
8685
dao.insertAll(HttpsUpgradeDomain(exactMatchDomain))
87-
assertFalse(dao.contains(otherDomain))
86+
assertFalse(dao.hasDomain(otherDomain))
8887
}
8988

9089
@Test
9190
fun whenExactMatchDomainIsInsertedThenModelContainsExactMatchDomain() {
9291
dao.insertAll(HttpsUpgradeDomain(exactMatchDomain))
93-
assertTrue(dao.contains(exactMatchDomain))
92+
assertTrue(dao.hasDomain(exactMatchDomain))
9493
}
9594

9695
@Test
9796
fun whenModelIsEmptyThenModelDoesNotContainExactMatchDomain() {
98-
assertFalse(dao.contains(exactMatchDomain))
97+
assertFalse(dao.hasDomain(exactMatchDomain))
98+
}
99+
100+
@Test
101+
fun whenModelIsEmptyThenCountIsZero() {
102+
assertEquals(0, dao.count())
103+
}
104+
105+
@Test
106+
fun whenModelContainsTwoItemsThenCountIsTwo() {
107+
dao.insertAll(HttpsUpgradeDomain(exactMatchDomain), HttpsUpgradeDomain(otherDomain))
108+
assertEquals(2, dao.count())
99109
}
100110

101111
}

0 commit comments

Comments
 (0)