Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Issue #11336 - Revert support for save credit card prompt
Browse files Browse the repository at this point in the history
This reverts commit bd5ad08.
  • Loading branch information
gabrielluong authored and mergify[bot] committed Nov 29, 2021
1 parent 0b6e618 commit 687041c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,43 +64,6 @@ typealias AC_FILE_FACING_MODE = PromptRequest.File.FacingMode
internal class GeckoPromptDelegate(private val geckoEngineSession: GeckoEngineSession) :
PromptDelegate {

override fun onCreditCardSave(
session: GeckoSession,
request: AutocompleteRequest<Autocomplete.CreditCardSaveOption>
): GeckoResult<PromptResponse>? {
val geckoResult = GeckoResult<PromptResponse>()

val onConfirm: (CreditCard) -> Unit = { creditCard ->
if (!request.isComplete) {
geckoResult.complete(
request.confirm(
Autocomplete.CreditCardSelectOption(creditCard.toAutocompleteCreditCard())
)
)
}
}

val onDismiss: () -> Unit = {
request.dismissSafely(geckoResult)
}

geckoEngineSession.notifyObservers {
onPromptRequest(
PromptRequest.SaveCreditCard(
creditCard = request.options[0].value.toCreditCard(),
onDismiss = onDismiss,
onConfirm = onConfirm
).also {
request.delegate = PromptInstanceDismissDelegate(
geckoEngineSession, it
)
}
)
}

return geckoResult
}

/**
* Handle a credit card selection prompt request. This is triggered by the user
* focusing on a credit card input field.
Expand Down Expand Up @@ -740,6 +703,7 @@ internal fun Date.toString(format: String): String {
* Only dismiss if the prompt is not already dismissed.
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)

internal fun PromptDelegate.BasePrompt.dismissSafely(geckoResult: GeckoResult<PromptResponse>) {
if (!this.isComplete) {
geckoResult.complete(dismiss())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,93 +796,6 @@ class GeckoPromptDelegateTest {
passwordField = passwordField
)

@Test
fun `Calling onCreditCardSave must provide an SaveCreditCard PromptRequest`() {
val mockSession = GeckoEngineSession(runtime)
var onCreditCardSaved = false
var onDismissWasCalled = false

var saveCreditCardPrompt: PromptRequest.SaveCreditCard = mock()

val promptDelegate = spy(GeckoPromptDelegate(mockSession))

mockSession.register(object : EngineSession.Observer {
override fun onPromptRequest(promptRequest: PromptRequest) {
saveCreditCardPrompt = promptRequest as PromptRequest.SaveCreditCard
}
})

val creditCard = CreditCard(
guid = "1",
name = "Banana Apple",
number = "4111111111111110",
expiryMonth = "5",
expiryYear = "2030",
cardType = "amex"
)
val creditCardSaveOption =
Autocomplete.CreditCardSaveOption(creditCard.toAutocompleteCreditCard())

var geckoResult = promptDelegate.onCreditCardSave(
mock(),
geckoCreditCardSavePrompt(arrayOf(creditCardSaveOption))
)

geckoResult!!.accept {
onDismissWasCalled = true
}

saveCreditCardPrompt.onDismiss()
assertTrue(onDismissWasCalled)

val geckoPrompt = geckoCreditCardSavePrompt(arrayOf(creditCardSaveOption))
geckoResult = promptDelegate.onCreditCardSave(mock(), geckoPrompt)

geckoResult!!.accept {
onCreditCardSaved = true
}

saveCreditCardPrompt.onConfirm(creditCard)

assertTrue(onCreditCardSaved)

whenever(geckoPrompt.isComplete).thenReturn(true)
onCreditCardSaved = false
saveCreditCardPrompt.onConfirm(creditCard)

assertFalse(onCreditCardSaved)
}

@Test
fun `Calling onCreditSave must set a PromptInstanceDismissDelegate`() {
val mockSession = GeckoEngineSession(runtime)
var saveCreditCardPrompt: PromptRequest.SaveCreditCard = mock()
val promptDelegate = spy(GeckoPromptDelegate(mockSession))

mockSession.register(object : EngineSession.Observer {
override fun onPromptRequest(promptRequest: PromptRequest) {
saveCreditCardPrompt = promptRequest as PromptRequest.SaveCreditCard
}
})

val creditCard = CreditCard(
guid = "1",
name = "Banana Apple",
number = "4111111111111110",
expiryMonth = "5",
expiryYear = "2030",
cardType = "amex"
)
val creditCardSaveOption =
Autocomplete.CreditCardSaveOption(creditCard.toAutocompleteCreditCard())
val geckoPrompt = spy(geckoCreditCardSavePrompt(arrayOf(creditCardSaveOption)))

promptDelegate.onCreditCardSave(mock(), geckoPrompt)

assertNotNull(saveCreditCardPrompt)
assertNotNull(geckoPrompt.delegate)
}

@Test
fun `Calling onCreditCardSelect must provide as CreditCardSelectOption PromptRequest`() {
val mockSession = GeckoEngineSession(runtime)
Expand Down Expand Up @@ -1616,12 +1529,4 @@ class GeckoPromptDelegateTest {
ReflectionUtils.setField(prompt, "options", creditCards)
return prompt
}

private fun geckoCreditCardSavePrompt(
creditCard: Array<Autocomplete.CreditCardSaveOption>
): GeckoSession.PromptDelegate.AutocompleteRequest<Autocomplete.CreditCardSaveOption> {
val prompt: GeckoSession.PromptDelegate.AutocompleteRequest<Autocomplete.CreditCardSaveOption> = mock()
ReflectionUtils.setField(prompt, "options", creditCard)
return prompt
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ sealed class PromptRequest(
val onStay: () -> Unit
) : PromptRequest()

/**
* Value type that represents a request for a save credit card prompt.
* @property creditCard the [CreditCard] to save or update.
* @property onDismiss callback to let the page know the user dismissed the dialog.
* @property onConfirm callback that is called when the user confirms the credit card selection.
*/
data class SaveCreditCard(
val creditCard: CreditCard,
override val onDismiss: () -> Unit,
val onConfirm: (CreditCard) -> Unit
) : PromptRequest(shouldDismissOnLoad = false), Dismissible

/**
* Value type that represents a request for a select credit card prompt.
* @property creditCards a list of [CreditCard]s to select from.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import mozilla.components.concept.engine.prompt.PromptRequest.MenuChoice
import mozilla.components.concept.engine.prompt.PromptRequest.MultipleChoice
import mozilla.components.concept.engine.prompt.PromptRequest.Popup
import mozilla.components.concept.engine.prompt.PromptRequest.Repost
import mozilla.components.concept.engine.prompt.PromptRequest.SaveCreditCard
import mozilla.components.concept.engine.prompt.PromptRequest.SaveLoginPrompt
import mozilla.components.concept.engine.prompt.PromptRequest.SelectCreditCard
import mozilla.components.concept.engine.prompt.PromptRequest.SelectLoginPrompt
Expand Down Expand Up @@ -801,7 +800,6 @@ class PromptFeature private constructor(
is SaveLoginPrompt,
is SelectLoginPrompt,
is SelectCreditCard,
is SaveCreditCard,
is Share -> true
is Alert, is TextPrompt, is Confirm, is Repost, is Popup -> promptAbuserDetector.shouldShowMoreDialogs
}
Expand Down
3 changes: 0 additions & 3 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ permalink: /changelog/
* [Gecko](/~https://github.com/mozilla-mobile/android-components/blob/main/buildSrc/src/main/java/Gecko.kt)
* [Configuration](/~https://github.com/mozilla-mobile/android-components/blob/main/.config.yml)

* **concept-engine**
* Adds a new `SaveCreditCard` in `PromptRequest` to display a prompt for saving a credit card on autofill. [#11249](/~https://github.com/mozilla-mobile/android-components/issues/11249)

# 95.0.0
* [Commits](/~https://github.com/mozilla-mobile/android-components/compare/v94.0.0...v95.0.0)
* [Milestone](/~https://github.com/mozilla-mobile/android-components/milestone/142?closed=1)
Expand Down

0 comments on commit 687041c

Please sign in to comment.