diff --git a/fenix/app/src/main/java/org/mozilla/fenix/browser/tabstrip/TabStripState.kt b/fenix/app/src/main/java/org/mozilla/fenix/browser/tabstrip/TabStripState.kt index 5dacf2b4a4cc..f9bb1afb07da 100644 --- a/fenix/app/src/main/java/org/mozilla/fenix/browser/tabstrip/TabStripState.kt +++ b/fenix/app/src/main/java/org/mozilla/fenix/browser/tabstrip/TabStripState.kt @@ -5,6 +5,7 @@ package org.mozilla.fenix.browser.tabstrip import mozilla.components.browser.state.selector.getNormalOrPrivateTabs +import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.state.state.BrowserState /** @@ -41,23 +42,22 @@ data class TabStripItem( * Converts [BrowserState] to [TabStripState] that contains the information needed to render the * tabs strip. * - * @param isSelectDisabled When true, the tabs will show as selected. + * @param isSelectDisabled When true, the tabs will show as unselected. * @param isPrivateMode Whether or not the browser is in private mode. */ internal fun BrowserState.toTabStripState( isSelectDisabled: Boolean, isPrivateMode: Boolean, -): TabStripState { - return TabStripState( - tabs = getNormalOrPrivateTabs(isPrivateMode) - .map { - TabStripItem( - id = it.id, - title = it.content.title.ifBlank { it.content.url }, - url = it.content.url, - isPrivate = it.content.private, - isSelected = !isSelectDisabled && it.id == selectedTabId, - ) - }, - ) -} +): TabStripState = TabStripState( + tabs = getNormalOrPrivateTabs( + private = isPrivateMode || (!isSelectDisabled && selectedTab?.content?.private == true), + ).map { + TabStripItem( + id = it.id, + title = it.content.title.ifBlank { it.content.url }, + url = it.content.url, + isPrivate = it.content.private, + isSelected = !isSelectDisabled && it.id == selectedTabId, + ) + }, +) diff --git a/fenix/app/src/test/java/org/mozilla/fenix/browser/tabstrip/TabStripStateTest.kt b/fenix/app/src/test/java/org/mozilla/fenix/browser/tabstrip/TabStripStateTest.kt index e6c98b0eff22..b343728dc262 100644 --- a/fenix/app/src/test/java/org/mozilla/fenix/browser/tabstrip/TabStripStateTest.kt +++ b/fenix/app/src/test/java/org/mozilla/fenix/browser/tabstrip/TabStripStateTest.kt @@ -156,6 +156,55 @@ class TabStripStateTest { assertEquals(expected, actual) } + @Test + fun `WHEN isSelectDisabled is false and selected tab is private THEN tabs strip state tabs should have private tabs including the selected tab`() { + val browserState = BrowserState( + tabs = listOf( + createTab( + url = "https://example.com", + title = "Example 1", + private = false, + id = "1", + ), + createTab( + url = "https://example2.com", + title = "Example 2", + private = true, + id = "2", + ), + createTab( + url = "https://example3.com", + title = "Example 3", + private = true, + id = "3", + ), + ), + selectedTabId = "2", + ) + val actual = browserState.toTabStripState(isSelectDisabled = false, isPrivateMode = false) + + val expected = TabStripState( + tabs = listOf( + TabStripItem( + id = "2", + title = "Example 2", + url = "https://example2.com", + isSelected = true, + isPrivate = true, + ), + TabStripItem( + id = "3", + title = "Example 3", + url = "https://example3.com", + isSelected = false, + isPrivate = true, + ), + ), + ) + + assertEquals(expected, actual) + } + @Test fun `WHEN isSelectDisabled is true THEN tabs strip state tabs should not have a selected tab`() { val browserState = BrowserState(