2019-12-28 01:13:28 +01:00
|
|
|
package org.mozilla.fenix.session
|
|
|
|
|
|
|
|
import io.mockk.MockKAnnotations
|
|
|
|
import io.mockk.every
|
|
|
|
import io.mockk.impl.annotations.MockK
|
|
|
|
import io.mockk.mockk
|
|
|
|
import io.mockk.verify
|
|
|
|
import mozilla.components.support.test.robolectric.testContext
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
2020-04-01 23:00:32 +02:00
|
|
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
2019-12-28 01:13:28 +01:00
|
|
|
import mozilla.components.browser.session.Session
|
|
|
|
|
2020-04-01 23:00:32 +02:00
|
|
|
@RunWith(FenixRobolectricTestRunner::class)
|
2019-12-28 01:13:28 +01:00
|
|
|
class NotificationSessionObserverTest {
|
|
|
|
|
|
|
|
private lateinit var observer: NotificationSessionObserver
|
|
|
|
@MockK(relaxed = true) private lateinit var notificationService: SessionNotificationService.Companion
|
|
|
|
|
|
|
|
@Before
|
|
|
|
fun before() {
|
|
|
|
MockKAnnotations.init(this)
|
|
|
|
observer = NotificationSessionObserver(testContext, notificationService)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `GIVEN session is private and non-custom WHEN it is added THEN notification service should be started`() {
|
|
|
|
val privateSession = mockSession(true, false)
|
|
|
|
|
|
|
|
observer.onSessionAdded(privateSession)
|
|
|
|
verify(exactly = 1) { notificationService.start(any()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `GIVEN session is not private WHEN it is added THEN notification service should not be started`() {
|
|
|
|
val normalSession = mockSession(false, true)
|
|
|
|
val customSession = mockSession(false, false)
|
|
|
|
|
|
|
|
observer.onSessionAdded(normalSession)
|
|
|
|
verify(exactly = 0) { notificationService.start(any()) }
|
|
|
|
|
|
|
|
observer.onSessionAdded(customSession)
|
|
|
|
verify(exactly = 0) { notificationService.start(any()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `GIVEN session is custom tab WHEN it is added THEN notification service should not be started`() {
|
|
|
|
val privateCustomSession = mockSession(true, true)
|
|
|
|
val customSession = mockSession(false, true)
|
|
|
|
|
|
|
|
observer.onSessionAdded(privateCustomSession)
|
|
|
|
verify(exactly = 0) { notificationService.start(any()) }
|
|
|
|
|
|
|
|
observer.onSessionAdded(customSession)
|
|
|
|
verify(exactly = 0) { notificationService.start(any()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun mockSession(isPrivate: Boolean, isCustom: Boolean) = mockk<Session> {
|
|
|
|
every { private } returns isPrivate
|
|
|
|
every { isCustomTabSession() } returns isCustom
|
|
|
|
}
|