Skip to content

Commit 1d17a6b

Browse files
committed
Merge branch 'release/0.4.0'
2 parents f5d32c7 + ead95dc commit 1d17a6b

File tree

88 files changed

+864
-627
lines changed

Some content is hidden

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

88 files changed

+864
-627
lines changed

app/build.gradle

Lines changed: 6 additions & 6 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.3.0"
9+
VERSION_NAME = "0.4.0"
1010
}
1111

1212
android {
@@ -74,7 +74,7 @@ android {
7474
}
7575

7676
ext {
77-
supportLibrary = "27.0.1"
77+
supportLibrary = "27.0.2"
7878
architectureComponents = "1.0.0"
7979
dagger = "2.13"
8080
retrofit = "2.3.0"
@@ -87,11 +87,11 @@ dependencies {
8787
implementation "com.android.support:appcompat-v7:$supportLibrary"
8888
implementation "com.android.support:design:$supportLibrary"
8989
implementation "com.android.support.constraint:constraint-layout:1.0.2"
90-
implementation "com.squareup.okhttp3:okhttp:3.9.0"
90+
implementation "com.squareup.okhttp3:okhttp:3.9.1"
9191
implementation "com.squareup.retrofit2:retrofit:$retrofit"
9292
implementation "com.squareup.retrofit2:converter-moshi:$retrofit"
9393
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit"
94-
implementation "io.reactivex.rxjava2:rxjava:2.1.6"
94+
implementation "io.reactivex.rxjava2:rxjava:2.1.7"
9595
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
9696
implementation "com.jakewharton.timber:timber:4.6.0"
9797
implementation "android.arch.lifecycle:extensions:$architectureComponents"
@@ -103,14 +103,14 @@ dependencies {
103103
kapt "com.google.dagger:dagger-android-processor:$dagger"
104104
kapt "com.google.dagger:dagger-compiler:$dagger"
105105

106-
testImplementation "org.mockito:mockito-core:2.12.0"
106+
testImplementation "org.mockito:mockito-core:2.13.0"
107107
testImplementation "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
108108
testImplementation "junit:junit:4.12"
109109
testImplementation "android.arch.core:core-testing:$architectureComponents"
110110

111111
androidTestImplementation "com.android.support.test:runner:1.0.1"
112112
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
113-
androidTestImplementation "org.mockito:mockito-android:2.12.0"
113+
androidTestImplementation "org.mockito:mockito-android:2.13.0"
114114
androidTestImplementation "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
115115
androidTestImplementation "android.arch.core:core-testing:$architectureComponents"
116116
}

app/lint.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<lint>
3+
<issue id="IconColors">
4+
<ignore path="src/main/res/drawable*/privacy_icon_unknown.*" />
5+
</issue>
6+
<issue id="IconExpectedSize">
7+
<ignore path="src/main/res/drawable-*/privacy_icon_unknown.*" />
8+
</issue>
9+
</lint>

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,40 @@ import android.net.Uri
2222
import com.duckduckgo.app.browser.BrowserViewModel.NavigationCommand
2323
import com.duckduckgo.app.browser.BrowserViewModel.ViewState
2424
import com.duckduckgo.app.browser.omnibar.OmnibarEntryConverter
25-
import com.duckduckgo.app.trackerdetection.model.NetworkTrackers
25+
import com.duckduckgo.app.privacymonitor.store.PrivacyMonitorRepository
2626
import com.nhaarman.mockito_kotlin.mock
2727
import org.junit.After
2828
import org.junit.Assert.*
2929
import org.junit.Before
3030
import org.junit.Rule
3131
import org.junit.Test
3232
import org.mockito.ArgumentMatchers
33-
import org.mockito.Mock
3433
import org.mockito.Mockito.never
3534
import org.mockito.Mockito.verify
3635

3736
class BrowserViewModelTest {
3837

3938
@get:Rule
39+
@Suppress("unused")
4040
var instantTaskExecutorRule = InstantTaskExecutorRule()
4141

42-
@Mock
43-
private val viewStateObserver: Observer<ViewState> = mock()
44-
45-
@Mock
46-
private val queryObserver: Observer<String> = mock()
47-
48-
@Mock
49-
private val navigationObserver: Observer<NavigationCommand> = mock()
42+
private lateinit var viewStateObserver: Observer<ViewState>
43+
private lateinit var queryObserver: Observer<String>
44+
private lateinit var navigationObserver: Observer<NavigationCommand>
45+
private lateinit var testee: BrowserViewModel
5046

5147
private val testOmnibarConverter: OmnibarEntryConverter = object : OmnibarEntryConverter {
5248
override fun convertUri(input: String): String = "duckduckgo.com"
5349
override fun isWebUrl(inputQuery: String): Boolean = true
5450
override fun convertQueryToUri(inputQuery: String): Uri = Uri.parse("duckduckgo.com")
5551
}
5652

57-
private lateinit var testee: BrowserViewModel
58-
5953
@Before
6054
fun before() {
61-
testee = BrowserViewModel(testOmnibarConverter, DuckDuckGoUrlDetector(), NetworkTrackers())
55+
viewStateObserver = mock()
56+
queryObserver = mock()
57+
navigationObserver = mock()
58+
testee = BrowserViewModel(testOmnibarConverter, DuckDuckGoUrlDetector(), PrivacyMonitorRepository())
6259
testee.query.observeForever(queryObserver)
6360
testee.viewState.observeForever(viewStateObserver)
6461
testee.navigation.observeForever(navigationObserver)

app/src/androidTest/java/com/duckduckgo/app/global/UriExtensionTest.kt

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

1919
import android.net.Uri
20-
import org.junit.Assert.assertEquals
21-
import org.junit.Assert.assertNull
20+
import org.junit.Assert.*
2221
import org.junit.Test
2322

2423

@@ -38,26 +37,57 @@ class UriExtensionTest {
3837

3938
@Test
4039
fun whenUriBeginsWithWwwThenBaseHostReturnsWithoutWww() {
41-
val url = "http://www.somehost.com"
42-
assertEquals("somehost.com", Uri.parse(url).baseHost())
40+
val url = "http://www.example.com"
41+
assertEquals("example.com", Uri.parse(url).baseHost)
4342
}
4443

4544
@Test
4645
fun whenUriDoesNotBeginWithWwwThenBaseHosReturnsWithSameHost() {
47-
val url = "http://somehost.com"
48-
assertEquals("somehost.com", Uri.parse(url).baseHost())
46+
val url = "http://example.com"
47+
assertEquals("example.com", Uri.parse(url).baseHost)
4948
}
5049

5150
@Test
5251
fun whenUriDoesNotHaveASchemeThenBaseHostStillResolvesHost() {
53-
val url = "www.somehost.com"
54-
assertEquals("somehost.com", Uri.parse(url).baseHost())
52+
val url = "www.example.com"
53+
assertEquals("example.com", Uri.parse(url).baseHost)
5554
}
5655

5756
@Test
5857
fun whenUriContainsInvalidHostThenBaseHostIsNull() {
5958
val url = "about:blank"
60-
assertNull(Uri.parse(url).baseHost())
59+
assertNull(Uri.parse(url).baseHost)
6160
}
6261

62+
@Test
63+
fun whenUriIsHttpIrrespectiveOfCaseThenIsHttpIsTrue() {
64+
assertTrue(Uri.parse("http://example.com").isHttp)
65+
assertTrue(Uri.parse("HTTP://example.com").isHttp)
66+
}
67+
68+
@Test
69+
fun whenUriIsHttpsThenIsHttpIsFalse() {
70+
assertFalse(Uri.parse("https://example.com").isHttp)
71+
}
72+
73+
@Test
74+
fun whenUriIsMalformedThenIsHttpIsFalse() {
75+
assertFalse(Uri.parse("[example com]").isHttp)
76+
}
77+
78+
@Test
79+
fun whenUriIsHttpsIrrespectiveOfCaseThenIsHttpsIsTrue() {
80+
assertTrue(Uri.parse("https://example.com").isHttps)
81+
assertTrue(Uri.parse("HTTPS://example.com").isHttps)
82+
}
83+
84+
@Test
85+
fun whenUriIsHttpThenIsHttpsIsFalse() {
86+
assertFalse(Uri.parse("http://example.com").isHttps)
87+
}
88+
89+
@Test
90+
fun whenUriIsMalformedThenIsHtpsIsFalse() {
91+
assertFalse(Uri.parse("[example com]").isHttps)
92+
}
6393
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.privacydashboard
18+
19+
import android.arch.core.executor.testing.InstantTaskExecutorRule
20+
import android.arch.lifecycle.Observer
21+
import android.support.test.InstrumentationRegistry
22+
import com.duckduckgo.app.browser.R
23+
import com.duckduckgo.app.privacymonitor.HttpsStatus
24+
import com.duckduckgo.app.privacymonitor.PrivacyMonitor
25+
import com.nhaarman.mockito_kotlin.mock
26+
import com.nhaarman.mockito_kotlin.whenever
27+
import org.junit.After
28+
import org.junit.Assert.assertEquals
29+
import org.junit.Before
30+
import org.junit.Rule
31+
import org.junit.Test
32+
33+
class PrivacyDashboardViewModelTest {
34+
35+
@get:Rule
36+
@Suppress("unused")
37+
var instantTaskExecutorRule = InstantTaskExecutorRule()
38+
39+
private lateinit var viewStateObserver: Observer<PrivacyDashboardViewModel.ViewState>
40+
private lateinit var monitor: PrivacyMonitor
41+
private lateinit var testee: PrivacyDashboardViewModel
42+
43+
@Before
44+
fun before() {
45+
viewStateObserver = mock()
46+
monitor = mock()
47+
testee = PrivacyDashboardViewModel(InstrumentationRegistry.getTargetContext())
48+
testee.viewState.observeForever(viewStateObserver)
49+
whenever(monitor.https).thenReturn(HttpsStatus.SECURE)
50+
}
51+
52+
@After
53+
fun after() {
54+
testee.viewState.removeObserver(viewStateObserver)
55+
}
56+
57+
@Test
58+
fun whenHttpsStatusIsSecureThenTextAndIconReflectSame() {
59+
whenever(monitor.https).thenReturn(HttpsStatus.SECURE)
60+
testee.onPrivacyMonitorChanged(monitor)
61+
assertEquals(getStringResource(R.string.httpsGood), testee.viewState.value?.httpsText)
62+
assertEquals(R.drawable.dashboard_https_good, testee.viewState.value?.httpsIcon)
63+
}
64+
65+
@Test
66+
fun whenHttpsStatusIsMixedThenTextAndIconReflectSame() {
67+
whenever(monitor.https).thenReturn(HttpsStatus.MIXED)
68+
testee.onPrivacyMonitorChanged(monitor)
69+
assertEquals(getStringResource(R.string.httpsMixed), testee.viewState.value?.httpsText)
70+
assertEquals(R.drawable.dashboard_https_neutral, testee.viewState.value?.httpsIcon)
71+
}
72+
73+
@Test
74+
fun whenHttpsStatusIsNoneThenTextAndIconReflectSame() {
75+
whenever(monitor.https).thenReturn(HttpsStatus.NONE)
76+
testee.onPrivacyMonitorChanged(monitor)
77+
assertEquals(getStringResource(R.string.httpsBad), testee.viewState.value?.httpsText)
78+
assertEquals(R.drawable.dashboard_https_bad, testee.viewState.value?.httpsIcon)
79+
}
80+
81+
@Test
82+
fun whenNoTrackersNetworksThenNetworkTextShowsZero() {
83+
whenever(monitor.networkCount).thenReturn(0)
84+
testee.onPrivacyMonitorChanged(monitor)
85+
assertEquals("0 Tracker Networks Blocked", testee.viewState.value?.networksText)
86+
}
87+
88+
@Test
89+
fun whenTenTrackersNetworksThenNetworkTextShowsTen() {
90+
whenever(monitor.networkCount).thenReturn(10)
91+
testee.onPrivacyMonitorChanged(monitor)
92+
assertEquals("10 Tracker Networks Blocked", testee.viewState.value?.networksText)
93+
}
94+
95+
@Test
96+
fun whenNoMajorTrackersNetworksThenMajorNetworkTextShowsZero() {
97+
whenever(monitor.majorNetworkCount).thenReturn(0)
98+
testee.onPrivacyMonitorChanged(monitor)
99+
assertEquals("0 Major Tracker Networks Blocked", testee.viewState.value?.majorNetworksText)
100+
}
101+
102+
@Test
103+
fun whenTenMajorTrackersNetworksThenMajorNetworkTextShowsTen() {
104+
whenever(monitor.majorNetworkCount).thenReturn(10)
105+
testee.onPrivacyMonitorChanged(monitor)
106+
assertEquals("10 Major Tracker Networks Blocked", testee.viewState.value?.majorNetworksText)
107+
}
108+
109+
private fun getStringResource(id: Int): String =
110+
InstrumentationRegistry.getTargetContext().getString(id)
111+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.privacymonitor
18+
19+
import org.junit.Assert.assertEquals
20+
import org.junit.Test
21+
22+
class SiteMonitorInstrumentationTests {
23+
24+
companion object {
25+
private const val httpDocument = "http://example.com"
26+
private const val httpsDocument = "https://example.com"
27+
private const val malformesDocument = "[example com]"
28+
}
29+
30+
@Test
31+
fun whenUrlIsHttpsThenHttpsStatusIsSecure() {
32+
val testee = SiteMonitor(httpsDocument)
33+
assertEquals(HttpsStatus.SECURE, testee.https)
34+
}
35+
36+
@Test
37+
fun whenUrlIsHttpThenHttpsStatusIsNone() {
38+
val testee = SiteMonitor(httpDocument)
39+
assertEquals(HttpsStatus.NONE, testee.https)
40+
}
41+
42+
@Test
43+
fun whenUrlIsHttpsWithHttpResourcesThenHttpsStatusIsMixed() {
44+
val testee = SiteMonitor(httpsDocument)
45+
testee.hasHttpResources = true
46+
assertEquals(HttpsStatus.MIXED, testee.https)
47+
}
48+
49+
@Test
50+
fun whenUrlIsMalformedThenHttpsStatusIsNone() {
51+
val testee = SiteMonitor(malformesDocument)
52+
assertEquals(HttpsStatus.NONE, testee.https)
53+
}
54+
}

app/src/androidTest/java/com/duckduckgo/app/trackerdetection/AdBlockClientInstrumentationTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class AdBlockClientInstrumentationTest {
6666
assertFalse(testee.matches(nonTrackerUrl, documentUrl, resourceType))
6767
}
6868

69-
private fun data(): ByteArray {
70-
return javaClass.classLoader.getResource("binary/easylist_sample").readBytes()
71-
}
69+
private fun data(): ByteArray =
70+
javaClass.classLoader.getResource("binary/easylist_sample").readBytes()
7271
}

0 commit comments

Comments
 (0)