|
|
|
@ -28,6 +28,7 @@ import mozilla.components.concept.sync.TabData
|
|
|
|
|
import mozilla.components.feature.accounts.push.SendTabUseCases
|
|
|
|
|
import mozilla.components.feature.share.RecentAppsStorage
|
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
|
import org.junit.After
|
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
|
import org.junit.Assert.assertNotEquals
|
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
@ -55,6 +56,7 @@ class ShareControllerTest {
|
|
|
|
|
ShareData(url = "url0", title = "title0"),
|
|
|
|
|
ShareData(url = "url1", title = "title1")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Navigation between app fragments uses ShareTab as arguments. SendTabUseCases uses TabData.
|
|
|
|
|
private val tabsData = listOf(
|
|
|
|
|
TabData("title0", "url0"),
|
|
|
|
@ -77,6 +79,11 @@ class ShareControllerTest {
|
|
|
|
|
every { context.metrics } returns metrics
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
fun cleanUp() {
|
|
|
|
|
testCoroutineScope.cleanupTestCoroutines()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `handleShareClosed should call a passed in delegate to close this`() {
|
|
|
|
|
controller.handleShareClosed()
|
|
|
|
@ -95,8 +102,10 @@ class ShareControllerTest {
|
|
|
|
|
// needed for capturing the actual Intent used the `slot` one doesn't have this flag so we
|
|
|
|
|
// need to use an Activity Context.
|
|
|
|
|
val activityContext: Context = mockk<Activity>()
|
|
|
|
|
val testController = DefaultShareController(activityContext, shareSubject, shareData, mockk(),
|
|
|
|
|
mockk(), mockk(), recentAppStorage, testCoroutineScope, dismiss)
|
|
|
|
|
val testController = DefaultShareController(
|
|
|
|
|
activityContext, shareSubject, shareData, mockk(),
|
|
|
|
|
mockk(), mockk(), recentAppStorage, testCoroutineScope, dismiss
|
|
|
|
|
)
|
|
|
|
|
every { activityContext.startActivity(capture(shareIntent)) } just Runs
|
|
|
|
|
every { recentAppStorage.updateRecentApp(appShareOption.activityName) } just Runs
|
|
|
|
|
|
|
|
|
@ -129,8 +138,11 @@ class ShareControllerTest {
|
|
|
|
|
// needed for capturing the actual Intent used the `slot` one doesn't have this flag so we
|
|
|
|
|
// need to use an Activity Context.
|
|
|
|
|
val activityContext: Context = mockk<Activity>()
|
|
|
|
|
val testController = DefaultShareController(activityContext, shareSubject, shareData, mockk(),
|
|
|
|
|
snackbar, mockk(), mockk(), testCoroutineScope, dismiss)
|
|
|
|
|
val testController = DefaultShareController(
|
|
|
|
|
activityContext, shareSubject, shareData, mockk(),
|
|
|
|
|
snackbar, mockk(), recentAppStorage, testCoroutineScope, dismiss
|
|
|
|
|
)
|
|
|
|
|
every { recentAppStorage.updateRecentApp(appShareOption.activityName) } just Runs
|
|
|
|
|
every { activityContext.startActivity(capture(shareIntent)) } throws SecurityException()
|
|
|
|
|
every { activityContext.getString(R.string.share_error_snackbar) } returns "Cannot share to this app"
|
|
|
|
|
|
|
|
|
@ -154,8 +166,11 @@ class ShareControllerTest {
|
|
|
|
|
// needed for capturing the actual Intent used the `slot` one doesn't have this flag so we
|
|
|
|
|
// need to use an Activity Context.
|
|
|
|
|
val activityContext: Context = mockk<Activity>()
|
|
|
|
|
val testController = DefaultShareController(activityContext, shareSubject, shareData, mockk(),
|
|
|
|
|
snackbar, mockk(), mockk(), testCoroutineScope, dismiss)
|
|
|
|
|
val testController = DefaultShareController(
|
|
|
|
|
activityContext, shareSubject, shareData, mockk(),
|
|
|
|
|
snackbar, mockk(), recentAppStorage, testCoroutineScope, dismiss
|
|
|
|
|
)
|
|
|
|
|
every { recentAppStorage.updateRecentApp(appShareOption.activityName) } just Runs
|
|
|
|
|
every { activityContext.startActivity(capture(shareIntent)) } throws ActivityNotFoundException()
|
|
|
|
|
every { activityContext.getString(R.string.share_error_snackbar) } returns "Cannot share to this app"
|
|
|
|
|
|
|
|
|
@ -173,7 +188,8 @@ class ShareControllerTest {
|
|
|
|
|
@Suppress("DeferredResultUnused")
|
|
|
|
|
fun `handleShareToDevice should share to account device, inform callbacks and dismiss`() {
|
|
|
|
|
val deviceToShareTo = Device(
|
|
|
|
|
"deviceId", "deviceName", DeviceType.UNKNOWN, false, 0L, emptyList(), false, null)
|
|
|
|
|
"deviceId", "deviceName", DeviceType.UNKNOWN, false, 0L, emptyList(), false, null
|
|
|
|
|
)
|
|
|
|
|
val deviceId = slot<String>()
|
|
|
|
|
val tabsShared = slot<List<TabData>>()
|
|
|
|
|
|
|
|
|
@ -196,8 +212,26 @@ class ShareControllerTest {
|
|
|
|
|
@Suppress("DeferredResultUnused")
|
|
|
|
|
fun `handleShareToAllDevices calls handleShareToDevice multiple times`() {
|
|
|
|
|
val devicesToShareTo = listOf(
|
|
|
|
|
Device("deviceId0", "deviceName0", DeviceType.UNKNOWN, false, 0L, emptyList(), false, null),
|
|
|
|
|
Device("deviceId1", "deviceName1", DeviceType.UNKNOWN, true, 1L, emptyList(), false, null)
|
|
|
|
|
Device(
|
|
|
|
|
"deviceId0",
|
|
|
|
|
"deviceName0",
|
|
|
|
|
DeviceType.UNKNOWN,
|
|
|
|
|
false,
|
|
|
|
|
0L,
|
|
|
|
|
emptyList(),
|
|
|
|
|
false,
|
|
|
|
|
null
|
|
|
|
|
),
|
|
|
|
|
Device(
|
|
|
|
|
"deviceId1",
|
|
|
|
|
"deviceName1",
|
|
|
|
|
DeviceType.UNKNOWN,
|
|
|
|
|
true,
|
|
|
|
|
1L,
|
|
|
|
|
emptyList(),
|
|
|
|
|
false,
|
|
|
|
|
null
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
val tabsShared = slot<List<TabData>>()
|
|
|
|
|
|
|
|
|
|