diff --git a/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt b/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt index fb61c8aace84..e221f3ded1a9 100644 --- a/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt +++ b/app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt @@ -2303,6 +2303,37 @@ class BrowserTabViewModelTest { assertEquals("false", argumentCaptor.firstValue[PixelParameter.BOOKMARK_CAPABLE]) } + @Test + fun whenSearchSuggestionSubmittedWithTabsThenAutoCompleteSearchSelectionPixelSent() = runTest { + whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false) + whenever(mockNavigationHistory.hasHistory()).thenReturn(false) + tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0), TabEntity("2", "https://example.com", position = 1)) + val suggestions = listOf(AutoCompleteSwitchToTabSuggestion("example", "", "", "")) + testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult("", suggestions)) + testee.fireAutocompletePixel(AutoCompleteSwitchToTabSuggestion("example", "", "", "")) + + val argumentCaptor = argumentCaptor>() + verify(mockPixel).fire(eq(AppPixelName.AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION), argumentCaptor.capture(), any(), any()) + + assertEquals("true", argumentCaptor.firstValue[PixelParameter.SHOWED_SWITCH_TO_TAB]) + assertEquals("true", argumentCaptor.firstValue[PixelParameter.SWITCH_TO_TAB_CAPABLE]) + } + + @Test + fun whenSearchSuggestionSubmittedWithoutTabsThenAutoCompleteSearchSelectionPixelSent() = runTest { + whenever(mockSavedSitesRepository.hasBookmarks()).thenReturn(false) + whenever(mockNavigationHistory.hasHistory()).thenReturn(false) + tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0)) + testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult("", emptyList())) + testee.fireAutocompletePixel(AutoCompleteSwitchToTabSuggestion("example", "", "", "")) + + val argumentCaptor = argumentCaptor>() + verify(mockPixel).fire(eq(AppPixelName.AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION), argumentCaptor.capture(), any(), any()) + + assertEquals("false", argumentCaptor.firstValue[PixelParameter.SHOWED_SWITCH_TO_TAB]) + assertEquals("false", argumentCaptor.firstValue[PixelParameter.SWITCH_TO_TAB_CAPABLE]) + } + @Test fun whenUserSelectToEditQueryThenMoveCaretToTheEnd() = runTest { testee.onUserSelectedToEditQuery("foo") diff --git a/app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt b/app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt index abe392180e27..a40e25560aad 100644 --- a/app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt +++ b/app/src/main/java/com/duckduckgo/app/browser/BrowserTabViewModel.kt @@ -838,10 +838,14 @@ class BrowserTabViewModel @Inject constructor( val hasHistory = withContext(dispatchers.io()) { history.hasHistory() } + val hasTabs = withContext(dispatchers.io()) { + (tabRepository.liveTabs.value?.size ?: 0) > 1 + } val hasBookmarkResults = currentViewState.searchResults.suggestions.any { it is AutoCompleteBookmarkSuggestion && !it.isFavorite } val hasFavoriteResults = currentViewState.searchResults.suggestions.any { it is AutoCompleteBookmarkSuggestion && it.isFavorite } val hasHistoryResults = currentViewState.searchResults.suggestions.any { it is AutoCompleteHistorySuggestion || it is AutoCompleteHistorySearchSuggestion } + val hasSwitchToTabResults = currentViewState.searchResults.suggestions.any { it is AutoCompleteSwitchToTabSuggestion } val params = mapOf( PixelParameter.SHOWED_BOOKMARKS to hasBookmarkResults.toString(), PixelParameter.SHOWED_FAVORITES to hasFavoriteResults.toString(), @@ -849,6 +853,8 @@ class BrowserTabViewModel @Inject constructor( PixelParameter.FAVORITE_CAPABLE to hasFavorites.toString(), PixelParameter.HISTORY_CAPABLE to hasHistory.toString(), PixelParameter.SHOWED_HISTORY to hasHistoryResults.toString(), + PixelParameter.SWITCH_TO_TAB_CAPABLE to hasTabs.toString(), + PixelParameter.SHOWED_SWITCH_TO_TAB to hasSwitchToTabResults.toString(), ) val pixelName = when (suggestion) { is AutoCompleteBookmarkSuggestion -> { @@ -861,6 +867,7 @@ class BrowserTabViewModel @Inject constructor( is AutoCompleteSearchSuggestion -> if (suggestion.isUrl) AUTOCOMPLETE_SEARCH_WEBSITE_SELECTION else AUTOCOMPLETE_SEARCH_PHRASE_SELECTION is AutoCompleteHistorySuggestion -> AUTOCOMPLETE_HISTORY_SITE_SELECTION is AutoCompleteHistorySearchSuggestion -> AUTOCOMPLETE_HISTORY_SEARCH_SELECTION + is AutoCompleteSwitchToTabSuggestion -> AppPixelName.AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION else -> return } @@ -3653,6 +3660,9 @@ class BrowserTabViewModel @Inject constructor( if (suggestions.any { it is AutoCompleteSearchSuggestion && it.isUrl }) { pixel.fire(AppPixelName.AUTOCOMPLETE_DISPLAYED_LOCAL_WEBSITE) } + if (suggestions.any { it is AutoCompleteSwitchToTabSuggestion }) { + pixel.fire(AppPixelName.AUTOCOMPLETE_DISPLAYED_LOCAL_SWITCH_TO_TAB) + } } lastAutoCompleteState = null } diff --git a/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt b/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt index 8be0a197711e..59dc5fd831cd 100644 --- a/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt +++ b/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt @@ -196,6 +196,8 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName { AUTOCOMPLETE_HISTORY_SEARCH_SELECTION("m_autocomplete_click_history_search"), AUTOCOMPLETE_HISTORY_SITE_SELECTION("m_autocomplete_click_history_site"), + AUTOCOMPLETE_SWITCH_TO_TAB_SELECTION("m_autocomplete_click_switch_to_tab"), + AUTOCOMPLETE_TOGGLED_OFF("m_autocomplete_recent_sites_toggled_off"), AUTOCOMPLETE_TOGGLED_ON("m_autocomplete_recent_sites_toggled_on"), @@ -216,6 +218,7 @@ enum class AppPixelName(override val pixelName: String) : Pixel.PixelName { AUTOCOMPLETE_DISPLAYED_LOCAL_WEBSITE("m_autocomplete_displayed_website"), AUTOCOMPLETE_DISPLAYED_LOCAL_HISTORY("m_autocomplete_displayed_history_site"), AUTOCOMPLETE_DISPLAYED_LOCAL_HISTORY_SEARCH("m_autocomplete_displayed_history_search"), + AUTOCOMPLETE_DISPLAYED_LOCAL_SWITCH_TO_TAB("m_autocomplete_displayed_switch_to_tab"), AUTOCOMPLETE_RESULT_DELETED("m_autocomplete_result_deleted"), diff --git a/statistics/statistics-api/src/main/java/com/duckduckgo/app/statistics/pixels/Pixel.kt b/statistics/statistics-api/src/main/java/com/duckduckgo/app/statistics/pixels/Pixel.kt index c4819bf2b771..bfd53c6808ee 100644 --- a/statistics/statistics-api/src/main/java/com/duckduckgo/app/statistics/pixels/Pixel.kt +++ b/statistics/statistics-api/src/main/java/com/duckduckgo/app/statistics/pixels/Pixel.kt @@ -31,9 +31,11 @@ interface Pixel { const val BOOKMARK_CAPABLE = "bc" const val FAVORITE_CAPABLE = "fc" const val HISTORY_CAPABLE = "hc" + const val SWITCH_TO_TAB_CAPABLE = "switch_to_tab_capable" const val SHOWED_BOOKMARKS = "sb" const val SHOWED_FAVORITES = "sf" const val SHOWED_HISTORY = "sh" + const val SHOWED_SWITCH_TO_TAB = "showed_switch_to_tab" const val DEFAULT_BROWSER_BEHAVIOUR_TRIGGERED = "bt" const val DEFAULT_BROWSER_SET_FROM_ONBOARDING = "fo" const val DEFAULT_BROWSER_SET_ORIGIN = "dbo"