-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
PrebidMobile/ConfigurationAndTargeting/PrebidEventDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright 2018-2021 Prebid.org, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import Foundation | ||
|
||
@objc | ||
public protocol PrebidEventDelegate { | ||
func prebidBidRequestDidFinish(requestData: Data?, responseData: Data?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
PrebidMobile/PrebidMobileRendering/Prebid/PBMCore/PBMEventDelegateHelper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Copyright 2018-2021 Prebid.org, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import Foundation | ||
|
||
@objc public extension Prebid { | ||
func callEventDelegate_prebidBidRequestDidFinishWith(requestData: Data?, responseData: Data?) { | ||
if let delegate = self.eventDelegate { | ||
delegate.prebidBidRequestDidFinish(requestData: requestData, responseData: responseData) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright 2018-2021 Prebid.org, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import XCTest | ||
@testable import PrebidMobile | ||
|
||
private typealias Callback = (Data?, Data?) -> Void | ||
|
||
class PrebidEventDelegateTests: XCTestCase { | ||
|
||
let mockRequestData = "req".data(using: .utf8) | ||
let mockResponseData = "res".data(using: .utf8) | ||
|
||
var delegate: PrebidEventDelegate? | ||
|
||
func test_eventDelegate_isCalled() { | ||
let exp = expectation(description: "Expect PrebidEventDelegate to be called") | ||
|
||
delegate = PrebidEventDelegateTestsMockDelegate(onRequestDidFinish: { requestData, responseData in | ||
XCTAssertEqual(requestData, self.mockRequestData) | ||
XCTAssertEqual(responseData, self.mockResponseData) | ||
exp.fulfill() | ||
}) | ||
|
||
Prebid.shared.eventDelegate = delegate | ||
|
||
Prebid.shared.callEventDelegate_prebidBidRequestDidFinishWith(requestData: mockRequestData, responseData: mockResponseData) | ||
waitForExpectations(timeout: 1.0) | ||
} | ||
|
||
func test_callEventDelegate_doesNothing_whenDelegateIsNil() { | ||
/// This test aims to ensure that there is no nullpointer exception if the delegate is unset | ||
/// and a call to `callEventDelegate_prebidBidRequestDidFinishWith(_:,:_)` is made | ||
Prebid.shared.eventDelegate = nil | ||
Prebid.shared.callEventDelegate_prebidBidRequestDidFinishWith(requestData: mockRequestData, responseData: mockResponseData) | ||
} | ||
} | ||
|
||
private class PrebidEventDelegateTestsMockDelegate: PrebidEventDelegate { | ||
private let onRequestDidFinish: Callback | ||
|
||
init(onRequestDidFinish: @escaping Callback) { | ||
self.onRequestDidFinish = onRequestDidFinish | ||
} | ||
|
||
func prebidBidRequestDidFinish(requestData: Data?, responseData: Data?) { | ||
onRequestDidFinish(requestData, responseData) | ||
} | ||
} |