Commit 4d42ae87 authored by Gabriel Luong's avatar Gabriel Luong
Browse files

Issue #6441: Part 1 - Add contextId support to ContextMenuCandidate

parent 1341d92f
......@@ -70,7 +70,7 @@ data class ContextMenuCandidate(
showFor = { tab, hitResult -> hitResult.isLink() && !tab.content.private },
action = { parent, hitResult ->
val tab = tabsUseCases.addTab(
hitResult.getLink(), selectTab = false, startLoading = true, parentId = parent.id)
hitResult.getLink(), selectTab = false, startLoading = true, parentId = parent.id, contextId = parent.contextId)
snackbarDelegate.show(
snackBarParentView = snackBarParentView,
......@@ -151,7 +151,7 @@ data class ContextMenuCandidate(
hitResult.src, selectTab = false, startLoading = true, parentId = parent.id)
} else {
tabsUseCases.addTab(
hitResult.src, selectTab = false, startLoading = true, parentId = parent.id)
hitResult.src, selectTab = false, startLoading = true, parentId = parent.id, contextId = parent.contextId)
}
snackbarDelegate.show(
......
......@@ -86,6 +86,28 @@ class ContextMenuCandidateTest {
HitResult.VIDEO("https://www.mozilla.org")))
}
@Test
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())
sessionManager.add(Session("https://www.mozilla.org", contextId = "1"))
val tabsUseCases = TabsUseCases(sessionManager)
val parentView = CoordinatorLayout(testContext)
val openInNewTab = ContextMenuCandidate.createOpenInNewTabCandidate(
testContext, tabsUseCases, parentView, snackbarDelegate)
assertEquals(1, store.state.tabs.size)
assertEquals("1", store.state.tabs.first().contextId)
openInNewTab.action.invoke(store.state.tabs.first(), HitResult.UNKNOWN("https://firefox.com"))
assertEquals(2, store.state.tabs.size)
assertEquals("https://firefox.com", store.state.tabs.last().content.url)
assertEquals("1", store.state.tabs.last().contextId)
}
@Test
fun `Candidate "Open Link in New Tab" action properly executes and shows snackbar`() {
val store = BrowserStore()
......@@ -336,6 +358,31 @@ class ContextMenuCandidateTest {
assertEquals("https://firefox.com", store.state.tabs.last().content.url)
}
@Test
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())
sessionManager.add(Session("https://www.mozilla.org", contextId = "1"))
val tabsUseCases = TabsUseCases(sessionManager)
val parentView = CoordinatorLayout(testContext)
val openImageInTab = ContextMenuCandidate.createOpenImageInNewTabCandidate(
testContext, tabsUseCases, parentView, snackbarDelegate)
assertEquals(1, store.state.tabs.size)
assertEquals("1", store.state.tabs.first().contextId)
openImageInTab.action.invoke(
store.state.tabs.first(),
HitResult.IMAGE_SRC("https://firefox.com", "https://getpocket.com"))
assertEquals(2, store.state.tabs.size)
assertEquals("https://firefox.com", store.state.tabs.last().content.url)
assertEquals("1", store.state.tabs.last().contextId)
}
@Test
fun `Candidate "Save image"`() {
val store = BrowserStore()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment