@ -18,6 +18,7 @@ import io.mockk.spyk
import io.mockk.unmockkObject
import io.mockk.verify
import kotlinx.coroutines.test.runTest
import mozilla.components.browser.state.action.AwesomeBarAction
import mozilla.components.browser.state.action.BrowserAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.search.SearchEngine
@ -112,6 +113,8 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( url )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = url ,
@ -124,6 +127,10 @@ class SearchDialogControllerTest {
)
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
assertNotNull ( Events . enteredUrl . testGetValue ( ) )
val snapshot = Events . enteredUrl . testGetValue ( ) !!
assertEquals ( 1 , snapshot . size )
@ -139,6 +146,8 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( url )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = url ,
@ -151,6 +160,10 @@ class SearchDialogControllerTest {
)
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
assertNotNull ( Events . enteredUrl . testGetValue ( ) )
val snapshot = Events . enteredUrl . testGetValue ( ) !!
assertEquals ( 1 , snapshot . size )
@ -168,6 +181,8 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( searchTerm )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = searchTerm ,
@ -181,6 +196,10 @@ class SearchDialogControllerTest {
) ,
)
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -194,6 +213,8 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( searchTerm )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = searchTerm ,
@ -207,6 +228,10 @@ class SearchDialogControllerTest {
) ,
)
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -220,7 +245,13 @@ class SearchDialogControllerTest {
} ,
) . handleUrlCommitted ( url )
browserStore . waitUntilIdle ( )
assertTrue ( dismissDialogInvoked )
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertTrue ( action . abandoned )
}
}
@Test
@ -229,6 +260,8 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( searchTerm )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = searchTerm ,
@ -240,6 +273,10 @@ class SearchDialogControllerTest {
additionalHeaders = null ,
)
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -255,6 +292,8 @@ class SearchDialogControllerTest {
} ,
) . handleUrlCommitted ( searchTerm )
browserStore . waitUntilIdle ( )
verify ( exactly = 0 ) {
activity . openToBrowserAndLoad (
searchTermOrURL = any ( ) ,
@ -265,6 +304,8 @@ class SearchDialogControllerTest {
}
assertFalse ( dismissDialogInvoked )
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -274,9 +315,15 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( url )
browserStore . waitUntilIdle ( )
verify {
activity . startActivity ( any ( ) )
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -286,7 +333,13 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( url )
browserStore . waitUntilIdle ( )
verify { navController . navigate ( directions ) }
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -298,6 +351,8 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlCommitted ( url )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = SupportUtils . getMozillaPageUrl ( SupportUtils . MozillaPage . MANIFESTO ) ,
@ -309,6 +364,10 @@ class SearchDialogControllerTest {
)
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
assertNotNull ( Events . enteredUrl . testGetValue ( ) )
val snapshot = Events . enteredUrl . testGetValue ( ) !!
assertEquals ( 1 , snapshot . size )
@ -338,7 +397,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . UpdateQuery ( text ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -347,7 +410,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . UpdateQuery ( text ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -357,7 +424,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( true ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -368,7 +439,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( true ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -379,7 +454,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( false ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -391,7 +470,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( false ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -400,7 +483,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( false ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -411,7 +498,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( false ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -422,7 +513,11 @@ class SearchDialogControllerTest {
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( false ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -432,9 +527,14 @@ class SearchDialogControllerTest {
val text = " mozilla "
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
val actionSlot = mutableListOf < SearchFragmentAction > ( )
verify { store . dispatch ( capture ( actionSlot ) ) }
assertFalse ( actionSlot . any { it is SearchFragmentAction . AllowSearchSuggestionsInPrivateModePrompt } )
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -444,9 +544,14 @@ class SearchDialogControllerTest {
val text = " mozilla "
createController ( ) . handleTextChanged ( text )
browserStore . waitUntilIdle ( )
val actionSlot = mutableListOf < SearchFragmentAction > ( )
verify { store . dispatch ( capture ( actionSlot ) ) }
assertTrue ( actionSlot . any { it is SearchFragmentAction . AllowSearchSuggestionsInPrivateModePrompt } )
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -458,6 +563,8 @@ class SearchDialogControllerTest {
createController ( ) . handleUrlTapped ( url , flags )
createController ( ) . handleUrlTapped ( url )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = url ,
@ -472,6 +579,10 @@ class SearchDialogControllerTest {
assertEquals ( 2 , snapshot . size )
assertEquals ( " false " , snapshot . first ( ) . extra ?. getValue ( " autocomplete " ) )
assertEquals ( " false " , snapshot [ 1 ] . extra ?. getValue ( " autocomplete " ) )
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -480,6 +591,8 @@ class SearchDialogControllerTest {
createController ( ) . handleSearchTermsTapped ( searchTerms )
browserStore . waitUntilIdle ( )
verify {
activity . openToBrowserAndLoad (
searchTermOrURL = searchTerms ,
@ -491,6 +604,10 @@ class SearchDialogControllerTest {
additionalHeaders = null ,
)
}
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -506,9 +623,13 @@ class SearchDialogControllerTest {
} ,
) . handleSearchShortcutEngineSelected ( searchEngine )
browserStore . waitUntilIdle ( )
assertTrue ( focusToolbarInvoked )
verify { store . dispatch ( SearchFragmentAction . SearchShortcutEngineSelected ( searchEngine , browsingMode , settings ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
assertNotNull ( SearchShortcuts . selected . testGetValue ( ) )
val recordedEvents = SearchShortcuts . selected . testGetValue ( ) !!
assertEquals ( 1 , recordedEvents . size )
@ -534,9 +655,13 @@ class SearchDialogControllerTest {
} ,
) . handleSearchShortcutEngineSelected ( searchEngine )
browserStore . waitUntilIdle ( )
assertTrue ( focusToolbarInvoked )
verify { store . dispatch ( SearchFragmentAction . SearchHistoryEngineSelected ( searchEngine ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
assertNotNull ( UnifiedSearch . engineSelected . testGetValue ( ) )
val recordedEvents = UnifiedSearch . engineSelected . testGetValue ( ) !!
assertEquals ( 1 , recordedEvents . size )
@ -562,9 +687,13 @@ class SearchDialogControllerTest {
} ,
) . handleSearchShortcutEngineSelected ( searchEngine )
browserStore . waitUntilIdle ( )
assertTrue ( focusToolbarInvoked )
verify { store . dispatch ( SearchFragmentAction . SearchBookmarksEngineSelected ( searchEngine ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
assertNotNull ( UnifiedSearch . engineSelected . testGetValue ( ) )
val recordedEvents = UnifiedSearch . engineSelected . testGetValue ( ) !!
assertEquals ( 1 , recordedEvents . size )
@ -590,9 +719,13 @@ class SearchDialogControllerTest {
} ,
) . handleSearchShortcutEngineSelected ( searchEngine )
browserStore . waitUntilIdle ( )
assertTrue ( focusToolbarInvoked )
verify { store . dispatch ( SearchFragmentAction . SearchTabsEngineSelected ( searchEngine ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
assertNotNull ( UnifiedSearch . engineSelected . testGetValue ( ) )
val recordedEvents = UnifiedSearch . engineSelected . testGetValue ( ) !!
assertEquals ( 1 , recordedEvents . size )
@ -608,7 +741,13 @@ class SearchDialogControllerTest {
createController ( ) . handleClickSearchEngineSettings ( )
browserStore . waitUntilIdle ( )
verify { navController . navigate ( directions ) }
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertTrue ( action . abandoned )
}
}
@Test
@ -617,7 +756,11 @@ class SearchDialogControllerTest {
createController ( ) . handleSearchShortcutsButtonClicked ( )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( false ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -626,7 +769,11 @@ class SearchDialogControllerTest {
createController ( ) . handleSearchShortcutsButtonClicked ( )
browserStore . waitUntilIdle ( )
verify { store . dispatch ( SearchFragmentAction . ShowSearchShortcutEnginePicker ( true ) ) }
middleware . assertNotDispatched ( AwesomeBarAction . EngagementFinished :: class )
}
@Test
@ -640,6 +787,10 @@ class SearchDialogControllerTest {
}
verify { activity . openToBrowser ( from = BrowserDirection . FromSearchDialog ) }
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test
@ -652,6 +803,10 @@ class SearchDialogControllerTest {
assertEquals ( " tab-id " , action . tabId )
}
verify { activity . openToBrowser ( from = BrowserDirection . FromSearchDialog ) }
middleware . assertLastAction ( AwesomeBarAction . EngagementFinished :: class ) { action ->
assertFalse ( action . abandoned )
}
}
@Test