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

Module tidy up for autofill #2030

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import android.webkit.WebView
import androidx.test.annotation.UiThreadTest
import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import com.duckduckgo.app.autofill.FileBasedJavaScriptInjector
import com.duckduckgo.app.autofill.FileBasedJavascriptInjector
import com.duckduckgo.app.autofill.JavascriptInjector
import com.duckduckgo.app.browser.DuckDuckGoUrlDetector
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.global.DispatcherProvider
import com.duckduckgo.feature.toggles.api.FeatureToggle
import com.duckduckgo.privacy.config.api.Autofill
Expand All @@ -38,7 +39,7 @@ class EmailInjectorJsTest {
private val mockDispatcherProvider: DispatcherProvider = mock()
private val mockFeatureToggle: FeatureToggle = mock()
private val mockAutofill: Autofill = mock()
private val javascriptInjector: JavascriptInjector = FileBasedJavaScriptInjector()
private val javascriptInjector: JavascriptInjector = FileBasedJavascriptInjector()
lateinit var testee: EmailInjectorJs

@Before
Expand Down Expand Up @@ -148,15 +149,15 @@ class EmailInjectorJsTest {
}

private fun getAliasJsToEvaluate(): String {
val js = InstrumentationRegistry.getInstrumentation().targetContext.resources.openRawResource(com.duckduckgo.app.global.R.raw.inject_alias)
val js = InstrumentationRegistry.getInstrumentation().targetContext.resources.openRawResource(R.raw.inject_alias)
.bufferedReader()
.use { it.readText() }
return "javascript:$js"
}

private fun getNotifySignOutJsToEvaluate(): String {
val js =
InstrumentationRegistry.getInstrumentation().targetContext.resources.openRawResource(com.duckduckgo.app.global.R.raw.signout_autofill)
InstrumentationRegistry.getInstrumentation().targetContext.resources.openRawResource(R.raw.signout_autofill)
.bufferedReader()
.use { it.readText() }
return "javascript:$js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,14 @@
package com.duckduckgo.app.autofill

import android.content.Context
import com.duckduckgo.app.global.R
import com.duckduckgo.app.browser.R
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesBinding
import java.io.BufferedReader
import javax.inject.Inject

interface JavascriptInjector {
fun getFunctionsJS(): String
fun getAliasFunctions(
context: Context,
alias: String?
): String

fun getSignOutFunctions(
context: Context
): String
}

@ContributesBinding(AppScope::class)
class FileBasedJavaScriptInjector @Inject constructor() : JavascriptInjector {
class FileBasedJavascriptInjector @Inject constructor() : JavascriptInjector {
private lateinit var functions: String
private lateinit var aliasFunctions: String
private lateinit var signOutFunctions: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 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.autofill

import android.content.Context

interface JavascriptInjector {
fun getFunctionsJS(): String

fun getAliasFunctions(
context: Context,
alias: String?
): String

fun getSignOutFunctions(
context: Context
): String
}
1 change: 1 addition & 0 deletions modules/autofill/autofill-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation project(path: ':autofill-api')
implementation project(path: ':secure-storage-api')
implementation project(path: ':device-auth-api')
implementation project(path: ':browser-api')
api project(path: ':autofill-store')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

Expand Down