feat(event): 공통 라우팅과 AppsFlyer 전달을 연결한다
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
package kr.co.vividnext.sodalive.v2.event
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.os.Looper
|
||||
import com.appsflyer.AppsFlyerLib
|
||||
import com.appsflyer.deeplink.DeepLink
|
||||
import com.appsflyer.deeplink.DeepLinkListener
|
||||
import com.appsflyer.deeplink.DeepLinkResult
|
||||
import io.mockk.every
|
||||
import io.mockk.confirmVerified
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkObject
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.slot
|
||||
import io.mockk.unmockkAll
|
||||
import io.mockk.verify
|
||||
import kr.co.vividnext.sodalive.app.SodaLiveApp
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.main.DeepLinkActivity
|
||||
import kr.co.vividnext.sodalive.tracking.FirebaseTracking
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class EventAppsFlyerIntegrationTest {
|
||||
private val listener = slot<DeepLinkListener>()
|
||||
private lateinit var app: SodaLiveApp
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mockkObject(SharedPreferenceManager)
|
||||
every { SharedPreferenceManager.alreadyTrackingAppLaunch = any() } returns Unit
|
||||
every { SharedPreferenceManager.marketingLinkValue = any() } returns Unit
|
||||
every { SharedPreferenceManager.marketingLinkValueId = any() } returns Unit
|
||||
every { SharedPreferenceManager.marketingPid = any() } returns Unit
|
||||
every { SharedPreferenceManager.marketingUtmSource = any() } returns Unit
|
||||
every { SharedPreferenceManager.marketingUtmMedium = any() } returns Unit
|
||||
every { SharedPreferenceManager.marketingUtmCampaign = any() } returns Unit
|
||||
mockkStatic(AppsFlyerLib::class)
|
||||
mockkObject(FirebaseTracking)
|
||||
every { FirebaseTracking.logUtm() } returns Unit
|
||||
val sdk = mockk<AppsFlyerLib>(relaxed = true)
|
||||
every { AppsFlyerLib.getInstance() } returns sdk
|
||||
every { sdk.subscribeForDeepLink(capture(listener)) } returns Unit
|
||||
every { sdk.start(any()) } answers {
|
||||
assertEquals(true, listener.isCaptured)
|
||||
callback("event-detail", "7")
|
||||
}
|
||||
app = SodaLiveApp()
|
||||
SodaLiveApp::class.java.getDeclaredMethod("setupAppsFlyer").apply { isAccessible = true }.invoke(app)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
unmockkAll()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `start 시점 callback은 설치된 helper에 보관되고 마케팅과 Firebase 추적은 유지된다`() {
|
||||
verify(exactly = 1) {
|
||||
SharedPreferenceManager.alreadyTrackingAppLaunch = false
|
||||
SharedPreferenceManager.marketingLinkValue = "event-detail"
|
||||
SharedPreferenceManager.marketingLinkValueId = 7L
|
||||
SharedPreferenceManager.marketingPid = "pid"
|
||||
SharedPreferenceManager.marketingUtmSource = "source"
|
||||
SharedPreferenceManager.marketingUtmMedium = "medium"
|
||||
SharedPreferenceManager.marketingUtmCampaign = "campaign"
|
||||
}
|
||||
confirmVerified(SharedPreferenceManager)
|
||||
verify(exactly = 1) { FirebaseTracking.logUtm() }
|
||||
val host = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
app.eventDeepLinkDelivery.onActivityResumed(host.get())
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
val handoff = shadowOf(host.get()).nextStartedActivity
|
||||
assertEquals(DeepLinkActivity::class.java.name, handoff.component?.className)
|
||||
assertEquals(EventDeepLinkContract.Direct(7), EventDeepLinkEntry.classify(handoff))
|
||||
callback("event-detail", "+8")
|
||||
callback("live", "9")
|
||||
shadowOf(Looper.getMainLooper()).idle()
|
||||
assertNull(shadowOf(host.get()).nextStartedActivity)
|
||||
verify(exactly = 3) {
|
||||
SharedPreferenceManager.alreadyTrackingAppLaunch = false
|
||||
SharedPreferenceManager.marketingPid = "pid"
|
||||
SharedPreferenceManager.marketingUtmSource = "source"
|
||||
SharedPreferenceManager.marketingUtmMedium = "medium"
|
||||
SharedPreferenceManager.marketingUtmCampaign = "campaign"
|
||||
FirebaseTracking.logUtm()
|
||||
}
|
||||
verify(exactly = 2) { SharedPreferenceManager.marketingLinkValue = "event-detail" }
|
||||
verify(exactly = 1) {
|
||||
SharedPreferenceManager.marketingLinkValue = "live"
|
||||
SharedPreferenceManager.marketingLinkValueId = 7L
|
||||
SharedPreferenceManager.marketingLinkValueId = 8L
|
||||
SharedPreferenceManager.marketingLinkValueId = 9L
|
||||
}
|
||||
confirmVerified(SharedPreferenceManager)
|
||||
host.pause().stop().destroy()
|
||||
app.eventDeepLinkDelivery.onActivityDestroyed(host.get())
|
||||
}
|
||||
|
||||
private fun callback(value: String, id: String) {
|
||||
val payload = mockk<DeepLink>()
|
||||
every { payload.getStringValue(any()) } answers {
|
||||
when (firstArg<String>()) {
|
||||
"deep_link_value" -> value
|
||||
"deep_link_sub1" -> "pid"
|
||||
"deep_link_sub2" -> "source"
|
||||
"deep_link_sub3" -> "medium"
|
||||
"deep_link_sub4" -> "campaign"
|
||||
"deep_link_sub5" -> id
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
val result = mockk<DeepLinkResult>()
|
||||
every { result.status } returns DeepLinkResult.Status.FOUND
|
||||
every { result.deepLink } returns payload
|
||||
listener.captured.onDeepLinking(result)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
package kr.co.vividnext.sodalive.v2.event
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.IntentFilter
|
||||
import android.net.Uri
|
||||
import android.os.Looper
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import io.mockk.mockk
|
||||
import kr.co.vividnext.sodalive.BuildConfig
|
||||
import kr.co.vividnext.sodalive.app.SodaLiveApp
|
||||
import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.live.room.LiveRoomActivity
|
||||
import kr.co.vividnext.sodalive.main.DeepLinkActivity
|
||||
import kr.co.vividnext.sodalive.splash.SplashActivity
|
||||
import kr.co.vividnext.sodalive.v2.main.MainV2Activity
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Before
|
||||
import org.junit.After
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class EventDeepLinkDeliveryTest {
|
||||
private lateinit var delivery: EventDeepLinkDelivery
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
delivery = EventDeepLinkDelivery(ApplicationProvider.getApplicationContext())
|
||||
SharedPreferenceManager.resetForTest()
|
||||
SharedPreferenceManager.init(ApplicationProvider.getApplicationContext())
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
SharedPreferenceManager.resetForTest()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `선도착 이벤트들은 resumed 호스트에서 FIFO로 명시적 trampoline에 전달한다`() {
|
||||
delivery.offer(7)
|
||||
delivery.offer(Long.MAX_VALUE)
|
||||
idle()
|
||||
val controller = Robolectric.buildActivity(RecordingActivity::class.java).setup()
|
||||
idle()
|
||||
assertEquals(2, controller.get().handoffs.size)
|
||||
assertHandoff(controller.get().handoffs[0], 7)
|
||||
assertHandoff(controller.get().handoffs[1], Long.MAX_VALUE)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `이미 resumed인 호스트에도 후도착과 동일 ID 새 전달이 도달한다`() {
|
||||
val controller = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
idle()
|
||||
repeat(2) {
|
||||
delivery.offer(7)
|
||||
idle()
|
||||
assertHandoff(shadowOf(controller.get()).nextStartedActivity, 7)
|
||||
}
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `pause와 destroy는 예약된 실행을 중단하고 다음 resumed 호스트로 전달한다`() {
|
||||
val first = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
delivery.offer(7)
|
||||
first.pause().stop().destroy()
|
||||
idle()
|
||||
assertNull(shadowOf(first.get()).nextStartedActivity)
|
||||
val next = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
idle()
|
||||
assertHandoff(shadowOf(next.get()).nextStartedActivity, 7)
|
||||
next.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Splash와 DeepLink 및 초기 Main에서는 대기하고 Main ready 후 전달한다`() {
|
||||
delivery.offer(7)
|
||||
com.google.firebase.FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext())
|
||||
val splash = Robolectric.buildActivity(SplashActivity::class.java).get()
|
||||
delivery.onActivityResumed(splash)
|
||||
idle()
|
||||
assertNull(shadowOf(splash).nextStartedActivity)
|
||||
val trampoline = Robolectric.buildActivity(DeepLinkActivity::class.java).get()
|
||||
delivery.onActivityResumed(trampoline)
|
||||
idle()
|
||||
assertNull(shadowOf(trampoline).nextStartedActivity)
|
||||
val main = Robolectric.buildActivity(MainV2Activity::class.java).get()
|
||||
delivery.onActivityResumed(main)
|
||||
idle()
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
MainV2Activity::class.java.getDeclaredField("isEventDeepLinkRoutingReady").apply { isAccessible = true }
|
||||
.setBoolean(main, true)
|
||||
delivery.onMainRoutingReady()
|
||||
idle()
|
||||
assertHandoff(shadowOf(main).nextStartedActivity, 7)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `초기 Main 오디오 우선 라우팅은 같은 entry 이벤트만 소비하고 별도 UDL은 보존한다`() {
|
||||
val entry = Intent(Intent.ACTION_VIEW, Uri.parse("${BuildConfig.APPSCHEME}://event-detail/7"))
|
||||
.putExtra(MainV2Activity.EXTRA_AUDIO_NOTIFICATION_ROUTE, MainV2Activity.ROUTE_AUDIO_PLAYER)
|
||||
val main = Robolectric.buildActivity(MainV2Activity::class.java, entry).get()
|
||||
MainV2Activity::class.java.getDeclaredField("routeLoadingDialog").apply { isAccessible = true }
|
||||
.set(main, mockk<LoadingDialog>(relaxed = true))
|
||||
delivery.onActivityResumed(main)
|
||||
delivery.offer(9)
|
||||
idle()
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
val initialRoute = MainV2Activity::class.java.getDeclaredField("deferredRouteRunnable")
|
||||
.apply { isAccessible = true }.get(main) as Runnable
|
||||
initialRoute.run()
|
||||
assertEquals(true, main.isEventDeepLinkRoutingReady)
|
||||
assertEquals(false, EventDeepLinkEntry.consume(entry))
|
||||
delivery.onMainRoutingReady()
|
||||
idle()
|
||||
assertHandoff(shadowOf(main).nextStartedActivity, 9)
|
||||
assertEquals(
|
||||
kr.co.vividnext.sodalive.user.login.LoginActivity::class.java.name,
|
||||
shadowOf(main).nextStartedActivity?.component?.className
|
||||
)
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OneLink URI와 UDL 어느 도착 순서에서도 UDL만 상세를 한 번 연다`() {
|
||||
SodaLiveApp.isAppInForeground = true
|
||||
try {
|
||||
listOf(true, false).forEach { uriFirst ->
|
||||
val host = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
fun uriArrival() {
|
||||
val uri = Uri.parse(
|
||||
"https://${BuildConfig.APPSCHEME}.onelink.me/a?deep_link_value=event-detail&deep_link_sub5=7"
|
||||
)
|
||||
val trampoline = Robolectric.buildActivity(
|
||||
DeepLinkActivity::class.java,
|
||||
Intent(Intent.ACTION_VIEW, uri)
|
||||
).setup()
|
||||
assertNull(shadowOf(trampoline.get()).nextStartedActivity)
|
||||
trampoline.pause().stop().destroy()
|
||||
delivery.onActivityResumed(host.get())
|
||||
}
|
||||
if (uriFirst) uriArrival()
|
||||
delivery.offer(7)
|
||||
idle()
|
||||
val handoff = shadowOf(host.get()).nextStartedActivity
|
||||
assertHandoff(handoff, 7)
|
||||
val trampoline = Robolectric.buildActivity(DeepLinkActivity::class.java, handoff).setup()
|
||||
val detail = shadowOf(trampoline.get()).nextStartedActivity
|
||||
assertEquals(EventDetailActivity::class.java.name, detail.component?.className)
|
||||
assertEquals(7L, detail.getLongExtra(EventDetailActivity.EXTRA_EVENT_ID, 0))
|
||||
assertNull(shadowOf(trampoline.get()).nextStartedActivity)
|
||||
trampoline.pause().stop().destroy()
|
||||
if (!uriFirst) uriArrival()
|
||||
idle()
|
||||
assertNull(shadowOf(host.get()).nextStartedActivity)
|
||||
host.pause().stop().destroy()
|
||||
}
|
||||
} finally {
|
||||
SodaLiveApp.isAppInForeground = false
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `라이브룸 확인을 취소한 handoff는 복귀해도 재전달하지 않는다`() {
|
||||
SodaLiveApp.isAppInForeground = true
|
||||
LiveRoomActivity.isForeground = true
|
||||
val broadcasts = mutableListOf<Intent>()
|
||||
val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent) { broadcasts += intent }
|
||||
}
|
||||
val manager = LocalBroadcastManager.getInstance(ApplicationProvider.getApplicationContext())
|
||||
manager.registerReceiver(receiver, IntentFilter(Constants.ACTION_LIVE_ROOM_DEEPLINK_CONFIRM))
|
||||
val host = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
try {
|
||||
delivery.offer(7)
|
||||
idle()
|
||||
val trampoline = Robolectric.buildActivity(
|
||||
DeepLinkActivity::class.java,
|
||||
shadowOf(host.get()).nextStartedActivity
|
||||
).setup()
|
||||
idle()
|
||||
assertEquals(1, broadcasts.size)
|
||||
assertNull(shadowOf(trampoline.get()).nextStartedActivity)
|
||||
trampoline.pause().stop().destroy()
|
||||
host.pause().resume()
|
||||
idle()
|
||||
assertNull(shadowOf(host.get()).nextStartedActivity)
|
||||
assertEquals(1, broadcasts.size)
|
||||
} finally {
|
||||
manager.unregisterReceiver(receiver)
|
||||
host.pause().stop().destroy()
|
||||
SodaLiveApp.isAppInForeground = false
|
||||
LiveRoomActivity.isForeground = false
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `background 스레드 callback은 main에서만 전달하며 종료 호스트를 사용하지 않는다`() {
|
||||
val first = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
Thread { delivery.offer(7) }.apply { start(); join() }
|
||||
first.get().finish()
|
||||
idle()
|
||||
assertNull(shadowOf(first.get()).nextStartedActivity)
|
||||
first.pause().stop().destroy()
|
||||
val next = Robolectric.buildActivity(Activity::class.java).setup()
|
||||
idle()
|
||||
assertHandoff(shadowOf(next.get()).nextStartedActivity, 7)
|
||||
next.pause().stop().destroy()
|
||||
}
|
||||
|
||||
private fun idle() = shadowOf(Looper.getMainLooper()).idle()
|
||||
|
||||
class RecordingActivity : Activity() {
|
||||
val handoffs = mutableListOf<Intent>()
|
||||
override fun startActivity(intent: Intent) {
|
||||
handoffs += intent
|
||||
super.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun assertHandoff(intent: Intent?, id: Long) {
|
||||
assertEquals(DeepLinkActivity::class.java.name, intent?.component?.className)
|
||||
assertEquals("${BuildConfig.APPSCHEME}://event-detail/$id", intent?.dataString)
|
||||
assertEquals(EventDeepLinkContract.Direct(id), intent?.let(EventDeepLinkEntry::classify))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
package kr.co.vividnext.sodalive.v2.event
|
||||
|
||||
import android.app.Application
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.IntentFilter
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import io.mockk.mockk
|
||||
import kr.co.vividnext.sodalive.BuildConfig
|
||||
import kr.co.vividnext.sodalive.app.SodaLiveApp
|
||||
import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.live.room.LiveRoomActivity
|
||||
import kr.co.vividnext.sodalive.main.DeepLinkActivity
|
||||
import kr.co.vividnext.sodalive.splash.SplashActivity
|
||||
import kr.co.vividnext.sodalive.v2.main.MainV2Activity
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], application = Application::class)
|
||||
class EventDeepLinkRoutingTest {
|
||||
@Before
|
||||
fun setUp() {
|
||||
SharedPreferenceManager.resetForTest()
|
||||
SharedPreferenceManager.init(ApplicationProvider.getApplicationContext())
|
||||
SodaLiveApp.isAppInForeground = true
|
||||
LiveRoomActivity.isForeground = false
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
SodaLiveApp.isAppInForeground = false
|
||||
LiveRoomActivity.isForeground = false
|
||||
SharedPreferenceManager.resetForTest()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `결제 완료 URI는 충돌한 이벤트 query보다 기존 결제 전달을 우선한다`() {
|
||||
val controller = Robolectric.buildActivity(
|
||||
DeepLinkActivity::class.java,
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("${BuildConfig.APPSCHEME}://payverse/result?deep_link_value=event-detail&deep_link_sub5=7")
|
||||
)
|
||||
).setup()
|
||||
val payment = shadowOf(controller.get()).nextStartedActivity
|
||||
assertEquals(
|
||||
kr.co.vividnext.sodalive.mypage.can.payment.CanPaymentActivity::class.java.name,
|
||||
payment?.component?.className
|
||||
)
|
||||
assertEquals("payverse", payment?.data?.host)
|
||||
assertNull(shadowOf(controller.get()).nextStartedActivity)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `foreground 직접 이벤트는 로그인 없이 Long ID 상세를 연다`() {
|
||||
val controller = Robolectric.buildActivity(DeepLinkActivity::class.java, direct(Long.MAX_VALUE)).setup()
|
||||
assertDetail(shadowOf(controller.get()).nextStartedActivity, Long.MAX_VALUE)
|
||||
assertNull(shadowOf(controller.get()).nextStartedActivity)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `cold 이벤트는 Splash 전달 Bundle을 통해 Main에서 단회 소비한다`() {
|
||||
SodaLiveApp.isAppInForeground = false
|
||||
val controller = Robolectric.buildActivity(DeepLinkActivity::class.java, direct(2147483648L)).setup()
|
||||
val splash = shadowOf(controller.get()).nextStartedActivity
|
||||
assertEquals(SplashActivity::class.java.name, splash.component?.className)
|
||||
com.google.firebase.FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext())
|
||||
val splashActivity = Robolectric.buildActivity(SplashActivity::class.java, splash).get()
|
||||
SplashActivity::class.java.getDeclaredMethod("startNextActivity").apply { isAccessible = true }.invoke(splashActivity)
|
||||
org.robolectric.shadows.ShadowLooper.idleMainLooper(500, java.util.concurrent.TimeUnit.MILLISECONDS)
|
||||
val mainIntent = shadowOf(splashActivity).nextStartedActivity
|
||||
assertEquals(MainV2Activity::class.java.name, mainIntent.component?.className)
|
||||
val main = Robolectric.buildActivity(MainV2Activity::class.java, mainIntent).get()
|
||||
execute(main, mainIntent)
|
||||
assertDetail(shadowOf(main).nextStartedActivity, 2147483648L)
|
||||
execute(main, mainIntent)
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `푸시 root와 nested의 두 URL 별칭은 같은 공개 이벤트로 정규화된다`() {
|
||||
listOf("deep_link", "deepLink").forEach { key ->
|
||||
listOf(false, true).forEach { nested ->
|
||||
val entry = if (nested) {
|
||||
Intent().putExtra(Constants.EXTRA_DATA, Bundle().apply { putString(key, direct(7).dataString) })
|
||||
} else {
|
||||
Intent().putExtra(key, direct(7).dataString)
|
||||
}
|
||||
val main = Robolectric.buildActivity(MainV2Activity::class.java, entry).get()
|
||||
execute(main, entry)
|
||||
assertDetail(shadowOf(main).nextStartedActivity, 7)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OneLink URI는 foreground에서 상세나 라이브 확인을 실행하지 않고 cold bootstrap만 유지한다`() {
|
||||
val raw = "https://${BuildConfig.APPSCHEME}.onelink.me/a?deep_link_value=event-detail&deep_link_sub5=7&room_id=9"
|
||||
listOf(true, false).forEach { foreground ->
|
||||
SodaLiveApp.isAppInForeground = foreground
|
||||
LiveRoomActivity.isForeground = true
|
||||
val controller = Robolectric.buildActivity(
|
||||
DeepLinkActivity::class.java,
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(raw))
|
||||
).setup()
|
||||
val started = shadowOf(controller.get()).nextStartedActivity
|
||||
if (foreground) assertNull(started) else assertEquals(SplashActivity::class.java.name, started.component?.className)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Main 새 Intent는 guest 동일 ID 재클릭을 허용하고 비이벤트 로그인 가드는 유지한다`() {
|
||||
val controller = Robolectric.buildActivity(MainV2Activity::class.java)
|
||||
val main = controller.get()
|
||||
MainV2Activity::class.java.getDeclaredField("routeLoadingDialog").apply { isAccessible = true }
|
||||
.set(main, mockk<LoadingDialog>(relaxed = true))
|
||||
repeat(2) {
|
||||
controller.newIntent(direct(7))
|
||||
assertDetail(shadowOf(main).nextStartedActivity, 7)
|
||||
assertTrue(main.isEventDeepLinkRoutingReady)
|
||||
}
|
||||
controller.newIntent(
|
||||
Intent().putExtra(Constants.EXTRA_DATA, Bundle().apply { putString("deep_link", "sodalive://content/9") })
|
||||
)
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `같은 entry의 오디오 알림이 이기면 이벤트는 나중에도 재생하지 않는다`() {
|
||||
val entry = direct(7).putExtra(MainV2Activity.EXTRA_AUDIO_NOTIFICATION_ROUTE, MainV2Activity.ROUTE_AUDIO_PLAYER)
|
||||
val controller = Robolectric.buildActivity(MainV2Activity::class.java)
|
||||
val main = controller.get()
|
||||
MainV2Activity::class.java.getDeclaredField("routeLoadingDialog").apply { isAccessible = true }
|
||||
.set(main, mockk<LoadingDialog>(relaxed = true))
|
||||
controller.newIntent(entry)
|
||||
val audioGuard = shadowOf(main).nextStartedActivity
|
||||
assertTrue(audioGuard?.component?.className != EventDetailActivity::class.java.name)
|
||||
execute(main, entry)
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `실제 trampoline 재생성은 같은 cold handoff를 반복하지 않는다`() {
|
||||
SodaLiveApp.isAppInForeground = false
|
||||
val original = direct(7)
|
||||
val controller = Robolectric.buildActivity(DeepLinkActivity::class.java, Intent(original)).setup()
|
||||
assertEquals(SplashActivity::class.java.name, shadowOf(controller.get()).nextStartedActivity.component?.className)
|
||||
controller.get().intent = Intent(original)
|
||||
controller.recreate()
|
||||
assertNull(shadowOf(controller.get()).nextStartedActivity)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `라이브룸 이벤트는 확인 broadcast의 canonical Bundle로 Main에 단회 전달된다`() {
|
||||
LiveRoomActivity.isForeground = true
|
||||
val broadcasts = mutableListOf<Intent>()
|
||||
val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent) { broadcasts += intent }
|
||||
}
|
||||
val manager = LocalBroadcastManager.getInstance(ApplicationProvider.getApplicationContext())
|
||||
manager.registerReceiver(receiver, IntentFilter(Constants.ACTION_LIVE_ROOM_DEEPLINK_CONFIRM))
|
||||
val controller = Robolectric.buildActivity(DeepLinkActivity::class.java, direct(7)).setup()
|
||||
org.robolectric.shadows.ShadowLooper.idleMainLooper()
|
||||
assertNull(shadowOf(controller.get()).nextStartedActivity)
|
||||
assertEquals(1, broadcasts.size)
|
||||
val confirmed = Intent().putExtra(Constants.EXTRA_DATA, broadcasts.single().getBundleExtra(Constants.EXTRA_DATA))
|
||||
val main = Robolectric.buildActivity(MainV2Activity::class.java, confirmed).get()
|
||||
execute(main, confirmed)
|
||||
assertDetail(shadowOf(main).nextStartedActivity, 7)
|
||||
execute(main, confirmed)
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
manager.unregisterReceiver(receiver)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `잘못된 이벤트는 충돌한 live 정보로 라우팅하지 않는다`() {
|
||||
val controller = Robolectric.buildActivity(
|
||||
DeepLinkActivity::class.java,
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse("${BuildConfig.APPSCHEME}://event-detail/0?room_id=9"))
|
||||
).setup()
|
||||
assertNull(shadowOf(controller.get()).nextStartedActivity)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `두 기존 dispatcher는 정규화 이벤트를 단회 실행하고 전달 원본만 소비한다`() {
|
||||
listOf(
|
||||
Robolectric.buildActivity(DeepLinkActivity::class.java).get() to "routeForegroundDeepLink",
|
||||
Robolectric.buildActivity(MainV2Activity::class.java).get() to "executeBundleRoute"
|
||||
).forEach { (activity, dispatcher) ->
|
||||
val unrelatedActivityEntry = direct(99)
|
||||
activity.intent = unrelatedActivityEntry
|
||||
val original = direct(Long.MAX_VALUE)
|
||||
val normalized = requireNotNull(EventDeepLinkEntry.normalize(original))
|
||||
assertTrue(dispatch(activity, dispatcher, normalized))
|
||||
assertDetail(shadowOf(activity).nextStartedActivity, Long.MAX_VALUE)
|
||||
assertTrue(dispatch(activity, dispatcher, normalized))
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
assertFalse(EventDeepLinkEntry.consume(original))
|
||||
assertTrue(EventDeepLinkEntry.consume(unrelatedActivityEntry))
|
||||
val saved = Bundle()
|
||||
EventDeepLinkEntry.save(original, saved)
|
||||
val restored = direct(Long.MAX_VALUE)
|
||||
EventDeepLinkEntry.restore(restored, saved)
|
||||
assertTrue(dispatch(activity, dispatcher, requireNotNull(EventDeepLinkEntry.normalize(restored))))
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
assertTrue(dispatch(activity, dispatcher, requireNotNull(EventDeepLinkEntry.normalize(direct(Long.MAX_VALUE)))))
|
||||
assertDetail(shadowOf(activity).nextStartedActivity, Long.MAX_VALUE)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `두 dispatcher는 invalid SDK 소유 forged ID와 불일치 ID를 다른 도메인으로 실행하지 않는다`() {
|
||||
listOf(
|
||||
Robolectric.buildActivity(DeepLinkActivity::class.java).get() to "routeForegroundDeepLink",
|
||||
Robolectric.buildActivity(MainV2Activity::class.java).get() to "executeBundleRoute"
|
||||
).forEach { (activity, dispatcher) ->
|
||||
val invalid = requireNotNull(
|
||||
EventDeepLinkEntry.normalize(
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse("${BuildConfig.APPSCHEME}://event-detail/0"))
|
||||
)
|
||||
)
|
||||
val sdkOwned = requireNotNull(
|
||||
EventDeepLinkEntry.normalize(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("https://${BuildConfig.APPSCHEME}.onelink.me/a?deep_link_value=event-detail&deep_link_sub5=7")
|
||||
)
|
||||
)
|
||||
)
|
||||
val mismatch = requireNotNull(EventDeepLinkEntry.normalize(direct(7))).apply { putLong("event_id", 8L) }
|
||||
val forged = Bundle().apply {
|
||||
putString("deep_link_value", "event-detail")
|
||||
putLong("event_id", 7L)
|
||||
}
|
||||
listOf(invalid, sdkOwned, mismatch, forged).forEach { bundle ->
|
||||
bundle.putString("message_id", "9")
|
||||
bundle.putString("gift_application_no", "attacker")
|
||||
assertTrue(dispatch(activity, dispatcher, bundle))
|
||||
assertNull(shadowOf(activity).nextStartedActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `기존 두 Bundle 작성 seam은 이벤트 입력을 typed 정규화하고 data를 우선한다`() {
|
||||
listOf(
|
||||
Robolectric.buildActivity(DeepLinkActivity::class.java).get() to "buildDeepLinkExtras",
|
||||
Robolectric.buildActivity(MainV2Activity::class.java).get() to "resolveDeepLinkBundle"
|
||||
).forEach { (activity, normalizer) ->
|
||||
val entry = direct(7).putExtra("deepLink", direct(8).dataString)
|
||||
.putExtra(Constants.EXTRA_DATA, Bundle().apply { putString("content_id", "9") })
|
||||
val bundle = activity.javaClass.getDeclaredMethod(normalizer, Intent::class.java)
|
||||
.apply { isAccessible = true }.invoke(activity, entry) as Bundle
|
||||
assertEquals(7L, bundle.get("event_id"))
|
||||
assertEquals("event-detail", bundle.getString("deep_link_value"))
|
||||
assertNull(bundle.getString("content_id"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Main 초기 지연 라우팅도 guest 이벤트를 공통 dispatcher로 단회 실행한다`() {
|
||||
val entry = direct(7)
|
||||
val main = Robolectric.buildActivity(MainV2Activity::class.java, entry).get()
|
||||
MainV2Activity::class.java.getDeclaredField("routeLoadingDialog").apply { isAccessible = true }
|
||||
.set(main, mockk<LoadingDialog>(relaxed = true))
|
||||
val runnable = MainV2Activity::class.java.getDeclaredField("deferredRouteRunnable")
|
||||
.apply { isAccessible = true }.get(main) as Runnable
|
||||
runnable.run()
|
||||
assertDetail(shadowOf(main).nextStartedActivity, 7)
|
||||
assertTrue(main.isEventDeepLinkRoutingReady)
|
||||
runnable.run()
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Main guest의 invalid와 SDK 입력은 live 메타데이터가 있어도 지연이나 fallback 없이 종료한다`() {
|
||||
LiveRoomActivity.isForeground = true
|
||||
val controller = Robolectric.buildActivity(MainV2Activity::class.java)
|
||||
val main = controller.get()
|
||||
MainV2Activity::class.java.getDeclaredField("routeLoadingDialog").apply { isAccessible = true }
|
||||
.set(main, mockk<LoadingDialog>(relaxed = true))
|
||||
listOf(
|
||||
"${BuildConfig.APPSCHEME}://event-detail/0?room_id=9",
|
||||
"https://${BuildConfig.APPSCHEME}.onelink.me/a?deep_link_value=event-detail&deep_link_sub5=7&room_id=9"
|
||||
).forEach { url ->
|
||||
controller.newIntent(Intent().putExtra(Constants.EXTRA_DATA, Bundle().apply { putString("deepLink", url) }))
|
||||
assertNull(shadowOf(main).nextStartedActivity)
|
||||
assertTrue(main.isEventDeepLinkRoutingReady)
|
||||
}
|
||||
}
|
||||
|
||||
private fun dispatch(activity: Activity, dispatcher: String, bundle: Bundle): Boolean =
|
||||
activity.javaClass.getDeclaredMethod(dispatcher, Bundle::class.java)
|
||||
.apply { isAccessible = true }.invoke(activity, bundle) as Boolean
|
||||
|
||||
private fun direct(id: Long) = Intent(Intent.ACTION_VIEW, Uri.parse("${BuildConfig.APPSCHEME}://event-detail/$id"))
|
||||
|
||||
private fun execute(activity: MainV2Activity, entry: Intent) {
|
||||
MainV2Activity::class.java.getDeclaredMethod("executeDeeplink", Intent::class.java)
|
||||
.apply { isAccessible = true }.invoke(activity, entry)
|
||||
}
|
||||
|
||||
private fun assertDetail(intent: Intent?, id: Long) {
|
||||
assertEquals(EventDetailActivity::class.java.name, intent?.component?.className)
|
||||
assertEquals(id, intent?.getLongExtra(EventDetailActivity.EXTRA_EVENT_ID, 0))
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,28 @@ class EventDetailNavigationTest {
|
||||
SharedPreferenceManager.resetForTest()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `직접 이벤트 딥링크는 신규 상세의 fake API에 원본 Long ID를 조회한다`() {
|
||||
val previousForeground = kr.co.vividnext.sodalive.app.SodaLiveApp.isAppInForeground
|
||||
kr.co.vividnext.sodalive.app.SodaLiveApp.isAppInForeground = true
|
||||
try {
|
||||
val entry = Robolectric.buildActivity(
|
||||
kr.co.vividnext.sodalive.main.DeepLinkActivity::class.java,
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
android.net.Uri.parse("${kr.co.vividnext.sodalive.BuildConfig.APPSCHEME}://event-detail/9223372036854775807")
|
||||
)
|
||||
).setup()
|
||||
val detail = open(shadowOf(entry.get()).nextStartedActivity)
|
||||
assertEquals(listOf(Long.MAX_VALUE), api.requests)
|
||||
assertFalse(detail.get().isFinishing)
|
||||
close(detail)
|
||||
entry.pause().stop().destroy()
|
||||
} finally {
|
||||
kr.co.vividnext.sodalive.app.SodaLiveApp.isAppInForeground = previousForeground
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ID 전용 진입은 Int 초과와 Long 최대 ID를 그대로 조회한다`() {
|
||||
listOf(Int.MAX_VALUE.toLong() + 1L, Long.MAX_VALUE).forEach { id ->
|
||||
|
||||
+2
-2
@@ -26,13 +26,13 @@ class MainV2AudioNotificationRouteSourceTest {
|
||||
fun `오디오 알림 route는 채팅 필터 이후 딥링크 이전에 처리된다`() {
|
||||
val onNewIntentSource = source.substringFrom("override fun onNewIntent(intent: Intent)")
|
||||
assertBefore(onNewIntentSource, "if (intent.hasExtra(EXTRA_CHAT_FILTER))", "handleAudioNotificationRoute(intent)")
|
||||
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "isV2AccessAllowed(AccessRequirement.Login)")
|
||||
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "isDeepLinkAccessAllowed(intent)")
|
||||
assertBefore(onNewIntentSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
|
||||
|
||||
val onCreateSource = source.substringFrom("override fun onCreate(savedInstanceState: Bundle?)")
|
||||
val deferredRouteSource = source.substringFrom("private val deferredRouteRunnable = Runnable")
|
||||
assertTrue(onCreateSource.contains("handler.postDelayed(deferredRouteRunnable, 1000)"))
|
||||
assertBefore(deferredRouteSource, "handleAudioNotificationRoute(intent)", "isV2AccessAllowed(AccessRequirement.Login)")
|
||||
assertBefore(deferredRouteSource, "handleAudioNotificationRoute(intent)", "isDeepLinkAccessAllowed(intent)")
|
||||
assertBefore(deferredRouteSource, "handleAudioNotificationRoute(intent)", "executeDeeplink(intent)")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user