Skip to content

Commit

Permalink
For mozilla-mobile#24210: Remove wrapper from uri opened count.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed Mar 31, 2022
1 parent cd0cb4a commit ad126d7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ sealed class Event {
object CustomTabsClosed : Event()
object CustomTabsActionTapped : Event()
object CustomTabsMenuOpened : Event()
object NormalAndPrivateUriOpened : Event()
object SyncAuthOpened : Event()
object SyncAuthClosed : Event()
object SyncAuthSignUp : Event()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ private val Event.wrapper: EventWrapper<*>?
is Event.CustomTabsClosed -> EventWrapper<NoExtraKeys>(
{ CustomTab.closed.record(it) }
)
is Event.NormalAndPrivateUriOpened -> EventWrapper<NoExtraKeys>(
{ Events.normalAndPrivateUriCount.add(1) }
)
is Event.SyncAuthOpened -> EventWrapper<NoExtraKeys>(
{ SyncAuth.opened.record(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import mozilla.components.lib.state.Middleware
import mozilla.components.lib.state.MiddlewareContext
import mozilla.components.support.base.android.Clock
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.utils.Settings
Expand Down Expand Up @@ -51,7 +52,7 @@ class TelemetryMiddleware(
context.state.findTab(action.sessionId)?.let { tab ->
// Record UriOpened event when a non-private page finishes loading
if (tab.content.loading && !action.loading) {
metrics.track(Event.NormalAndPrivateUriOpened)
Events.normalAndPrivateUriCount.add()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
Expand Down Expand Up @@ -183,23 +184,30 @@ class TelemetryMiddlewareTest {
@Test
fun `GIVEN a normal page is loading WHEN loading is complete THEN we record a UriOpened event`() {
val tab = createTab(id = "1", url = "https://mozilla.org")
assertFalse(Events.normalAndPrivateUriCount.testHasValue())

store.dispatch(TabListAction.AddTabAction(tab)).joinBlocking()
store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, true)).joinBlocking()
verify(exactly = 0) { metrics.track(Event.NormalAndPrivateUriOpened) }
assertFalse(Events.normalAndPrivateUriCount.testHasValue())

store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, false)).joinBlocking()
verify(exactly = 1) { metrics.track(Event.NormalAndPrivateUriOpened) }
assertTrue(Events.normalAndPrivateUriCount.testHasValue())
val count = Events.normalAndPrivateUriCount.testGetValue()
assertEquals(1, count)
}

@Test
fun `GIVEN a private page is loading WHEN loading is complete THEN we record a UriOpened event`() {
val tab = createTab(id = "1", url = "https://mozilla.org", private = true)
assertFalse(Events.normalAndPrivateUriCount.testHasValue())

store.dispatch(TabListAction.AddTabAction(tab)).joinBlocking()
store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, true)).joinBlocking()
verify(exactly = 0) { metrics.track(Event.NormalAndPrivateUriOpened) }
assertFalse(Events.normalAndPrivateUriCount.testHasValue())

store.dispatch(ContentAction.UpdateLoadingStateAction(tab.id, false)).joinBlocking()
verify(exactly = 1) { metrics.track(Event.NormalAndPrivateUriOpened) }
val count = Events.normalAndPrivateUriCount.testGetValue()
assertEquals(1, count)
}

@Test
Expand Down

0 comments on commit ad126d7

Please sign in to comment.