Skip to content

Commit

Permalink
feat: tune GAM case
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaPostindustria committed Jan 7, 2025
1 parent 9a19411 commit 4a29828
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ struct TestCaseManager {

let bannerController = PrebidUniversalCreativeTestingGAMController(rootController: adapterVC)
bannerController.adSize = CGSize(width: 300, height: 250)
bannerController.gamAdUnitID = "/21808260008/prebid_puc_testing"
bannerController.gamAdUnitID = "/21808260008/puc-testing-secure-banner-300x250"

adapterVC.setup(adapter: bannerController)
setupCustomParams(for: bannerController.prebidConfigId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@
<wkPreferences key="preferences"/>
</wkWebViewConfiguration>
</wkWebView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="IP address(f.e. 192.168.0.108:9876)" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Zgi-DY-0kd">
<rect key="frame" x="62.5" y="35" width="250.5" height="18"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Scheme, IP, port(f.e. http://192.168.0.108:9876)" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Zgi-DY-0kd">
<rect key="frame" x="20.5" y="35" width="334" height="18"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand Down
11 changes: 0 additions & 11 deletions InternalTestApp/PrebidMobileDemoRendering/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@
<true/>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>192.168.0.102</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
<key>NSLocationAlwaysUsageDescription</key>
<string>Access to GPS is needed for testing purposes.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import GoogleMobileAds
final class PrebidUniversalCreativeTestingGAMController:
NSObject,
AdaptedController,
PrebidConfigurableBannerController,
GADBannerViewDelegate, WKNavigationDelegate {
PrebidConfigurableBannerController {

var refreshInterval: TimeInterval = 0
var prebidConfigId: String = ""
Expand All @@ -30,7 +29,15 @@ final class PrebidUniversalCreativeTestingGAMController:

private var gamBanner: GAMBannerView!

private let configIdLabel = UILabel()
private let bannerViewDidReceiveAd = EventReportContainer()
private let bannerViewDidFailToReceiveAd = EventReportContainer()

private let configIdLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 12)
return label
}()

private let reloadButton = ThreadCheckingButton()

init(rootController: AdapterViewController) {
Expand All @@ -44,18 +51,9 @@ final class PrebidUniversalCreativeTestingGAMController:
return PrebidBannerConfigurationController(controller: self)
}

private func setupAdapterController() {
rootController.showButton.isHidden = true

configIdLabel.isHidden = true
rootController.actionsView.addArrangedSubview(configIdLabel)

reloadButton.addTarget(self, action: #selector(reload), for: .touchUpInside)
}

func loadAd() {
configIdLabel.isHidden = false
configIdLabel.text = "GAM AdUnit ID: \(gamAdUnitID)"
configIdLabel.text = "AdUnit ID: \(gamAdUnitID)"

gamBanner = GAMBannerView(adSize: GADAdSizeFromCGSize(adSize))
gamBanner.adUnitID = gamAdUnitID
Expand All @@ -74,13 +72,66 @@ final class PrebidUniversalCreativeTestingGAMController:
gamBanner.load(gamRequest)
}

private func setupAdapterController() {
rootController.showButton.isHidden = true

configIdLabel.isHidden = true
rootController.actionsView.addArrangedSubview(configIdLabel)

reloadButton.addTarget(self, action: #selector(reload), for: .touchUpInside)

setupActions()
}

private func setupActions() {
rootController.setupAction(bannerViewDidReceiveAd, "bannerViewDidReceiveAd called", accessibilityLabel: "bannerViewDidReceiveAd called")
rootController.setupAction(bannerViewDidFailToReceiveAd, "bannerViewDidFailToReceiveAd called")
rootController.setupAction(reloadButton, "[Reload]")
}

private func resetEvents() {
bannerViewDidReceiveAd.isEnabled = false
bannerViewDidFailToReceiveAd.isEnabled = false
reloadButton.isEnabled = true
}
}

// MARK: - GADBannerViewDelegate

extension PrebidUniversalCreativeTestingGAMController: GADBannerViewDelegate {

func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
rootController.bannerView.backgroundColor = .clear
bannerViewDidReceiveAd.isEnabled = true
reloadButton.isEnabled = true
rootController.bannerView.constraints.first { $0.firstAttribute == .width }?.constant = 300
rootController.bannerView.constraints.first { $0.firstAttribute == .height }?.constant = 500
rootController.bannerView.constraints.first { $0.firstAttribute == .height }?.constant = 250

// let targetWebView = bannerView.allSubViewsOf(type: WKWebView.self).first
// targetWebView?.load(URLRequest(url: URL(string: "http://192.168.0.102:9876")!))
let targetWebView = bannerView.allSubViewsOf(type: WKWebView.self).first
targetWebView?.navigationDelegate = self
}

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: any Error) {
resetEvents()
bannerViewDidFailToReceiveAd.isEnabled = true
print(error.localizedDescription)
}
}

// MARK: - WKNavigationDelegate

extension PrebidUniversalCreativeTestingGAMController: WKNavigationDelegate {

func webView(
_ webView: WKWebView,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @MainActor @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
if let serverTrust = challenge.protectionSpace.serverTrust {
let credential = URLCredential(trust: serverTrust)
completionHandler(.useCredential, credential)
} else {
print("Error: failed to get server trust.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,36 @@ final class PrebidUniversalCreativeTestingWebViewController: UIViewController {
@IBOutlet weak var webView: WKWebView!
@IBOutlet weak var textField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

webView.navigationDelegate = self
}

@IBAction func onOpenURLPressed(_ sender: Any) {
guard let urlString = textField.text, let url = URL(string: "http://\(urlString)") else {
guard let urlString = textField.text, let url = URL(string: "\(urlString)") else {
return
}

let request = URLRequest(url: url)
webView.load(request)
}
}

// MARK: - WKNavigationDelegate

extension PrebidUniversalCreativeTestingWebViewController: WKNavigationDelegate {

func webView(
_ webView: WKWebView,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @MainActor @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
if let serverTrust = challenge.protectionSpace.serverTrust {
let credential = URLCredential(trust: serverTrust)
completionHandler(.useCredential, credential)
} else {
print("Error: failed to get server trust.")
}
}
}

0 comments on commit 4a29828

Please sign in to comment.