From ae2236a4b656ac797452b346de19282ed4c18140 Mon Sep 17 00:00:00 2001 From: Alexandru2909 Date: Tue, 19 Jul 2022 10:17:38 +0300 Subject: [PATCH] For #12523 - Add telemetry for credit card save prompt show --- .../feature/prompts/PromptFeature.kt | 3 ++ .../facts/CreditCardAutofillDialogFacts.kt | 8 ++++ .../feature/prompts/PromptFeatureTest.kt | 47 +++++++++++++++++++ .../CreditCardAutofillDialogFactsTest.kt | 17 +++++++ 4 files changed, 75 insertions(+) diff --git a/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt b/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt index 5ac032e113e..74a0bc7f0a3 100644 --- a/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt +++ b/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt @@ -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 @@ -625,6 +626,8 @@ class PromptFeature private constructor( return } + emitCreditCardSaveShownFact() + CreditCardSaveDialogFragment.newInstance( sessionId = session.id, promptRequestUID = promptRequest.uid, diff --git a/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFacts.kt b/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFacts.kt index ce816daa7c9..a2a6b4ad3f1 100644 --- a/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFacts.kt +++ b/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFacts.kt @@ -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" } } @@ -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 + ) +} diff --git a/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/PromptFeatureTest.kt b/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/PromptFeatureTest.kt index 98b18cb4931..5c964384dad 100644 --- a/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/PromptFeatureTest.kt +++ b/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/PromptFeatureTest.kt @@ -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 @@ -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( diff --git a/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFactsTest.kt b/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFactsTest.kt index a138651ae4c..b5fcf3e601b 100644 --- a/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFactsTest.kt +++ b/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFactsTest.kt @@ -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 + ) + } + } }