Skip to content

Commit 4fa1716

Browse files
Introduce test cases for PUC (#807)
1 parent 53cf250 commit 4fa1716

File tree

10 files changed

+278
-0
lines changed

10 files changed

+278
-0
lines changed

Diff for: Example/PrebidInternalTestApp/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
android:hardwareAccelerated="true"
3636
android:label="@string/app_name"
3737
android:networkSecurityConfig="@xml/network_security_config"
38+
android:usesCleartextTraffic="true"
3839
android:theme="@style/SdkDemoTheme"
3940
tools:ignore="GoogleAppIndexingWarning">
4041
<activity

Diff for: Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/InternalTestApplication.kt

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class InternalTestApplication : MultiDexApplication() {
4242
super.onCreate()
4343
instance = this
4444

45+
WebView.setWebContentsDebuggingEnabled(true)
46+
4547
PrebidMobile.setPrebidServerHost(Host.createCustomHost("https://prebid-server-test-j.prebid.org/openrtb2/auction"))
4648
PrebidMobile.initializeSdk(this, null)
4749
PrebidMobile.setPrebidServerAccountId(getString(R.string.prebid_account_id_prod))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.prebid.mobile.renderingtestapp.plugplay.bidding.testing
2+
3+
import android.annotation.SuppressLint
4+
import android.os.Bundle
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.webkit.WebView
8+
import org.prebid.mobile.renderingtestapp.AdFragment
9+
import org.prebid.mobile.renderingtestapp.R
10+
import org.prebid.mobile.renderingtestapp.databinding.FragmentPucTestingBinding
11+
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment
12+
13+
/**
14+
* Example for testing memory leaks with original API ad units.
15+
* It doesn't use Google ad view because it causes another memory leak after loadAd().
16+
*/
17+
open class PrebidUniversalCreativeTestingFragment : AdFragment() {
18+
19+
override val layoutRes = R.layout.fragment_puc_testing
20+
21+
private val binding: FragmentPucTestingBinding
22+
get() = getBinding()
23+
24+
override fun configuratorMode() = AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER
25+
26+
@Suppress("HttpUrlsUsage")
27+
@SuppressLint("SetJavaScriptEnabled")
28+
override fun initUi(view: View, savedInstanceState: Bundle?) {
29+
super.initUi(view, savedInstanceState)
30+
binding.btnLoadUrl.setOnClickListener {
31+
val ipAddress = binding.ipAddress.text
32+
if (ipAddress.isNotBlank()) {
33+
binding.webViewContainer.removeAllViews()
34+
35+
val webView = WebView(requireContext())
36+
webView.settings.javaScriptEnabled = true
37+
webView.loadUrl("http://$ipAddress")
38+
binding.webViewContainer.addView(
39+
webView,
40+
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
41+
)
42+
}
43+
}
44+
}
45+
46+
override fun initAd(): Any {
47+
return ""
48+
}
49+
50+
override fun loadAd() {}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package org.prebid.mobile.renderingtestapp.plugplay.bidding.testing
2+
3+
import android.os.Bundle
4+
import android.util.Log
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.webkit.WebSettings
8+
import android.webkit.WebView
9+
import android.widget.Toast
10+
import com.google.android.gms.ads.AdListener
11+
import com.google.android.gms.ads.AdSize
12+
import com.google.android.gms.ads.LoadAdError
13+
import com.google.android.gms.ads.admanager.AdManagerAdRequest
14+
import com.google.android.gms.ads.admanager.AdManagerAdView
15+
import org.prebid.mobile.renderingtestapp.AdFragment
16+
import org.prebid.mobile.renderingtestapp.R
17+
import org.prebid.mobile.renderingtestapp.databinding.FragmentEmptyBinding
18+
import org.prebid.mobile.renderingtestapp.databinding.FragmentPucTestingGamBinding
19+
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment
20+
21+
/**
22+
* Example for testing memory leaks with original API ad units.
23+
* It doesn't use Google ad view because it causes another memory leak after loadAd().
24+
*/
25+
open class PrebidUniversalCreativeTestingGamFragment : AdFragment() {
26+
27+
override val layoutRes = R.layout.fragment_puc_testing_gam
28+
29+
private lateinit var adView: AdManagerAdView
30+
31+
private val binding: FragmentPucTestingGamBinding
32+
get() = getBinding()
33+
34+
override fun configuratorMode() = AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER
35+
36+
override fun initUi(view: View, savedInstanceState: Bundle?) {
37+
super.initUi(view, savedInstanceState)
38+
}
39+
40+
override fun initAd(): Any {
41+
val adView = AdManagerAdView(requireContext()).apply { adView = this }
42+
adView.adUnitId = "/21808260008/prebid_puc_testing"
43+
adView.setAdSizes(AdSize(300, 250))
44+
adView.adListener = createListener()
45+
adView.loadAd(AdManagerAdRequest.Builder().build())
46+
binding.container.addView(adView)
47+
return adView
48+
}
49+
50+
private fun createListener(): AdListener = object : AdListener() {
51+
52+
override fun onAdLoaded() {
53+
super.onAdLoaded()
54+
55+
val webView = WebViewSearcher.findIn(adView)
56+
if (webView == null) {
57+
Log.e("TESTV", "WebView is null")
58+
return
59+
}
60+
61+
webView.getSettings().mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
62+
}
63+
64+
override fun onAdFailedToLoad(error: LoadAdError) {
65+
Toast.makeText(requireContext(), "Error loading GAM ad: ${error.message}", Toast.LENGTH_SHORT).show()
66+
}
67+
}
68+
69+
70+
override fun loadAd() {}
71+
72+
internal object WebViewSearcher {
73+
74+
fun findIn(root: View): WebView? {
75+
if (root is WebView) return root
76+
77+
if (root is ViewGroup) return findRecursively(root)
78+
79+
return null
80+
}
81+
82+
private fun findRecursively(root: ViewGroup): WebView? {
83+
for (i in 0 until root.childCount) {
84+
val child = root.getChildAt(i)
85+
if (child is WebView) return child
86+
87+
if (child is ViewGroup) {
88+
val result = findRecursively(child)
89+
if (result != null) return result
90+
}
91+
}
92+
93+
return null
94+
}
95+
96+
}
97+
98+
}

Diff for: Example/PrebidInternalTestApp/src/main/java/org/prebid/mobile/renderingtestapp/utils/DemoItemProvider.kt

+12
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ class DemoItemProvider private constructor() {
107107
private fun addSdkTestingExamples() {
108108
demoList.addAll(
109109
arrayListOf(
110+
DemoItem(
111+
getString(R.string.demo_bidding_sdk_testing_puc_webview),
112+
R.id.action_header_bidding_to_puc_webview,
113+
listOf(Tag.ALL, Tag.IN_APP, Tag.BANNER, Tag.REMOTE),
114+
createBannerBundle(null)
115+
),
116+
DemoItem(
117+
getString(R.string.demo_bidding_sdk_testing_puc_gam),
118+
R.id.action_header_bidding_to_puc_gam,
119+
listOf(Tag.ALL, Tag.IN_APP, Tag.BANNER, Tag.REMOTE),
120+
createBannerBundle(null)
121+
),
110122
DemoItem(
111123
getString(R.string.demo_bidding_sdk_testing_memory_leak_rendering_api_interstitial_display),
112124
R.id.action_header_bidding_to_interstitial_memory_leak_testing,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<ScrollView
5+
android:id="@+id/scrollView"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:fillViewport="true">
9+
10+
<LinearLayout
11+
android:id="@+id/container"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:orientation="vertical">
15+
16+
17+
18+
</LinearLayout>
19+
20+
</ScrollView>
21+
</layout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<ScrollView
5+
android:id="@+id/scrollView"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:fillViewport="true">
9+
10+
<LinearLayout
11+
android:id="@+id/container"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:orientation="vertical">
15+
16+
<TextView
17+
android:text="Please enter IP address (f.e. '192.168.0.10:9876')"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:gravity="center"/>
21+
22+
<EditText
23+
android:id="@+id/ipAddress"
24+
android:layout_width="match_parent"
25+
android:layout_marginHorizontal="24dp"
26+
android:layout_height="wrap_content"/>
27+
28+
<Button
29+
android:id="@+id/btnLoadUrl"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:layout_gravity="center"
33+
android:text="Open URL" />
34+
35+
<LinearLayout
36+
android:id="@+id/webViewContainer"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:orientation="vertical">
40+
41+
</LinearLayout>
42+
43+
</LinearLayout>
44+
45+
</ScrollView>
46+
</layout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<ScrollView
5+
android:id="@+id/scrollView"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:fillViewport="true">
9+
10+
<LinearLayout
11+
android:id="@+id/container"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:orientation="vertical">
15+
16+
<TextView
17+
android:text="Please enter IP address (f.e. '192.168.0.10:9876')"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:gravity="center"/>
21+
22+
</LinearLayout>
23+
24+
</ScrollView>
25+
</layout>

Diff for: Example/PrebidInternalTestApp/src/main/res/navigation/bidding_navigation.xml

+19
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@
125125
app:popExitAnim="@anim/nav_default_pop_exit_anim"
126126
app:popUpTo="@+id/headerBiddingFragment" />
127127

128+
<action
129+
android:id="@+id/action_header_bidding_to_puc_webview"
130+
app:destination="@id/testing_puc_webview"
131+
app:popUpTo="@+id/headerBiddingFragment" />
132+
133+
<action
134+
android:id="@+id/action_header_bidding_to_puc_gam"
135+
app:destination="@id/testing_puc_gam"
136+
app:popUpTo="@+id/headerBiddingFragment" />
137+
128138
<action
129139
android:id="@+id/action_header_bidding_to_in_app_interstitial_multiformat"
130140
app:destination="@id/navigation_in_app_interstitial_multiformat"
@@ -814,6 +824,15 @@
814824
android:id="@+id/gamOriginalBannerMemoryLeakTestingFragment"
815825
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.testing.MemoryLeakTestingOriginalApiBannerFragment"
816826
android:label="GamOriginalBannerMemoryLeakTestingFragment" />
827+
828+
<fragment
829+
android:id="@+id/testing_puc_webview"
830+
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.testing.PrebidUniversalCreativeTestingFragment"
831+
android:label="PrebidUniversalCreativeTestingFragment" />
832+
<fragment
833+
android:id="@+id/testing_puc_gam"
834+
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.testing.PrebidUniversalCreativeTestingGamFragment"
835+
android:label="PrebidUniversalCreativeTestingGamFragment" />
817836
<fragment
818837
android:id="@+id/gamOriginalBannerFragmentMultiformat"
819838
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.gam.original.GamOriginalBannerRandomMultiformatFragment"

Diff for: Example/PrebidInternalTestApp/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
<string name="demo_bidding_sdk_testing_memory_leak_rendering_api_banner">SDK Testing: Rendering API Banner Memory Leak </string>
293293
<string name="demo_bidding_sdk_testing_memory_leak_rendering_api_interstitial_display">SDK Testing: Rendering API Display Interstitial Memory Leak</string>
294294
<string name="demo_bidding_sdk_testing_memory_leak_rendering_api_interstitial_video">SDK Testing: Rendering API Video Interstitial Memory Leak</string>
295+
<string name="demo_bidding_sdk_testing_puc_webview">SDK Testing: Prebid Universal Creative (WebView)</string>
296+
<string name="demo_bidding_sdk_testing_puc_gam">SDK Testing: Prebid Universal Creative (GAM)</string>
295297

296298
<!--GAM AdUnits-->
297299
<string name="adunit_dynamic">Ad unit id is set in another place</string>

0 commit comments

Comments
 (0)