Skip to content

Commit

Permalink
Merge branch 'release/0.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
subsymbolic committed Jan 12, 2018
2 parents 69926fe + e1c824e commit 3697a95
Show file tree
Hide file tree
Showing 66 changed files with 1,302 additions and 132 deletions.
14 changes: 1 addition & 13 deletions 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.9.0"
VERSION_NAME = "0.10.0"
}

android {
Expand Down Expand Up @@ -52,18 +52,6 @@ android {
testOptions {
unitTests.returnDefaultValues = true
}
sourceSets {
String sharedTestJavaDir = 'src/sharedTest/java'
String sharedTestResourcesDir = 'src/sharedTest/resources'
test {
java.srcDir sharedTestJavaDir
resources.srcDir sharedTestResourcesDir
}
androidTest {
java.srcDir sharedTestJavaDir
resources.srcDir sharedTestResourcesDir
}
}

def staticConfigPath = "${System.getenv('HOME')}/jenkins_static/com.duckduckgo.mobile.android"
def propertiesPath = "${staticConfigPath}/ddg_android_build.properties"
Expand Down
124 changes: 124 additions & 0 deletions app/schemas/com.duckduckgo.app.global.db.AppDatabase/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "df2202389ba5b11018b57a417457b11b",
"entities": [
{
"tableName": "https_upgrade_domain",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`domain` TEXT NOT NULL, PRIMARY KEY(`domain`))",
"fields": [
{
"fieldPath": "domain",
"columnName": "domain",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"domain"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "disconnect_tracker",
"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`))",
"fields": [
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "category",
"columnName": "category",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "networkName",
"columnName": "networkName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "networkUrl",
"columnName": "networkUrl",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"url"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "network_leaderboard",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`networkName` TEXT NOT NULL, `domainVisited` TEXT NOT NULL, PRIMARY KEY(`networkName`, `domainVisited`))",
"fields": [
{
"fieldPath": "networkName",
"columnName": "networkName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "domainVisited",
"columnName": "domainVisited",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"networkName",
"domainVisited"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "app_configuration",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `appConfigurationDownloaded` INTEGER NOT NULL, PRIMARY KEY(`key`))",
"fields": [
{
"fieldPath": "key",
"columnName": "key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "appConfigurationDownloaded",
"columnName": "appConfigurationDownloaded",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"key"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"df2202389ba5b11018b57a417457b11b\")"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class BrowserViewModelTest {

private var lastEntry: NetworkLeaderboardEntry? = null

private val testStringResolver: StringResolver = object : StringResolver {
override fun getString(stringId: Int): String = ""
override fun getString(stringId: Int, vararg formatArgs: Any): String = ""
}
private val testStringResolver: StringResolver = object : StringResolver {}

private val testNetworkLeaderboardDao: NetworkLeaderboardDao = object : NetworkLeaderboardDao {
override fun insert(leaderboardEntry: NetworkLeaderboardEntry) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018 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.global.view

import android.graphics.Color
import org.junit.Assert.assertEquals
import org.junit.Test

class ColorCombinerTest {

private val testee = ColorCombiner()

@Test
fun whenColorsCombineWithZeroRatioThenCombinedColorIsFirstColor() {
val from = Color.argb(200, 200, 200, 200)
val to = Color.argb(100, 100, 100, 100)
assertEquals(from, testee.combine(from, to, 0.toFloat()))
}

@Test
fun whenColorsCombineWithFullRatioThenCombinedColorIsSecondColor() {
val from = Color.argb(200, 200, 200, 200)
val to = Color.argb(100, 100, 100, 100)
assertEquals(to, testee.combine(from, to, 1.toFloat()))
}

@Test
fun whenColorsCombinedWithHalfRatioThenCombinedColorIsMixed() {
val from = Color.argb(200, 200, 200, 200)
val to = Color.argb(100, 100, 100, 100)
val expected = Color.argb(150, 150, 150, 150)
val actual = testee.combine(from, to, 0.5.toFloat())
assertEquals(expected, actual)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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.verify
import com.nhaarman.mockito_kotlin.whenever
import org.junit.Assert.*
import org.junit.Before
Expand All @@ -35,16 +36,38 @@ class HttpsUpgraderTest {
testee = HttpsUpgrader(mockDao)
}

@Test
fun whenMixedCaseDomainIsASubdominOfAWildCardInTheDatabaseThenShouldUpgrade() {
whenever(mockDao.hasDomain("www.example.com")).thenReturn(false)
whenever(mockDao.hasDomain("*.example.com")).thenReturn(true)
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.EXAMPLE.com")))
verify(mockDao).hasDomain("*.example.com")
}

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

@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 whenDomainIsASubdominOfAWildCardInTheDatabaseThenShouldUpgrade() {
whenever(mockDao.hasDomain("www.example.com")).thenReturn(false)
whenever(mockDao.hasDomain("*.example.com")).thenReturn(true)
assertTrue(testee.shouldUpgrade(Uri.parse("http://www.example.com")))
verify(mockDao).hasDomain("*.example.com")
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,33 @@

package com.duckduckgo.app.httpsupgrade.api

import com.duckduckgo.app.httpsupgrade.db.HttpsUpgradeDomain
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
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 type = Types.newParameterizedType(List::class.java, HttpsUpgradeDomain::class.java)
val adapter: JsonAdapter<List<HttpsUpgradeDomain>> = moshi.adapter(type)

val list = adapter.fromJson(json())
assertEquals(5, list.simpleUpgrade.top500.count())
assertEquals(5, list.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
Expand Up @@ -20,8 +20,7 @@ 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.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test

Expand Down Expand Up @@ -54,48 +53,59 @@ class HttpsUpgradeDomainDaoTest {
fun whenExactMatchDomainAddedAndThenAllDeletedThenDoesNotContainExactMatchDomain() {
dao.insertAll(HttpsUpgradeDomain(exactMatchDomain))
dao.deleteAll()
assertFalse(dao.contains(exactMatchDomain))
assertFalse(dao.hasDomain(exactMatchDomain))
}

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

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

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

@Test
fun whenWildcardDomainInsertedThenModelContainsExampleWildcardDomain() {
dao.insertAll(HttpsUpgradeDomain(wildcardDomain))
assertTrue(dao.contains(exampleWildcardDomain))
assertTrue(dao.hasDomain("*.$parentOfWildcardDomain"))
}

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

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

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

@Test
fun whenModelIsEmptyThenCountIsZero() {
assertEquals(0, dao.count())
}

@Test
fun whenModelContainsTwoItemsThenCountIsTwo() {
dao.insertAll(HttpsUpgradeDomain(exactMatchDomain), HttpsUpgradeDomain(otherDomain))
assertEquals(2, dao.count())
}

}
Loading

0 comments on commit 3697a95

Please sign in to comment.