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

[firebase_admob] Provide a default MobileAdTargetingInfo for RewardedVideoAd.load() #2245

Merged
merged 9 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions packages/firebase_admob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.9.3+3

* Provide a default `MobileAdTargetingInfo` for `RewardedVideoAd.load()`. `RewardedVideoAd.load()`
would inadvertently cause a crash if `MobileAdTargetingInfo` was excluded.

## 0.9.3+2

* Fixed bug related to simultaneous ad loading behavior on iOS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed\n/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin\n";
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -270,9 +270,12 @@
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../Flutter/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
106 changes: 106 additions & 0 deletions packages/firebase_admob/example/test_driver/firebase_admob.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2017 The Chromium 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 'dart:async';

import 'package:flutter_driver/driver_extension.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:firebase_admob/firebase_admob.dart';

void main() {
final Completer<String> completer = Completer<String>();
enableFlutterDriverExtension(handler: (_) => completer.future);
tearDownAll(() => completer.complete(null));

group('$FirebaseAdMob', () {
test('Initialize Firebase Admob', () async {
expect(
FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId),
completes,
);
});

test('$BannerAd', () async {
final Completer<void> adCompleter = Completer<void>();

final BannerAd bannerAd = BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.banner,
targetingInfo: MobileAdTargetingInfo(
keywords: <String>['foo', 'bar'],
contentUrl: 'http://foo.com/bar.html',
childDirected: true,
nonPersonalizedAds: true,
),
listener: (MobileAdEvent event) {
if (event == MobileAdEvent.loaded) adCompleter.complete();
},
);

await bannerAd.load();
expect(adCompleter.future, completes);
});

test('$InterstitialAd', () async {
final Completer<void> adCompleter = Completer<void>();

final InterstitialAd interstitialAd = InterstitialAd(
adUnitId: InterstitialAd.testAdUnitId,
targetingInfo: MobileAdTargetingInfo(
keywords: <String>['foo', 'bar'],
contentUrl: 'http://foo.com/bar.html',
childDirected: true,
nonPersonalizedAds: true,
),
listener: (MobileAdEvent event) {
if (event == MobileAdEvent.loaded) adCompleter.complete();
},
);

await interstitialAd.load();
expect(adCompleter.future, completes);
});

test('$RewardedVideoAd', () async {
// Request without a targeting info
bool hasStartedLoading = await RewardedVideoAd.instance.load(
adUnitId: RewardedVideoAd.testAdUnitId,
);
expect(hasStartedLoading, isTrue);

// Request with a targeting info
hasStartedLoading = await RewardedVideoAd.instance.load(
adUnitId: RewardedVideoAd.testAdUnitId,
targetingInfo: MobileAdTargetingInfo(
keywords: <String>['foo', 'bar'],
contentUrl: 'http://foo.com/bar.html',
childDirected: true,
nonPersonalizedAds: true,
),
);
expect(hasStartedLoading, isTrue);
});

test('$NativeAd', () async {
final Completer<void> adCompleter = Completer<void>();

final NativeAd nativeAd = NativeAd(
adUnitId: NativeAd.testAdUnitId,
factoryId: 'adFactoryExample',
targetingInfo: MobileAdTargetingInfo(
keywords: <String>['foo', 'bar'],
contentUrl: 'http://foo.com/bar.html',
childDirected: true,
nonPersonalizedAds: true,
),
listener: (MobileAdEvent event) {
if (event == MobileAdEvent.loaded) adCompleter.complete();
},
);

await nativeAd.load();
expect(adCompleter.future, completes);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2017 The Chromium 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 'package:flutter_driver/flutter_driver.dart';

void main() async {
final FlutterDriver driver = await FlutterDriver.connect();
await driver.requestData(null, timeout: const Duration(minutes: 1));
await driver.close();
}
3 changes: 2 additions & 1 deletion packages/firebase_admob/lib/firebase_admob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ class RewardedVideoAd {

/// Loads a rewarded video ad using the provided ad unit ID.
Future<bool> load(
{@required String adUnitId, MobileAdTargetingInfo targetingInfo}) {
{@required String adUnitId,
MobileAdTargetingInfo targetingInfo = const MobileAdTargetingInfo()}) {
assert(adUnitId.isNotEmpty);
return _invokeBooleanMethod("loadRewardedVideoAd", <String, dynamic>{
'adUnitId': adUnitId,
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_admob/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: firebase_admob
description: Flutter plugin for Firebase AdMob, supporting
banner, interstitial (full-screen), and rewarded video ads
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_admob
version: 0.9.3+2
version: 0.9.3+3

flutter:
plugin:
Expand Down