Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2924,11 +2924,27 @@ class BrowserTabViewModelTest {
}

@Test
fun whenCloseCurrentTabSelectedThenTabDeletedFromRepository() =
fun whenCloseCurrentTabSelectedAndNotInCustomTabThenTabDeletedFromRepository() =
runTest {
testee.setIsCustomTab(false)
givenOneActiveTabSelected()
testee.closeCurrentTab()
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
verify(mockTabRepository).deleteTabAndSelectSource(selectedTabLiveData.value!!.tabId)
val command = commandCaptor.allValues.find { it is Command.NavigateBackInCustomTab }
assertNull(command)
}

@Test
fun whenCloseCurrentTabAndCustomTabAndCustomTabScreenEmitNavigateBackInCustomTabCommand() =
runTest {
testee.setIsCustomTab(true)
testee.closeCurrentTab()
verify(mockTabRepository, never()).deleteTabAndSelectSource(any())
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
val command = commandCaptor.allValues.find { it is Command.NavigateBackInCustomTab }
assertNotNull(command)
assertTrue(command is Command.NavigateBackInCustomTab)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,12 @@ class BrowserTabFragment :
browserActivity?.launchNewTab()
}

is Command.NavigateBackInCustomTab -> {
if (isActiveCustomTab() && parentFragmentManager.backStackEntryCount > 0) {
parentFragmentManager.popBackStack()
}
}

is Command.ShowSavedSiteAddedConfirmation -> savedSiteAdded(it.savedSiteChangedViewState)
is Command.ShowEditSavedSiteDialog -> editSavedSite(it.savedSiteChangedViewState)
is Command.DeleteFavoriteConfirmation ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,12 @@ class BrowserTabViewModel @Inject constructor(
}

override fun closeCurrentTab() {
viewModelScope.launch {
removeCurrentTabFromRepository()
if (isCustomTabScreen) {
command.value = Command.NavigateBackInCustomTab
} else {
viewModelScope.launch {
removeCurrentTabFromRepository()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ sealed class Command {
val query: String,
) : Command()

object NavigateBackInCustomTab : Command()

data object LaunchNewTab : Command()

data object ResetHistory : Command()
Expand Down
Loading