Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e47e054

Browse files
committedJan 6, 2025
feat: add GAM test case
1 parent 46e330f commit e47e054

File tree

5 files changed

+168
-0
lines changed

5 files changed

+168
-0
lines changed
 

‎InternalTestApp/InternalTestApp.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
53514CEC2D08416B00A480C0 /* SampleInterstitialController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53514CDA2D08416B00A480C0 /* SampleInterstitialController.swift */; };
4040
53514CED2D08416B00A480C0 /* SampleAdView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53514CD82D08416B00A480C0 /* SampleAdView.swift */; };
4141
53514CEE2D08416B00A480C0 /* CustomRendererBannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53514CDE2D08416B00A480C0 /* CustomRendererBannerController.swift */; };
42+
535ADDFB2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 535ADDFA2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift */; };
43+
535ADDFC2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 535ADDFA2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift */; };
4244
5397BD142936185400ABDA22 /* PrebidOriginalAPIDisplayBannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5397BD132936185400ABDA22 /* PrebidOriginalAPIDisplayBannerController.swift */; };
4345
5397BD26293760F500ABDA22 /* PrebidOriginalAPIDisplayInterstitialController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5397BD25293760F500ABDA22 /* PrebidOriginalAPIDisplayInterstitialController.swift */; };
4446
5397BD2A29376C9700ABDA22 /* PrebidOriginalAPIVideoRewardedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5397BD2929376C9700ABDA22 /* PrebidOriginalAPIVideoRewardedController.swift */; };
@@ -393,6 +395,7 @@
393395
53514CDC2D08416B00A480C0 /* SampleModalViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleModalViewController.swift; sourceTree = "<group>"; };
394396
53514CDE2D08416B00A480C0 /* CustomRendererBannerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomRendererBannerController.swift; sourceTree = "<group>"; };
395397
53514CDF2D08416B00A480C0 /* CustomRendererInterstitialController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomRendererInterstitialController.swift; sourceTree = "<group>"; };
398+
535ADDFA2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrebidUniversalCreativeTestingGAMController.swift; sourceTree = "<group>"; };
396399
5397BD132936185400ABDA22 /* PrebidOriginalAPIDisplayBannerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrebidOriginalAPIDisplayBannerController.swift; sourceTree = "<group>"; };
397400
5397BD25293760F500ABDA22 /* PrebidOriginalAPIDisplayInterstitialController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrebidOriginalAPIDisplayInterstitialController.swift; sourceTree = "<group>"; };
398401
5397BD2929376C9700ABDA22 /* PrebidOriginalAPIVideoRewardedController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrebidOriginalAPIVideoRewardedController.swift; sourceTree = "<group>"; };
@@ -746,6 +749,7 @@
746749
5397BD312937895700ABDA22 /* PrebidOriginalAPIVideoInstreamViewController.swift */,
747750
539F961329DEF2670061E7A5 /* PrebidOriginalAPIVideoInterstitialController.swift */,
748751
5397BD2929376C9700ABDA22 /* PrebidOriginalAPIVideoRewardedController.swift */,
752+
535ADDFA2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift */,
749753
);
750754
path = OriginalAPI;
751755
sourceTree = "<group>";
@@ -1639,6 +1643,7 @@
16391643
53514CE52D08416B00A480C0 /* SampleInterstitialController.swift in Sources */,
16401644
53514CE62D08416B00A480C0 /* SampleAdView.swift in Sources */,
16411645
53514CE72D08416B00A480C0 /* CustomRendererBannerController.swift in Sources */,
1646+
535ADDFC2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift in Sources */,
16421647
53ED300E29798104007D13EE /* NativeAdViewBoxProtocol.swift in Sources */,
16431648
53ED300F29798104007D13EE /* FormViewController+RowBuildHelpers.swift in Sources */,
16441649
53ED301029798104007D13EE /* PrebidGAMBannerController.swift in Sources */,
@@ -1739,6 +1744,7 @@
17391744
53514CEC2D08416B00A480C0 /* SampleInterstitialController.swift in Sources */,
17401745
53514CED2D08416B00A480C0 /* SampleAdView.swift in Sources */,
17411746
53514CEE2D08416B00A480C0 /* CustomRendererBannerController.swift in Sources */,
1747+
535ADDFB2D19731000DB888F /* PrebidUniversalCreativeTestingGAMController.swift in Sources */,
17421748
92F9A5D127A15BD1007B0B17 /* NativeAdViewBoxProtocol.swift in Sources */,
17431749
341CC3142562C9D000186F29 /* FormViewController+RowBuildHelpers.swift in Sources */,
17441750
3493021C2473F408004A6086 /* PrebidGAMBannerController.swift in Sources */,

‎InternalTestApp/PrebidMobileDemoRendering/AppDelegate.swift

+2
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
183183
func applicationWillTerminate(_ application: UIApplication) {
184184
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
185185
}
186+
187+
186188
}

‎InternalTestApp/PrebidMobileDemoRendering/Model/TestCasesManager.swift

+19
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,25 @@ struct TestCaseManager {
467467
setupCustomParams(for: interstitialController.prebidConfigId)
468468
}),
469469

470+
471+
// MARK: ---- Prebid Universal Creative Tests
472+
473+
TestCase(title: "Prebid Universal Creative (GAM)",
474+
tags: [.banner, .originalAPI, .server],
475+
exampleVCStoryboardID: "AdapterViewController",
476+
configurationClosure: { vc in
477+
guard let adapterVC = vc as? AdapterViewController else {
478+
return
479+
}
480+
481+
let bannerController = PrebidUniversalCreativeTestingGAMController(rootController: adapterVC)
482+
bannerController.adSize = CGSize(width: 300, height: 250)
483+
bannerController.gamAdUnitID = "/21808260008/prebid_puc_testing"
484+
485+
adapterVC.setup(adapter: bannerController)
486+
setupCustomParams(for: bannerController.prebidConfigId)
487+
}),
488+
470489
// MARK: ---- Native (Original API)
471490

472491
TestCase(title: "Native Banner (GAM Original) [OK, PUC]",

‎InternalTestApp/PrebidMobileDemoRendering/Resources/Info.plist

+13
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,21 @@
3535
<true/>
3636
<key>NSAppTransportSecurity</key>
3737
<dict>
38+
<key>NSAllowsArbitraryLoadsInWebContent</key>
39+
<true/>
3840
<key>NSAllowsArbitraryLoads</key>
3941
<true/>
42+
<key>NSAppTransportSecurity</key>
43+
<dict>
44+
<key>NSExceptionDomains</key>
45+
<dict>
46+
<key>192.168.0.102</key>
47+
<dict>
48+
<key>NSExceptionAllowsInsecureHTTPLoads</key>
49+
<true/>
50+
</dict>
51+
</dict>
52+
</dict>
4053
</dict>
4154
<key>NSLocationAlwaysUsageDescription</key>
4255
<string>Access to GPS is needed for testing purposes.</string>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*   Copyright 2018-2024 Prebid.org, Inc.
2+
3+
 Licensed under the Apache License, Version 2.0 (the "License");
4+
 you may not use this file except in compliance with the License.
5+
 You may obtain a copy of the License at
6+
7+
 http://www.apache.org/licenses/LICENSE-2.0
8+
9+
 Unless required by applicable law or agreed to in writing, software
10+
 distributed under the License is distributed on an "AS IS" BASIS,
11+
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
 See the License for the specific language governing permissions and
13+
 limitations under the License.
14+
 */
15+
16+
import GoogleMobileAds
17+
18+
final class PrebidUniversalCreativeTestingGAMController:
19+
NSObject,
20+
AdaptedController,
21+
PrebidConfigurableBannerController,
22+
GADBannerViewDelegate, WKNavigationDelegate {
23+
24+
var refreshInterval: TimeInterval = 0
25+
var prebidConfigId: String = ""
26+
var gamAdUnitID: String = ""
27+
var adSize = CGSize.zero
28+
29+
let rootController: AdapterViewController
30+
31+
private var gamBanner: GAMBannerView!
32+
33+
private let configIdLabel = UILabel()
34+
private let reloadButton = ThreadCheckingButton()
35+
36+
init(rootController: AdapterViewController) {
37+
self.rootController = rootController
38+
super.init()
39+
40+
setupAdapterController()
41+
}
42+
43+
func configurationController() -> BaseConfigurationController? {
44+
return PrebidBannerConfigurationController(controller: self)
45+
}
46+
47+
private func setupAdapterController() {
48+
rootController.showButton.isHidden = true
49+
50+
configIdLabel.isHidden = true
51+
rootController.actionsView.addArrangedSubview(configIdLabel)
52+
53+
reloadButton.addTarget(self, action: #selector(reload), for: .touchUpInside)
54+
}
55+
56+
func loadAd() {
57+
configIdLabel.isHidden = false
58+
configIdLabel.text = "GAM AdUnit ID: \(gamAdUnitID)"
59+
60+
gamBanner = GAMBannerView(adSize: GADAdSizeFromCGSize(adSize))
61+
gamBanner.adUnitID = gamAdUnitID
62+
gamBanner.rootViewController = rootController
63+
gamBanner.delegate = self
64+
65+
rootController.bannerView?.addSubview(gamBanner)
66+
67+
let gamRequest = GAMRequest()
68+
gamBanner.load(gamRequest)
69+
}
70+
71+
@objc private func reload() {
72+
reloadButton.isEnabled = false
73+
let gamRequest = GAMRequest()
74+
gamBanner.load(gamRequest)
75+
}
76+
77+
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
78+
rootController.bannerView.backgroundColor = .clear
79+
reloadButton.isEnabled = true
80+
rootController.bannerView.constraints.first { $0.firstAttribute == .width }?.constant = 300
81+
rootController.bannerView.constraints.first { $0.firstAttribute == .height }?.constant = 500
82+
83+
let targetWebView = bannerView.allSubViewsOf(type: WKWebView.self).first
84+
85+
if #available(iOS 14.0, *) {
86+
targetWebView?.configuration.defaultWebpagePreferences.allowsContentJavaScript = true
87+
} else {
88+
targetWebView?.configuration.preferences.javaScriptEnabled = true
89+
}
90+
91+
targetWebView?.navigationDelegate = self
92+
93+
// let js = """
94+
// function loadNewIframe() {
95+
// // The URL to load in the iframe
96+
// const iframeUrl = "http://192.168.0.102:9876"; // You can change this dynamically
97+
//
98+
// // Create the iframe element
99+
// const iframe = document.createElement("iframe");
100+
// iframe.src = iframeUrl;
101+
//
102+
// // Optional: Set other attributes like width, height, and frameBorder
103+
// iframe.width = "100%";
104+
// iframe.height = "400px";
105+
// iframe.frameBorder = "0"; // Removes the border of the iframe
106+
//
107+
// // Append the iframe to the end of the body
108+
// document.body.appendChild(iframe);
109+
// }
110+
//
111+
// // Call the function to load the iframe (you can bind this to a button or another event)
112+
// loadNewIframe();
113+
// """
114+
//
115+
// targetWebView?.evaluateJavaScript(js)
116+
117+
// targetWebView?.load(URLRequest(url: URL(string: "http://192.168.0.102:9876")!))
118+
}
119+
120+
func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: any Error) {
121+
print(error.localizedDescription)
122+
}
123+
124+
125+
126+
127+
128+
}

0 commit comments

Comments
 (0)
Please sign in to comment.