From 2f7edfe924d69430357264b3e5ea69edc7df74f5 Mon Sep 17 00:00:00 2001 From: ekager Date: Fri, 18 Sep 2020 22:34:47 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/15121 - Ensure tabs removed while on browser select an available parent session --- .../java/org/mozilla/fenix/browser/BaseBrowserFragment.kt | 7 ++++++- .../fenix/components/toolbar/BrowserToolbarController.kt | 4 +++- .../toolbar/DefaultBrowserToolbarControllerTest.kt | 7 +------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 4b662e4b18..cff3b5a4d1 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -940,7 +940,12 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session true } else { if (session.hasParentSession) { - requireComponents.useCases.tabsUseCases.removeTab(session) + // The removeTab use case does not currently select a parent session, so + // we are using sessionManager.remove + requireComponents.core.sessionManager.remove( + session, + selectParentIfExists = true + ) } // We want to return to home if this session didn't have a parent session to select. val goToOverview = !session.hasParentSession diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt index 5b70eae286..56d2c37119 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt @@ -145,7 +145,9 @@ class DefaultBrowserToolbarController( ) } else { onCloseTab.invoke(it) - activity.components.useCases.tabsUseCases.removeTab.invoke(it) + // The removeTab use case does not currently select a parent session, so + // we are using sessionManager.remove + sessionManager.remove(it, selectParentIfExists = true) } } } diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt index 124cf312aa..4bd1274190 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt @@ -21,7 +21,6 @@ import mozilla.components.browser.session.SessionManager import mozilla.components.concept.engine.EngineView import mozilla.components.feature.search.SearchUseCases import mozilla.components.feature.session.SessionUseCases -import mozilla.components.feature.tabs.TabsUseCases import mozilla.components.feature.top.sites.TopSitesUseCases import org.junit.Assert.assertEquals import org.junit.Before @@ -200,17 +199,13 @@ class DefaultBrowserToolbarControllerTest { @Test fun handleToolbarCloseTabPress() { - val tabsUseCases: TabsUseCases = mockk(relaxed = true) - val removeTabUseCase: TabsUseCases.RemoveTabUseCase = mockk(relaxed = true) val item = TabCounterMenu.Item.CloseTab every { sessionManager.sessions } returns emptyList() - every { activity.components.useCases.tabsUseCases } returns tabsUseCases - every { tabsUseCases.removeTab } returns removeTabUseCase val controller = createController() controller.handleTabCounterItemInteraction(item) - verify { removeTabUseCase.invoke(currentSession) } + verify { sessionManager.remove(currentSession, selectParentIfExists = true) } } @Test