diff --git a/app/src/main/java/kr/co/vividnext/sodalive/app/SodaLiveApp.kt b/app/src/main/java/kr/co/vividnext/sodalive/app/SodaLiveApp.kt index 5979a264..02a002f0 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/app/SodaLiveApp.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/app/SodaLiveApp.kt @@ -22,9 +22,13 @@ import kr.co.vividnext.sodalive.common.SharedPreferenceManager import kr.co.vividnext.sodalive.common.SodaLiveApplicationHolder import kr.co.vividnext.sodalive.di.AppDI import kr.co.vividnext.sodalive.tracking.FirebaseTracking +import kr.co.vividnext.sodalive.v2.event.EventDeepLinkDelivery +import kr.co.vividnext.sodalive.v2.event.EventDeepLinkContract import tech.notifly.Notifly class SodaLiveApp : Application(), DefaultLifecycleObserver { + val eventDeepLinkDelivery by lazy { EventDeepLinkDelivery(this) } + override fun onCreate() { super.onCreate() ProcessLifecycleOwner.get().lifecycle.addObserver(this) @@ -77,9 +81,9 @@ class SodaLiveApp : Application(), DefaultLifecycleObserver { private fun setupAppsFlyer() { // Appsflyer SDK 초기화 AppsFlyerLib.getInstance().init("tWF2wbJ5nSkya5Ru9mGcPU", null, this) - AppsFlyerLib.getInstance().start(this) // 딥링크 및 디퍼드 딥링크 처리 + val eventDelivery = eventDeepLinkDelivery AppsFlyerLib.getInstance().subscribeForDeepLink { deepLinkResult -> when (deepLinkResult.status) { DeepLinkResult.Status.FOUND -> { @@ -112,6 +116,10 @@ class SodaLiveApp : Application(), DefaultLifecycleObserver { )?.toLongOrNull() ?: 0L logUtmInFirebase() + EventDeepLinkContract.parseUdl( + deepLink?.getStringValue("deep_link_value"), + deepLink?.getStringValue("deep_link_sub5") + )?.let(eventDelivery::offer) } DeepLinkResult.Status.NOT_FOUND -> Logger.d( @@ -123,6 +131,7 @@ class SodaLiveApp : Application(), DefaultLifecycleObserver { ) } } + AppsFlyerLib.getInstance().start(this) } private fun logUtmInFirebase() { diff --git a/app/src/main/java/kr/co/vividnext/sodalive/main/DeepLinkActivity.kt b/app/src/main/java/kr/co/vividnext/sodalive/main/DeepLinkActivity.kt index c09f9486..3dc064fe 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/main/DeepLinkActivity.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/main/DeepLinkActivity.kt @@ -20,6 +20,9 @@ import kr.co.vividnext.sodalive.v2.content.action.ContentActionCommand import kr.co.vividnext.sodalive.v2.content.action.handleContentAction import kr.co.vividnext.sodalive.v2.creator.action.CreatorActionCommand import kr.co.vividnext.sodalive.v2.creator.action.handleCreatorAction +import kr.co.vividnext.sodalive.v2.event.EventDeepLinkContract +import kr.co.vividnext.sodalive.v2.event.EventDeepLinkEntry +import kr.co.vividnext.sodalive.v2.event.EventDetailActivity import kr.co.vividnext.sodalive.v2.gift.GiftDetailActivity import kr.co.vividnext.sodalive.v2.main.MainV2Activity import java.util.Locale @@ -29,8 +32,6 @@ class DeepLinkActivity : AppCompatActivity() { super.onCreate(savedInstanceState) val data: Uri? = intent?.data - val deepLinkExtras = buildDeepLinkExtras(intent) - val deepLinkUrl = deepLinkExtras?.getString("deep_link") if (data != null && data.scheme != null) { val host = data.host @@ -48,6 +49,18 @@ class DeepLinkActivity : AppCompatActivity() { } } + EventDeepLinkEntry.restore(intent, savedInstanceState) + val deepLinkExtras = buildDeepLinkExtras(intent) + val deepLinkUrl = deepLinkExtras?.getString("deep_link") + val eventRoute = deepLinkExtras?.let(EventDeepLinkEntry::route) ?: EventDeepLinkContract.Unrelated + if (eventRoute == EventDeepLinkContract.InvalidEvent || + (eventRoute != EventDeepLinkContract.Unrelated && !EventDeepLinkEntry.forward(intent)) || + (eventRoute == EventDeepLinkContract.SdkOwned && SodaLiveApp.isAppInForeground) + ) { + finish() + return + } + if (SodaLiveApp.isAppInForeground && deepLinkExtras != null && isDmChatDeepLink(deepLinkExtras)) { if (routeForegroundDeepLink(deepLinkExtras)) { finish() @@ -94,7 +107,13 @@ class DeepLinkActivity : AppCompatActivity() { finish() } + override fun onSaveInstanceState(outState: Bundle) { + EventDeepLinkEntry.save(intent, outState) + super.onSaveInstanceState(outState) + } + private fun buildDeepLinkExtras(intent: Intent): Bundle? { + EventDeepLinkEntry.normalize(intent)?.let { return it } val extras = Bundle() val data = intent.data @@ -264,6 +283,16 @@ class DeepLinkActivity : AppCompatActivity() { } private fun routeForegroundDeepLink(bundle: Bundle): Boolean { + when (val route = EventDeepLinkEntry.route(bundle)) { + is EventDeepLinkContract.Direct -> { + if (EventDeepLinkEntry.consume(bundle)) { + startActivity(EventDetailActivity.newIntent(this, route.eventId)) + } + return true + } + EventDeepLinkContract.InvalidEvent, EventDeepLinkContract.SdkOwned -> return true + EventDeepLinkContract.Unrelated -> Unit + } val giftApplicationNo = bundle.getString("gift_application_no")?.takeIf { it.isNotBlank() } val roomId = bundle.getString("room_id")?.toLongOrNull() ?: bundle.getLong(Constants.EXTRA_ROOM_ID).takeIf { it > 0 } diff --git a/app/src/main/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkDelivery.kt b/app/src/main/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkDelivery.kt new file mode 100644 index 00000000..dee40da1 --- /dev/null +++ b/app/src/main/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkDelivery.kt @@ -0,0 +1,68 @@ +package kr.co.vividnext.sodalive.v2.event + +import android.app.Activity +import android.app.Application +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import kr.co.vividnext.sodalive.BuildConfig +import kr.co.vividnext.sodalive.main.DeepLinkActivity +import kr.co.vividnext.sodalive.splash.SplashActivity +import kr.co.vividnext.sodalive.v2.main.MainV2Activity +import java.lang.ref.WeakReference +import java.util.ArrayDeque + +class EventDeepLinkDelivery(application: Application) : Application.ActivityLifecycleCallbacks { + private val handler = Handler(Looper.getMainLooper()) + private val pending = ArrayDeque() + private var resumed = WeakReference(null) + + init { + application.registerActivityLifecycleCallbacks(this) + } + + fun offer(eventId: Long) { + handler.post { + pending.addLast(eventId) + drain() + } + } + + fun onMainRoutingReady() { + handler.post { drain() } + } + + override fun onActivityResumed(activity: Activity) { + resumed = WeakReference(activity) + handler.post { drain() } + } + + override fun onActivityPaused(activity: Activity) { + if (resumed.get() === activity) resumed.clear() + } + + override fun onActivityDestroyed(activity: Activity) { + if (resumed.get() === activity) resumed.clear() + } + + private fun drain() { + while (pending.isNotEmpty()) { + val host = resumed.get() ?: return + if (host.isFinishing || host.isDestroyed || host is SplashActivity || host is DeepLinkActivity) return + if (host is MainV2Activity && !host.isEventDeepLinkRoutingReady) return + val handoff = Intent(host, DeepLinkActivity::class.java).apply { + action = Intent.ACTION_VIEW + data = EventDeepLinkContract.canonicalUri(pending.first, BuildConfig.APPSCHEME) + } + EventDeepLinkEntry.payload(handoff) + host.startActivity(handoff) + pending.removeFirst() + } + } + + override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit + override fun onActivityStarted(activity: Activity) = Unit + override fun onActivityStopped(activity: Activity) = Unit + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit +} diff --git a/app/src/main/java/kr/co/vividnext/sodalive/v2/main/MainV2Activity.kt b/app/src/main/java/kr/co/vividnext/sodalive/v2/main/MainV2Activity.kt index 45c11372..25e4cf0c 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/v2/main/MainV2Activity.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/v2/main/MainV2Activity.kt @@ -41,6 +41,7 @@ import com.orhanobut.logger.Logger import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kr.co.vividnext.sodalive.R +import kr.co.vividnext.sodalive.app.SodaLiveApp import kr.co.vividnext.sodalive.audio_content.AudioContentPlayService import kr.co.vividnext.sodalive.audio_content.detail.AudioContentDetailActivity import kr.co.vividnext.sodalive.audio_content.player.AudioContentPlayerFragment @@ -74,6 +75,8 @@ import kr.co.vividnext.sodalive.v2.content.action.ContentActionCommand import kr.co.vividnext.sodalive.v2.content.action.handleContentAction import kr.co.vividnext.sodalive.v2.creator.action.CreatorActionCommand import kr.co.vividnext.sodalive.v2.creator.action.handleCreatorAction +import kr.co.vividnext.sodalive.v2.event.EventDeepLinkContract +import kr.co.vividnext.sodalive.v2.event.EventDeepLinkEntry import kr.co.vividnext.sodalive.v2.gift.GiftDetailActivity import kr.co.vividnext.sodalive.v2.live.action.LiveActionCoordinator import kr.co.vividnext.sodalive.v2.live.action.LiveCreationResult @@ -90,6 +93,9 @@ import kotlin.math.max @UnstableApi class MainV2Activity : BaseActivity(ActivityMainV2Binding::inflate) { + var isEventDeepLinkRoutingReady = false + private set + private val viewModel: MainV2ViewModel by inject() private val liveViewModel: LiveViewModel by inject() private val liveActionCoordinator: LiveActionCoordinator by lazy { @@ -113,12 +119,13 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding if (isFinishing || isDestroyed) return@Runnable try { - if (!handleAudioNotificationRoute(intent) && isV2AccessAllowed(AccessRequirement.Login)) { + if (!handleAudioNotificationRoute(intent) && isDeepLinkAccessAllowed(intent)) { executeDeeplink(intent) } } finally { isDeferredRouteLoading = false updateRouteLoadingDialog() + markEventDeepLinkRoutingReady() } } private val audioContentReceiver = AudioContentReceiver() @@ -148,6 +155,7 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + EventDeepLinkEntry.restore(intent, savedInstanceState) overrideRootWindowInsets() isDeferredRouteLoading = @@ -185,27 +193,42 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) setIntent(intent) + isEventDeepLinkRoutingReady = false handler.removeCallbacks(deferredRouteRunnable) isDeferredRouteLoading = false updateRouteLoadingDialog() - if (intent.hasExtra(EXTRA_CHAT_FILTER)) { - openChatWithInitialFilter() - return - } + try { + if (intent.hasExtra(EXTRA_CHAT_FILTER)) { + openChatWithInitialFilter() + return + } - if (handleAudioNotificationRoute(intent) || !isV2AccessAllowed(AccessRequirement.Login)) { - return - } + if (handleAudioNotificationRoute(intent) || !isDeepLinkAccessAllowed(intent)) { + return + } - if (LiveRoomActivity.isForeground && isLiveRoomDeepLink(intent)) { - isDeferredRouteLoading = true - updateRouteLoadingDialog() - handler.postDelayed(deferredRouteRunnable, 1000) - return - } + if (LiveRoomActivity.isForeground && isLiveRoomDeepLink(intent)) { + isDeferredRouteLoading = true + updateRouteLoadingDialog() + handler.postDelayed(deferredRouteRunnable, 1000) + return + } - executeDeeplink(intent) + executeDeeplink(intent) + } finally { + if (!isDeferredRouteLoading) markEventDeepLinkRoutingReady() + } + } + + private fun markEventDeepLinkRoutingReady() { + isEventDeepLinkRoutingReady = true + (application as? SodaLiveApp)?.eventDeepLinkDelivery?.onMainRoutingReady() + } + + override fun onSaveInstanceState(outState: Bundle) { + EventDeepLinkEntry.save(intent, outState) + super.onSaveInstanceState(outState) } @SuppressLint("UnspecifiedRegisterReceiverFlag") @@ -673,6 +696,7 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding return when (route) { ROUTE_AUDIO_PLAYER -> { + EventDeepLinkEntry.consume(intent) ensureV2Access(AccessRequirement.Login) { showPlayerFragment() } @@ -683,6 +707,7 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding val contentId = intent.getLongExtra(Constants.EXTRA_AUDIO_CONTENT_ID, 0) intent.removeExtra(Constants.EXTRA_AUDIO_CONTENT_ID) if (contentId > 0) { + EventDeepLinkEntry.consume(intent) handleContentAction(ContentActionCommand.AudioDetail(contentId)) } contentId > 0 @@ -784,7 +809,7 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding val routeBundle = resolveDeepLinkBundle(intent) ?: return val giftApplicationNo = routeBundle.getString("gift_application_no")?.takeIf { it.isNotBlank() } - if (executeBundleRoute(routeBundle)) { + if (executeBundleRoute(routeBundle) && EventDeepLinkEntry.route(routeBundle) == EventDeepLinkContract.Unrelated) { if (giftApplicationNo != null) { intent.removeExtra(Constants.EXTRA_DATA) } @@ -792,7 +817,14 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding } } + private fun isDeepLinkAccessAllowed(intent: Intent): Boolean { + val bundle = resolveDeepLinkBundle(intent) + return (bundle != null && EventDeepLinkEntry.route(bundle) != EventDeepLinkContract.Unrelated) || + isV2AccessAllowed(AccessRequirement.Login) + } + private fun resolveDeepLinkBundle(intent: Intent): Bundle? { + EventDeepLinkEntry.normalize(intent)?.let { return it } val bundle = intent.getBundleExtra(Constants.EXTRA_DATA) ?: return null val deepLinkUrl = bundle.getString("deep_link") return if (!deepLinkUrl.isNullOrBlank()) { @@ -934,6 +966,16 @@ class MainV2Activity : BaseActivity(ActivityMainV2Binding } private fun executeBundleRoute(bundle: Bundle): Boolean { + when (val route = EventDeepLinkEntry.route(bundle)) { + is EventDeepLinkContract.Direct -> { + if (EventDeepLinkEntry.consume(bundle)) { + startActivity(kr.co.vividnext.sodalive.v2.event.EventDetailActivity.newIntent(this, route.eventId)) + } + return true + } + EventDeepLinkContract.InvalidEvent, EventDeepLinkContract.SdkOwned -> return true + EventDeepLinkContract.Unrelated -> Unit + } val giftApplicationNo = bundle.getString("gift_application_no")?.takeIf { it.isNotBlank() } val roomId = bundle.getString("room_id")?.toLongOrNull() ?: bundle.getLong(Constants.EXTRA_ROOM_ID).takeIf { it > 0 } diff --git a/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventAppsFlyerIntegrationTest.kt b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventAppsFlyerIntegrationTest.kt new file mode 100644 index 00000000..dba93df1 --- /dev/null +++ b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventAppsFlyerIntegrationTest.kt @@ -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() + 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(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() + every { payload.getStringValue(any()) } answers { + when (firstArg()) { + "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() + every { result.status } returns DeepLinkResult.Status.FOUND + every { result.deepLink } returns payload + listener.captured.onDeepLinking(result) + } +} diff --git a/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkDeliveryTest.kt b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkDeliveryTest.kt new file mode 100644 index 00000000..b2bf61f4 --- /dev/null +++ b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkDeliveryTest.kt @@ -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(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() + 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() + 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)) + } +} diff --git a/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkRoutingTest.kt b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkRoutingTest.kt new file mode 100644 index 00000000..c0dc7e05 --- /dev/null +++ b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDeepLinkRoutingTest.kt @@ -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(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(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() + 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(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(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)) + } +} diff --git a/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDetailNavigationTest.kt b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDetailNavigationTest.kt index d44a661a..f0b8ff08 100644 --- a/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDetailNavigationTest.kt +++ b/app/src/test/java/kr/co/vividnext/sodalive/v2/event/EventDetailNavigationTest.kt @@ -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 -> diff --git a/app/src/test/java/kr/co/vividnext/sodalive/v2/main/MainV2AudioNotificationRouteSourceTest.kt b/app/src/test/java/kr/co/vividnext/sodalive/v2/main/MainV2AudioNotificationRouteSourceTest.kt index e81c563e..2bbf2921 100644 --- a/app/src/test/java/kr/co/vividnext/sodalive/v2/main/MainV2AudioNotificationRouteSourceTest.kt +++ b/app/src/test/java/kr/co/vividnext/sodalive/v2/main/MainV2AudioNotificationRouteSourceTest.kt @@ -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)") }