Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ public class VideoControlsConfiguration: NSObject {

/// This property indicates whether mute controls is visible on the screen.
public var isSoundButtonVisible = false

/// The fallback rewarded-ad completion timeout, in seconds, used when the bid does not provide completion criteria.
public var rewardedCompletionTimeout: TimeInterval {
Comment thread
mdanylov-sigma marked this conversation as resolved.
Outdated
Comment thread
mdanylov-sigma marked this conversation as resolved.
Outdated
set {
if newValue >= 0 {
_rewardedCompletionTimeout = newValue
} else {
Log.warn("The rewarded completion timeout must not be negative.")
}
}
get { _rewardedCompletionTimeout }
}

/// Use to initialize video controls with server values.
public func initialize(with ortbAdConfiguration: ORTBAdConfiguration?) {
Expand Down Expand Up @@ -136,4 +148,6 @@ public class VideoControlsConfiguration: NSObject {

private var _skipButtonArea = PrebidConstants.BUTTON_AREA_DEFAULT.doubleValue
private var _skipButtonPosition = Position.topLeft

private var _rewardedCompletionTimeout: TimeInterval = 120
Comment thread
mdanylov-sigma marked this conversation as resolved.
Outdated
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public class RewardedAdUnit: NSObject, BaseInterstitialAdUnitProtocol {
get { adUnitConfig.adConfiguration.videoControlsConfig.isSoundButtonVisible }
set { adUnitConfig.adConfiguration.videoControlsConfig.isSoundButtonVisible = newValue }
}

/// The fallback completion timeout used when the bid omits rewarded completion criteria.
public var rewardedCompletionTimeout: TimeInterval {
get { adUnitConfig.adConfiguration.videoControlsConfig.rewardedCompletionTimeout }
set { adUnitConfig.adConfiguration.videoControlsConfig.rewardedCompletionTimeout = newValue }
}

// MARK: Internal Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class RewardedConfig: NSObject {
// MARK: - Default Values

/// The timeout duration for rewarded completion, measured in seconds.
public let defaultCompletionTime: NSNumber = 120
public var defaultCompletionTime: NSNumber = 120
Comment thread
mdanylov-sigma marked this conversation as resolved.
Outdated

/// The playback event when the SDK should send a signal to the application that the user has earned the reward
public let defaultVideoPlaybackEvent = "complete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class MediationBaseInterstitialAdUnit : NSObject {
get { adUnitConfig.adConfiguration.videoControlsConfig.isSoundButtonVisible }
set { adUnitConfig.adConfiguration.videoControlsConfig.isSoundButtonVisible = newValue }
}

/// The fallback completion timeout used when the bid omits rewarded completion criteria.
public var rewardedCompletionTimeout: TimeInterval {
get { adUnitConfig.adConfiguration.videoControlsConfig.rewardedCompletionTimeout }
set { adUnitConfig.adConfiguration.videoControlsConfig.rewardedCompletionTimeout = newValue }
}

/// The area for the close button in the video ad.
public var closeButtonArea: Double {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class DisplayView: UIView, PrebidMobileDisplayViewProtocol, AdViewManagerDelegat
guard transactionFactory == nil else { return }

adConfiguration.adConfiguration.winningBidAdFormat = bid.adFormat
adConfiguration.adConfiguration.rewardedConfig = RewardedConfig(ortbRewarded: bid.rewardedConfig)
let rewardedConfig = RewardedConfig(ortbRewarded: bid.rewardedConfig)
rewardedConfig.defaultCompletionTime = NSNumber(
value: adConfiguration.adConfiguration.videoControlsConfig.rewardedCompletionTimeout
)
adConfiguration.adConfiguration.rewardedConfig = rewardedConfig

transactionFactory = Factory.createTransactionFactory(
bid: bid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class InterstitialController:
get { adConfiguration.adConfiguration.videoControlsConfig }
set { adConfiguration.adConfiguration.videoControlsConfig = newValue }
}

public var rewardedCompletionTimeout: TimeInterval {
get { videoControlsConfig.rewardedCompletionTimeout }
set { videoControlsConfig.rewardedCompletionTimeout = newValue }
}

public var videoParameters: VideoParameters {
get { adConfiguration.adConfiguration.videoParameters }
Expand Down Expand Up @@ -72,14 +77,17 @@ public class InterstitialController:
}

adConfiguration.adConfiguration.winningBidAdFormat = bid.adFormat
adConfiguration.adConfiguration.rewardedConfig = RewardedConfig(ortbRewarded: bid.rewardedConfig)
videoControlsConfig.initialize(with: bid.videoAdConfiguration)

// This part is dedicating to test server-side ad configurations.
// Need to be removed when ext.prebid.passthrough will be available.
#if DEBUG
adConfiguration.adConfiguration.videoControlsConfig.initialize(with: bid.testVideoAdConfiguration)
#endif

let rewardedConfig = RewardedConfig(ortbRewarded: bid.rewardedConfig)
rewardedConfig.defaultCompletionTime = NSNumber(value: videoControlsConfig.rewardedCompletionTimeout)
adConfiguration.adConfiguration.rewardedConfig = rewardedConfig

transactionFactory = Factory.createTransactionFactory(
bid: bid,
Expand Down
33 changes: 33 additions & 0 deletions PrebidMobileTests/RenderingTests/Tests/PBMHTMLCreativeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,39 @@ class PBMHTMLCreativeTest : XCTestCase, CreativeResolutionDelegate, CreativeView

waitForExpectations(timeout: 10)
}

func testRewardEvent_EndcardUsesConfiguredFallback() {
let exp = expectation(description: "Reward completion")

let rewardedConfig = RewardedConfig(ortbRewarded: ORTBRewardedConfiguration())
rewardedConfig.defaultCompletionTime = 1

let adConfiguration = AdConfiguration()
adConfiguration.rewardedConfig = rewardedConfig
adConfiguration.isRewarded = true
let creativeModel = CreativeModel(adConfiguration: adConfiguration)
self.htmlCreative = MockPBMHTMLCreative(
creativeModel: creativeModel,
transaction: UtilitiesForTesting.createEmptyTransaction()
)

htmlCreative.creativeModel.isCompanionAd = true
htmlCreative.onViewabilityChanged(
true,
viewExposure: Factory.createViewExposure(
exposureFactor: 5,
visibleRectangle: CGRect(origin: .zero, size: CGSize(width: 300, height: 250))
)
)

DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
if self.htmlCreative.creativeModel.userHasEarnedReward == true {
exp.fulfill()
}
}

waitForExpectations(timeout: 3)
}

func testPostRewardEvent_Banner() {
let rewardTime: NSNumber = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,50 @@ class VideoControlsConfigTests: XCTestCase {
XCTAssertTrue(adConfiguration.isSoundButtonVisible == false)
}

func testRewardedCompletionTimeout() {
let adConfiguration = VideoControlsConfiguration()
XCTAssertEqual(adConfiguration.rewardedCompletionTimeout, 120)

adConfiguration.rewardedCompletionTimeout = 15
XCTAssertEqual(adConfiguration.rewardedCompletionTimeout, 15)

adConfiguration.rewardedCompletionTimeout = -1
XCTAssertEqual(adConfiguration.rewardedCompletionTimeout, 15)
}

func testInterstitialControllerPropagatesRewardedCompletionTimeout() {
let adConfiguration = AdUnitConfig(configId: "test")
let controller = InterstitialController(
bid: makeBid(),
adConfiguration: adConfiguration
)
controller.rewardedCompletionTimeout = 15

controller.loadAd()

XCTAssertEqual(
adConfiguration.adConfiguration.rewardedConfig?.defaultCompletionTime,
15
)
}

func testDisplayViewPropagatesRewardedCompletionTimeout() {
let adConfiguration = AdUnitConfig(configId: "test")
adConfiguration.adConfiguration.videoControlsConfig.rewardedCompletionTimeout = 20
let displayView = DisplayView(
frame: .zero,
bid: makeBid(),
adConfiguration: adConfiguration
)

displayView.loadAd()

XCTAssertEqual(
adConfiguration.adConfiguration.rewardedConfig?.defaultCompletionTime,
20
)
}

func testCloseButtonArea() {
let adConfiguration = VideoControlsConfiguration()
XCTAssertEqual(adConfiguration.closeButtonArea, PrebidConstants.BUTTON_AREA_DEFAULT.doubleValue)
Expand Down Expand Up @@ -73,4 +117,8 @@ class VideoControlsConfigTests: XCTestCase {
XCTAssertEqual(adConfiguration.closeButtonPosition, .topLeft)

}

private func makeBid() -> Bid {
Bid(bid: ORTBBid<ORTBBidExt>(bidID: "test", impid: "imp1", price: 1))
}
}
Loading