From 7cce63c489244c79cab72f3419311ffbac117bdf Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Thu, 22 Apr 2021 12:10:23 -0400 Subject: [PATCH] Issue #10140 - Part 1: Refactor autocomplete extension functions into ext/Login.kt - Moves `Autocomplete.LoginEntry.toLogin()` and `Login.toLoginEntry()` extension functions into `ext/Login.kt` - Remove duplicates of `Autocomplete.LoginEntry.toLogin()` and `Login.toLoginEntry()`. --- .../autofill/GeckoLoginDelegateWrapper.kt | 26 ++------------- .../browser/engine/gecko/ext/Login.kt | 32 +++++++++++++++++++ .../gecko/prompt/GeckoPromptDelegate.kt | 20 ++---------- .../gecko/prompt/GeckoPromptDelegateTest.kt | 13 +------- 4 files changed, 37 insertions(+), 54 deletions(-) create mode 100644 components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/ext/Login.kt diff --git a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/autofill/GeckoLoginDelegateWrapper.kt b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/autofill/GeckoLoginDelegateWrapper.kt index 71288f44b21..a32c40d75b9 100644 --- a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/autofill/GeckoLoginDelegateWrapper.kt +++ b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/autofill/GeckoLoginDelegateWrapper.kt @@ -7,6 +7,8 @@ package mozilla.components.browser.engine.gecko.autofill import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import mozilla.components.browser.engine.gecko.ext.toLogin +import mozilla.components.browser.engine.gecko.ext.toLoginEntry import mozilla.components.concept.storage.Login import mozilla.components.concept.storage.LoginStorageDelegate import org.mozilla.geckoview.Autocomplete @@ -42,27 +44,3 @@ class GeckoLoginDelegateWrapper(private val storageDelegate: LoginStorageDelegat return result } } - -/** - * Converts a GeckoView [LoginStorage.LoginEntry] to an Android Components [Login] - */ -private fun Autocomplete.LoginEntry.toLogin() = Login( - guid = guid, - origin = origin, - formActionOrigin = formActionOrigin, - httpRealm = httpRealm, - username = username, - password = password -) - -/** - * Converts an Android Components [Login] to a GeckoView [LoginStorage.LoginEntry] - */ -private fun Login.toLoginEntry() = Autocomplete.LoginEntry.Builder() - .guid(guid) - .origin(origin) - .formActionOrigin(formActionOrigin) - .httpRealm(httpRealm) - .username(username) - .password(password) - .build() diff --git a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/ext/Login.kt b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/ext/Login.kt new file mode 100644 index 00000000000..d18e13a9f51 --- /dev/null +++ b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/ext/Login.kt @@ -0,0 +1,32 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.components.browser.engine.gecko.ext + +import mozilla.components.concept.storage.Login +import org.mozilla.geckoview.Autocomplete + +/** + * Converts a GeckoView [Autocomplete.LoginEntry] to an Android Components [Login]. + */ +fun Autocomplete.LoginEntry.toLogin() = Login( + guid = guid, + origin = origin, + formActionOrigin = formActionOrigin, + httpRealm = httpRealm, + username = username, + password = password +) + +/** + * Converts an Android Components [Login] to a GeckoView [Autocomplete.LoginEntry]. + */ +fun Login.toLoginEntry() = Autocomplete.LoginEntry.Builder() + .guid(guid) + .origin(origin) + .formActionOrigin(formActionOrigin) + .httpRealm(httpRealm) + .username(username) + .password(password) + .build() diff --git a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt index fc5d38bb6d8..f38948f8bef 100644 --- a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt +++ b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt @@ -8,6 +8,8 @@ import android.content.Context import android.net.Uri import androidx.annotation.VisibleForTesting import mozilla.components.browser.engine.gecko.GeckoEngineSession +import mozilla.components.browser.engine.gecko.ext.toLogin +import mozilla.components.browser.engine.gecko.ext.toLoginEntry import mozilla.components.concept.engine.prompt.Choice import mozilla.components.concept.engine.prompt.PromptRequest import mozilla.components.concept.engine.prompt.PromptRequest.MenuChoice @@ -57,24 +59,6 @@ typealias AC_FILE_FACING_MODE = PromptRequest.File.FacingMode internal class GeckoPromptDelegate(private val geckoEngineSession: GeckoEngineSession) : PromptDelegate { - private fun Autocomplete.LoginEntry.toLogin() = Login( - guid = guid, - origin = origin, - formActionOrigin = formActionOrigin, - httpRealm = httpRealm, - username = username, - password = password - ) - - private fun Login.toLoginEntry() = Autocomplete.LoginEntry.Builder() - .guid(guid) - .origin(origin) - .formActionOrigin(formActionOrigin) - .httpRealm(httpRealm) - .username(username) - .password(password) - .build() - override fun onLoginSave( session: GeckoSession, prompt: PromptDelegate.AutocompleteRequest diff --git a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegateTest.kt b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegateTest.kt index 984f919ce0f..fd63a9212c4 100644 --- a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegateTest.kt +++ b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegateTest.kt @@ -7,6 +7,7 @@ package mozilla.components.browser.engine.gecko.prompt import android.net.Uri import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.browser.engine.gecko.GeckoEngineSession +import mozilla.components.browser.engine.gecko.ext.toLoginEntry import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.prompt.Choice import mozilla.components.concept.engine.prompt.PromptRequest @@ -754,18 +755,6 @@ class GeckoPromptDelegateTest { passwordField = passwordField ) - /** - * Converts an Android Components [Login] to a GeckoView [LoginStorage.LoginEntry] - */ - private fun Login.toLoginEntry() = Autocomplete.LoginEntry.Builder() - .guid(guid) - .origin(origin) - .formActionOrigin(formActionOrigin) - .httpRealm(httpRealm) - .username(username) - .password(password) - .build() - @Test fun `Calling onAuthPrompt must provide an Authentication PromptRequest`() { val mockSession = GeckoEngineSession(runtime)