Skip to content

Commit 2d7d379

Browse files
committed
Merge branch 'release/0.7.0'
2 parents 2bf6772 + ce9be2a commit 2d7d379

File tree

121 files changed

+1795
-556
lines changed

Some content is hidden

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

121 files changed

+1795
-556
lines changed

app/build.gradle

Lines changed: 4 additions & 1 deletion
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.6.0"
9+
VERSION_NAME = "0.7.0"
1010
}
1111

1212
android {
@@ -99,17 +99,20 @@ dependencies {
9999
implementation "com.jakewharton.timber:timber:4.6.0"
100100
implementation "android.arch.lifecycle:extensions:$architectureComponents"
101101
implementation "android.arch.lifecycle:reactivestreams:$architectureComponents"
102+
implementation "android.arch.persistence.room:runtime:$architectureComponents"
102103
implementation "com.google.dagger:dagger-android:$dagger"
103104
implementation "com.google.dagger:dagger-android-support:$dagger"
104105
releaseImplementation 'com.faendir:acra:4.10.0'
105106

106107
kapt "com.google.dagger:dagger-android-processor:$dagger"
107108
kapt "com.google.dagger:dagger-compiler:$dagger"
109+
kapt "android.arch.persistence.room:compiler:$architectureComponents"
108110

109111
testImplementation "org.mockito:mockito-core:2.13.0"
110112
testImplementation "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
111113
testImplementation "junit:junit:4.12"
112114
testImplementation "android.arch.core:core-testing:$architectureComponents"
115+
testImplementation "android.arch.persistence.room:testing:$architectureComponents"
113116

114117
androidTestImplementation "com.android.support.test:runner:1.0.1"
115118
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,43 @@ class BrowserViewModelTest {
101101

102102
@Test
103103
fun whenViewModelNotifiedThatUrlGotFocusThenViewStateIsUpdated() {
104-
testee.onUrlInputStateChanged("", true)
104+
testee.onOmnibarInputStateChanged("", true)
105105
assertTrue(testee.viewState.value!!.isEditing)
106106
}
107107

108108
@Test
109109
fun whenViewModelNotifiedThatUrlLostFocusThenViewStateIsUpdated() {
110-
testee.onUrlInputStateChanged("", false)
110+
testee.onOmnibarInputStateChanged("", false)
111111
assertFalse(testee.viewState.value!!.isEditing)
112112
}
113113

114114
@Test
115-
fun whenNoUrlEverEnteredThenViewStateHasNull() {
116-
assertNull(testee.viewState.value!!.url)
115+
fun whenNoOmnibarTextEverEnteredThenViewStateHasNull() {
116+
assertNull(testee.viewState.value!!.omnibarText)
117117
}
118118

119119
@Test
120120
fun whenUrlChangedThenViewStateIsUpdated() {
121121
testee.urlChanged("duckduckgo.com")
122-
assertEquals("duckduckgo.com", testee.viewState.value!!.url)
122+
assertEquals("duckduckgo.com", testee.viewState.value!!.omnibarText)
123+
}
124+
125+
@Test
126+
fun whenUrlChangedWithDuckDuckGoUrlContainingQueryThenUrlRewrittenToContainQuery() {
127+
testee.urlChanged("http://duckduckgo.com?q=test")
128+
assertEquals("test", testee.viewState.value!!.omnibarText)
129+
}
130+
131+
@Test
132+
fun whenUrlChangedWithDuckDuckGoUrlNotContainingQueryThenFullUrlShown() {
133+
testee.urlChanged("http://duckduckgo.com")
134+
assertEquals("http://duckduckgo.com", testee.viewState.value!!.omnibarText)
135+
}
136+
137+
@Test
138+
fun whenUrlChangedWithNonDuckDuckGoUrlThenFullUrlShown() {
139+
testee.urlChanged("http://example.com")
140+
assertEquals("http://example.com", testee.viewState.value!!.omnibarText)
123141
}
124142

125143
@Test
@@ -160,20 +178,20 @@ class BrowserViewModelTest {
160178
@Test
161179
fun whenLoadingStartedThenPrivacyGradeIsCleared() {
162180
testee.loadingStarted()
163-
assertNull(testee.viewState.value!!.privacyGrade)
181+
assertNull(testee.privacyGrade.value)
164182
}
165183

166184
@Test
167185
fun whenUrlChangedThenPrivacyGradeIsReset() {
168186
testee.urlChanged("https://example.com")
169-
assertEquals(PrivacyGrade.B, testee.viewState.value!!.privacyGrade)
187+
assertEquals(PrivacyGrade.B, testee.privacyGrade.value)
170188
}
171189

172190
@Test
173191
fun whenTrackerDetectedThenPrivacyGradeIsUpdated() {
174192
testee.urlChanged("https://example.com")
175193
testee.trackerDetected(TrackingEvent("", "", null, false))
176-
assertEquals(PrivacyGrade.C, testee.viewState.value!!.privacyGrade)
194+
assertEquals(PrivacyGrade.C, testee.privacyGrade.value)
177195
}
178196

179197
@Test

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package com.duckduckgo.app.browser
1818

19-
import org.junit.Assert.assertFalse
20-
import org.junit.Assert.assertTrue
19+
import org.junit.Assert.*
2120
import org.junit.Before
2221
import org.junit.Test
2322

@@ -44,5 +43,27 @@ class DuckDuckGoUrlDetectorTest {
4443
fun whenCheckingFullDDGUrlThenIdentifiedAsDDGUrl() {
4544
assertTrue(testee.isDuckDuckGoUrl("https://duckduckgo.com/?q=test%20search&tappv=android_0_2_0&t=ddg_android"))
4645
}
46+
47+
@Test
48+
fun whenDDGUrlContainsQueryThenQueryCanBeExtracted() {
49+
val query = testee.extractQuery("https://duckduck.com?q=test%20search")
50+
assertEquals("test search", query)
51+
}
52+
53+
@Test
54+
fun whenDDGUrlDoesNotContainsQueryThenQueryIsNull() {
55+
val query = testee.extractQuery("https://duckduck.com")
56+
assertNull(query)
57+
}
58+
59+
@Test
60+
fun whenDDGUrlContainsQueryThenQueryDetected() {
61+
assertTrue(testee.hasQuery("https://duckduck.com?q=test%20search"))
62+
}
63+
64+
@Test
65+
fun whenDDGUrlDoesNotContainsQueryThenQueryIsNotDetected() {
66+
assertFalse(testee.hasQuery("https://duckduck.com"))
67+
}
4768
}
4869

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2017 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.httpsupgrade
18+
19+
import android.net.Uri
20+
import com.duckduckgo.app.httpsupgrade.db.HTTPSUpgradeDomainDAO
21+
import com.nhaarman.mockito_kotlin.mock
22+
import com.nhaarman.mockito_kotlin.whenever
23+
import org.junit.Assert.*
24+
import org.junit.Before
25+
import org.junit.Test
26+
27+
class HTTPSUpgraderTest {
28+
29+
lateinit var testee: HTTPSUpgrader
30+
lateinit var mockDao: HTTPSUpgradeDomainDAO
31+
32+
@Before
33+
fun before() {
34+
mockDao = mock()
35+
testee = HTTPSUpgrader(mockDao)
36+
}
37+
38+
@Test
39+
fun whenGivenUriItIsUpgradedToHttps() {
40+
val input = Uri.parse("http://www.example.com/some/path/to/a/file.txt")
41+
val expected = Uri.parse("https://www.example.com/some/path/to/a/file.txt")
42+
assertEquals(expected, testee.upgrade(input))
43+
}
44+
45+
@Test
46+
fun whenUriIsHttpAndInUpgradeListThenShouldUpgrade() {
47+
whenever(mockDao.contains("www.example.com")).thenReturn(true)
48+
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.example.com")))
49+
}
50+
51+
@Test
52+
fun whenUriIsHttpAndIsNotInUpgradeListThenShouldNotUpgrade() {
53+
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.example.com")))
54+
}
55+
56+
@Test
57+
fun whenUriIsHttpsThenShouldNotUpgrade() {
58+
assertFalse(testee.shouldUpgrade(Uri.parse("https://www.example.com")))
59+
}
60+
61+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2017 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.httpsupgrade.api
18+
19+
import com.squareup.moshi.Moshi
20+
import org.junit.Assert.assertEquals
21+
import org.junit.Test
22+
23+
24+
class HTTPSUpgradeJsonTest {
25+
26+
@Test
27+
fun whenGivenValidJsonThenParsesCorrectly() {
28+
val moshi = Moshi.Builder().add(HTTPSUpgradeDomainFromStringAdapter()).build()
29+
val adapter = moshi.adapter(HTTPSUpgradeJson::class.java)
30+
val list = adapter.fromJson(json())
31+
assertEquals(5, list.simpleUpgrade.top500.count())
32+
}
33+
34+
private fun json() : String = """
35+
{ "simpleUpgrade" : { "top500": [
36+
"1337x.to",
37+
"1688.com",
38+
"2ch.net",
39+
"adobe.com",
40+
"alibaba.com"
41+
]}}
42+
"""
43+
44+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) 2017 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.httpsupgrade.db
18+
19+
import android.arch.persistence.room.Room
20+
import android.support.test.InstrumentationRegistry
21+
import com.duckduckgo.app.global.db.AppDatabase
22+
import org.junit.After
23+
import org.junit.Assert.*
24+
import org.junit.Before
25+
import org.junit.Test
26+
27+
class HTTPSUpgradeDomainDAOTest {
28+
29+
companion object {
30+
var exactMatchDomain = "bbc.co.uk"
31+
var otherDomain = "other.com"
32+
var wildcardDomain = "*.wordpress.com"
33+
var otherWildcardDomain = "*.google.com"
34+
var exampleWildcardDomain = "example.wordpress.com"
35+
var parentOfWildcardDomain = "wordpress.com"
36+
}
37+
38+
private lateinit var db: AppDatabase
39+
private lateinit var dao: HTTPSUpgradeDomainDAO
40+
41+
@Before
42+
fun before() {
43+
db = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(), AppDatabase::class.java).build()
44+
dao = db.httpsUpgradeDomainDAO()
45+
}
46+
47+
@After
48+
fun after() {
49+
db.close()
50+
}
51+
52+
@Test
53+
fun whenExactMatchDomainAddedAndThenAllDeletedThenDoesNotContainExactMatchDomain() {
54+
dao.insertAll(HTTPSUpgradeDomain(exactMatchDomain))
55+
dao.deleteAll()
56+
assertFalse(dao.contains(exactMatchDomain))
57+
}
58+
59+
@Test
60+
fun whenWildcardDomainInsertedModelThenDoesNotContainParentOfWildcardDomain() {
61+
dao.insertAll(HTTPSUpgradeDomain(wildcardDomain))
62+
assertFalse(dao.contains(parentOfWildcardDomain))
63+
}
64+
65+
@Test
66+
fun whenOtherWildcardDomainInsertedThenModelDoesNotContainExampleWildcardDomain() {
67+
dao.insertAll(HTTPSUpgradeDomain(otherWildcardDomain))
68+
assertFalse(dao.contains(exampleWildcardDomain))
69+
}
70+
71+
@Test
72+
fun whenWildcardDomainInsertedThenModelDoesNotContainExactMatchDomain() {
73+
dao.insertAll(HTTPSUpgradeDomain(wildcardDomain))
74+
assertFalse(dao.contains(exactMatchDomain))
75+
}
76+
77+
@Test
78+
fun whenWildcardDomainInsertedThenModelContainsExampleWildcardDomain() {
79+
dao.insertAll(HTTPSUpgradeDomain(wildcardDomain))
80+
assertTrue(dao.contains(exampleWildcardDomain))
81+
}
82+
83+
@Test
84+
fun whenExactMatchDomainInsertedThenModelDoesNotContainOtherDomain() {
85+
dao.insertAll(HTTPSUpgradeDomain(exactMatchDomain))
86+
assertFalse(dao.contains(otherDomain))
87+
}
88+
89+
@Test
90+
fun whenExactMatchDomainIsInsertedThenModelContainsExactMatchDomain() {
91+
dao.insertAll(HTTPSUpgradeDomain(exactMatchDomain))
92+
assertTrue(dao.contains(exactMatchDomain))
93+
}
94+
95+
@Test
96+
fun whenModelIsEmptyThenModelDoesNotContainExactMatchDomain() {
97+
assertFalse(dao.contains(exactMatchDomain))
98+
}
99+
100+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.junit.Assert.assertEquals
2323
import org.junit.Assert.assertTrue
2424
import org.junit.Test
2525

26-
class SiteMonitorInstrumentationTests {
26+
class SiteMonitorInstrumentationTest {
2727

2828
companion object {
2929
private const val httpDocument = "http://example.com"

0 commit comments

Comments
 (0)