Commit e240de7e authored by Sawyer Blatz's avatar Sawyer Blatz Committed by Emily Kager
Browse files

For #4908: Adds telemetry for send tab

parent d0ef2d40
......@@ -242,6 +242,12 @@ private val Event.wrapper: EventWrapper<*>?
is Event.SyncAccountSyncNow -> EventWrapper<NoExtraKeys>(
{ SyncAccount.syncNow.record(it) }
)
is Event.SignInToSendTab -> EventWrapper<NoExtraKeys>(
{ SyncAccount.signInToSendTab.record(it) }
)
is Event.SendTab -> EventWrapper<NoExtraKeys>(
{ SyncAccount.sendTab.record(it) }
)
is Event.PreferenceToggled -> EventWrapper(
{ Events.preferenceToggled.record(it) },
{ Events.preferenceToggledKeys.valueOf(it) }
......
......@@ -71,6 +71,8 @@ sealed class Event {
object SyncAccountOpened : Event()
object SyncAccountClosed : Event()
object SyncAccountSyncNow : Event()
object SendTab : Event()
object SignInToSendTab : Event()
object HistoryOpened : Event()
object HistoryItemShared : Event()
object HistoryItemOpened : Event()
......
......@@ -4,6 +4,7 @@
package org.mozilla.fenix.share
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_SEND
import android.content.Intent.EXTRA_TEXT
......@@ -16,6 +17,8 @@ import mozilla.components.concept.sync.Device
import mozilla.components.concept.sync.TabData
import mozilla.components.feature.sendtab.SendTabUseCases
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.share.listadapters.AppShareOption
......@@ -43,6 +46,7 @@ interface ShareController {
* @param dismiss - callback signalling sharing can be closed.
*/
class DefaultShareController(
private val context: Context,
private val fragment: Fragment,
private val sharedTabs: List<ShareTab>,
private val sendTabUseCases: SendTabUseCases,
......@@ -73,6 +77,7 @@ class DefaultShareController(
}
override fun handleShareToDevice(device: Device) {
context.metrics.track(Event.SendTab)
sendTabUseCases.sendToDeviceAsync(device.id, sharedTabs.toTabData())
(fragment.activity as ShareFragment.TabsSharedCallback).onTabsShared(sharedTabs.size)
dismiss()
......@@ -85,6 +90,7 @@ class DefaultShareController(
}
override fun handleSignIn() {
context.metrics.track(Event.SignInToSendTab)
val directions = ShareFragmentDirections.actionShareFragmentToTurnOnSyncFragment()
navController.nav(R.id.shareFragment, directions)
dismiss()
......
......@@ -86,6 +86,7 @@ class ShareFragment : AppCompatDialogFragment() {
shareInteractor = ShareInteractor(
DefaultShareController(
context = requireContext(),
fragment = this,
sharedTabs = tabs,
navController = findNavController(),
......
......@@ -4,6 +4,7 @@
package org.mozilla.fenix.share
import android.content.Context
import android.content.Intent
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
......@@ -24,11 +25,15 @@ import mozilla.components.concept.sync.Device
import mozilla.components.concept.sync.DeviceType
import mozilla.components.concept.sync.TabData
import mozilla.components.feature.sendtab.SendTabUseCases
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.TestApplication
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.share.listadapters.AppShareOption
import org.robolectric.RobolectricTestRunner
......@@ -38,6 +43,8 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class ShareControllerTest {
private val context: Context = mockk(relaxed = true)
private val metrics: MetricController = mockk(relaxed = true)
private val fragment = mockk<Fragment>(relaxed = true)
private val shareTabs = listOf(
ShareTab("url0", "title0"),
......@@ -52,7 +59,12 @@ class ShareControllerTest {
private val sendTabUseCases = mockk<SendTabUseCases>(relaxed = true)
private val navController = mockk<NavController>(relaxed = true)
private val dismiss = mockk<() -> Unit>(relaxed = true)
private val controller = DefaultShareController(fragment, shareTabs, sendTabUseCases, navController, dismiss)
private val controller = DefaultShareController(context, fragment, shareTabs, sendTabUseCases, navController, dismiss)
@Before
fun setUp() {
every { context.metrics } returns metrics
}
@Test
fun `handleShareClosed should call a passed in delegate to close this`() {
......@@ -102,6 +114,7 @@ class ShareControllerTest {
// Verify all the needed methods are called.
verifyOrder {
metrics.track(Event.SendTab)
sendTabUseCases.sendToDeviceAsync(capture(deviceId), capture(tabsShared))
tabSharedCallbackActivity.onTabsShared(capture(sharedTabsNumber))
dismiss()
......@@ -153,6 +166,7 @@ class ShareControllerTest {
controller.handleSignIn()
verifyOrder {
metrics.track(Event.SignInToSendTab)
navController.nav(
R.id.shareFragment,
ShareFragmentDirections.actionShareFragmentToTurnOnSyncFragment()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment