Skip to content

Commit 4ac0c4d

Browse files
authored
Extensible PixelName API (#1129)
* Extensible PixelName API * Moved pixel names used only in the app to the gradle app module * Added the new pixel names to PixelNameTest * Better test error message
1 parent 18e24c3 commit 4ac0c4d

File tree

70 files changed

+517
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+517
-448
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserTabViewModelTest.kt

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import com.duckduckgo.app.notification.model.UseOurAppNotification
8686
import com.duckduckgo.app.onboarding.store.AppStage
8787
import com.duckduckgo.app.onboarding.store.OnboardingStore
8888
import com.duckduckgo.app.onboarding.store.UserStageStore
89+
import com.duckduckgo.app.pixels.AppPixelName
8990
import com.duckduckgo.app.privacy.db.NetworkLeaderboardDao
9091
import com.duckduckgo.app.privacy.db.UserWhitelistDao
9192
import com.duckduckgo.app.privacy.model.PrivacyGrade
@@ -1095,15 +1096,15 @@ class BrowserTabViewModelTest {
10951096
loadUrl("http://example.com")
10961097
testee.onDesktopSiteModeToggled(true)
10971098
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
1098-
verify(mockPixel).fire(Pixel.PixelName.MENU_ACTION_DESKTOP_SITE_ENABLE_PRESSED)
1099+
verify(mockPixel).fire(AppPixelName.MENU_ACTION_DESKTOP_SITE_ENABLE_PRESSED)
10991100
assertTrue(browserViewState().isDesktopBrowsingMode)
11001101
}
11011102

11021103
@Test
11031104
fun whenUserSelectsMobileSiteThenMobileModeStateUpdated() {
11041105
loadUrl("http://example.com")
11051106
testee.onDesktopSiteModeToggled(false)
1106-
verify(mockPixel).fire(Pixel.PixelName.MENU_ACTION_DESKTOP_SITE_DISABLE_PRESSED)
1107+
verify(mockPixel).fire(AppPixelName.MENU_ACTION_DESKTOP_SITE_DISABLE_PRESSED)
11071108
assertFalse(browserViewState().isDesktopBrowsingMode)
11081109
}
11091110

@@ -1385,7 +1386,7 @@ class BrowserTabViewModelTest {
13851386
loadUrl("http://www.example.com/home.html")
13861387
testee.onWhitelistSelected()
13871388
verify(mockUserWhitelistDao).insert(UserWhitelistedDomain("www.example.com"))
1388-
verify(mockPixel).fire(Pixel.PixelName.BROWSER_MENU_WHITELIST_ADD)
1389+
verify(mockPixel).fire(AppPixelName.BROWSER_MENU_WHITELIST_ADD)
13891390
verify(mockCommandObserver).onChanged(Command.Refresh)
13901391
}
13911392

@@ -1395,7 +1396,7 @@ class BrowserTabViewModelTest {
13951396
loadUrl("http://www.example.com/home.html")
13961397
testee.onWhitelistSelected()
13971398
verify(mockUserWhitelistDao).delete(UserWhitelistedDomain("www.example.com"))
1398-
verify(mockPixel).fire(Pixel.PixelName.BROWSER_MENU_WHITELIST_REMOVE)
1399+
verify(mockPixel).fire(AppPixelName.BROWSER_MENU_WHITELIST_REMOVE)
13991400
verify(mockCommandObserver).onChanged(Command.Refresh)
14001401
}
14011402

@@ -1635,7 +1636,7 @@ class BrowserTabViewModelTest {
16351636
val suggestion = AutoCompleteBookmarkSuggestion("example", "Example", "https://example.com")
16361637
testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult("", listOf(suggestion)))
16371638
testee.fireAutocompletePixel(suggestion)
1638-
verify(mockPixel).fire(Pixel.PixelName.AUTOCOMPLETE_BOOKMARK_SELECTION, pixelParams(showedBookmarks = true, bookmarkCapable = true))
1639+
verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_BOOKMARK_SELECTION, pixelParams(showedBookmarks = true, bookmarkCapable = true))
16391640
}
16401641

16411642
@Test
@@ -1645,7 +1646,7 @@ class BrowserTabViewModelTest {
16451646
testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult("", suggestions))
16461647
testee.fireAutocompletePixel(AutoCompleteSearchSuggestion("example", false))
16471648

1648-
verify(mockPixel).fire(Pixel.PixelName.AUTOCOMPLETE_SEARCH_SELECTION, pixelParams(showedBookmarks = true, bookmarkCapable = true))
1649+
verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_SEARCH_SELECTION, pixelParams(showedBookmarks = true, bookmarkCapable = true))
16491650
}
16501651

16511652
@Test
@@ -1654,7 +1655,7 @@ class BrowserTabViewModelTest {
16541655
testee.autoCompleteViewState.value = autoCompleteViewState().copy(searchResults = AutoCompleteResult("", emptyList()))
16551656
testee.fireAutocompletePixel(AutoCompleteSearchSuggestion("example", false))
16561657

1657-
verify(mockPixel).fire(Pixel.PixelName.AUTOCOMPLETE_SEARCH_SELECTION, pixelParams(showedBookmarks = false, bookmarkCapable = false))
1658+
verify(mockPixel).fire(AppPixelName.AUTOCOMPLETE_SEARCH_SELECTION, pixelParams(showedBookmarks = false, bookmarkCapable = false))
16581659
}
16591660

16601661
@Test
@@ -2061,7 +2062,7 @@ class BrowserTabViewModelTest {
20612062
fun whenFireproofWebsiteAddedThenPixelSent() {
20622063
loadUrl("http://example.com/", isBrowserShowing = true)
20632064
testee.onFireproofWebsiteMenuClicked()
2064-
verify(mockPixel).fire(Pixel.PixelName.FIREPROOF_WEBSITE_ADDED)
2065+
verify(mockPixel).fire(AppPixelName.FIREPROOF_WEBSITE_ADDED)
20652066
}
20662067

20672068
@Test
@@ -2077,7 +2078,7 @@ class BrowserTabViewModelTest {
20772078
givenFireproofWebsiteDomain("mobile.example.com")
20782079
loadUrl("http://mobile.example.com/", isBrowserShowing = true)
20792080
testee.onFireproofWebsiteMenuClicked()
2080-
verify(mockPixel).fire(Pixel.PixelName.FIREPROOF_WEBSITE_REMOVE)
2081+
verify(mockPixel).fire(AppPixelName.FIREPROOF_WEBSITE_REMOVE)
20812082
}
20822083

20832084
@Test
@@ -2098,7 +2099,7 @@ class BrowserTabViewModelTest {
20982099
assertCommandIssued<Command.ShowFireproofWebSiteConfirmation> {
20992100
testee.onFireproofWebsiteSnackbarUndoClicked(this.fireproofWebsiteEntity)
21002101
}
2101-
verify(mockPixel).fire(Pixel.PixelName.FIREPROOF_WEBSITE_UNDO)
2102+
verify(mockPixel).fire(AppPixelName.FIREPROOF_WEBSITE_UNDO)
21022103
}
21032104

21042105
@Test
@@ -2313,7 +2314,7 @@ class BrowserTabViewModelTest {
23132314

23142315
testee.onViewReady()
23152316

2316-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED_AFTER_NOTIFICATION)
2317+
verify(mockPixel).fire(AppPixelName.UOA_VISITED_AFTER_NOTIFICATION)
23172318
}
23182319

23192320
@Test
@@ -2323,7 +2324,7 @@ class BrowserTabViewModelTest {
23232324

23242325
testee.onViewReady()
23252326

2326-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED_AFTER_SHORTCUT)
2327+
verify(mockPixel).fire(AppPixelName.UOA_VISITED_AFTER_SHORTCUT)
23272328
}
23282329

23292330
@Test
@@ -2333,7 +2334,7 @@ class BrowserTabViewModelTest {
23332334

23342335
testee.onViewReady()
23352336

2336-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED_AFTER_DELETE_CTA)
2337+
verify(mockPixel).fire(AppPixelName.UOA_VISITED_AFTER_DELETE_CTA)
23372338
}
23382339

23392340
@Test
@@ -2342,7 +2343,7 @@ class BrowserTabViewModelTest {
23422343

23432344
testee.onViewReady()
23442345

2345-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED)
2346+
verify(mockPixel).fire(AppPixelName.UOA_VISITED)
23462347
}
23472348

23482349
@Test
@@ -2352,7 +2353,7 @@ class BrowserTabViewModelTest {
23522353

23532354
testee.onViewReady()
23542355

2355-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED_AFTER_NOTIFICATION)
2356+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED_AFTER_NOTIFICATION)
23562357
}
23572358

23582359
@Test
@@ -2362,7 +2363,7 @@ class BrowserTabViewModelTest {
23622363

23632364
testee.onViewReady()
23642365

2365-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED_AFTER_SHORTCUT)
2366+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED_AFTER_SHORTCUT)
23662367
}
23672368

23682369
@Test
@@ -2372,7 +2373,7 @@ class BrowserTabViewModelTest {
23722373

23732374
testee.onViewReady()
23742375

2375-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED_AFTER_DELETE_CTA)
2376+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED_AFTER_DELETE_CTA)
23762377
}
23772378

23782379
@Test
@@ -2381,7 +2382,7 @@ class BrowserTabViewModelTest {
23812382

23822383
testee.onViewReady()
23832384

2384-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED)
2385+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED)
23852386
}
23862387

23872388
@Test
@@ -2391,7 +2392,7 @@ class BrowserTabViewModelTest {
23912392

23922393
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
23932394

2394-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED_AFTER_NOTIFICATION)
2395+
verify(mockPixel).fire(AppPixelName.UOA_VISITED_AFTER_NOTIFICATION)
23952396
}
23962397

23972398
@Test
@@ -2401,7 +2402,7 @@ class BrowserTabViewModelTest {
24012402

24022403
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
24032404

2404-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED_AFTER_SHORTCUT)
2405+
verify(mockPixel).fire(AppPixelName.UOA_VISITED_AFTER_SHORTCUT)
24052406
}
24062407

24072408
@Test
@@ -2411,7 +2412,7 @@ class BrowserTabViewModelTest {
24112412

24122413
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
24132414

2414-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED_AFTER_DELETE_CTA)
2415+
verify(mockPixel).fire(AppPixelName.UOA_VISITED_AFTER_DELETE_CTA)
24152416
}
24162417

24172418
@Test
@@ -2420,7 +2421,7 @@ class BrowserTabViewModelTest {
24202421

24212422
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
24222423

2423-
verify(mockPixel).fire(Pixel.PixelName.UOA_VISITED)
2424+
verify(mockPixel).fire(AppPixelName.UOA_VISITED)
24242425
}
24252426

24262427
@Test
@@ -2430,7 +2431,7 @@ class BrowserTabViewModelTest {
24302431

24312432
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
24322433

2433-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED_AFTER_NOTIFICATION)
2434+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED_AFTER_NOTIFICATION)
24342435
}
24352436

24362437
@Test
@@ -2441,7 +2442,7 @@ class BrowserTabViewModelTest {
24412442

24422443
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
24432444

2444-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED_AFTER_SHORTCUT)
2445+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED_AFTER_SHORTCUT)
24452446
}
24462447

24472448
@Test
@@ -2451,7 +2452,7 @@ class BrowserTabViewModelTest {
24512452

24522453
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
24532454

2454-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED_AFTER_DELETE_CTA)
2455+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED_AFTER_DELETE_CTA)
24552456
}
24562457

24572458
@Test
@@ -2460,7 +2461,7 @@ class BrowserTabViewModelTest {
24602461

24612462
loadUrl(USE_OUR_APP_DOMAIN, isBrowserShowing = true)
24622463

2463-
verify(mockPixel, never()).fire(Pixel.PixelName.UOA_VISITED)
2464+
verify(mockPixel, never()).fire(AppPixelName.UOA_VISITED)
24642465
}
24652466

24662467
@Test
@@ -2565,7 +2566,7 @@ class BrowserTabViewModelTest {
25652566

25662567
testee.onSystemLocationPermissionDeniedOneTime()
25672568

2568-
verify(mockPixel).fire(Pixel.PixelName.PRECISE_LOCATION_SETTINGS_LOCATION_PERMISSION_DISABLE)
2569+
verify(mockPixel).fire(AppPixelName.PRECISE_LOCATION_SETTINGS_LOCATION_PERMISSION_DISABLE)
25692570
verify(geoLocationPermissions).clear(domain)
25702571
}
25712572

@@ -2592,7 +2593,7 @@ class BrowserTabViewModelTest {
25922593

25932594
testee.onSystemLocationPermissionGranted()
25942595

2595-
verify(mockPixel).fire(Pixel.PixelName.PRECISE_LOCATION_SETTINGS_LOCATION_PERMISSION_ENABLE)
2596+
verify(mockPixel).fire(AppPixelName.PRECISE_LOCATION_SETTINGS_LOCATION_PERMISSION_ENABLE)
25962597
}
25972598

25982599
@Test
@@ -2674,7 +2675,7 @@ class BrowserTabViewModelTest {
26742675

26752676
testee.onSystemLocationPermissionNotAllowed()
26762677

2677-
verify(mockPixel).fire(Pixel.PixelName.PRECISE_LOCATION_SYSTEM_DIALOG_LATER)
2678+
verify(mockPixel).fire(AppPixelName.PRECISE_LOCATION_SYSTEM_DIALOG_LATER)
26782679
verify(geoLocationPermissions).clear(domain)
26792680
}
26802681

@@ -2688,7 +2689,7 @@ class BrowserTabViewModelTest {
26882689

26892690
testee.onSystemLocationPermissionNeverAllowed()
26902691

2691-
verify(mockPixel).fire(Pixel.PixelName.PRECISE_LOCATION_SYSTEM_DIALOG_NEVER)
2692+
verify(mockPixel).fire(AppPixelName.PRECISE_LOCATION_SYSTEM_DIALOG_NEVER)
26922693
verify(geoLocationPermissions).clear(domain)
26932694
assertEquals(locationPermissionsDao.getPermission(domain)!!.permission, LocationPermissionType.DENY_ALWAYS)
26942695
}

app/src/androidTest/java/com/duckduckgo/app/browser/BrowserViewModelTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.duckduckgo.app.global.rating.AppEnjoymentUserEventRecorder
3131
import com.duckduckgo.app.global.rating.PromptCount
3232
import com.duckduckgo.app.global.useourapp.UseOurAppDetector
3333
import com.duckduckgo.app.global.useourapp.UseOurAppDetector.Companion.USE_OUR_APP_DOMAIN
34+
import com.duckduckgo.app.pixels.AppPixelName
3435
import com.duckduckgo.app.privacy.ui.PrivacyDashboardActivity
3536
import com.duckduckgo.app.runBlocking
3637
import com.duckduckgo.app.statistics.pixels.Pixel
@@ -215,15 +216,15 @@ class BrowserViewModelTest {
215216
val url = "http://m.$USE_OUR_APP_DOMAIN"
216217
whenever(mockOmnibarEntryConverter.convertQueryToUrl(url)).thenReturn(url)
217218
testee.onOpenShortcut(url)
218-
verify(mockPixel).fire(Pixel.PixelName.USE_OUR_APP_SHORTCUT_OPENED)
219+
verify(mockPixel).fire(AppPixelName.USE_OUR_APP_SHORTCUT_OPENED)
219220
}
220221

221222
@Test
222223
fun whenOpenShortcutIfUrlIsNotUSeOurAppUrlThenFirePixel() {
223224
val url = "example.com"
224225
whenever(mockOmnibarEntryConverter.convertQueryToUrl(url)).thenReturn(url)
225226
testee.onOpenShortcut(url)
226-
verify(mockPixel).fire(Pixel.PixelName.SHORTCUT_OPENED)
227+
verify(mockPixel).fire(AppPixelName.SHORTCUT_OPENED)
227228
}
228229

229230
companion object {

app/src/androidTest/java/com/duckduckgo/app/browser/WebViewLongPressHandlerTest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.view.MenuItem
2121
import android.webkit.WebView.HitTestResult
2222
import androidx.test.platform.app.InstrumentationRegistry
2323
import com.duckduckgo.app.browser.model.LongPressTarget
24+
import com.duckduckgo.app.pixels.AppPixelName
2425
import com.duckduckgo.app.statistics.pixels.Pixel
2526
import com.nhaarman.mockitokotlin2.eq
2627
import com.nhaarman.mockitokotlin2.never
@@ -62,19 +63,19 @@ class WebViewLongPressHandlerTest {
6263
@Test
6364
fun whenUserLongPressesWithImageTypeThenPixelFired() {
6465
testee.handleLongPress(HitTestResult.IMAGE_TYPE, HTTPS_IMAGE_URL, mockMenu)
65-
verify(mockPixel).fire(Pixel.PixelName.LONG_PRESS)
66+
verify(mockPixel).fire(AppPixelName.LONG_PRESS)
6667
}
6768

6869
@Test
6970
fun whenUserLongPressesWithAnchorImageTypeThenPixelFired() {
7071
testee.handleLongPress(HitTestResult.SRC_IMAGE_ANCHOR_TYPE, HTTPS_IMAGE_URL, mockMenu)
71-
verify(mockPixel).fire(Pixel.PixelName.LONG_PRESS)
72+
verify(mockPixel).fire(AppPixelName.LONG_PRESS)
7273
}
7374

7475
@Test
7576
fun whenUserLongPressesWithUnknownTypeThenPixelNotFired() {
7677
testee.handleLongPress(HitTestResult.UNKNOWN_TYPE, HTTPS_IMAGE_URL, mockMenu)
77-
verify(mockPixel, never()).fire(Pixel.PixelName.LONG_PRESS)
78+
verify(mockPixel, never()).fire(AppPixelName.LONG_PRESS)
7879
}
7980

8081
@Test

app/src/androidTest/java/com/duckduckgo/app/browser/defaultbrowsing/DefaultBrowserObserverTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.duckduckgo.app.browser.defaultbrowsing
1818

1919
import com.duckduckgo.app.global.install.AppInstallStore
20+
import com.duckduckgo.app.pixels.AppPixelName
2021
import com.duckduckgo.app.statistics.pixels.Pixel
2122
import com.nhaarman.mockitokotlin2.*
2223
import org.junit.Before
@@ -53,7 +54,7 @@ class DefaultBrowserObserverTest {
5354

5455
testee.onApplicationResumed()
5556

56-
verify(mockPixel).fire(Pixel.PixelName.DEFAULT_BROWSER_SET, params)
57+
verify(mockPixel).fire(AppPixelName.DEFAULT_BROWSER_SET, params)
5758
}
5859

5960
@Test
@@ -63,7 +64,7 @@ class DefaultBrowserObserverTest {
6364

6465
testee.onApplicationResumed()
6566

66-
verify(mockPixel, never()).fire(eq(Pixel.PixelName.DEFAULT_BROWSER_SET), any(), any())
67+
verify(mockPixel, never()).fire(eq(AppPixelName.DEFAULT_BROWSER_SET), any(), any())
6768
}
6869

6970
@Test
@@ -73,7 +74,7 @@ class DefaultBrowserObserverTest {
7374

7475
testee.onApplicationResumed()
7576

76-
verify(mockPixel, never()).fire(eq(Pixel.PixelName.DEFAULT_BROWSER_SET), any(), any())
77+
verify(mockPixel, never()).fire(eq(AppPixelName.DEFAULT_BROWSER_SET), any(), any())
7778
}
7879

7980
@Test
@@ -83,6 +84,6 @@ class DefaultBrowserObserverTest {
8384

8485
testee.onApplicationResumed()
8586

86-
verify(mockPixel).fire(Pixel.PixelName.DEFAULT_BROWSER_UNSET)
87+
verify(mockPixel).fire(AppPixelName.DEFAULT_BROWSER_UNSET)
8788
}
8889
}

app/src/androidTest/java/com/duckduckgo/app/browser/downloader/UriUtilsFilenameExtractorTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.duckduckgo.app.browser.downloader
1818

19+
import com.duckduckgo.app.pixels.AppPixelName
1920
import com.duckduckgo.app.statistics.pixels.Pixel
2021
import com.nhaarman.mockitokotlin2.mock
2122
import com.nhaarman.mockitokotlin2.verify
@@ -159,7 +160,7 @@ class UriUtilsFilenameExtractorTest {
159160
val mimeType: String? = null
160161
val contentDisposition: String? = null
161162
val extracted = testee.extract(buildPendingDownload(url, contentDisposition, mimeType))
162-
verify(mockedPixel).fire(Pixel.PixelName.DOWNLOAD_FILE_DEFAULT_GUESSED_NAME)
163+
verify(mockedPixel).fire(AppPixelName.DOWNLOAD_FILE_DEFAULT_GUESSED_NAME)
163164
}
164165

165166
private fun buildPendingDownload(url: String, contentDisposition: String?, mimeType: String?): FileDownloader.PendingFileDownload {

0 commit comments

Comments
 (0)