-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
121 changed files
with
1,795 additions
and
556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/HTTPSUpgraderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))) | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/api/HTTPSUpgradeJsonTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
]}} | ||
""" | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
app/src/androidTest/java/com/duckduckgo/app/httpsupgrade/db/HTTPSUpgradeDomainDAOTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.