50
50
namespace firebase_testapp_automated {
51
51
52
52
// The AdMob app IDs for the test app.
53
- #if defined(__ANDROID__ )
53
+ #if defined(ANDROID )
54
54
// If you change the AdMob app ID for your Android app, make sure to change it
55
55
// in AndroidManifest.xml as well.
56
56
const char * kAdMobAppID = " ca-app-pub-3940256099942544~3347511713" ;
@@ -62,7 +62,7 @@ const char* kAdMobAppID = "ca-app-pub-3940256099942544~1458002511";
62
62
63
63
// These ad units IDs have been created specifically for testing, and will
64
64
// always return test ads.
65
- #if defined(__ANDROID__ )
65
+ #if defined(ANDROID )
66
66
const char * kBannerAdUnit = " ca-app-pub-3940256099942544/6300978111" ;
67
67
const char * kInterstitialAdUnit = " ca-app-pub-3940256099942544/1033173712" ;
68
68
#else
@@ -86,7 +86,7 @@ enum AdCallbackEvent {
86
86
};
87
87
88
88
// Error domains vary across phone SDKs.
89
- #if defined(__ANDROID__ )
89
+ #if defined(ANDROID )
90
90
const char * kErrorDomain = " com.google.android.gms.ads" ;
91
91
#else
92
92
const char * kErrorDomain = " com.google.admob" ;
@@ -105,7 +105,7 @@ static const std::map<std::string, std::string> kAdMobAdapterExtras = {
105
105
{" the_name_of_an_extra" , " the_value_for_that_extra" },
106
106
{" heres" , " a second example" }};
107
107
108
- #if defined(__ANDROID__ )
108
+ #if defined(ANDROID )
109
109
static const char * kAdNetworkExtrasClassName =
110
110
" com/google/ads/mediation/admob/AdMobAdapter" ;
111
111
#else
@@ -123,6 +123,12 @@ using app_framework::ProcessEvents;
123
123
124
124
using firebase_test_framework::FirebaseTest;
125
125
126
+ using testing::AnyOf;
127
+ using testing::Contains;
128
+ using testing::HasSubstr;
129
+ using testing::Pair;
130
+ using testing::Property;
131
+
126
132
class FirebaseAdMobTest : public FirebaseTest {
127
133
public:
128
134
FirebaseAdMobTest ();
@@ -151,20 +157,22 @@ void FirebaseAdMobTest::SetUpTestSuite() {
151
157
152
158
FindFirebaseConfig (FIREBASE_CONFIG_STRING);
153
159
154
- #if defined(__ANDROID__ )
160
+ #if defined(ANDROID )
155
161
shared_app_ = ::firebase::App::Create (app_framework::GetJniEnv (),
156
162
app_framework::GetActivity ());
157
163
#else
158
164
shared_app_ = ::firebase::App::Create ();
159
- #endif // defined(__ANDROID__ )
165
+ #endif // defined(ANDROID )
160
166
161
167
LogDebug (" Initializing AdMob." );
162
168
163
169
::firebase::ModuleInitializer initializer;
164
170
initializer.Initialize (shared_app_, nullptr ,
165
171
[](::firebase::App* app, void * /* userdata */ ) {
166
172
LogDebug (" Try to initialize AdMob" );
167
- return ::firebase::admob::Initialize (*app);
173
+ firebase::InitResult result;
174
+ ::firebase::admob::Initialize (*app, &result);
175
+ return result;
168
176
});
169
177
170
178
WaitForCompletion (initializer.InitializeLastResult (), " Initialize" );
@@ -231,6 +239,45 @@ firebase::admob::AdRequest FirebaseAdMobTest::GetAdRequest() {
231
239
}
232
240
233
241
// Test cases below.
242
+ TEST_F (FirebaseAdMobTest, TestInitializationStatus) {
243
+ // Ensure Initialize()'s result matches GetInitializationStatus().
244
+ auto initialize_future = firebase::admob::InitializeLastResult ();
245
+ WaitForCompletion (initialize_future, " admob::Initialize" );
246
+ ASSERT_NE (initialize_future.result (), nullptr );
247
+ EXPECT_EQ (*initialize_future.result (),
248
+ firebase::admob::GetInitializationStatus ());
249
+
250
+ for (auto adapter_status :
251
+ firebase::admob::GetInitializationStatus ().GetAdapterStatusMap ()) {
252
+ LogDebug (" AdMob Mediation Adapter '%s' %s (latency %d ms): %s" ,
253
+ adapter_status.first .c_str (),
254
+ (adapter_status.second .is_initialized () ? " loaded" : " NOT loaded" ),
255
+ adapter_status.second .latency (),
256
+ adapter_status.second .description ().c_str ());
257
+ }
258
+
259
+ #if defined(ANDROID)
260
+ const char kAdMobClassName [] = " com.google.android.gms.ads.MobileAds" ;
261
+ #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
262
+ const char kAdMobClassName [] = " GADMobileAds" ;
263
+ #else // desktop
264
+ const char kAdMobClassName [] = " stub" ;
265
+ #endif
266
+
267
+ // Confirm that the default Google Mobile Ads SDK class name shows up in the
268
+ // list. It should either be is_initialized = true, or description should say
269
+ // "Timeout" (this is a special case we are using to deflake this test on
270
+ // Android emulator).
271
+ EXPECT_THAT (
272
+ initialize_future.result ()->GetAdapterStatusMap (),
273
+ Contains (Pair (
274
+ kAdMobClassName ,
275
+ AnyOf (Property (&firebase::admob::AdapterStatus::is_initialized, true ),
276
+ Property (&firebase::admob::AdapterStatus::description,
277
+ HasSubstr (" Timeout" ))))))
278
+ << " Expected adapter class '" << kAdMobClassName << " ' is not loaded." ;
279
+ }
280
+
234
281
TEST_F (FirebaseAdMobTest, TestGetAdRequest) { GetAdRequest (); }
235
282
236
283
TEST_F (FirebaseAdMobTest, TestGetAdRequestValues) {
@@ -465,7 +512,7 @@ TEST_F(FirebaseAdMobTest, TestRequestConfigurationSetGet) {
465
512
EXPECT_EQ (retrieved_configuration.max_ad_content_rating ,
466
513
firebase::admob::RequestConfiguration::kMaxAdContentRatingPG );
467
514
468
- #if defined(__ANDROID__ )
515
+ #if defined(ANDROID )
469
516
EXPECT_EQ (retrieved_configuration.tag_for_child_directed_treatment ,
470
517
firebase::admob::RequestConfiguration::kChildDirectedTreatmentTrue );
471
518
EXPECT_EQ (retrieved_configuration.tag_for_under_age_of_consent ,
@@ -643,7 +690,7 @@ TEST_F(FirebaseAdMobTest, TestBannerView) {
643
690
EXPECT_EQ (++expected_num_bounding_box_changes,
644
691
bounding_box_listener.bounding_box_changes_ .size ());
645
692
646
- #if defined(__ANDROID__ ) || TARGET_OS_IPHONE
693
+ #if defined(ANDROID ) || TARGET_OS_IPHONE
647
694
// As an extra check, all bounding boxes except the last should have the same
648
695
// size aspect ratio that we requested. For example if you requested a 320x50
649
696
// banner, you can get one with the size 960x150. Use EXPECT_NEAR because the
0 commit comments