Skip to content

Commit

Permalink
Issue mozilla-mobile#10140 - Part 1: Refactor autocomplete extension …
Browse files Browse the repository at this point in the history
…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()`.
  • Loading branch information
gabrielluong committed May 4, 2021
1 parent 7d53e94 commit 4c04d08
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Autocomplete.LoginSaveOption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4c04d08

Please sign in to comment.