This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #10836: Add Facts for Credit Card Autofill Feature
- Loading branch information
1 parent
2fb230c
commit bcea682
Showing
8 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...s/src/main/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFacts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* 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.feature.prompts.facts | ||
|
||
import mozilla.components.support.base.Component | ||
import mozilla.components.support.base.facts.Action | ||
import mozilla.components.support.base.facts.Fact | ||
import mozilla.components.support.base.facts.collect | ||
|
||
/** | ||
* Facts emitted for telemetry related to the Autofill prompt feature for credit cards. | ||
*/ | ||
class CreditCardAutofillDialogFacts { | ||
/** | ||
* Specific types of telemetry items. | ||
*/ | ||
object Items { | ||
const val AUTOFILL_CREDIT_CARD_FORM_DETECTED = "autofill_credit_card_form_detected" | ||
const val AUTOFILL_CREDIT_CARD_SUCCESS = "autofill_credit_card_success" | ||
const val AUTOFILL_CREDIT_CARD_PROMPT_SHOWN = "autofill_credit_card_prompt_shown" | ||
const val AUTOFILL_CREDIT_CARD_PROMPT_EXPANDED = "autofill_credit_card_prompt_expanded" | ||
const val AUTOFILL_CREDIT_CARD_PROMPT_DISMISSED = "autofill_credit_card_prompt_dismissed" | ||
} | ||
} | ||
|
||
private fun emitCreditCardAutofillDialogFact( | ||
action: Action, | ||
item: String, | ||
value: String? = null, | ||
metadata: Map<String, Any>? = null | ||
) { | ||
Fact( | ||
Component.FEATURE_PROMPTS, | ||
action, | ||
item, | ||
value, | ||
metadata | ||
).collect() | ||
} | ||
|
||
internal fun emitSuccessfulCreditCardAutofillFormDetectedFact() { | ||
emitCreditCardAutofillDialogFact( | ||
Action.INTERACTION, | ||
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_FORM_DETECTED | ||
) | ||
} | ||
|
||
internal fun emitSuccessfulCreditCardAutofillSuccessFact() { | ||
emitCreditCardAutofillDialogFact( | ||
Action.INTERACTION, | ||
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_SUCCESS | ||
) | ||
} | ||
|
||
internal fun emitCreditCardAutofillShownFact() { | ||
emitCreditCardAutofillDialogFact( | ||
Action.INTERACTION, | ||
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_SHOWN | ||
) | ||
} | ||
|
||
internal fun emitCreditCardAutofillExpandedFact() { | ||
emitCreditCardAutofillDialogFact( | ||
Action.INTERACTION, | ||
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_EXPANDED | ||
) | ||
} | ||
|
||
internal fun emitCreditCardAutofillDismissedFact() { | ||
emitCreditCardAutofillDialogFact( | ||
Action.INTERACTION, | ||
CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_DISMISSED | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...c/test/java/mozilla/components/feature/prompts/facts/CreditCardAutofillDialogFactsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* 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.feature.prompts.facts | ||
|
||
import mozilla.components.support.base.Component | ||
import mozilla.components.support.base.facts.Action | ||
import mozilla.components.support.base.facts.processor.CollectionProcessor | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class CreditCardAutofillDialogFactsTest { | ||
|
||
@Test | ||
fun `Emits facts for autofill form detected events`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
|
||
emitSuccessfulCreditCardAutofillFormDetectedFact() | ||
|
||
assertEquals(1, facts.size) | ||
|
||
facts[0].apply { | ||
assertEquals(Component.FEATURE_PROMPTS, component) | ||
assertEquals(Action.INTERACTION, action) | ||
assertEquals(CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_FORM_DETECTED, item) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `Emits facts for autofill success events`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
|
||
emitSuccessfulCreditCardAutofillSuccessFact() | ||
|
||
assertEquals(1, facts.size) | ||
|
||
facts[0].apply { | ||
assertEquals(Component.FEATURE_PROMPTS, component) | ||
assertEquals(Action.INTERACTION, action) | ||
assertEquals(CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_SUCCESS, item) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `Emits facts for autofill shown events`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
|
||
emitCreditCardAutofillShownFact() | ||
|
||
assertEquals(1, facts.size) | ||
|
||
facts[0].apply { | ||
assertEquals(Component.FEATURE_PROMPTS, component) | ||
assertEquals(Action.INTERACTION, action) | ||
assertEquals(CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_SHOWN, item) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `Emits facts for autofill expanded events`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
|
||
emitCreditCardAutofillExpandedFact() | ||
|
||
assertEquals(1, facts.size) | ||
|
||
facts[0].apply { | ||
assertEquals(Component.FEATURE_PROMPTS, component) | ||
assertEquals(Action.INTERACTION, action) | ||
assertEquals(CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_EXPANDED, item) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `Emits facts for autofill dismissed events`() { | ||
CollectionProcessor.withFactCollection { facts -> | ||
|
||
emitCreditCardAutofillDismissedFact() | ||
|
||
assertEquals(1, facts.size) | ||
|
||
facts[0].apply { | ||
assertEquals(Component.FEATURE_PROMPTS, component) | ||
assertEquals(Action.INTERACTION, action) | ||
assertEquals(CreditCardAutofillDialogFacts.Items.AUTOFILL_CREDIT_CARD_PROMPT_DISMISSED, item) | ||
} | ||
} | ||
} | ||
} |