@@ -448,6 +448,8 @@ class BrowserTabViewModelTest {
448
448
449
449
private val mockDuckAiFeatureStateInputScreenFlow = MutableStateFlow (false )
450
450
451
+ private val mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow = MutableStateFlow (false )
452
+
451
453
private val mockAppBuildConfig: AppBuildConfig = mock()
452
454
453
455
private val mockDuckDuckGoUrlDetector: DuckDuckGoUrlDetector = mock()
@@ -645,6 +647,7 @@ class BrowserTabViewModelTest {
645
647
whenever(subscriptions.isEligible()).thenReturn(false )
646
648
whenever(mockDuckAiFeatureState.showPopupMenuShortcut).thenReturn(MutableStateFlow (false ))
647
649
whenever(mockDuckAiFeatureState.showInputScreen).thenReturn(mockDuckAiFeatureStateInputScreenFlow)
650
+ whenever(mockDuckAiFeatureState.showInputScreenAutomaticallyOnNewTab).thenReturn(mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow)
648
651
whenever(mockOnboardingDesignExperimentManager.isModifiedControlEnrolledAndEnabled()).thenReturn(false )
649
652
whenever(mockOnboardingDesignExperimentManager.isBuckEnrolledAndEnabled()).thenReturn(false )
650
653
whenever(mockOnboardingDesignExperimentManager.isBbEnrolledAndEnabled()).thenReturn(false )
@@ -6991,8 +6994,8 @@ class BrowserTabViewModelTest {
6991
6994
whenever(mockTabRepository.getTab(ntpTabId)).thenReturn(ntpTab)
6992
6995
flowSelectedTab.emit(initialTab)
6993
6996
6994
- testee.loadData(ntpTabId, null , false , false )
6995
- mockDuckAiFeatureStateInputScreenFlow .emit(true )
6997
+ testee.loadData(tabId = ntpTabId, initialUrl = null , skipHome = false , isExternal = false )
6998
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow .emit(true )
6996
6999
6997
7000
flowSelectedTab.emit(ntpTab)
6998
7001
@@ -7005,7 +7008,7 @@ class BrowserTabViewModelTest {
7005
7008
}
7006
7009
7007
7010
@Test
7008
- fun whenInputScreenDisabledAndSwitchToNewTabThenLaunchInputScreenCommandTriggered () = runTest {
7011
+ fun whenInputScreenDisabledAndSwitchToNewTabThenLaunchInputScreenCommandNotTriggered () = runTest {
7009
7012
val initialTabId = " initial-tab"
7010
7013
val initialTab = TabEntity (tabId = initialTabId, url = " https://example.com" , title = " EX" , skipHome = false , viewed = true , position = 0 )
7011
7014
val ntpTabId = " ntp-tab"
@@ -7014,8 +7017,8 @@ class BrowserTabViewModelTest {
7014
7017
whenever(mockTabRepository.getTab(ntpTabId)).thenReturn(ntpTab)
7015
7018
flowSelectedTab.emit(initialTab)
7016
7019
7017
- testee.loadData(ntpTabId, null , false , false )
7018
- mockDuckAiFeatureStateInputScreenFlow .emit(false )
7020
+ testee.loadData(tabId = ntpTabId, initialUrl = null , skipHome = false , isExternal = false )
7021
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow .emit(false )
7019
7022
7020
7023
flowSelectedTab.emit(ntpTab)
7021
7024
@@ -7037,8 +7040,8 @@ class BrowserTabViewModelTest {
7037
7040
whenever(mockTabRepository.getTab(targetTabId)).thenReturn(targetTab)
7038
7041
flowSelectedTab.emit(initialTab)
7039
7042
7040
- testee.loadData(targetTabId, null , false , false )
7041
- mockDuckAiFeatureStateInputScreenFlow .emit(true )
7043
+ testee.loadData(tabId = targetTabId, initialUrl = null , skipHome = false , isExternal = false )
7044
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow .emit(true )
7042
7045
7043
7046
flowSelectedTab.emit(targetTab)
7044
7047
@@ -7060,8 +7063,8 @@ class BrowserTabViewModelTest {
7060
7063
whenever(mockTabRepository.getTab(ntpTabId)).thenReturn(ntpTab)
7061
7064
flowSelectedTab.emit(initialTab)
7062
7065
7063
- testee.loadData(initialTabId, null , false , false )
7064
- mockDuckAiFeatureStateInputScreenFlow .emit(true )
7066
+ testee.loadData(tabId = initialTabId, initialUrl = null , skipHome = false , isExternal = false )
7067
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow .emit(true )
7065
7068
7066
7069
flowSelectedTab.emit(ntpTab)
7067
7070
@@ -7083,11 +7086,11 @@ class BrowserTabViewModelTest {
7083
7086
whenever(mockTabRepository.getTab(ntpTabId)).thenReturn(ntpTab)
7084
7087
flowSelectedTab.emit(initialTab)
7085
7088
7086
- testee.loadData(ntpTabId, null , false , false )
7087
- mockDuckAiFeatureStateInputScreenFlow .emit(false )
7089
+ testee.loadData(tabId = ntpTabId, initialUrl = null , skipHome = false , isExternal = false )
7090
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow .emit(false )
7088
7091
7089
7092
flowSelectedTab.emit(ntpTab)
7090
- mockDuckAiFeatureStateInputScreenFlow .emit(true )
7093
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow .emit(true )
7091
7094
7092
7095
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
7093
7096
val commands = commandCaptor.allValues
@@ -7097,6 +7100,53 @@ class BrowserTabViewModelTest {
7097
7100
)
7098
7101
}
7099
7102
7103
+ @Test
7104
+ fun whenInputScreenEnabledAndSwitchToNewTabOpenedFromAnotherTabThenLaunchInputScreenCommandNotTriggered () = runTest {
7105
+ val initialTabId = " initial-tab"
7106
+ val initialTab = TabEntity (tabId = initialTabId, url = " https://example.com" , title = " EX" , skipHome = false , viewed = true , position = 0 )
7107
+ val sourceTabId = " source-tab"
7108
+ val ntpTabId = " ntp-tab"
7109
+ val ntpTab = TabEntity (tabId = ntpTabId, url = null , title = " " , skipHome = false , viewed = true , position = 0 , sourceTabId = sourceTabId)
7110
+ whenever(mockTabRepository.getTab(initialTabId)).thenReturn(initialTab)
7111
+ whenever(mockTabRepository.getTab(ntpTabId)).thenReturn(ntpTab)
7112
+ flowSelectedTab.emit(initialTab)
7113
+
7114
+ testee.loadData(tabId = ntpTabId, initialUrl = null , skipHome = false , isExternal = false )
7115
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow.emit(true )
7116
+
7117
+ flowSelectedTab.emit(ntpTab)
7118
+
7119
+ verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
7120
+ val commands = commandCaptor.allValues
7121
+ assertFalse(
7122
+ " LaunchInputScreen command should NOT be triggered when switching to new tab that was opened from another tab" ,
7123
+ commands.any { it is Command .LaunchInputScreen },
7124
+ )
7125
+ }
7126
+
7127
+ @Test
7128
+ fun whenInputScreenEnabledAndSwitchToNewTabNotOpenedFromAnotherTabThenLaunchInputScreenCommandTriggered () = runTest {
7129
+ val initialTabId = " initial-tab"
7130
+ val initialTab = TabEntity (tabId = initialTabId, url = " https://example.com" , title = " EX" , skipHome = false , viewed = true , position = 0 )
7131
+ val ntpTabId = " ntp-tab"
7132
+ val ntpTab = TabEntity (tabId = ntpTabId, url = null , title = " " , skipHome = false , viewed = true , position = 0 , sourceTabId = null )
7133
+ whenever(mockTabRepository.getTab(initialTabId)).thenReturn(initialTab)
7134
+ whenever(mockTabRepository.getTab(ntpTabId)).thenReturn(ntpTab)
7135
+ flowSelectedTab.emit(initialTab)
7136
+
7137
+ testee.loadData(tabId = ntpTabId, initialUrl = null , skipHome = false , isExternal = false )
7138
+ mockDuckAiFeatureStateInputScreenOpenAutomaticallyFlow.emit(true )
7139
+
7140
+ flowSelectedTab.emit(ntpTab)
7141
+
7142
+ verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
7143
+ val commands = commandCaptor.allValues
7144
+ assertTrue(
7145
+ " LaunchInputScreen command should be triggered when switching to new tab that was NOT opened from another tab" ,
7146
+ commands.any { it is Command .LaunchInputScreen },
7147
+ )
7148
+ }
7149
+
7100
7150
private fun aCredential (): LoginCredentials {
7101
7151
return LoginCredentials (domain = null , username = null , password = null )
7102
7152
}
0 commit comments