Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libraries #1299

Merged
merged 8 commits into from
Jul 24, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.duckduckgo.app.browser.downloader

import android.webkit.WebView
import androidx.test.annotation.UiThreadTest
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.browser.R
import com.nhaarman.mockitokotlin2.spy
Expand All @@ -37,6 +38,7 @@ class BlobConverterInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, spy is not supported on API < 24
mockito/mockito#2075 (comment)

fun whenConvertBlobIntoDataUriAndDownloadThenInjectJsCode() {
val jsToEvaluate = getJsToEvaluate().replace("%blobUrl%", blobUrl).replace("%contentType%", contentType)
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.net.Uri
import android.webkit.WebResourceRequest
import android.webkit.WebView
import androidx.test.annotation.UiThreadTest
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.CoroutineTestRule
import com.duckduckgo.app.browser.logindetection.LoginDetectionJavascriptInterface.Companion.JAVASCRIPT_INTERFACE_NAME
Expand All @@ -42,6 +43,7 @@ class JsLoginDetectorTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenAddLoginDetectionThenJSInterfaceAdded() = coroutinesTestRule.runBlocking {
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
testee.addLoginDetection(webView) {}
Expand All @@ -50,6 +52,7 @@ class JsLoginDetectorTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenLoginDetectionDisabledAndPageStartedEventThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
whenever(settingsDataStore.appLoginDetection).thenReturn(false)
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -59,6 +62,7 @@ class JsLoginDetectorTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenLoginDetectionDisabledAndInterceptRequestEventThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
whenever(settingsDataStore.appLoginDetection).thenReturn(false)
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -69,6 +73,7 @@ class JsLoginDetectorTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenLoginDetectionEnabledAndPageStartedEventThenJSLoginDetectionInjected() = coroutinesTestRule.runBlocking {
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -78,6 +83,7 @@ class JsLoginDetectorTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenLoginDetectionEnabledAndLoginPostRequestCapturedThenJSLoginDetectionInjected() = coroutinesTestRule.runBlocking {
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -88,6 +94,7 @@ class JsLoginDetectorTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenLoginDetectionEnabledAndNoLoginPostRequestCapturedThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -98,6 +105,7 @@ class JsLoginDetectorTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenLoginDetectionEnabledAndGetRequestCapturedThenNoWebViewInteractions() = coroutinesTestRule.runBlocking {
whenever(settingsDataStore.appLoginDetection).thenReturn(true)
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.duckduckgo.app.email

import android.webkit.WebView
import androidx.test.annotation.UiThreadTest
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.browser.DuckDuckGoUrlDetector
import com.duckduckgo.app.browser.R
Expand All @@ -38,6 +39,7 @@ class EmailInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectEmailAutofillJsAndUrlIsFromDuckDuckGoDomainThenInjectJsCode() {
val jsToEvaluate = getJsToEvaluate()
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -49,6 +51,7 @@ class EmailInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectEmailAutofillJsAndUrlIsFromDuckDuckGoSubdomainThenInjectJsCode() {
val jsToEvaluate = getJsToEvaluate()
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -60,6 +63,7 @@ class EmailInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectEmailAutofillJsAndUrlIsNotFromDuckDuckGoAndEmailIsSignedInThenInjectJsCode() {
whenever(mockEmailManager.isSignedIn()).thenReturn(true)
val jsToEvaluate = getJsToEvaluate()
Expand All @@ -72,6 +76,7 @@ class EmailInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectEmailAutofillJsAndUrlIsNotFromDuckDuckGoAndEmailIsNotSignedInThenDoNotInjectJsCode() {
whenever(mockEmailManager.isSignedIn()).thenReturn(false)
val jsToEvaluate = getJsToEvaluate()
Expand All @@ -84,6 +89,7 @@ class EmailInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectEmailAutofillJsTwiceThenDoNotInjectJsCodeTwice() {
whenever(mockEmailManager.isSignedIn()).thenReturn(true)
val jsToEvaluate = getJsToEvaluate()
Expand All @@ -97,6 +103,7 @@ class EmailInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenResetInjectedFlagCalledBetweenTwoInjectEmailJsCallsThenInjectJsCodeTwice() {
whenever(mockEmailManager.isSignedIn()).thenReturn(true)
val jsToEvaluate = getJsToEvaluate()
Expand All @@ -111,6 +118,7 @@ class EmailInjectorJsTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectAddressThenInjectJsCodeReplacingTheAlias() {
val address = "address"
val jsToEvaluate = getAliasJsToEvaluate().replace("%s", address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.duckduckgo.app.globalprivacycontrol
import android.webkit.WebView
import androidx.core.net.toUri
import androidx.test.annotation.UiThreadTest
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.globalprivacycontrol.GlobalPrivacyControlManager.Companion.GPC_HEADER
Expand Down Expand Up @@ -47,6 +48,7 @@ class GlobalPrivacyControlManagerTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectDoNotSellToDomAndGcpIsEnabledThenInjectToDom() {
val jsToEvaluate = getJsToEvaluate()
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand All @@ -59,6 +61,7 @@ class GlobalPrivacyControlManagerTest {

@UiThreadTest
@Test
@SdkSuppress(minSdkVersion = 24)
fun whenInjectDoNotSellToDomAndGcpIsNotEnabledThenDoNotInjectToDom() {
val jsToEvaluate = getJsToEvaluate()
val webView = spy(WebView(InstrumentationRegistry.getInstrumentation().targetContext))
Expand Down
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.30'
ext.spotless = "5.7.0"
ext.anvil_version = "2.2.0"
ext.spotless = "5.14.0"
ext.anvil_version = "2.3.3"

ext.min_sdk = 21
ext.target_sdk = 29
Expand All @@ -16,7 +14,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:_"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aitorvs I think this is the way we can avoid having to duplicate the kotlin version in 2 files, but not 100% sure.

By executing ./gradlew buildEnvironment seems this will work: org.jetbrains.kotlin:kotlin-gradle-plugin:{require 1.5.20; reject _} -> 1.5.20, so I guess is ok

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting! I seems it works because the _ is not really a valid version and then it falls back to any other (latest) version we might have. I think a more secure approach might be the following, in the root build.gradle

buildscript {
    def versionPropsFile = file('versions.properties')
    Properties versionProps = new Properties()

    if (versionPropsFile.canRead()) {
        versionProps.load(new FileInputStream(versionPropsFile))
    }

    ext.kotlin_version = versionProps['version.kotlin']
    ...

classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless"
classpath "com.squareup.anvil:gradle-plugin:$anvil_version"

Expand Down
14 changes: 7 additions & 7 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ version.androidx.recyclerview=1.2.1

version.androidx.core=1.6.0

version.androidx.fragment=1.2.5
version.androidx.fragment=1.3.5

version.androidx.legacy=1.0.0

version.androidx.lifecycle=2.4.0-alpha01

version.androidx.room=2.2.6
version.androidx.room=2.3.0

version.androidx.swiperefreshlayout=1.1.0

version.androidx.test=1.4.0-beta02

version.androidx.webkit=1.3.0
version.androidx.webkit=1.4.0

version.androidx.work=2.4.0
version.androidx.work=2.5.0

version.androidx.security=1.1.0-alpha03

Expand Down Expand Up @@ -64,17 +64,17 @@ version.io.reactivex.rxjava2..rxandroid=2.0.2

version.io.reactivex.rxjava2..rxjava=2.2.9

version.kotlin=1.4.10
version.kotlin=1.5.20
Copy link
Collaborator

@aitorvs aitorvs Jul 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe remove the one we have in the main build.gradle and used this one. They are easy to get out of sync, in fact, they had different versions :/


version.kotlinx.coroutines=1.5.0

version.leakcanary=2.7

version.okhttp3=4.9.0
version.okhttp3=4.9.1

version.org.apache.commons..commons-math3=3.6.1

version.mockito=3.4.6
version.mockito=3.10.0

version.retrofit2=2.9.0

Expand Down