Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating iOS rootViewController use from loading time to showing time for fullscreen ads #1153

Merged
merged 15 commits into from
Aug 13, 2024
2 changes: 1 addition & 1 deletion packages/google_mobile_ads/example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ target 'Runner' do
inherit! :search_paths

# Matches test_spec dependency.
pod 'OCMock', '3.6'
pod 'OCMock', '3.9.3'
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ - (void)testLoadShowGAMRequest {
// Helper method for testing with FLTAdRequest and FLTGAMAdRequest.
- (void)testLoadShowAppOpenAd:(FLTAdRequest *)request
gadOrGAMRequest:(GADRequest *)gadOrGAMRequest {
UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTAppOpenAd *ad =
[[FLTAppOpenAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

// Stub the load call to invoke successful load callback.
Expand Down Expand Up @@ -130,8 +126,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request

[ad show];

OCMVerify([appOpenClassMock
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]);
OCMVerify([appOpenClassMock presentFromRootViewController:[OCMArg isNil]]);

// Verify full screen callbacks.
OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);
Expand Down Expand Up @@ -162,13 +157,9 @@ - (void)testFailedToLoadGAMRequest {

// Helper for testing failed to load.
- (void)testFailedToLoad:(FLTAdRequest *)request {
UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTAppOpenAd *ad =
[[FLTAppOpenAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

id appOpenClassMock = OCMClassMock([GADAppOpenAd class]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ - (void)testLoadShowInterstitialAd {
GAMRequest *gadRequest = OCMClassMock([GAMRequest class]);
OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest);

UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTGAMInterstitialAd *ad =
[[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
ad.manager = mockManager;

Expand Down Expand Up @@ -120,8 +117,8 @@ - (void)testLoadShowInterstitialAd {
// Show the ad
[ad show];

OCMVerify([interstitialClassMock
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]);
OCMVerify(
[interstitialClassMock presentFromRootViewController:[OCMArg isNil]]);

// Verify full screen callbacks.
OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);
Expand All @@ -145,12 +142,9 @@ - (void)testFailToLoad {
GAMRequest *gadRequest = OCMClassMock([GAMRequest class]);
OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest);

UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTGAMInterstitialAd *ad =
[[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
ad.manager = mockManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,10 @@ - (void)testAdInstanceManagerOnNativeAdEvents {
}

- (void)testAdInstanceManagerOnRewardedAdUserEarnedReward {
FLTRewardedAd *ad = [[FLTRewardedAd alloc]
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
rootViewController:OCMClassMock([UIViewController class])
adId:@1];
FLTRewardedAd *ad =
[[FLTRewardedAd alloc] initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
adId:@1];
[_manager loadAd:ad];

[_manager onRewardedAdUserEarnedReward:ad
Expand All @@ -277,10 +276,9 @@ - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward {

- (void)testAdInstanceManagerOnRewardedInterstitialAdUserEarnedReward {
FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc]
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
rootViewController:OCMClassMock([UIViewController class])
adId:@1];
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
adId:@1];
[_manager loadAd:ad];

[_manager
Expand Down Expand Up @@ -369,11 +367,10 @@ - (void)testBannerEvents {
}

- (void)testFullScreenEventsRewardedAd {
FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc]
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
rootViewController:OCMClassMock([UIViewController class])
adId:@1];
FLTRewardedAd *rewardedAd =
[[FLTRewardedAd alloc] initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
adId:@1];
[_manager loadAd:rewardedAd];

[_manager adWillPresentFullScreenContent:rewardedAd];
Expand All @@ -400,10 +397,9 @@ - (void)testFullScreenEventsRewardedAd {
- (void)testFullScreenEventsRewardedInterstitialAd {
FLTRewardedInterstitialAd *rewardedInterstitialAd =
[[FLTRewardedInterstitialAd alloc]
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
rootViewController:OCMClassMock([UIViewController class])
adId:@1];
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
adId:@1];
[_manager loadAd:rewardedInterstitialAd];

[_manager adWillPresentFullScreenContent:rewardedInterstitialAd];
Expand Down Expand Up @@ -464,10 +460,9 @@ - (NSData *)getDataForEvent:(NSString *)name adId:(NSNumber *)adId {
- (void)testAdClick {
FLTRewardedInterstitialAd *rewardedInterstitialAd =
[[FLTRewardedInterstitialAd alloc]
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
rootViewController:OCMClassMock([UIViewController class])
adId:@1];
initWithAdUnitId:@"testId"
request:[[FLTAdRequest alloc] init]
adId:@1];

[_manager adDidRecordClick:rewardedInterstitialAd];
NSData *impressionData = [self getDataForEvent:@"adDidRecordClick" adId:@1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ - (void)testLoadShowInterstitialAd {
GADRequest *gadRequest = OCMClassMock([GADRequest class]);
OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest);

UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTInterstitialAd *ad =
[[FLTInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

id interstitialClassMock = OCMClassMock([GADInterstitialAd class]);
Expand Down Expand Up @@ -109,8 +105,8 @@ - (void)testLoadShowInterstitialAd {
// Show the ad
[ad show];

OCMVerify([interstitialClassMock
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]);
OCMVerify(
[interstitialClassMock presentFromRootViewController:[OCMArg isNil]]);

// Verify full screen callbacks.
OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);
Expand All @@ -129,13 +125,9 @@ - (void)testFailedToLoad {
GADRequest *gadRequest = OCMClassMock([GADRequest class]);
OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest);

UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTInterstitialAd *ad =
[[FLTInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

id interstitialClassMock = OCMClassMock([GADInterstitialAd class]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@ - (void)testLoadShowRewardedAdGAMRequest {
// Helper method for testing with FLTAdRequest and FLTGAMAdRequest.
- (void)testLoadShowRewardedAd:(FLTAdRequest *)request
gadOrGAMRequest:(GADRequest *)gadOrGAMRequest {
UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTRewardedAd *ad =
[[FLTRewardedAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

// Stub the load call to invoke successful load callback.
Expand Down Expand Up @@ -149,9 +145,8 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
// Show the ad and verify callbacks invoked
[ad show];

OCMVerify([rewardedClassMock
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]
userDidEarnRewardHandler:[OCMArg any]]);
OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isNil]
userDidEarnRewardHandler:[OCMArg any]]);

[fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock];
OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);
Expand Down Expand Up @@ -216,13 +211,9 @@ - (void)testFailedToLoadGAMRequest {

// Helper for testing failed to load.
- (void)testFailedToLoad:(FLTAdRequest *)request {
UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTRewardedAd *ad =
[[FLTRewardedAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId"
request:request
adId:@1];
ad.manager = mockManager;

id rewardedClassMock = OCMClassMock([GADRewardedAd class]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ - (void)testLoadShowRewardedInterstitialAdGAMRequest {
// Helper method for testing with FLTAdRequest and FLTGAMAdRequest.
- (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request
gadOrGAMRequest:(GADRequest *)gadOrGAMRequest {
UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTRewardedInterstitialAd *ad =
[[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
ad.manager = mockManager;

Expand Down Expand Up @@ -155,7 +152,7 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request
[ad show];

OCMVerify([rewardedInterstitialClassMock
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]
presentFromRootViewController:[OCMArg isNil]
userDidEarnRewardHandler:[OCMArg any]]);

// Verify full screen callbacks.
Expand Down Expand Up @@ -202,12 +199,9 @@ - (void)testFailedToLoadGAMRequest {

// Helper for testing failed to load.
- (void)testFailedToLoad:(FLTAdRequest *)request {
UIViewController *mockRootViewController =
OCMClassMock([UIViewController class]);
FLTRewardedInterstitialAd *ad =
[[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId"
request:request
rootViewController:mockRootViewController
adId:@1];
ad.manager = mockManager;

Expand Down
10 changes: 0 additions & 10 deletions packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@
@interface FLTInterstitialAd : FLTFullScreenAd
- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId
request:(FLTAdRequest *_Nonnull)request
rootViewController:
(UIViewController *_Nonnull)rootViewController
adId:(NSNumber *_Nonnull)adId;
- (GADInterstitialAd *_Nullable)interstitial;
- (NSString *_Nonnull)adUnitId;
Expand All @@ -226,16 +224,12 @@
@interface FLTGAMInterstitialAd : FLTInterstitialAd <GADAppEventDelegate>
- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId
request:(FLTGAMAdRequest *_Nonnull)request
rootViewController:
(UIViewController *_Nonnull)rootViewController
adId:(NSNumber *_Nonnull)adId;
@end

@interface FLTRewardedAd : FLTFullScreenAd
- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId
request:(FLTAdRequest *_Nonnull)request
rootViewController:
(UIViewController *_Nonnull)rootViewController
adId:(NSNumber *_Nonnull)adId;
- (GADRewardedAd *_Nullable)rewardedAd;
- (void)setServerSideVerificationOptions:
Expand All @@ -245,8 +239,6 @@
@interface FLTRewardedInterstitialAd : FLTFullScreenAd
- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId
request:(FLTAdRequest *_Nonnull)request
rootViewController:
(UIViewController *_Nonnull)rootViewController
adId:(NSNumber *_Nonnull)adId;
- (GADRewardedInterstitialAd *_Nullable)rewardedInterstitialAd;
- (void)setServerSideVerificationOptions:
Expand All @@ -256,8 +248,6 @@
@interface FLTAppOpenAd : FLTFullScreenAd
- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId
request:(FLTAdRequest *_Nonnull)request
rootViewController:
(UIViewController *_Nonnull)rootViewController
adId:(NSNumber *_Nonnull)adId;
- (GADAppOpenAd *_Nullable)appOpenAd;
@end
Expand Down
Loading