[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/1000 - Remove isCustomTab flag (https://github.com/mozilla-mobile/fenix/pull/4656)
parent
0e376bb266
commit
efe2e2e466
@ -0,0 +1,57 @@
|
||||
/* 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.os.Bundle
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavDestination
|
||||
import io.sentry.Sentry
|
||||
import io.sentry.event.Breadcrumb
|
||||
import io.sentry.event.BreadcrumbBuilder
|
||||
import org.mozilla.fenix.components.isSentryEnabled
|
||||
|
||||
/**
|
||||
* Records breadcrumbs in Sentry when the fragment changes.
|
||||
*
|
||||
* Should be registered as a [LifecycleObserver] on an activity if telemetry is enabled.
|
||||
* It will automatically be removed when the lifecycle owner is destroyed.
|
||||
*/
|
||||
class SentryBreadcrumbsRecorder(
|
||||
private val navController: NavController,
|
||||
private val getBreadcrumbMessage: (NavDestination) -> String
|
||||
) : NavController.OnDestinationChangedListener, LifecycleObserver {
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
||||
fun onCreate() {
|
||||
if (isSentryEnabled()) {
|
||||
navController.addOnDestinationChangedListener(this)
|
||||
}
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
fun onDestroy() {
|
||||
navController.removeOnDestinationChangedListener(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* When the destination changes, record the new destination as a breadcrumb.
|
||||
*/
|
||||
override fun onDestinationChanged(
|
||||
controller: NavController,
|
||||
destination: NavDestination,
|
||||
arguments: Bundle?
|
||||
) {
|
||||
Sentry.getContext().recordBreadcrumb(
|
||||
BreadcrumbBuilder()
|
||||
.setCategory("DestinationChanged")
|
||||
.setMessage(getBreadcrumbMessage(destination))
|
||||
.setLevel(Breadcrumb.Level.INFO)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
@ -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
|
||||
|
||||
import android.content.Intent
|
||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||
import mozilla.components.support.utils.toSafeIntent
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@ObsoleteCoroutinesApi
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(application = TestApplication::class)
|
||||
class HomeActivityTest {
|
||||
|
||||
@Test
|
||||
fun getIntentSource() {
|
||||
val activity = HomeActivity()
|
||||
|
||||
val launcherIntent = Intent(Intent.ACTION_MAIN).apply {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}.toSafeIntent()
|
||||
assertEquals(Event.OpenedApp.Source.APP_ICON, activity.getIntentSource(launcherIntent))
|
||||
|
||||
val viewIntent = Intent(Intent.ACTION_VIEW).toSafeIntent()
|
||||
assertEquals(Event.OpenedApp.Source.LINK, activity.getIntentSource(viewIntent))
|
||||
|
||||
val otherIntent = Intent().toSafeIntent()
|
||||
assertNull(activity.getIntentSource(otherIntent))
|
||||
}
|
||||
}
|
@ -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.customtabs
|
||||
|
||||
import android.content.Intent
|
||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||
import mozilla.components.support.utils.toSafeIntent
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.TestApplication
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@ObsoleteCoroutinesApi
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(application = TestApplication::class)
|
||||
class CustomTabActivityTest {
|
||||
|
||||
@Test
|
||||
fun getIntentSource() {
|
||||
val activity = CustomTabActivity()
|
||||
|
||||
val launcherIntent = Intent(Intent.ACTION_MAIN).apply {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}.toSafeIntent()
|
||||
assertEquals(Event.OpenedApp.Source.CUSTOM_TAB, activity.getIntentSource(launcherIntent))
|
||||
|
||||
val viewIntent = Intent(Intent.ACTION_VIEW).toSafeIntent()
|
||||
assertEquals(Event.OpenedApp.Source.CUSTOM_TAB, activity.getIntentSource(viewIntent))
|
||||
|
||||
val otherIntent = Intent().toSafeIntent()
|
||||
assertEquals(Event.OpenedApp.Source.CUSTOM_TAB, activity.getIntentSource(otherIntent))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue