mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/16807 - Make sure there's only one instance of search dialog
This commit is contained in:
parent
0f3b3668db
commit
cbf04e3fb8
@ -6,8 +6,10 @@ package org.mozilla.fenix.home.intent
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.navOptions
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.NavGraphDirections
|
import org.mozilla.fenix.NavGraphDirections
|
||||||
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.components.metrics.MetricController
|
import org.mozilla.fenix.components.metrics.MetricController
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
@ -22,25 +24,25 @@ class StartSearchIntentProcessor(
|
|||||||
|
|
||||||
override fun process(intent: Intent, navController: NavController, out: Intent): Boolean {
|
override fun process(intent: Intent, navController: NavController, out: Intent): Boolean {
|
||||||
val event = intent.extras?.getString(HomeActivity.OPEN_TO_SEARCH)
|
val event = intent.extras?.getString(HomeActivity.OPEN_TO_SEARCH)
|
||||||
var source: Event.PerformedSearch.SearchAccessPoint? = null
|
|
||||||
return if (event != null) {
|
return if (event != null) {
|
||||||
when (event) {
|
val source = when (event) {
|
||||||
SEARCH_WIDGET -> {
|
SEARCH_WIDGET -> {
|
||||||
metrics.track(Event.SearchWidgetNewTabPressed)
|
metrics.track(Event.SearchWidgetNewTabPressed)
|
||||||
source = Event.PerformedSearch.SearchAccessPoint.WIDGET
|
Event.PerformedSearch.SearchAccessPoint.WIDGET
|
||||||
}
|
}
|
||||||
STATIC_SHORTCUT_NEW_TAB -> {
|
STATIC_SHORTCUT_NEW_TAB -> {
|
||||||
metrics.track(Event.PrivateBrowsingStaticShortcutTab)
|
metrics.track(Event.PrivateBrowsingStaticShortcutTab)
|
||||||
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
|
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
|
||||||
}
|
}
|
||||||
STATIC_SHORTCUT_NEW_PRIVATE_TAB -> {
|
STATIC_SHORTCUT_NEW_PRIVATE_TAB -> {
|
||||||
metrics.track(Event.PrivateBrowsingStaticShortcutPrivateTab)
|
metrics.track(Event.PrivateBrowsingStaticShortcutPrivateTab)
|
||||||
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
|
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
|
||||||
}
|
}
|
||||||
PRIVATE_BROWSING_PINNED_SHORTCUT -> {
|
PRIVATE_BROWSING_PINNED_SHORTCUT -> {
|
||||||
metrics.track(Event.PrivateBrowsingPinnedShortcutPrivateTab)
|
metrics.track(Event.PrivateBrowsingPinnedShortcutPrivateTab)
|
||||||
source = Event.PerformedSearch.SearchAccessPoint.SHORTCUT
|
Event.PerformedSearch.SearchAccessPoint.SHORTCUT
|
||||||
}
|
}
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
out.removeExtra(HomeActivity.OPEN_TO_SEARCH)
|
out.removeExtra(HomeActivity.OPEN_TO_SEARCH)
|
||||||
@ -51,7 +53,12 @@ class StartSearchIntentProcessor(
|
|||||||
searchAccessPoint = it
|
searchAccessPoint = it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
directions?.let { navController.nav(null, it) }
|
directions?.let {
|
||||||
|
val options = navOptions {
|
||||||
|
popUpTo = R.id.homeFragment
|
||||||
|
}
|
||||||
|
navController.nav(null, it, options)
|
||||||
|
}
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_global_search_dialog"
|
android:id="@+id/action_global_search_dialog"
|
||||||
app:destination="@id/searchDialogFragment" />
|
app:destination="@id/searchDialogFragment"
|
||||||
|
app:popUpTo="@id/searchDialogFragment"
|
||||||
|
app:popUpToInclusive="true"/>
|
||||||
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_global_recently_closed"
|
android:id="@+id/action_global_recently_closed"
|
||||||
@ -109,7 +111,9 @@
|
|||||||
app:destination="@id/quickSettingsSheetDialogFragment" />
|
app:destination="@id/quickSettingsSheetDialogFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_global_tabTrayDialogFragment"
|
android:id="@+id/action_global_tabTrayDialogFragment"
|
||||||
app:destination="@id/tabTrayDialogFragment" />
|
app:destination="@id/tabTrayDialogFragment"
|
||||||
|
app:popUpTo="@id/tabTrayDialogFragment"
|
||||||
|
app:popUpToInclusive="true"/>
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_global_savedLoginsAuthFragment"
|
android:id="@+id/action_global_savedLoginsAuthFragment"
|
||||||
app:destination="@id/savedLoginsAuthFragment" />
|
app:destination="@id/savedLoginsAuthFragment" />
|
||||||
@ -204,9 +208,6 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_trackingProtectionPanelDialogFragment"
|
android:id="@+id/action_browserFragment_to_trackingProtectionPanelDialogFragment"
|
||||||
app:destination="@id/trackingProtectionPanelDialogFragment" />
|
app:destination="@id/trackingProtectionPanelDialogFragment" />
|
||||||
<action
|
|
||||||
android:id="@+id/action_browserFragment_to_tabsTrayFragment"
|
|
||||||
app:destination="@+id/tabTrayFragment" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
|
@ -6,6 +6,7 @@ package org.mozilla.fenix.home.intent
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.navOptions
|
||||||
import io.mockk.Called
|
import io.mockk.Called
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
@ -13,8 +14,10 @@ import org.junit.Test
|
|||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.NavGraphDirections
|
import org.mozilla.fenix.NavGraphDirections
|
||||||
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.components.metrics.MetricController
|
import org.mozilla.fenix.components.metrics.MetricController
|
||||||
|
import org.mozilla.fenix.ext.nav
|
||||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||||
|
|
||||||
@RunWith(FenixRobolectricTestRunner::class)
|
@RunWith(FenixRobolectricTestRunner::class)
|
||||||
@ -51,15 +54,19 @@ class StartSearchIntentProcessorTest {
|
|||||||
putExtra(HomeActivity.OPEN_TO_SEARCH, StartSearchIntentProcessor.SEARCH_WIDGET)
|
putExtra(HomeActivity.OPEN_TO_SEARCH, StartSearchIntentProcessor.SEARCH_WIDGET)
|
||||||
}
|
}
|
||||||
StartSearchIntentProcessor(metrics).process(intent, navController, out)
|
StartSearchIntentProcessor(metrics).process(intent, navController, out)
|
||||||
|
val options = navOptions {
|
||||||
|
popUpTo = R.id.homeFragment
|
||||||
|
}
|
||||||
|
|
||||||
verify { metrics.track(Event.SearchWidgetNewTabPressed) }
|
verify { metrics.track(Event.SearchWidgetNewTabPressed) }
|
||||||
verify {
|
verify {
|
||||||
navController.navigate(
|
navController.nav(
|
||||||
|
null,
|
||||||
NavGraphDirections.actionGlobalSearchDialog(
|
NavGraphDirections.actionGlobalSearchDialog(
|
||||||
sessionId = null,
|
sessionId = null,
|
||||||
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.WIDGET
|
searchAccessPoint = Event.PerformedSearch.SearchAccessPoint.WIDGET
|
||||||
),
|
),
|
||||||
null
|
options
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
verify { out.removeExtra(HomeActivity.OPEN_TO_SEARCH) }
|
verify { out.removeExtra(HomeActivity.OPEN_TO_SEARCH) }
|
||||||
|
Loading…
Reference in New Issue
Block a user