Skip to content

Commit

Permalink
Add missing launch sources to autofill management screen (#4926)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/488551667048375/1208092525366316/f

### Description
Adds a few more launch sources to the autofill management screen pixel,
and ensures the pixel fires regardless of the source of entry.
  • Loading branch information
CDRussell authored Aug 21, 2024
1 parent 1711fd8 commit af8ae21
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ import com.duckduckgo.app.browser.favicon.FaviconManager
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.BrowserOverflow
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.BrowserSnackbar
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.DisableInSettingsPrompt
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.InternalDevSettings
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.NewTabShortcut
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.SettingsActivity
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.Sync
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.Unknown
import com.duckduckgo.autofill.api.domain.app.LoginCredentials
import com.duckduckgo.autofill.api.email.EmailManager
import com.duckduckgo.autofill.impl.R
Expand Down Expand Up @@ -648,10 +652,7 @@ class AutofillSettingsViewModel @Inject constructor(
Timber.v("Opened autofill management screen from from %s", launchSource)

val source = launchSource.asString()

if (source != null) {
pixel.fire(AUTOFILL_MANAGEMENT_SCREEN_OPENED, mapOf("source" to source))
}
pixel.fire(AUTOFILL_MANAGEMENT_SCREEN_OPENED, mapOf("source" to source))
}

fun onUserConfirmationToClearNeverSavedSites() {
Expand Down Expand Up @@ -756,13 +757,17 @@ class AutofillSettingsViewModel @Inject constructor(
pixel.fire(AUTOFILL_SITE_BREAKAGE_REPORT_CONFIRMATION_DISMISSED)
}

private fun AutofillSettingsLaunchSource.asString(): String? {
private fun AutofillSettingsLaunchSource.asString(): String {
return when (this) {
SettingsActivity -> "settings"
BrowserOverflow -> "overflow_menu"
Sync -> "sync"
DisableInSettingsPrompt -> "disable_prompt"
else -> null
DisableInSettingsPrompt -> "save_login_disable_prompt"
NewTabShortcut -> "new_tab_page_shortcut"
BrowserSnackbar -> "browser_snackbar"
InternalDevSettings -> "internal_dev_settings"
Unknown -> "unknown"
else -> this.name
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import app.cash.turbine.test
import com.duckduckgo.app.browser.favicon.FaviconManager
import com.duckduckgo.app.statistics.pixels.Pixel
import com.duckduckgo.app.statistics.pixels.Pixel.PixelName
import com.duckduckgo.app.statistics.pixels.Pixel.PixelType.COUNT
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.BrowserOverflow
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.BrowserSnackbar
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.DisableInSettingsPrompt
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.InternalDevSettings
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.NewTabShortcut
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.SettingsActivity
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.Sync
import com.duckduckgo.autofill.api.domain.app.LoginCredentials
Expand Down Expand Up @@ -693,33 +694,52 @@ class AutofillSettingsViewModelTest {
}

@Test
fun whenScreenLaunchedFromSnackbarThenNoLaunchPixelSent() {
fun whenScreenLaunchedFromSnackbarThenCorrectLaunchPixelSent() {
testee.sendLaunchPixel(BrowserSnackbar)
verify(pixel, never()).fire(any<PixelName>(), any(), any(), eq(COUNT))
val expectedParams = mapOf("source" to "browser_snackbar")
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), eq(expectedParams), any(), eq(COUNT))
}

@Test
fun whenScreenLaunchedFromBrowserThenCorrectLaunchPixelSent() {
testee.sendLaunchPixel(BrowserOverflow)
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), any(), any(), eq(COUNT))
val expectedParams = mapOf("source" to "overflow_menu")
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), eq(expectedParams), any(), eq(COUNT))
}

@Test
fun whenScreenLaunchedFromSyncThenCorrectLaunchPixelSent() {
testee.sendLaunchPixel(Sync)
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), any(), any(), eq(COUNT))
val expectedParams = mapOf("source" to "sync")
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), eq(expectedParams), any(), eq(COUNT))
}

@Test
fun whenScreenLaunchedFromDisablePromptThenCorrectLaunchPixelSent() {
testee.sendLaunchPixel(DisableInSettingsPrompt)
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), any(), any(), eq(COUNT))
val expectedParams = mapOf("source" to "save_login_disable_prompt")
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), eq(expectedParams), any(), eq(COUNT))
}

@Test
fun whenScreenLaunchedFromNewTabShortcutThenCorrectLaunchPixelSent() {
testee.sendLaunchPixel(NewTabShortcut)
val expectedParams = mapOf("source" to "new_tab_page_shortcut")
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), eq(expectedParams), any(), eq(COUNT))
}

@Test
fun whenScreenLaunchedFromSettingsActivityThenCorrectLaunchPixelSent() {
testee.sendLaunchPixel(SettingsActivity)
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), any(), any(), eq(COUNT))
val expectedParams = mapOf("source" to "settings")
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), eq(expectedParams), any(), eq(COUNT))
}

@Test
fun whenScreenLaunchedFromInternalDevSettingsActivityThenCorrectLaunchPixelSent() {
testee.sendLaunchPixel(InternalDevSettings)
val expectedParams = mapOf("source" to "internal_dev_settings")
verify(pixel).fire(eq(AUTOFILL_MANAGEMENT_SCREEN_OPENED), eq(expectedParams), any(), eq(COUNT))
}

@Test
Expand Down

0 comments on commit af8ae21

Please sign in to comment.