react-native-daro 2.0.0-rc.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/android/build.gradle +2 -1
  2. package/android/src/main/java/com/daro/reactnative/DaroRNModule.kt +12 -0
  3. package/android/src/main/java/com/daro/reactnative/event/DaroRNEvent.kt +2 -1
  4. package/android/src/main/java/com/daro/reactnative/impl/DaroRNLightPopupModuleImpl.kt +86 -73
  5. package/android/src/main/java/com/daro/reactnative/impl/LightPopupRequest.kt +51 -0
  6. package/android/src/main/java/com/daro/reactnative/view/DaroRNAdNativeViewContainer.kt +20 -0
  7. package/android/src/oldarch/java/com/daro/reactnative/DaroRNModuleSpec.kt +3 -0
  8. package/android/src/test/java/com/daro/reactnative/impl/LightPopupRequestTest.kt +62 -0
  9. package/ios/DaroRNModule+LightPopup.swift +130 -102
  10. package/ios/DaroRNModule+Qa.swift +38 -37
  11. package/ios/DaroRNModule.mm +1 -0
  12. package/ios/DaroRNModule.swift +12 -0
  13. package/ios/Fabric/DaroRNNativeAdComponentView.mm +14 -0
  14. package/ios/Paper/DaroRNNativeAdViewManager.m +1 -0
  15. package/ios/Shared/DaroRNAdEventSink.swift +1 -0
  16. package/ios/Shared/DaroRNNativeAdView.swift +8 -0
  17. package/lib/commonjs/DaroRNNativeAdViewNativeComponent.ts +3 -0
  18. package/lib/commonjs/LightPopupAd.js +15 -1
  19. package/lib/commonjs/LightPopupAd.js.map +1 -1
  20. package/lib/commonjs/NativeDaroModule.js.map +1 -1
  21. package/lib/commonjs/hooks/useLightPopupAd.js +6 -4
  22. package/lib/commonjs/hooks/useLightPopupAd.js.map +1 -1
  23. package/lib/commonjs/nativeAd/NativeAdView.js +7 -0
  24. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  25. package/lib/commonjs/types/NativeAdViewProps.js +21 -0
  26. package/lib/commonjs/types/NativeAdViewProps.js.map +1 -1
  27. package/lib/module/DaroRNNativeAdViewNativeComponent.ts +3 -0
  28. package/lib/module/LightPopupAd.js +15 -1
  29. package/lib/module/LightPopupAd.js.map +1 -1
  30. package/lib/module/NativeDaroModule.js.map +1 -1
  31. package/lib/module/hooks/useLightPopupAd.js +6 -4
  32. package/lib/module/hooks/useLightPopupAd.js.map +1 -1
  33. package/lib/module/nativeAd/NativeAdView.js +7 -0
  34. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  35. package/lib/module/types/NativeAdViewProps.js +22 -1
  36. package/lib/module/types/NativeAdViewProps.js.map +1 -1
  37. package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts +3 -0
  38. package/lib/typescript/commonjs/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/src/LightPopupAd.d.ts +3 -0
  40. package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +1 -0
  42. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +2 -0
  45. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
  46. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts +9 -0
  47. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
  48. package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts +3 -0
  49. package/lib/typescript/module/src/DaroRNNativeAdViewNativeComponent.d.ts.map +1 -1
  50. package/lib/typescript/module/src/LightPopupAd.d.ts +3 -0
  51. package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
  52. package/lib/typescript/module/src/NativeDaroModule.d.ts +1 -0
  53. package/lib/typescript/module/src/NativeDaroModule.d.ts.map +1 -1
  54. package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts.map +1 -1
  55. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +2 -0
  56. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
  57. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts +9 -0
  58. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
  59. package/package.json +6 -3
  60. package/plugin/build/withAndroid.js +2 -2
  61. package/react-native-daro.podspec +1 -1
  62. package/src/DaroRNNativeAdViewNativeComponent.ts +3 -0
  63. package/src/LightPopupAd.ts +18 -1
  64. package/src/NativeDaroModule.ts +1 -0
  65. package/src/hooks/useLightPopupAd.ts +6 -4
  66. package/src/nativeAd/NativeAdView.tsx +21 -0
  67. package/src/types/NativeAdViewProps.ts +10 -0
@@ -33,7 +33,7 @@ apply plugin: "kotlin-android"
33
33
  apply plugin: "com.facebook.react"
34
34
 
35
35
  // 통합 daro-sdk 는 AdMob·MAX 미디에이션을 한 아티팩트에 담는다 — 빌드타임 분기가 없다.
36
- def daroSdkDependency = "so.daro:daro-sdk:2.0.0-rc.2"
36
+ def daroSdkDependency = "so.daro:daro-sdk:2.0.1"
37
37
  def isNewArchitectureEnabled =
38
38
  (project.hasProperty("newArchEnabled") && project.property("newArchEnabled").toString().toBoolean()) ||
39
39
  (project.hasProperty("react.newArchEnabled") && project.property("react.newArchEnabled").toString().toBoolean())
@@ -77,6 +77,7 @@ android {
77
77
  }
78
78
 
79
79
  dependencies {
80
+ testImplementation "junit:junit:4.13.2"
80
81
  implementation "com.facebook.react:react-android"
81
82
  compileOnly daroSdkDependency
82
83
  // QA 표면(DaroQaProbe)이 벤더 API 를 직접 부른다 — 런타임 클래스는 daro-sdk 가
@@ -292,6 +292,8 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
292
292
  internal abstract class DaroRNLightPopupModule(context: ReactContext) :
293
293
  DaroRNComponentModule(context) {
294
294
  abstract fun isLightPopupReady(requestId: Int, adUnitId: String, promise: Promise)
295
+ abstract fun destroyLightPopup(requestId: Int)
296
+ abstract fun invalidate()
295
297
  abstract fun loadLightPopup(requestId: Int, adUnitId: String)
296
298
  abstract fun showLightPopup(requestId: Int, adUnitId: String)
297
299
 
@@ -307,6 +309,16 @@ class DaroRNModule(reactContext: ReactApplicationContext) :
307
309
  getCurrentActivity = { reactApplicationContext.currentActivity }
308
310
  )
309
311
 
312
+ override fun invalidate() {
313
+ daroRNLightPopupModule.invalidate()
314
+ super.invalidate()
315
+ }
316
+
317
+ @ReactMethod
318
+ override fun destroyLightPopup(requestId: Double, adUnitId: String) {
319
+ daroRNLightPopupModule.destroyLightPopup(requestId.toInt())
320
+ }
321
+
310
322
  @ReactMethod
311
323
  override fun isLightPopupReady(requestId: Double, adUnitId: String, promise: Promise) {
312
324
  daroRNLightPopupModule.isLightPopupReady(requestId.toInt(), adUnitId, promise)
@@ -64,5 +64,6 @@ internal enum class AdViewEvent(
64
64
  ON_AD_CLICKED("onAdClickedEvent", "topAdClickedEvent"),
65
65
  ON_AD_FAILED_TO_LOAD("onAdLoadFailedEvent", "topAdLoadFailedEvent"),
66
66
  ON_AD_IMPRESSION("onAdImpressionRecordedEvent", "topAdImpressionRecordedEvent"),
67
- ON_AD_LOADED("onAdLoadedEvent", "topAdLoadedEvent");
67
+ ON_AD_LOADED("onAdLoadedEvent", "topAdLoadedEvent"),
68
+ ON_NATIVE_ASSETS_LOADED("onNativeAdAssetLoadedEvent", "topNativeAdAssetLoadedEvent");
68
69
  }
@@ -5,6 +5,7 @@ import androidx.core.graphics.toColorInt
5
5
  import com.daro.reactnative.DaroRNModule
6
6
  import com.daro.reactnative.event.LightPopupEvent
7
7
  import com.daro.reactnative.util.AdInfoUtil
8
+ import com.facebook.react.bridge.LifecycleEventListener
8
9
  import com.facebook.react.bridge.Promise
9
10
  import com.facebook.react.bridge.ReactApplicationContext
10
11
  import com.facebook.react.bridge.ReadableMap
@@ -21,22 +22,43 @@ import droom.daro.loader.DaroLightPopupAdLoader
21
22
  internal class DaroRNLightPopupModuleImpl(
22
23
  context: ReactApplicationContext,
23
24
  private val getCurrentActivity: () -> Activity?,
24
- ) : DaroRNModule.DaroRNLightPopupModule(context) {
25
+ ) : DaroRNModule.DaroRNLightPopupModule(context), LifecycleEventListener {
25
26
 
26
27
  private val currentActivity: Activity?
27
28
  get() = getCurrentActivity()
28
29
 
29
- private val lightpopupAdMap: MutableMap<Int, DaroLightPopupAd> = mutableMapOf()
30
+ private val requests = mutableMapOf<Int, LightPopupRequest<DaroLightPopupAd>>()
31
+ private var invalidated = false
32
+
33
+ init { context.addLifecycleEventListener(this) }
30
34
  private val optionMap: MutableMap<Int, DaroLightPopupAdOptions> = mutableMapOf()
31
- private val loaderMap: MutableMap<Int, DaroLightPopupAdLoader> = mutableMapOf()
32
35
 
33
36
  override fun isLightPopupReady(requestId: Int, adUnitId: String, promise: Promise) {
34
- promise.resolve(retrieveAd(requestId) != null)
37
+ context.runOnUiQueueThread { promise.resolve(requests[requestId]?.isReady == true) }
35
38
  }
36
39
 
37
40
  override fun loadLightPopup(requestId: Int, adUnitId: String) {
38
41
  context.runOnUiQueueThread {
39
- retrieveLoader(requestId, adUnitId).load()
42
+ if (invalidated) return@runOnUiQueueThread
43
+ requests.remove(requestId)?.destroy()
44
+ val loader = DaroLightPopupAdLoader(
45
+ context, DaroLightPopupAdUnit(adUnitId, optionMap[requestId] ?: DaroLightPopupAdOptions())
46
+ )
47
+ val request = LightPopupRequest(loader::destroy, DaroLightPopupAd::destroy)
48
+ requests[requestId] = request
49
+ loader.setListener(object : DaroLightPopupAdLoaderListener {
50
+ override fun onAdLoadSuccess(ad: DaroLightPopupAd, responseInfo: DaroAdInfo) {
51
+ if (!request.accept(ad)) return
52
+ sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_LOADED_EVENT,
53
+ AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo))
54
+ }
55
+ override fun onAdLoadFail(err: DaroAdLoadError) {
56
+ if (!request.active) return
57
+ sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_LOAD_FAILED_EVENT,
58
+ AdInfoUtil.getAdLoadFailedInfo(requestId, adUnitId, err))
59
+ }
60
+ })
61
+ loader.load()
40
62
  }
41
63
  }
42
64
 
@@ -67,84 +89,75 @@ internal class DaroRNLightPopupModuleImpl(
67
89
  )
68
90
  }
69
91
 
70
- optionMap[requestId] = newOption
92
+ context.runOnUiQueueThread {
93
+ if (!invalidated) optionMap[requestId] = newOption
94
+ }
71
95
  }
72
96
 
73
97
  override fun showLightPopup(requestId: Int, adUnitId: String) {
74
- currentActivity?.let {
75
- it.runOnUiThread {
76
- retrieveAd(requestId)?.apply {
77
- setListener(object : DaroLightPopupAdListener {
78
- override fun onDismiss(ad: DaroAdInfo) {
79
- sendNativeEvent(
80
- event = LightPopupEvent.ON_LIGHTPOPUP_HIDDEN_EVENT,
81
- params = AdInfoUtil.getAdInfo(requestId, adUnitId, ad),
82
- )
83
- }
84
-
85
- override fun onFailedToShow(ad: DaroAdInfo, error: DaroAdDisplayFailError) {
86
- sendNativeEvent(
87
- event = LightPopupEvent.ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT,
88
- params = AdInfoUtil.getAdDisplayFailedInfo(requestId, adUnitId, ad, error),
89
- )
90
- }
91
-
92
- override fun onShown(ad: DaroAdInfo) {
93
- sendNativeEvent(
94
- event = LightPopupEvent.ON_LIGHTPOPUP_DISPLAYED_EVENT,
95
- params = AdInfoUtil.getAdInfo(requestId, adUnitId, ad),
96
- )
97
-
98
- lightpopupAdMap.remove(requestId)
99
- }
100
-
101
- override fun onAdClicked(responseInfo: DaroAdInfo) {
102
- sendNativeEvent(
103
- event = LightPopupEvent.ON_LIGHTPOPUP_CLICKED_EVENT,
104
- params = AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo),
105
- )
106
- }
107
-
108
- override fun onAdImpression(responseInfo: DaroAdInfo) {
109
- sendNativeEvent(
110
- event = LightPopupEvent.ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
111
- params = AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo),
112
- )
113
- }
114
- })
115
-
116
- show(it)
98
+ context.runOnUiQueueThread {
99
+ val activity = currentActivity ?: return@runOnUiQueueThread
100
+ val request = requests[requestId] ?: return@runOnUiQueueThread
101
+ val popup = request.takeForPresentation() ?: return@runOnUiQueueThread
102
+ popup.setListener(object : DaroLightPopupAdListener {
103
+ override fun onDismiss(ad: DaroAdInfo) {
104
+ if (!request.ownsPresentation(popup)) return
105
+ request.finishPresentation(popup)
106
+ sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_HIDDEN_EVENT,
107
+ AdInfoUtil.getAdInfo(requestId, adUnitId, ad))
117
108
  }
118
- }
109
+ override fun onFailedToShow(ad: DaroAdInfo, error: DaroAdDisplayFailError) {
110
+ if (!request.ownsPresentation(popup)) return
111
+ request.finishPresentation(popup)
112
+ sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_AD_FAILED_TO_DISPLAY_EVENT,
113
+ AdInfoUtil.getAdDisplayFailedInfo(requestId, adUnitId, ad, error))
114
+ }
115
+ override fun onShown(ad: DaroAdInfo) {
116
+ if (!request.ownsPresentation(popup)) return
117
+ sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_DISPLAYED_EVENT,
118
+ AdInfoUtil.getAdInfo(requestId, adUnitId, ad))
119
+ }
120
+ override fun onAdClicked(responseInfo: DaroAdInfo) {
121
+ if (!request.ownsPresentation(popup)) return
122
+ sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_CLICKED_EVENT,
123
+ AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo))
124
+ }
125
+ override fun onAdImpression(responseInfo: DaroAdInfo) {
126
+ if (!request.ownsPresentation(popup)) return
127
+ sendNativeEvent(LightPopupEvent.ON_LIGHTPOPUP_AD_IMPRESSION_RECORDED,
128
+ AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo))
129
+ }
130
+ })
131
+ popup.show(activity)
119
132
  }
120
133
  }
121
134
 
122
- private fun retrieveLoader(requestId: Int, adUnitId: String): DaroLightPopupAdLoader {
123
- return loaderMap[requestId] ?: DaroLightPopupAdLoader(
124
- context,
125
- DaroLightPopupAdUnit(adUnitId, optionMap[requestId] ?: DaroLightPopupAdOptions())
126
- ).also {
127
- loaderMap[requestId] = it
128
- it.setListener(object : DaroLightPopupAdLoaderListener {
129
- override fun onAdLoadSuccess(ad: DaroLightPopupAd, responseInfo: DaroAdInfo) {
130
- lightpopupAdMap[requestId] = ad
131
- sendNativeEvent(
132
- event = LightPopupEvent.ON_LIGHTPOPUP_LOADED_EVENT,
133
- params = AdInfoUtil.getAdInfo(requestId, adUnitId, responseInfo),
134
- )
135
- }
135
+ override fun destroyLightPopup(requestId: Int) {
136
+ context.runOnUiQueueThread {
137
+ requests.remove(requestId)?.destroy()
138
+ optionMap.remove(requestId)
139
+ }
140
+ }
136
141
 
137
- override fun onAdLoadFail(err: DaroAdLoadError) {
138
- sendNativeEvent(
139
- event = LightPopupEvent.ON_LIGHTPOPUP_LOAD_FAILED_EVENT,
140
- params = AdInfoUtil.getAdLoadFailedInfo(requestId, adUnitId, err),
141
- )
142
- }
143
- })
142
+ override fun invalidate() {
143
+ context.removeLifecycleEventListener(this)
144
+ context.runOnUiQueueThread {
145
+ invalidated = true
146
+ clearRequests()
144
147
  }
145
148
  }
146
149
 
147
- private fun retrieveAd(requestId: Int): DaroLightPopupAd? {
148
- return lightpopupAdMap[requestId]
150
+ private fun clearRequests() {
151
+ val owned = requests.values.toList()
152
+ requests.clear()
153
+ optionMap.clear()
154
+ owned.forEach { it.destroy() }
155
+ }
156
+
157
+ override fun onHostDestroy() {
158
+ // RN configuration changes do not destroy the host Activity; native layout handles rotation.
159
+ context.runOnUiQueueThread { clearRequests() }
149
160
  }
161
+ override fun onHostResume() = Unit
162
+ override fun onHostPause() = Unit
150
163
  }
@@ -0,0 +1,51 @@
1
+ package com.daro.reactnative.impl
2
+
3
+ /** Owns one native load and presentation. All access runs on the UI thread. */
4
+ internal class LightPopupRequest<Ad : Any>(
5
+ private val cancelLoad: () -> Unit,
6
+ private val destroyAd: (Ad) -> Unit,
7
+ ) {
8
+ var active = true
9
+ private set
10
+ private var loaded: Ad? = null
11
+ private var presented: Ad? = null
12
+ val isReady: Boolean get() = active && loaded != null && presented == null
13
+
14
+ fun accept(ad: Ad): Boolean {
15
+ if (!active) {
16
+ destroyAd(ad)
17
+ return false
18
+ }
19
+ loaded?.let(destroyAd)
20
+ loaded = ad
21
+ return true
22
+ }
23
+
24
+ fun takeForPresentation(): Ad? {
25
+ if (!isReady) return null
26
+ return loaded?.also {
27
+ loaded = null
28
+ presented = it
29
+ }
30
+ }
31
+
32
+ fun ownsPresentation(ad: Ad): Boolean = active && presented === ad
33
+
34
+ fun finishPresentation(ad: Ad) {
35
+ if (!ownsPresentation(ad)) return
36
+ presented = null
37
+ destroyAd(ad)
38
+ }
39
+
40
+ fun destroy() {
41
+ if (!active) return
42
+ active = false
43
+ val ready = loaded
44
+ val showing = presented
45
+ loaded = null
46
+ presented = null
47
+ cancelLoad()
48
+ ready?.let(destroyAd)
49
+ showing?.let(destroyAd)
50
+ }
51
+ }
@@ -15,6 +15,7 @@ import androidx.core.view.children
15
15
  import com.daro.reactnative.event.AdViewEvent
16
16
  import com.daro.reactnative.util.AdInfoUtil
17
17
  import com.daro.reactnative.util.EventEmitterUtil.sendNativeViewEvent
18
+ import com.facebook.react.bridge.Arguments
18
19
  import com.facebook.react.bridge.ReactContext
19
20
  import com.facebook.react.views.text.ReactTextView
20
21
  import com.facebook.react.views.view.ReactViewGroup
@@ -24,6 +25,7 @@ import droom.daro.core.model.DaroAdLoadError
24
25
  import droom.daro.core.model.DaroNativeAdBinder
25
26
  import droom.daro.core.model.DaroNativeAdChoicePlacement
26
27
  import droom.daro.core.model.DaroViewAd
28
+ import droom.daro.core.model.NativeAdAssetType
27
29
  import droom.daro.view.DaroAdViewListener
28
30
  import droom.daro.view.DaroNativeAdView
29
31
  import kotlin.math.min
@@ -194,6 +196,24 @@ class DaroRNAdNativeViewContainer(val context: ReactContext) : ReactViewGroup(co
194
196
  }
195
197
  }
196
198
 
199
+ override fun onNativeAdAssetLoaded(assetTypes: Set<NativeAdAssetType>) {
200
+ if (isDestroyed) return
201
+ val values = Arguments.createArray()
202
+ assetTypes.forEach { type ->
203
+ values.pushString(when (type.name) {
204
+ "TITLE" -> "title"
205
+ "BODY" -> "body"
206
+ "ICON" -> "icon"
207
+ "MEDIA" -> "media"
208
+ "CALL_TO_ACTION" -> "callToAction"
209
+ "ADVERTISER" -> "advertiser"
210
+ else -> type.name.lowercase()
211
+ })
212
+ }
213
+ sendNativeViewEvent(context, AdViewEvent.ON_NATIVE_ASSETS_LOADED,
214
+ Arguments.createMap().apply { putArray("assetTypes", values) })
215
+ }
216
+
197
217
  override fun onAdLoadSuccess(
198
218
  ad: DaroViewAd,
199
219
  adInfo: DaroAdInfo,
@@ -100,6 +100,9 @@ abstract class DaroRNModuleSpec(reactContext: ReactApplicationContext) :
100
100
  promise: Promise,
101
101
  )
102
102
 
103
+ @ReactMethod
104
+ abstract fun destroyLightPopup(requestId: Double, adUnitId: String)
105
+
103
106
  @ReactMethod
104
107
  abstract fun isLightPopupReady(requestId: Double, adUnitId: String, promise: Promise)
105
108
 
@@ -0,0 +1,62 @@
1
+ package com.daro.reactnative.impl
2
+
3
+ import org.junit.Assert.*
4
+ import org.junit.Test
5
+
6
+ class LightPopupRequestTest {
7
+ private class Ad(var destroyed: Int = 0)
8
+
9
+ @Test fun disposeCancelsLoaderAndRejectsLateDelivery() {
10
+ var cancellations = 0
11
+ val request = LightPopupRequest({ cancellations++ }, { ad: Ad -> ad.destroyed++ })
12
+ request.destroy()
13
+ request.destroy()
14
+ val late = Ad()
15
+ assertFalse(request.accept(late))
16
+ assertEquals(1, late.destroyed)
17
+ assertEquals(1, cancellations)
18
+ assertNull(request.takeForPresentation())
19
+ }
20
+
21
+ @Test fun showingConsumesReadinessButRetainsOwnershipUntilDismissal() {
22
+ val request = LightPopupRequest({}, { ad: Ad -> ad.destroyed++ })
23
+ val ad = Ad()
24
+ assertTrue(request.accept(ad))
25
+ assertTrue(request.isReady)
26
+ assertSame(ad, request.takeForPresentation())
27
+ assertFalse(request.isReady)
28
+ assertNull(request.takeForPresentation())
29
+ assertTrue(request.ownsPresentation(ad))
30
+ request.finishPresentation(ad)
31
+ request.finishPresentation(ad)
32
+ assertFalse(request.ownsPresentation(ad))
33
+ assertEquals(1, ad.destroyed)
34
+ }
35
+
36
+ @Test fun disposalDestroysPresentedAdAndRevokesEventsBeforeCleanup() {
37
+ lateinit var request: LightPopupRequest<Ad>
38
+ val ad = Ad()
39
+ request = LightPopupRequest({}, { value ->
40
+ assertFalse(request.ownsPresentation(value))
41
+ value.destroyed++
42
+ })
43
+ request.accept(ad)
44
+ request.takeForPresentation()
45
+ request.destroy()
46
+ assertEquals(1, ad.destroyed)
47
+ assertFalse(request.active)
48
+ }
49
+
50
+ @Test fun staleDismissCannotReleaseAnotherAd() {
51
+ val request = LightPopupRequest({}, { ad: Ad -> ad.destroyed++ })
52
+ val stale = Ad()
53
+ val current = Ad()
54
+ request.accept(stale)
55
+ request.accept(current)
56
+ request.takeForPresentation()
57
+ request.finishPresentation(stale)
58
+ assertTrue(request.ownsPresentation(current))
59
+ assertEquals(0, current.destroyed)
60
+ assertEquals(1, stale.destroyed)
61
+ }
62
+ }