From a1541a337559b639d8b215bde1691f64f8e0dfcd Mon Sep 17 00:00:00 2001 From: Christian Sadilek Date: Tue, 9 Feb 2021 17:53:17 -0500 Subject: [PATCH] Closes #17889: Wrong tab selected/reloaded when restored from collection --- .../SessionControlController.kt | 6 +-- .../DefaultSessionControlControllerTest.kt | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt index 88f46fdac1..a181d1f698 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlController.kt @@ -215,10 +215,8 @@ class DefaultSessionControlController( tab, onTabRestored = { activity.openToBrowser(BrowserDirection.FromHome) - store.state.selectedTabId?.let { - selectTabUseCase.invoke(it) - reloadUrlUseCase.invoke(it) - } + selectTabUseCase.invoke(it) + reloadUrlUseCase.invoke(it) }, onFailure = { activity.openToBrowserAndLoad( diff --git a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt index 8b45154f64..16275ed792 100644 --- a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt @@ -182,8 +182,8 @@ class DefaultSessionControlControllerTest { } @Test - fun `handleCollectionOpenTabClicked onTabRestored`() { - val restoredTab = RecoverableTab( + fun `handleCollectionOpenTabClicked with existing selected tab`() { + val recoverableTab = RecoverableTab( id = "test", parentId = null, url = "https://www.mozilla.org", @@ -196,13 +196,42 @@ class DefaultSessionControlControllerTest { ) val tab = mockk { - every { restore(activity, engine, restoreSessionId = false) } returns restoredTab + every { restore(activity, engine, restoreSessionId = false) } returns recoverableTab } - store.dispatch(TabListAction.AddTabAction( - createTab(id = restoredTab.id, url = restoredTab.url)) - ).joinBlocking() - store.dispatch(TabListAction.SelectTabAction(restoredTab.id)).joinBlocking() + val restoredTab = createTab(id = recoverableTab.id, url = recoverableTab.url) + val otherTab = createTab(id = "otherTab", url = "https://mozilla.org") + store.dispatch(TabListAction.AddTabAction(otherTab)).joinBlocking() + store.dispatch(TabListAction.SelectTabAction(otherTab.id)).joinBlocking() + store.dispatch(TabListAction.AddTabAction(restoredTab)).joinBlocking() + + controller.handleCollectionOpenTabClicked(tab) + verify { metrics.track(Event.CollectionTabRestored) } + verify { activity.openToBrowser(BrowserDirection.FromHome) } + verify { selectTabUseCase.selectTab.invoke(restoredTab.id) } + verify { reloadUrlUseCase.reload.invoke(restoredTab.id) } + } + + @Test + fun `handleCollectionOpenTabClicked without existing selected tab`() { + val recoverableTab = RecoverableTab( + id = "test", + parentId = null, + url = "https://www.mozilla.org", + title = "Mozilla", + state = null, + contextId = null, + readerState = ReaderState(), + lastAccess = 0, + private = false + ) + + val tab = mockk { + every { restore(activity, engine, restoreSessionId = false) } returns recoverableTab + } + + val restoredTab = createTab(id = recoverableTab.id, url = recoverableTab.url) + store.dispatch(TabListAction.AddTabAction(restoredTab)).joinBlocking() controller.handleCollectionOpenTabClicked(tab) verify { metrics.track(Event.CollectionTabRestored) }