Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
subsymbolic committed Dec 22, 2017
2 parents 2bf6772 + ce9be2a commit 2d7d379
Show file tree
Hide file tree
Showing 121 changed files with 1,795 additions and 556 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'kotlin-kapt'
apply from: '../versioning.gradle'

ext {
VERSION_NAME = "0.6.0"
VERSION_NAME = "0.7.0"
}

android {
Expand Down Expand Up @@ -99,17 +99,20 @@ dependencies {
implementation "com.jakewharton.timber:timber:4.6.0"
implementation "android.arch.lifecycle:extensions:$architectureComponents"
implementation "android.arch.lifecycle:reactivestreams:$architectureComponents"
implementation "android.arch.persistence.room:runtime:$architectureComponents"
implementation "com.google.dagger:dagger-android:$dagger"
implementation "com.google.dagger:dagger-android-support:$dagger"
releaseImplementation 'com.faendir:acra:4.10.0'

kapt "com.google.dagger:dagger-android-processor:$dagger"
kapt "com.google.dagger:dagger-compiler:$dagger"
kapt "android.arch.persistence.room:compiler:$architectureComponents"

testImplementation "org.mockito:mockito-core:2.13.0"
testImplementation "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
testImplementation "junit:junit:4.12"
testImplementation "android.arch.core:core-testing:$architectureComponents"
testImplementation "android.arch.persistence.room:testing:$architectureComponents"

androidTestImplementation "com.android.support.test:runner:1.0.1"
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,43 @@ class BrowserViewModelTest {

@Test
fun whenViewModelNotifiedThatUrlGotFocusThenViewStateIsUpdated() {
testee.onUrlInputStateChanged("", true)
testee.onOmnibarInputStateChanged("", true)
assertTrue(testee.viewState.value!!.isEditing)
}

@Test
fun whenViewModelNotifiedThatUrlLostFocusThenViewStateIsUpdated() {
testee.onUrlInputStateChanged("", false)
testee.onOmnibarInputStateChanged("", false)
assertFalse(testee.viewState.value!!.isEditing)
}

@Test
fun whenNoUrlEverEnteredThenViewStateHasNull() {
assertNull(testee.viewState.value!!.url)
fun whenNoOmnibarTextEverEnteredThenViewStateHasNull() {
assertNull(testee.viewState.value!!.omnibarText)
}

@Test
fun whenUrlChangedThenViewStateIsUpdated() {
testee.urlChanged("duckduckgo.com")
assertEquals("duckduckgo.com", testee.viewState.value!!.url)
assertEquals("duckduckgo.com", testee.viewState.value!!.omnibarText)
}

@Test
fun whenUrlChangedWithDuckDuckGoUrlContainingQueryThenUrlRewrittenToContainQuery() {
testee.urlChanged("http://duckduckgo.com?q=test")
assertEquals("test", testee.viewState.value!!.omnibarText)
}

@Test
fun whenUrlChangedWithDuckDuckGoUrlNotContainingQueryThenFullUrlShown() {
testee.urlChanged("http://duckduckgo.com")
assertEquals("http://duckduckgo.com", testee.viewState.value!!.omnibarText)
}

@Test
fun whenUrlChangedWithNonDuckDuckGoUrlThenFullUrlShown() {
testee.urlChanged("http://example.com")
assertEquals("http://example.com", testee.viewState.value!!.omnibarText)
}

@Test
Expand Down Expand Up @@ -160,20 +178,20 @@ class BrowserViewModelTest {
@Test
fun whenLoadingStartedThenPrivacyGradeIsCleared() {
testee.loadingStarted()
assertNull(testee.viewState.value!!.privacyGrade)
assertNull(testee.privacyGrade.value)
}

@Test
fun whenUrlChangedThenPrivacyGradeIsReset() {
testee.urlChanged("https://example.com")
assertEquals(PrivacyGrade.B, testee.viewState.value!!.privacyGrade)
assertEquals(PrivacyGrade.B, testee.privacyGrade.value)
}

@Test
fun whenTrackerDetectedThenPrivacyGradeIsUpdated() {
testee.urlChanged("https://example.com")
testee.trackerDetected(TrackingEvent("", "", null, false))
assertEquals(PrivacyGrade.C, testee.viewState.value!!.privacyGrade)
assertEquals(PrivacyGrade.C, testee.privacyGrade.value)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package com.duckduckgo.app.browser

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test

Expand All @@ -44,5 +43,27 @@ class DuckDuckGoUrlDetectorTest {
fun whenCheckingFullDDGUrlThenIdentifiedAsDDGUrl() {
assertTrue(testee.isDuckDuckGoUrl("https://duckduckgo.com/?q=test%20search&tappv=android_0_2_0&t=ddg_android"))
}

@Test
fun whenDDGUrlContainsQueryThenQueryCanBeExtracted() {
val query = testee.extractQuery("https://duckduck.com?q=test%20search")
assertEquals("test search", query)
}

@Test
fun whenDDGUrlDoesNotContainsQueryThenQueryIsNull() {
val query = testee.extractQuery("https://duckduck.com")
assertNull(query)
}

@Test
fun whenDDGUrlContainsQueryThenQueryDetected() {
assertTrue(testee.hasQuery("https://duckduck.com?q=test%20search"))
}

@Test
fun whenDDGUrlDoesNotContainsQueryThenQueryIsNotDetected() {
assertFalse(testee.hasQuery("https://duckduck.com"))
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2017 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.httpsupgrade

import android.net.Uri
import com.duckduckgo.app.httpsupgrade.db.HTTPSUpgradeDomainDAO
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.whenever
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test

class HTTPSUpgraderTest {

lateinit var testee: HTTPSUpgrader
lateinit var mockDao: HTTPSUpgradeDomainDAO

@Before
fun before() {
mockDao = mock()
testee = HTTPSUpgrader(mockDao)
}

@Test
fun whenGivenUriItIsUpgradedToHttps() {
val input = Uri.parse("http://www.example.com/some/path/to/a/file.txt")
val expected = Uri.parse("https://www.example.com/some/path/to/a/file.txt")
assertEquals(expected, testee.upgrade(input))
}

@Test
fun whenUriIsHttpAndInUpgradeListThenShouldUpgrade() {
whenever(mockDao.contains("www.example.com")).thenReturn(true)
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.example.com")))
}

@Test
fun whenUriIsHttpAndIsNotInUpgradeListThenShouldNotUpgrade() {
assertFalse(testee.shouldUpgrade(Uri.parse("http://www.example.com")))
}

@Test
fun whenUriIsHttpsThenShouldNotUpgrade() {
assertFalse(testee.shouldUpgrade(Uri.parse("https://www.example.com")))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2017 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.httpsupgrade.api

import com.squareup.moshi.Moshi
import org.junit.Assert.assertEquals
import org.junit.Test


class HTTPSUpgradeJsonTest {

@Test
fun whenGivenValidJsonThenParsesCorrectly() {
val moshi = Moshi.Builder().add(HTTPSUpgradeDomainFromStringAdapter()).build()
val adapter = moshi.adapter(HTTPSUpgradeJson::class.java)
val list = adapter.fromJson(json())
assertEquals(5, list.simpleUpgrade.top500.count())
}

private fun json() : String = """
{ "simpleUpgrade" : { "top500": [
"1337x.to",
"1688.com",
"2ch.net",
"adobe.com",
"alibaba.com"
]}}
"""

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2017 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.httpsupgrade.db

import android.arch.persistence.room.Room
import android.support.test.InstrumentationRegistry
import com.duckduckgo.app.global.db.AppDatabase
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test

class HTTPSUpgradeDomainDAOTest {

companion object {
var exactMatchDomain = "bbc.co.uk"
var otherDomain = "other.com"
var wildcardDomain = "*.wordpress.com"
var otherWildcardDomain = "*.google.com"
var exampleWildcardDomain = "example.wordpress.com"
var parentOfWildcardDomain = "wordpress.com"
}

private lateinit var db: AppDatabase
private lateinit var dao: HTTPSUpgradeDomainDAO

@Before
fun before() {
db = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(), AppDatabase::class.java).build()
dao = db.httpsUpgradeDomainDAO()
}

@After
fun after() {
db.close()
}

@Test
fun whenExactMatchDomainAddedAndThenAllDeletedThenDoesNotContainExactMatchDomain() {
dao.insertAll(HTTPSUpgradeDomain(exactMatchDomain))
dao.deleteAll()
assertFalse(dao.contains(exactMatchDomain))
}

@Test
fun whenWildcardDomainInsertedModelThenDoesNotContainParentOfWildcardDomain() {
dao.insertAll(HTTPSUpgradeDomain(wildcardDomain))
assertFalse(dao.contains(parentOfWildcardDomain))
}

@Test
fun whenOtherWildcardDomainInsertedThenModelDoesNotContainExampleWildcardDomain() {
dao.insertAll(HTTPSUpgradeDomain(otherWildcardDomain))
assertFalse(dao.contains(exampleWildcardDomain))
}

@Test
fun whenWildcardDomainInsertedThenModelDoesNotContainExactMatchDomain() {
dao.insertAll(HTTPSUpgradeDomain(wildcardDomain))
assertFalse(dao.contains(exactMatchDomain))
}

@Test
fun whenWildcardDomainInsertedThenModelContainsExampleWildcardDomain() {
dao.insertAll(HTTPSUpgradeDomain(wildcardDomain))
assertTrue(dao.contains(exampleWildcardDomain))
}

@Test
fun whenExactMatchDomainInsertedThenModelDoesNotContainOtherDomain() {
dao.insertAll(HTTPSUpgradeDomain(exactMatchDomain))
assertFalse(dao.contains(otherDomain))
}

@Test
fun whenExactMatchDomainIsInsertedThenModelContainsExactMatchDomain() {
dao.insertAll(HTTPSUpgradeDomain(exactMatchDomain))
assertTrue(dao.contains(exactMatchDomain))
}

@Test
fun whenModelIsEmptyThenModelDoesNotContainExactMatchDomain() {
assertFalse(dao.contains(exactMatchDomain))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test

class SiteMonitorInstrumentationTests {
class SiteMonitorInstrumentationTest {

companion object {
private const val httpDocument = "http://example.com"
Expand Down
Loading

0 comments on commit 2d7d379

Please sign in to comment.