Commit 90b2b313 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Closes #6584: TabUseCases may call loadUrl twice

parent 52ca085f
......@@ -270,7 +270,10 @@ class LegacySessionManager(
/**
* Gets the linked engine session for the provided session and creates it if needed.
*/
fun getOrCreateEngineSession(session: Session = selectedSessionOrThrow): EngineSession {
fun getOrCreateEngineSession(
session: Session = selectedSessionOrThrow,
skipLoading: Boolean = false
): EngineSession {
getEngineSession(session)?.let { return it }
return engine.createSession(session.private, session.contextId).apply {
......@@ -280,15 +283,20 @@ class LegacySessionManager(
session.engineSessionHolder.engineSessionState = null
}
link(session, this, restored)
link(session, this, restored, skipLoading)
}
}
private fun link(session: Session, engineSession: EngineSession, restored: Boolean = false) {
private fun link(
session: Session,
engineSession: EngineSession,
restored: Boolean = false,
skipLoading: Boolean = false
) {
val parent = values.find { it.id == session.parentId }?.let {
this.getEngineSession(it)
}
engineSessionLinker.link(session, engineSession, parent, restored)
engineSessionLinker.link(session, engineSession, parent, restored, skipLoading)
if (session == selectedSession) {
engineSession.markActiveForWebExtensions(true)
......
......@@ -52,7 +52,8 @@ class SessionManager(
session: Session,
engineSession: EngineSession,
parentEngineSession: EngineSession?,
sessionRestored: Boolean = false
sessionRestored: Boolean = false,
skipLoading: Boolean = false
) {
unlink(session)
......@@ -60,7 +61,7 @@ class SessionManager(
this.engineSession = engineSession
this.engineObserver = EngineObserver(session, store).also { observer ->
engineSession.register(observer)
if (!sessionRestored) {
if (!sessionRestored && !skipLoading) {
engineSession.loadUrl(session.url, parentEngineSession)
}
}
......@@ -303,8 +304,11 @@ class SessionManager(
/**
* Gets the linked engine session for the provided session and creates it if needed.
*/
fun getOrCreateEngineSession(session: Session = selectedSessionOrThrow): EngineSession {
return delegate.getOrCreateEngineSession(session)
fun getOrCreateEngineSession(
session: Session = selectedSessionOrThrow,
skipLoading: Boolean = false
): EngineSession {
return delegate.getOrCreateEngineSession(session, skipLoading)
}
/**
......
......@@ -115,7 +115,7 @@ class FxaWebChannelFeatureTest {
whenever(ext.getConnectedPort(any(), any())).thenReturn(port)
whenever(controller.portConnected(any(), any())).thenReturn(true)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(sessionManager.selectedSession).thenReturn(session)
val webchannelFeature = spy(FxaWebChannelFeature(testContext, null, engine, sessionManager, accountManager, serverConfig))
webchannelFeature.extensionController = controller
......@@ -150,7 +150,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
val webchannelFeature = spy(FxaWebChannelFeature(testContext, null, engine, sessionManager, accountManager, serverConfig))
webchannelFeature.extensionController = controller
......@@ -172,7 +172,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.supportedSyncEngines()).thenReturn(null)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://bar.foo/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -217,7 +217,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -262,7 +262,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -314,7 +314,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -375,7 +375,7 @@ class FxaWebChannelFeatureTest {
whenever(accountManager.authenticatedAccount()).thenReturn(account)
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(accountManager.logoutAsync()).thenReturn(logoutDeferred)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -439,7 +439,7 @@ class FxaWebChannelFeatureTest {
whenever(accountManager.authenticatedAccount()).thenReturn(account)
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(accountManager.logoutAsync()).thenReturn(logoutDeferred)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -499,7 +499,7 @@ class FxaWebChannelFeatureTest {
whenever(accountManager.accountProfile()).thenReturn(null)
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -554,7 +554,7 @@ class FxaWebChannelFeatureTest {
whenever(accountManager.accountProfile()).thenReturn(null)
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -606,7 +606,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.supportedSyncEngines()).thenReturn(null)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -653,7 +653,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.finishAuthenticationAsync(any())).thenReturn(CompletableDeferred(false))
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -692,7 +692,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.finishAuthenticationAsync(any())).thenReturn(CompletableDeferred(false))
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -734,7 +734,7 @@ class FxaWebChannelFeatureTest {
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
whenever(accountManager.supportedSyncEngines()).thenReturn(expectedEngines)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
whenever(port.engineSession).thenReturn(engineSession)
whenever(port.senderUrl()).thenReturn("https://foo.bar/email")
whenever(serverConfig.contentUrl).thenReturn("https://foo.bar")
......@@ -796,7 +796,7 @@ class FxaWebChannelFeatureTest {
whenever(ext.getConnectedPort(eq(FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID), any())).thenReturn(port)
whenever(sessionManager.selectedSession).thenReturn(session)
whenever(sessionManager.getEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(session, false)).thenReturn(engineSession)
WebExtensionController.installedExtensions[FxaWebChannelFeature.WEB_CHANNEL_EXTENSION_ID] = ext
......
......@@ -59,7 +59,7 @@ class ContextMenuCandidateTest {
@Test
fun `Candidate "Open Link in New Tab" showFor displayed in correct cases`() {
val sessionManager = spy(SessionManager(mock()))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
val tabsUseCases = TabsUseCases(sessionManager)
val parentView = CoordinatorLayout(testContext)
val openInNewTab = ContextMenuCandidate.createOpenInNewTabCandidate(
......@@ -90,7 +90,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in New Tab" action properly executes for session with a contextId`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", contextId = "1"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -112,7 +112,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in New Tab" action properly executes and shows snackbar`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -135,7 +135,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in New Tab" snackbar action works`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -159,7 +159,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in New Tab" action properly handles link with an image`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -181,7 +181,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in Private Tab" showFor displayed in correct cases`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -214,7 +214,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in Private Tab" action properly executes and shows snackbar`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -237,7 +237,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in Private Tab" snackbar action works`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -260,7 +260,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Link in Private Tab" action properly handles link with an image`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -279,7 +279,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Image in New Tab"`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -338,7 +338,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Image in New Tab" opens in private tab if session is private`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", private = true))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -362,7 +362,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Open Image in New Tab" opens with the session's contextId`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", contextId = "1"))
val tabsUseCases = TabsUseCases(sessionManager)
......@@ -387,7 +387,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Save image"`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", private = true))
val saveImage = ContextMenuCandidate.createSaveImageCandidate(
......@@ -439,7 +439,7 @@ class ContextMenuCandidateTest {
fun `Candidate "Save video and audio"`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", private = true))
val saveVideoAudio = ContextMenuCandidate.createSaveVideoAudioCandidate(
......@@ -494,7 +494,7 @@ class ContextMenuCandidateTest {
fun `Candidate "download link"`() {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", private = true))
val downloadLink = ContextMenuCandidate.createDownloadLinkCandidate(
......@@ -639,7 +639,7 @@ class ContextMenuCandidateTest {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", private = true))
shareLink.action.invoke(
......@@ -682,7 +682,7 @@ class ContextMenuCandidateTest {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", private = true))
copyLink.action.invoke(
......@@ -731,7 +731,7 @@ class ContextMenuCandidateTest {
val store = BrowserStore()
val sessionManager = spy(SessionManager(mock(), store))
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any())
doReturn(mock<EngineSession>()).`when`(sessionManager).getOrCreateEngineSession(any(), anyBoolean())
sessionManager.add(Session("https://www.mozilla.org", private = true))
copyImageLocation.action.invoke(
......
......@@ -31,6 +31,7 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.spy
......@@ -53,7 +54,7 @@ class CustomTabIntentProcessorTest {
fun processCustomTabIntentWithDefaultHandlers() = runBlockingTest {
val engine = mock<Engine>()
val sessionManager = spy(SessionManager(engine))
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val useCases = SessionUseCases(sessionManager)
val handler =
......@@ -82,7 +83,7 @@ class CustomTabIntentProcessorTest {
fun processCustomTabIntentWithAdditionalHeaders() = runBlockingTest {
val engine = mock<Engine>()
val sessionManager = spy(SessionManager(engine))
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val useCases = SessionUseCases(sessionManager)
val handler =
......@@ -117,7 +118,7 @@ class CustomTabIntentProcessorTest {
fun processPrivateCustomTabIntentWithDefaultHandlers() = runBlockingTest {
val engine = mock<Engine>()
val sessionManager = spy(SessionManager(engine))
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val useCases = SessionUseCases(sessionManager)
val handler =
......
......@@ -21,6 +21,7 @@ import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.support.test.any
import mozilla.components.support.test.eq
import mozilla.components.support.test.mock
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.whenever
......@@ -30,6 +31,7 @@ import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
......@@ -49,7 +51,7 @@ class TabIntentProcessorTest {
@Before
fun setup() {
whenever(sessionManager.selectedSession).thenReturn(session)
whenever(sessionManager.getOrCreateEngineSession(session)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(eq(session), anyBoolean())).thenReturn(engineSession)
}
@Test
......@@ -63,7 +65,7 @@ class TabIntentProcessorTest {
whenever(intent.action).thenReturn(Intent.ACTION_VIEW)
val engineSession = mock<EngineSession>()
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
whenever(intent.dataString).thenReturn("")
handler.process(intent)
......@@ -98,7 +100,7 @@ class TabIntentProcessorTest {
@Test
fun processViewIntentHavingNoSelectedSession() = runBlockingTest {
whenever(sessionManager.selectedSession).thenReturn(null)
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val handler = TabIntentProcessor(
sessionManager,
......@@ -125,7 +127,7 @@ class TabIntentProcessorTest {
whenever(intent.action).thenReturn(ACTION_NDEF_DISCOVERED)
val engineSession = mock<EngineSession>()
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
whenever(intent.dataString).thenReturn("")
handler.process(intent)
......@@ -160,7 +162,7 @@ class TabIntentProcessorTest {
@Test
fun processNfcIntentHavingNoSelectedSession() = runBlockingTest {
whenever(sessionManager.selectedSession).thenReturn(null)
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val handler = TabIntentProcessor(
sessionManager,
......@@ -178,7 +180,7 @@ class TabIntentProcessorTest {
@Test
fun `load URL on ACTION_SEND if text contains URL`() = runBlockingTest {
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val handler = TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch)
......@@ -210,7 +212,7 @@ class TabIntentProcessorTest {
fun `perform search on ACTION_SEND if text (no URL) provided`() = runBlockingTest {
val engine = mock<Engine>()
val sessionManager = spy(SessionManager(engine))
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val searchUseCases = SearchUseCases(testContext, searchEngineManager, sessionManager)
val sessionUseCases = SessionUseCases(sessionManager)
......@@ -260,7 +262,7 @@ class TabIntentProcessorTest {
@Test
fun `load URL on ACTION_SEARCH if text is an URL`() = runBlockingTest {
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val handler = TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch)
......@@ -276,7 +278,7 @@ class TabIntentProcessorTest {
fun `perform search on ACTION_SEARCH if text (no URL) provided`() = runBlockingTest {
val engine = mock<Engine>()
val sessionManager = spy(SessionManager(engine))
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val searchUseCases = SearchUseCases(testContext, searchEngineManager, sessionManager)
val sessionUseCases = SessionUseCases(sessionManager)
......@@ -314,7 +316,7 @@ class TabIntentProcessorTest {
@Test
fun `load URL on ACTION_WEB_SEARCH if text is an URL`() = runBlockingTest {
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val handler = TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch)
......@@ -330,7 +332,7 @@ class TabIntentProcessorTest {
fun `perform search on ACTION_WEB_SEARCH if text (no URL) provided`() = runBlockingTest {
val engine = mock<Engine>()
val sessionManager = spy(SessionManager(engine))
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession())
doReturn(engineSession).`when`(sessionManager).getOrCreateEngineSession(anySession(), anyBoolean())
val searchUseCases = SearchUseCases(testContext, searchEngineManager, sessionManager)
val sessionUseCases = SessionUseCases(sessionManager)
......
......@@ -22,6 +22,7 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.Mockito.verify
@RunWith(AndroidJUnit4::class)
......@@ -66,7 +67,7 @@ class SearchUseCasesTest {
val engineSession = mock<EngineSession>()
whenever(searchEngine.buildSearchUrl(searchTerms)).thenReturn(searchUrl)
whenever(searchEngineManager.getDefaultSearchEngine(testContext)).thenReturn(searchEngine)
whenever(sessionManager.getOrCreateEngineSession(any())).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(any(), anyBoolean())).thenReturn(engineSession)
useCases.newTabSearch(searchTerms, Session.Source.NEW_TAB)
verify(engineSession).loadUrl(searchUrl)
......@@ -78,7 +79,7 @@ class SearchUseCasesTest {
whenever(searchEngine.buildSearchUrl("test")).thenReturn("https://search.example.com")
whenever(searchEngineManager.getDefaultSearchEngine(testContext)).thenReturn(searchEngine)
whenever(sessionManager.getOrCreateEngineSession(any())).thenReturn(mock())
whenever(sessionManager.getOrCreateEngineSession(any(), anyBoolean())).thenReturn(mock())
var sessionCreatedForUrl: String? = null
......@@ -102,7 +103,7 @@ class SearchUseCasesTest {
val engineSession = mock<EngineSession>()
whenever(searchEngine.buildSearchUrl(searchTerms)).thenReturn(searchUrl)
whenever(searchEngineManager.getDefaultSearchEngine(testContext)).thenReturn(searchEngine)
whenever(sessionManager.getOrCreateEngineSession(any())).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(any(), anyBoolean())).thenReturn(engineSession)
useCases.newPrivateTabSearch.invoke(searchTerms)
......
......@@ -80,7 +80,7 @@ class FullScreenFeatureTest {
val engineSession: EngineSession = mock()
val fullscreenFeature = spy(FullScreenFeatureTest(sessionManager, useCases) {})
whenever(sessionManager.getOrCreateEngineSession(activeSession)).thenReturn(engineSession)
whenever(sessionManager.getOrCreateEngineSession(activeSession, false)).thenReturn(engineSession)
whenever(fullscreenFeature.activeSession).thenReturn(activeSession)