19
19
#include < cstdlib>
20
20
#include < cstring>
21
21
#include < ctime>
22
+ #include < vector>
22
23
23
24
#include " app_framework.h" // NOLINT
24
25
#include " firebase/admob.h"
@@ -67,6 +68,10 @@ const char* kBannerAdUnit = "ca-app-pub-3940256099942544/2934735716";
67
68
const char * kInterstitialAdUnit = " ca-app-pub-3940256099942544/4411468910" ;
68
69
#endif
69
70
71
+ // Sample test device IDs to use in making the request.
72
+ const std::vector<std::string> kTestDeviceIDs = {
73
+ " 2077ef9a63d2b398840261c8221a0c9b" , " 098fe087d987c9a878965454a65654d7" };
74
+
70
75
using app_framework::LogDebug;
71
76
using app_framework::ProcessEvents;
72
77
@@ -137,18 +142,28 @@ FirebaseAdMobTest::FirebaseAdMobTest() {}
137
142
138
143
FirebaseAdMobTest::~FirebaseAdMobTest () {}
139
144
140
- void FirebaseAdMobTest::SetUp () { FirebaseTest::SetUp (); }
145
+ void FirebaseAdMobTest::SetUp () {
146
+ FirebaseTest::SetUp ();
147
+
148
+ // This example uses ad units that are specially configured to return test ads
149
+ // for every request. When using your own ad unit IDs, however, it's important
150
+ // to register the device IDs associated with any devices that will be used to
151
+ // test the app. This ensures that regardless of the ad unit ID, those
152
+ // devices will always receive test ads in compliance with AdMob policy.
153
+ //
154
+ // Device IDs can be obtained by checking the logcat or the Xcode log while
155
+ // debugging. They appear as a long string of hex characters.
156
+ firebase::admob::RequestConfiguration request_configuration;
157
+ request_configuration.test_device_ids = kTestDeviceIDs ;
158
+ firebase::admob::SetRequestConfiguration (request_configuration);
159
+ }
141
160
142
161
void FirebaseAdMobTest::TearDown () { FirebaseTest::TearDown (); }
143
162
144
163
firebase::admob::AdRequest FirebaseAdMobTest::GetAdRequest () {
145
164
// Sample keywords to use in making the request.
146
165
static const char * kKeywords [] = {" AdMob" , " C++" , " Fun" };
147
166
148
- // Sample test device IDs to use in making the request.
149
- static const char * kTestDeviceIDs [] = {" 2077ef9a63d2b398840261c8221a0c9b" ,
150
- " 098fe087d987c9a878965454a65654d7" };
151
-
152
167
firebase::admob::AdRequest request;
153
168
154
169
// Additional keywords to be used in targeting.
@@ -162,17 +177,6 @@ firebase::admob::AdRequest FirebaseAdMobTest::GetAdRequest() {
162
177
request.extras_count = sizeof (kRequestExtras ) / sizeof (kRequestExtras [0 ]);
163
178
request.extras = kRequestExtras ;
164
179
165
- // This example uses ad units that are specially configured to return test ads
166
- // for every request. When using your own ad unit IDs, however, it's important
167
- // to register the device IDs associated with any devices that will be used to
168
- // test the app. This ensures that regardless of the ad unit ID, those
169
- // devices will always receive test ads in compliance with AdMob policy.
170
- //
171
- // Device IDs can be obtained by checking the logcat or the Xcode log while
172
- // debugging. They appear as a long string of hex characters.
173
- request.test_device_id_count =
174
- sizeof (kTestDeviceIDs ) / sizeof (kTestDeviceIDs [0 ]);
175
- request.test_device_ids = kTestDeviceIDs ;
176
180
return request;
177
181
}
178
182
@@ -196,9 +200,75 @@ class TestBannerViewListener : public firebase::admob::BannerView::Listener {
196
200
std::vector<firebase::admob::BoundingBox> bounding_box_changes_;
197
201
};
198
202
203
+ TEST_F (FirebaseAdMobTest, TestRequestConfigurationSetGetEmptyConfig) {
204
+ SKIP_TEST_ON_DESKTOP;
205
+
206
+ firebase::admob::RequestConfiguration set_configuration;
207
+ firebase::admob::SetRequestConfiguration (set_configuration);
208
+ firebase::admob::RequestConfiguration retrieved_configuration =
209
+ firebase::admob::GetRequestConfiguration ();
210
+
211
+ EXPECT_EQ (
212
+ retrieved_configuration.max_ad_content_rating ,
213
+ firebase::admob::RequestConfiguration::kMaxAdContentRatingUnspecified );
214
+ EXPECT_EQ (retrieved_configuration.tag_for_child_directed_treatment ,
215
+ firebase::admob::RequestConfiguration::
216
+ kChildDirectedTreatmentUnspecified );
217
+ EXPECT_EQ (
218
+ retrieved_configuration.tag_for_under_age_of_consent ,
219
+ firebase::admob::RequestConfiguration::kUnderAgeOfConsentUnspecified );
220
+ EXPECT_EQ (retrieved_configuration.test_device_ids .size (), 0 );
221
+ }
222
+
223
+ TEST_F (FirebaseAdMobTest, TestRequestConfigurationSetGet) {
224
+ SKIP_TEST_ON_DESKTOP;
225
+
226
+ firebase::admob::RequestConfiguration set_configuration;
227
+ set_configuration.max_ad_content_rating =
228
+ firebase::admob::RequestConfiguration::kMaxAdContentRatingPG ;
229
+ set_configuration.tag_for_child_directed_treatment =
230
+ firebase::admob::RequestConfiguration::kChildDirectedTreatmentTrue ;
231
+ set_configuration.tag_for_under_age_of_consent =
232
+ firebase::admob::RequestConfiguration::kUnderAgeOfConsentFalse ;
233
+ set_configuration.test_device_ids .push_back (" 1" );
234
+ set_configuration.test_device_ids .push_back (" 2" );
235
+ set_configuration.test_device_ids .push_back (" 3" );
236
+ firebase::admob::SetRequestConfiguration (set_configuration);
237
+
238
+ firebase::admob::RequestConfiguration retrieved_configuration =
239
+ firebase::admob::GetRequestConfiguration ();
240
+
241
+ EXPECT_EQ (retrieved_configuration.max_ad_content_rating ,
242
+ firebase::admob::RequestConfiguration::kMaxAdContentRatingPG );
243
+
244
+ #if defined(__ANDROID__)
245
+ EXPECT_EQ (retrieved_configuration.tag_for_child_directed_treatment ,
246
+ firebase::admob::RequestConfiguration::kChildDirectedTreatmentTrue );
247
+ EXPECT_EQ (retrieved_configuration.tag_for_under_age_of_consent ,
248
+ firebase::admob::RequestConfiguration::kUnderAgeOfConsentFalse );
249
+ #else // iOS
250
+ // iOS doesn't allow for the querying of these values.
251
+ EXPECT_EQ (retrieved_configuration.tag_for_child_directed_treatment ,
252
+ firebase::admob::RequestConfiguration::
253
+ kChildDirectedTreatmentUnspecified );
254
+ EXPECT_EQ (
255
+ retrieved_configuration.tag_for_under_age_of_consent ,
256
+ firebase::admob::RequestConfiguration::kUnderAgeOfConsentUnspecified );
257
+ #endif
258
+
259
+ EXPECT_EQ (retrieved_configuration.test_device_ids .size (), 3 );
260
+ EXPECT_TRUE (std::count (retrieved_configuration.test_device_ids .begin (),
261
+ retrieved_configuration.test_device_ids .end (), " 1" ));
262
+ EXPECT_TRUE (std::count (retrieved_configuration.test_device_ids .begin (),
263
+ retrieved_configuration.test_device_ids .end (), " 2" ));
264
+ EXPECT_TRUE (std::count (retrieved_configuration.test_device_ids .begin (),
265
+ retrieved_configuration.test_device_ids .end (), " 3" ));
266
+ }
267
+
199
268
TEST_F (FirebaseAdMobTest, TestBannerView) {
200
269
// AdMob cannot be tested on Firebase Test Lab, so disable tests on FTL.
201
270
TEST_REQUIRES_USER_INTERACTION;
271
+ SKIP_TEST_ON_DESKTOP;
202
272
203
273
static const int kBannerWidth = 320 ;
204
274
static const int kBannerHeight = 50 ;
@@ -409,6 +479,7 @@ class TestInterstitialAdListener
409
479
410
480
TEST_F (FirebaseAdMobTest, TestInterstitialAd) {
411
481
TEST_REQUIRES_USER_INTERACTION;
482
+ SKIP_TEST_ON_DESKTOP;
412
483
413
484
firebase::admob::InterstitialAd* interstitial =
414
485
new firebase::admob::InterstitialAd ();
0 commit comments