For #16807 - Make sure there's only one instance of search dialog

upstream-sync
ekager 4 years ago
parent 813693f1d3
commit 1ca34a2bc9

@ -6,8 +6,10 @@ package org.mozilla.fenix.home.intent
import android.content.Intent
import androidx.navigation.NavController
import androidx.navigation.navOptions
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.nav
@ -22,25 +24,25 @@ class StartSearchIntentProcessor(
override fun process(intent: Intent, navController: NavController, out: Intent): Boolean {
val event = intent.extras?.getString(HomeActivity.OPEN_TO_SEARCH)
var source: Event.PerformedSearch.SearchAccessPoint? = null
return if (event != null) {
when (event) {
val source = when (event) {
SEARCH_WIDGET -> {
metrics.track(Event.SearchWidgetNewTabPressed)
source = Event.PerformedSearch.SearchAccessPoint.WIDGET
Event.PerformedSearch.SearchAccessPoint.WIDGET
}
STATIC_SHORTCUT_NEW_TAB -> {
metrics.track(Event.PrivateBrowsingStaticShortcutTab)
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
}
STATIC_SHORTCUT_NEW_PRIVATE_TAB -> {
metrics.track(Event.PrivateBrowsingStaticShortcutPrivateTab)
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
}
PRIVATE_BROWSING_PINNED_SHORTCUT -> {
metrics.track(Event.PrivateBrowsingPinnedShortcutPrivateTab)
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
}
else -> null
}
out.removeExtra(HomeActivity.OPEN_TO_SEARCH)
@ -51,7 +53,12 @@ class StartSearchIntentProcessor(
searchAccessPoint = it
)
}
directions?.let { navController.nav(null, it) }
directions?.let {
val options = navOptions {
popUpTo = R.id.homeFragment
}
navController.nav(null, it, options)
}
true
} else {
false

@ -25,7 +25,9 @@
<action
android:id="@+id/action_global_search_dialog"
app:destination="@id/searchDialogFragment" />
app:destination="@id/searchDialogFragment"
app:popUpTo="@id/searchDialogFragment"
app:popUpToInclusive="true"/>
<action
android:id="@+id/action_global_recently_closed"
@ -109,7 +111,9 @@
app:destination="@id/quickSettingsSheetDialogFragment" />
<action
android:id="@+id/action_global_tabTrayDialogFragment"
app:destination="@id/tabTrayDialogFragment" />
app:destination="@id/tabTrayDialogFragment"
app:popUpTo="@id/tabTrayDialogFragment"
app:popUpToInclusive="true"/>
<action
android:id="@+id/action_global_savedLoginsAuthFragment"
app:destination="@id/savedLoginsAuthFragment" />
@ -204,9 +208,6 @@
<action
android:id="@+id/action_browserFragment_to_trackingProtectionPanelDialogFragment"
app:destination="@id/trackingProtectionPanelDialogFragment" />
<action
android:id="@+id/action_browserFragment_to_tabsTrayFragment"
app:destination="@+id/tabTrayFragment" />
</fragment>
<fragment

@ -6,6 +6,7 @@ package org.mozilla.fenix.home.intent
import android.content.Intent
import androidx.navigation.NavController
import androidx.navigation.navOptions
import io.mockk.Called
import io.mockk.mockk
import io.mockk.verify
@ -13,8 +14,10 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
@ -51,15 +54,19 @@ class StartSearchIntentProcessorTest {
putExtra(HomeActivity.OPEN_TO_SEARCH, StartSearchIntentProcessor.SEARCH_WIDGET)
}
StartSearchIntentProcessor(metrics).process(intent, navController, out)
val options = navOptions {
popUpTo = R.id.homeFragment
}
verify { metrics.track(Event.SearchWidgetNewTabPressed) }
verify {
navController.navigate(
navController.nav(
null,
NavGraphDirections.actionGlobalSearchDialog(
sessionId = null,
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.WIDGET
),
null
options
)
}
verify { out.removeExtra(HomeActivity.OPEN_TO_SEARCH) }

Loading…
Cancel
Save