Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce test cases for PUC #807

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Example/PrebidInternalTestApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:usesCleartextTraffic="true"
android:theme="@style/SdkDemoTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class InternalTestApplication : MultiDexApplication() {
super.onCreate()
instance = this

WebView.setWebContentsDebuggingEnabled(true)

PrebidMobile.setPrebidServerHost(Host.createCustomHost("https://prebid-server-test-j.prebid.org/openrtb2/auction"))
PrebidMobile.initializeSdk(this, null)
PrebidMobile.setPrebidServerAccountId(getString(R.string.prebid_account_id_prod))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.prebid.mobile.renderingtestapp.plugplay.bidding.testing

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import org.prebid.mobile.renderingtestapp.AdFragment
import org.prebid.mobile.renderingtestapp.R
import org.prebid.mobile.renderingtestapp.databinding.FragmentPucTestingBinding
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment

/**
* Example for testing memory leaks with original API ad units.
* It doesn't use Google ad view because it causes another memory leak after loadAd().
*/
open class PrebidUniversalCreativeTestingFragment : AdFragment() {

override val layoutRes = R.layout.fragment_puc_testing

private val binding: FragmentPucTestingBinding
get() = getBinding()

override fun configuratorMode() = AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER

@Suppress("HttpUrlsUsage")
@SuppressLint("SetJavaScriptEnabled")
override fun initUi(view: View, savedInstanceState: Bundle?) {
super.initUi(view, savedInstanceState)
binding.btnLoadUrl.setOnClickListener {
val ipAddress = binding.ipAddress.text
if (ipAddress.isNotBlank()) {
binding.webViewContainer.removeAllViews()

val webView = WebView(requireContext())
webView.settings.javaScriptEnabled = true
webView.loadUrl("http://$ipAddress")
binding.webViewContainer.addView(
webView,
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
)
}
}
}

override fun initAd(): Any {
return ""
}

override fun loadAd() {}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package org.prebid.mobile.renderingtestapp.plugplay.bidding.testing

import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.webkit.WebSettings
import android.webkit.WebView
import android.widget.Toast
import com.google.android.gms.ads.AdListener
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.admanager.AdManagerAdRequest
import com.google.android.gms.ads.admanager.AdManagerAdView
import org.prebid.mobile.renderingtestapp.AdFragment
import org.prebid.mobile.renderingtestapp.R
import org.prebid.mobile.renderingtestapp.databinding.FragmentEmptyBinding
import org.prebid.mobile.renderingtestapp.databinding.FragmentPucTestingGamBinding
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment

/**
* Example for testing memory leaks with original API ad units.
* It doesn't use Google ad view because it causes another memory leak after loadAd().
*/
open class PrebidUniversalCreativeTestingGamFragment : AdFragment() {

override val layoutRes = R.layout.fragment_puc_testing_gam

private lateinit var adView: AdManagerAdView

private val binding: FragmentPucTestingGamBinding
get() = getBinding()

override fun configuratorMode() = AdConfiguratorDialogFragment.AdConfiguratorMode.BANNER

override fun initUi(view: View, savedInstanceState: Bundle?) {
super.initUi(view, savedInstanceState)
}

override fun initAd(): Any {
val adView = AdManagerAdView(requireContext()).apply { adView = this }
adView.adUnitId = "/21808260008/prebid_puc_testing"
adView.setAdSizes(AdSize(300, 250))
adView.adListener = createListener()
adView.loadAd(AdManagerAdRequest.Builder().build())
binding.container.addView(adView)
return adView
}

private fun createListener(): AdListener = object : AdListener() {

override fun onAdLoaded() {
super.onAdLoaded()

val webView = WebViewSearcher.findIn(adView)
if (webView == null) {
Log.e("TESTV", "WebView is null")
return
}

webView.getSettings().mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
}

override fun onAdFailedToLoad(error: LoadAdError) {
Toast.makeText(requireContext(), "Error loading GAM ad: ${error.message}", Toast.LENGTH_SHORT).show()
}
}


override fun loadAd() {}

internal object WebViewSearcher {

fun findIn(root: View): WebView? {
if (root is WebView) return root

if (root is ViewGroup) return findRecursively(root)

return null
}

private fun findRecursively(root: ViewGroup): WebView? {
for (i in 0 until root.childCount) {
val child = root.getChildAt(i)
if (child is WebView) return child

if (child is ViewGroup) {
val result = findRecursively(child)
if (result != null) return result
}
}

return null
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ class DemoItemProvider private constructor() {
private fun addSdkTestingExamples() {
demoList.addAll(
arrayListOf(
DemoItem(
getString(R.string.demo_bidding_sdk_testing_puc_webview),
R.id.action_header_bidding_to_puc_webview,
listOf(Tag.ALL, Tag.IN_APP, Tag.BANNER, Tag.REMOTE),
createBannerBundle(null)
),
DemoItem(
getString(R.string.demo_bidding_sdk_testing_puc_gam),
R.id.action_header_bidding_to_puc_gam,
listOf(Tag.ALL, Tag.IN_APP, Tag.BANNER, Tag.REMOTE),
createBannerBundle(null)
),
DemoItem(
getString(R.string.demo_bidding_sdk_testing_memory_leak_rendering_api_interstitial_display),
R.id.action_header_bidding_to_interstitial_memory_leak_testing,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">



</LinearLayout>

</ScrollView>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:text="Please enter IP address (f.e. '192.168.0.10:9876')"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"/>

<EditText
android:id="@+id/ipAddress"
android:layout_width="match_parent"
android:layout_marginHorizontal="24dp"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/btnLoadUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Open URL" />

<LinearLayout
android:id="@+id/webViewContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

</LinearLayout>

</LinearLayout>

</ScrollView>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:text="Please enter IP address (f.e. '192.168.0.10:9876')"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"/>

</LinearLayout>

</ScrollView>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@+id/headerBiddingFragment" />

<action
android:id="@+id/action_header_bidding_to_puc_webview"
app:destination="@id/testing_puc_webview"
app:popUpTo="@+id/headerBiddingFragment" />

<action
android:id="@+id/action_header_bidding_to_puc_gam"
app:destination="@id/testing_puc_gam"
app:popUpTo="@+id/headerBiddingFragment" />

<action
android:id="@+id/action_header_bidding_to_in_app_interstitial_multiformat"
app:destination="@id/navigation_in_app_interstitial_multiformat"
Expand Down Expand Up @@ -814,6 +824,15 @@
android:id="@+id/gamOriginalBannerMemoryLeakTestingFragment"
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.testing.MemoryLeakTestingOriginalApiBannerFragment"
android:label="GamOriginalBannerMemoryLeakTestingFragment" />

<fragment
android:id="@+id/testing_puc_webview"
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.testing.PrebidUniversalCreativeTestingFragment"
android:label="PrebidUniversalCreativeTestingFragment" />
<fragment
android:id="@+id/testing_puc_gam"
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.testing.PrebidUniversalCreativeTestingGamFragment"
android:label="PrebidUniversalCreativeTestingGamFragment" />
<fragment
android:id="@+id/gamOriginalBannerFragmentMultiformat"
android:name="org.prebid.mobile.renderingtestapp.plugplay.bidding.gam.original.GamOriginalBannerRandomMultiformatFragment"
Expand Down
2 changes: 2 additions & 0 deletions Example/PrebidInternalTestApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@
<string name="demo_bidding_sdk_testing_memory_leak_rendering_api_banner">SDK Testing: Rendering API Banner Memory Leak </string>
<string name="demo_bidding_sdk_testing_memory_leak_rendering_api_interstitial_display">SDK Testing: Rendering API Display Interstitial Memory Leak</string>
<string name="demo_bidding_sdk_testing_memory_leak_rendering_api_interstitial_video">SDK Testing: Rendering API Video Interstitial Memory Leak</string>
<string name="demo_bidding_sdk_testing_puc_webview">SDK Testing: Prebid Universal Creative (WebView)</string>
<string name="demo_bidding_sdk_testing_puc_gam">SDK Testing: Prebid Universal Creative (GAM)</string>

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