forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[interactive_media_ads] Adds initial iOS implementation (flutter#7063)
iOS implementation for flutter#134228
- Loading branch information
1 parent
b20d2c5
commit 46a712f
Showing
69 changed files
with
10,301 additions
and
164 deletions.
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
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
171 changes: 167 additions & 4 deletions
171
packages/interactive_media_ads/example/ios/Runner.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
packages/interactive_media_ads/example/ios/Runner.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
20 changes: 20 additions & 0 deletions
20
packages/interactive_media_ads/example/ios/RunnerTests/AdDisplayContainerTests.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,20 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import Flutter | ||
import XCTest | ||
|
||
@testable import interactive_media_ads | ||
|
||
final class AdDisplayContainerTests: XCTestCase { | ||
func testPigeonDefaultConstructor() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) | ||
|
||
let instance = try? api.pigeonDelegate.pigeonDefaultConstructor( | ||
pigeonApi: api, adContainer: UIView(), adContainerViewController: UIViewController()) | ||
|
||
XCTAssertNotNil(instance) | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
packages/interactive_media_ads/example/ios/RunnerTests/AdErrorTests.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,65 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import Flutter | ||
import GoogleInteractiveMediaAds | ||
import XCTest | ||
|
||
@testable import interactive_media_ads | ||
|
||
final class AdErrorTests: XCTestCase { | ||
func testType() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdError(registrar) | ||
|
||
let instance = TestAdError.customInit() | ||
|
||
let value = try? api.pigeonDelegate.type(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, .loadingFailed) | ||
} | ||
|
||
func testCode() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdError(registrar) | ||
|
||
let instance = TestAdError.customInit() | ||
|
||
let value = try? api.pigeonDelegate.code(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, .apiError) | ||
} | ||
|
||
func testMessage() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdError(registrar) | ||
|
||
let instance = TestAdError.customInit() | ||
|
||
let value = try? api.pigeonDelegate.message(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, "message") | ||
} | ||
} | ||
|
||
class TestAdError: IMAAdError { | ||
// Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE | ||
static func customInit() -> IMAAdError { | ||
let instance = | ||
TestAdError.perform(NSSelectorFromString("new")).takeRetainedValue() as! TestAdError | ||
return instance | ||
} | ||
|
||
override var type: IMAErrorType { | ||
return .adLoadingFailed | ||
} | ||
|
||
override var code: IMAErrorCode { | ||
return .API_ERROR | ||
} | ||
|
||
override var message: String? { | ||
return "message" | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/interactive_media_ads/example/ios/RunnerTests/AdEventTests.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,50 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import Flutter | ||
import GoogleInteractiveMediaAds | ||
import XCTest | ||
|
||
@testable import interactive_media_ads | ||
|
||
final class AdEventTests: XCTestCase { | ||
func testType() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdEvent(registrar) | ||
|
||
let instance = TestAdEvent.customInit() | ||
|
||
let value = try? api.pigeonDelegate.type(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, .adBreakEnded) | ||
} | ||
|
||
func testMessage() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdEvent(registrar) | ||
|
||
let instance = TestAdEvent.customInit() | ||
|
||
let value = try? api.pigeonDelegate.typeString(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, "message") | ||
} | ||
} | ||
|
||
class TestAdEvent: IMAAdEvent { | ||
// Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE | ||
static func customInit() -> TestAdEvent { | ||
let instance = | ||
TestAdEvent.perform(NSSelectorFromString("new")).takeRetainedValue() as! TestAdEvent | ||
return instance | ||
} | ||
|
||
override var type: IMAAdEventType { | ||
return .AD_BREAK_ENDED | ||
} | ||
|
||
override var typeString: String { | ||
return "message" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/interactive_media_ads/example/ios/RunnerTests/AdLoadingErrorDataTests.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,36 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import Flutter | ||
import GoogleInteractiveMediaAds | ||
import XCTest | ||
|
||
@testable import interactive_media_ads | ||
|
||
final class AdLoadingErrorTests: XCTestCase { | ||
func testAdError() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdLoadingErrorData(registrar) | ||
|
||
let instance = TestAdLoadingErrorData.customInit() | ||
|
||
let value = try? api.pigeonDelegate.adError(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertTrue(value is TestAdError) | ||
} | ||
} | ||
|
||
class TestAdLoadingErrorData: IMAAdLoadingErrorData { | ||
// Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE | ||
static func customInit() -> TestAdLoadingErrorData { | ||
let instance = | ||
TestAdLoadingErrorData.perform(NSSelectorFromString("new")).takeRetainedValue() | ||
as! TestAdLoadingErrorData | ||
return instance | ||
} | ||
|
||
override var adError: IMAAdError { | ||
return TestAdError.customInit() | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/interactive_media_ads/example/ios/RunnerTests/AdsLoadedDataTests.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,36 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import Flutter | ||
import GoogleInteractiveMediaAds | ||
import XCTest | ||
|
||
@testable import interactive_media_ads | ||
|
||
final class AdsLoadedDataTests: XCTestCase { | ||
func testAdsManager() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdsLoadedData(registrar) | ||
|
||
let instance = TestAdsLoadedData.customInit() | ||
|
||
let value = try? api.pigeonDelegate.adsManager(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertTrue(value is TestAdsManager) | ||
} | ||
} | ||
|
||
class TestAdsLoadedData: IMAAdsLoadedData { | ||
// Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE | ||
static func customInit() -> TestAdsLoadedData { | ||
let instance = | ||
TestAdsLoadedData.perform(NSSelectorFromString("new")).takeRetainedValue() | ||
as! TestAdsLoadedData | ||
return instance | ||
} | ||
|
||
override var adsManager: IMAAdsManager? { | ||
return TestAdsManager.customInit() | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/interactive_media_ads/example/ios/RunnerTests/AdsLoaderDelegateTests.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,63 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import Flutter | ||
import GoogleInteractiveMediaAds | ||
import XCTest | ||
|
||
@testable import interactive_media_ads | ||
|
||
final class AdsLoaderDelegateTests: XCTestCase { | ||
func testPigeonDefaultConstructor() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMAAdsLoaderDelegate(registrar) | ||
|
||
let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api) | ||
|
||
XCTAssertTrue(instance is AdsLoaderDelegateImpl) | ||
} | ||
|
||
func testAdLoaderLoadedWith() { | ||
let api = TestAdsLoaderDelegateApi() | ||
let instance = AdsLoaderDelegateImpl(api: api) | ||
|
||
let adsLoader = IMAAdsLoader(settings: nil) | ||
let data = TestAdsLoadedData() | ||
instance.adsLoader(adsLoader, adsLoadedWith: data) | ||
|
||
XCTAssertEqual(api.adLoaderLoadedWithArgs, [adsLoader, data]) | ||
} | ||
|
||
func testAdsLoaderFailedWithErrorData() { | ||
let api = TestAdsLoaderDelegateApi() | ||
let instance = AdsLoaderDelegateImpl(api: api) | ||
|
||
let adsLoader = IMAAdsLoader(settings: nil) | ||
let error = TestAdLoadingErrorData.customInit() | ||
instance.adsLoader(adsLoader, failedWith: error) | ||
|
||
XCTAssertEqual(api.adsLoaderFailedWithErrorDataArgs, [adsLoader, error]) | ||
} | ||
} | ||
|
||
class TestAdsLoaderDelegateApi: PigeonApiProtocolIMAAdsLoaderDelegate { | ||
var adLoaderLoadedWithArgs: [AnyHashable?]? = nil | ||
var adsLoaderFailedWithErrorDataArgs: [AnyHashable?]? = nil | ||
|
||
func adLoaderLoadedWith( | ||
pigeonInstance pigeonInstanceArg: IMAAdsLoaderDelegate, loader loaderArg: IMAAdsLoader, | ||
adsLoadedData adsLoadedDataArg: IMAAdsLoadedData, | ||
completion: @escaping (Result<Void, PigeonError>) -> Void | ||
) { | ||
adLoaderLoadedWithArgs = [loaderArg, adsLoadedDataArg] | ||
} | ||
|
||
func adsLoaderFailedWithErrorData( | ||
pigeonInstance pigeonInstanceArg: IMAAdsLoaderDelegate, loader loaderArg: IMAAdsLoader, | ||
adErrorData adErrorDataArg: IMAAdLoadingErrorData, | ||
completion: @escaping (Result<Void, PigeonError>) -> Void | ||
) { | ||
adsLoaderFailedWithErrorDataArgs = [loaderArg, adErrorDataArg] | ||
} | ||
} |
Oops, something went wrong.