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

Commit

Permalink
For #12523 - Add telemetry for credit card save prompt show
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru2909 committed Jul 19, 2022
1 parent 1873c69 commit ae2236a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import mozilla.components.feature.prompts.dialog.Prompter
import mozilla.components.feature.prompts.dialog.SaveLoginDialogFragment
import mozilla.components.feature.prompts.dialog.TextPromptDialogFragment
import mozilla.components.feature.prompts.dialog.TimePickerDialogFragment
import mozilla.components.feature.prompts.facts.emitCreditCardSaveShownFact
import mozilla.components.feature.prompts.facts.emitSuccessfulAddressAutofillFormDetectedFact
import mozilla.components.feature.prompts.facts.emitSuccessfulCreditCardAutofillFormDetectedFact
import mozilla.components.feature.prompts.file.FilePicker
Expand Down Expand Up @@ -625,6 +626,8 @@ class PromptFeature private constructor(
return
}

emitCreditCardSaveShownFact()

CreditCardSaveDialogFragment.newInstance(
sessionId = session.id,
promptRequestUID = promptRequest.uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CreditCardAutofillDialogFacts {
const val AUTOFILL_CREDIT_CARD_PROMPT_DISMISSED = "autofill_credit_card_prompt_dismissed"
const val AUTOFILL_CREDIT_CARD_CREATED = "autofill_credit_card_created"
const val AUTOFILL_CREDIT_CARD_UPDATED = "autofill_credit_card_updated"
const val AUTOFILL_CREDIT_CARD_SAVE_PROMPT_SHOWN = "autofill_credit_card_save_prompt_shown"
}
}

Expand Down Expand Up @@ -90,3 +91,10 @@ internal fun emitCreditCardAutofillUpdatedFact() {
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_UPDATED
)
}

internal fun emitCreditCardSaveShownFact() {
emitCreditCardAutofillDialogFact(
Action.DISPLAY,
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_SAVE_PROMPT_SHOWN
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ import mozilla.components.feature.prompts.dialog.ConfirmDialogFragment
import mozilla.components.feature.prompts.dialog.MultiButtonDialogFragment
import mozilla.components.feature.prompts.dialog.PromptDialogFragment
import mozilla.components.feature.prompts.dialog.SaveLoginDialogFragment
import mozilla.components.feature.prompts.facts.CreditCardAutofillDialogFacts
import mozilla.components.feature.prompts.file.FilePicker.Companion.FILE_PICKER_ACTIVITY_REQUEST_CODE
import mozilla.components.feature.prompts.login.LoginDelegate
import mozilla.components.feature.prompts.login.LoginPicker
import mozilla.components.feature.prompts.share.ShareDelegate
import mozilla.components.support.base.Component
import mozilla.components.support.base.facts.Action
import mozilla.components.support.base.facts.processor.CollectionProcessor
import mozilla.components.support.test.any
import mozilla.components.support.test.eq
import mozilla.components.support.test.ext.joinBlocking
Expand Down Expand Up @@ -2310,6 +2314,49 @@ class PromptFeatureTest {
verify(dialogFragment).dismissAllowingStateLoss()
}

@Test
fun `WHEN SaveCreditCard is handled THEN the credit card save prompt shown fact is emitted`() {
val feature = PromptFeature(
activity = mock(),
store = store,
fragmentManager = fragmentManager,
isCreditCardAutofillEnabled = { true },
creditCardValidationDelegate = mock()
) { }
val creditCardEntry = CreditCardEntry(
guid = "1",
name = "CC",
number = "4111111111111110",
expiryMonth = "5",
expiryYear = "2030",
cardType = ""
)
val request = PromptRequest.SaveCreditCard(
creditCard = creditCardEntry,
onConfirm = {},
onDismiss = {}
)
val session: TabSessionState = mock()
val sessionId = "sessionId"
`when`(session.id).thenReturn(sessionId)

CollectionProcessor.withFactCollection { facts ->
feature.handleDialogsRequest(
promptRequest = request,
session = session
)

assertEquals(1, facts.size)
val fact = facts.single()
assertEquals(Component.FEATURE_PROMPTS, fact.component)
assertEquals(Action.DISPLAY, fact.action)
assertEquals(
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_SAVE_PROMPT_SHOWN,
fact.item
)
}
}

@Test
fun `WHEN promptRequest is updated THEN the replaced active prompt will be dismissed`() {
val feature = spy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,21 @@ class CreditCardAutofillDialogFactsTest {
)
}
}

@Test
fun `Emits facts for autofill save prompt shown event`() {
CollectionProcessor.withFactCollection { facts ->
emitCreditCardSaveShownFact()

assertEquals(1, facts.size)

val fact = facts.single()
assertEquals(Component.FEATURE_PROMPTS, fact.component)
assertEquals(Action.DISPLAY, fact.action)
assertEquals(
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_SAVE_PROMPT_SHOWN,
fact.item
)
}
}
}

0 comments on commit ae2236a

Please sign in to comment.