This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #6556: Adds Telemetry counts for Search Access Points
Added two new sources to be counted ('widget' and 'shortcut') besides 'action' and 'suggestion'. Also modified/fixed some tests.
- Loading branch information
1 parent
dd14337
commit 791c566
Showing
16 changed files
with
226 additions
and
49 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
38 changes: 38 additions & 0 deletions
38
app/src/main/java/org/mozilla/fenix/components/metrics/MetricsUtils.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,38 @@ | ||
/* 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 org.mozilla.fenix.components.metrics | ||
|
||
import android.content.Context | ||
import mozilla.components.browser.search.SearchEngine | ||
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.ACTION | ||
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.NONE | ||
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.SHORTCUT | ||
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.SUGGESTION | ||
import org.mozilla.fenix.components.metrics.Event.PerformedSearch.SearchAccessPoint.WIDGET | ||
import org.mozilla.fenix.components.searchengine.CustomSearchEngineStore | ||
import org.mozilla.fenix.ext.searchEngineManager | ||
|
||
object MetricsUtils { | ||
fun createSearchEvent( | ||
engine: SearchEngine, | ||
context: Context, | ||
searchAccessPoint: Event.PerformedSearch.SearchAccessPoint | ||
): Event.PerformedSearch? { | ||
val isShortcut = engine != context.searchEngineManager.defaultSearchEngine | ||
val isCustom = CustomSearchEngineStore.isCustomSearchEngine(context, engine.identifier) | ||
|
||
val engineSource = | ||
if (isShortcut) Event.PerformedSearch.EngineSource.Shortcut(engine, isCustom) | ||
else Event.PerformedSearch.EngineSource.Default(engine, isCustom) | ||
|
||
return when (searchAccessPoint) { | ||
SUGGESTION -> Event.PerformedSearch(Event.PerformedSearch.EventSource.Suggestion(engineSource)) | ||
ACTION -> Event.PerformedSearch(Event.PerformedSearch.EventSource.Action(engineSource)) | ||
WIDGET -> Event.PerformedSearch(Event.PerformedSearch.EventSource.Widget(engineSource)) | ||
SHORTCUT -> Event.PerformedSearch(Event.PerformedSearch.EventSource.Shortcut(engineSource)) | ||
NONE -> null | ||
} | ||
} | ||
} |
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
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
62 changes: 62 additions & 0 deletions
62
app/src/test/java/org/mozilla/fenix/components/metrics/MetricsUtilsTest.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,62 @@ | ||
package org.mozilla.fenix.components.metrics | ||
|
||
import io.mockk.every | ||
import io.mockk.mockk | ||
import mozilla.components.browser.search.SearchEngine | ||
import mozilla.components.support.test.robolectric.testContext | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.TestApplication | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(application = TestApplication::class) | ||
class MetricsUtilsTest { | ||
|
||
@Test | ||
fun createSearchEvent() { | ||
val engine: SearchEngine = mockk(relaxed = true) | ||
val context = testContext | ||
|
||
every { engine.identifier } returns ENGINE_SOURCE_IDENTIFIER | ||
|
||
assertEquals( | ||
"$ENGINE_SOURCE_IDENTIFIER.suggestion", | ||
MetricsUtils.createSearchEvent( | ||
engine, | ||
context, | ||
Event.PerformedSearch.SearchAccessPoint.SUGGESTION | ||
)?.eventSource?.countLabel | ||
) | ||
assertEquals( | ||
"$ENGINE_SOURCE_IDENTIFIER.action", | ||
MetricsUtils.createSearchEvent( | ||
engine, | ||
context, | ||
Event.PerformedSearch.SearchAccessPoint.ACTION | ||
)?.eventSource?.countLabel | ||
) | ||
assertEquals( | ||
"$ENGINE_SOURCE_IDENTIFIER.widget", | ||
MetricsUtils.createSearchEvent( | ||
engine, | ||
context, | ||
Event.PerformedSearch.SearchAccessPoint.WIDGET | ||
)?.eventSource?.countLabel | ||
) | ||
assertEquals( | ||
"$ENGINE_SOURCE_IDENTIFIER.shortcut", | ||
MetricsUtils.createSearchEvent( | ||
engine, | ||
context, | ||
Event.PerformedSearch.SearchAccessPoint.SHORTCUT | ||
)?.eventSource?.countLabel | ||
) | ||
} | ||
|
||
companion object { | ||
const val ENGINE_SOURCE_IDENTIFIER = "google-2018" | ||
} | ||
} |
Oops, something went wrong.