Skip to content

Commit af88093

Browse files
committed
Integrate Latest @ 138260531
Changes to all testapps ... - Increment Firebase C++ SDK version to 2.0.0, and Firebase Android to 9.8.0. Changes to admob/testapp ... - Add support for Native Express ads. Changes to auth/testapp ... - Add AuthStateListener API for callers to get auth state changes. - Minor fix of log message typo. Changes to database/testapp ... - Added Firebase Realtime Database test app. Changes to invites/testapp ... - Support simplified C++ Invites API, removing InvitesSender and InvitesReceiver. Changes to messaging/testapp ... - Update to use MessageForwardingService on Android. Changes to remote_config/testapp ... - Fixed assert in desktop build of remote config sample. CL: 138260531
1 parent b9133b3 commit af88093

File tree

40 files changed

+3157
-142
lines changed

40 files changed

+3157
-142
lines changed

admob/testapp/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ android {
8989

9090
dependencies {
9191
compile fileTree(dir: 'libs', include: ['*.jar'])
92-
compile 'com.google.firebase:firebase-ads:9.6.0'
93-
compile 'com.google.android.gms:play-services-base:9.6.0'
92+
compile 'com.google.firebase:firebase-ads:9.8.0'
93+
compile 'com.google.android.gms:play-services-base:9.8.0'
9494
}
9595

9696
apply plugin: 'com.google.gms.google-services'

admob/testapp/src/common_main.cc

+146-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "firebase/admob.h"
1616
#include "firebase/admob/banner_view.h"
1717
#include "firebase/admob/interstitial_ad.h"
18+
#include "firebase/admob/native_express_ad_view.h"
1819
#include "firebase/admob/rewarded_video.h"
1920
#include "firebase/admob/types.h"
2021
#include "firebase/app.h"
@@ -53,6 +54,27 @@ class LoggingInterstitialAdListener
5354
}
5455
};
5556

57+
// A simple listener that logs changes to a NativeExpressAdView.
58+
class LoggingNativeExpressAdViewListener
59+
: public firebase::admob::NativeExpressAdView::Listener {
60+
public:
61+
LoggingNativeExpressAdViewListener() {}
62+
void OnPresentationStateChanged(
63+
firebase::admob::NativeExpressAdView* native_express_ad_view,
64+
firebase::admob::NativeExpressAdView::PresentationState state) override {
65+
::LogMessage("NativeExpressAdView PresentationState has changed to %d.",
66+
state);
67+
}
68+
void OnBoundingBoxChanged(
69+
firebase::admob::NativeExpressAdView* native_express_ad_view,
70+
firebase::admob::BoundingBox box) override {
71+
::LogMessage(
72+
"NativeExpressAdView BoundingBox has changed to (x: %d, y: %d, width: "
73+
"%d, height %d).",
74+
box.x, box.y, box.width, box.height);
75+
}
76+
};
77+
5678
// A simple listener that logs changes to rewarded video state.
5779
class LoggingRewardedVideoListener
5880
: public firebase::admob::rewarded_video::Listener {
@@ -79,17 +101,23 @@ const char* kAdMobAppID = "ca-app-pub-3940256099942544~1458002511";
79101
#if defined(__ANDROID__)
80102
const char* kBannerAdUnit = "ca-app-pub-3940256099942544/6300978111";
81103
const char* kInterstitialAdUnit = "ca-app-pub-3940256099942544/1033173712";
104+
const char* kNativeExpressAdUnit = "ca-app-pub-3940256099942544/1072772517";
82105
const char* kRewardedVideoAdUnit = "YOUR_REWARDED_VIDEO_AD_UNIT_ID";
83106
#else
84107
const char* kBannerAdUnit = "ca-app-pub-3940256099942544/2934735716";
85108
const char* kInterstitialAdUnit = "ca-app-pub-3940256099942544/4411468910";
109+
const char* kNativeExpressAdUnit = "ca-app-pub-3940256099942544/2562852117";
86110
const char* kRewardedVideoAdUnit = "YOUR_REWARDED_VIDEO_AD_UNIT_ID";
87111
#endif
88112

89113
// Standard mobile banner size is 320x50.
90114
static const int kBannerWidth = 320;
91115
static const int kBannerHeight = 50;
92116

117+
// The native express ad's width and height.
118+
static const int kNativeExpressAdWidth = 320;
119+
static const int kNativeExpressAdHeight = 220;
120+
93121
// Sample keywords to use in making the request.
94122
static const char* kKeywords[] = {"AdMob", "C++", "Fun"};
95123

@@ -121,10 +149,9 @@ extern "C" int common_main(int argc, const char* argv[]) {
121149
LogMessage("Initializing the AdMob library.");
122150

123151
#if defined(__ANDROID__)
124-
app =
125-
firebase::App::Create(firebase::AppOptions(), GetJniEnv(), GetActivity());
152+
app = ::firebase::App::Create(GetJniEnv(), GetActivity());
126153
#else
127-
app = firebase::App::Create(firebase::AppOptions());
154+
app = ::firebase::App::Create();
128155
#endif // defined(__ANDROID__)
129156

130157
LogMessage("Created the Firebase App %x.",
@@ -174,33 +201,33 @@ extern "C" int common_main(int argc, const char* argv[]) {
174201
request.test_device_ids = kTestDeviceIDs;
175202

176203
// Create an ad size for the BannerView.
177-
firebase::admob::AdSize ad_size;
178-
ad_size.ad_size_type = firebase::admob::kAdSizeStandard;
179-
ad_size.width = kBannerWidth;
180-
ad_size.height = kBannerHeight;
204+
firebase::admob::AdSize banner_ad_size;
205+
banner_ad_size.ad_size_type = firebase::admob::kAdSizeStandard;
206+
banner_ad_size.width = kBannerWidth;
207+
banner_ad_size.height = kBannerHeight;
181208

182209
LogMessage("Creating the BannerView.");
183210
firebase::admob::BannerView* banner = new firebase::admob::BannerView();
184-
banner->Initialize(GetWindowContext(), kBannerAdUnit, ad_size);
211+
banner->Initialize(GetWindowContext(), kBannerAdUnit, banner_ad_size);
185212

186213
WaitForFutureCompletion(banner->InitializeLastResult());
187214

188215
// Set the listener.
189216
LoggingBannerViewListener banner_listener;
190217
banner->SetListener(&banner_listener);
191218

219+
// Load the banner ad.
220+
LogMessage("Loading a banner ad.");
221+
banner->LoadAd(request);
222+
223+
WaitForFutureCompletion(banner->LoadAdLastResult());
224+
192225
// Make the BannerView visible.
193226
LogMessage("Showing the banner ad.");
194227
banner->Show();
195228

196229
WaitForFutureCompletion(banner->ShowLastResult());
197230

198-
// When the BannerView is visible, load an ad into it.
199-
LogMessage("Loading a banner ad.");
200-
banner->LoadAd(request);
201-
202-
WaitForFutureCompletion(banner->LoadAdLastResult());
203-
204231
// Move to each of the six pre-defined positions.
205232
LogMessage("Moving the banner ad to top-center.");
206233
banner->MoveTo(firebase::admob::BannerView::kPositionTop);
@@ -301,6 +328,110 @@ extern "C" int common_main(int argc, const char* argv[]) {
301328
ProcessEvents(1000);
302329
}
303330

331+
// Create an ad size for the NativeExpressAdView.
332+
firebase::admob::AdSize native_express_ad_size;
333+
native_express_ad_size.ad_size_type = firebase::admob::kAdSizeStandard;
334+
native_express_ad_size.width = kNativeExpressAdWidth;
335+
native_express_ad_size.height = kNativeExpressAdHeight;
336+
337+
LogMessage("Creating the NativeExpressAdView.");
338+
firebase::admob::NativeExpressAdView* native_express_ad =
339+
new firebase::admob::NativeExpressAdView();
340+
native_express_ad->Initialize(GetWindowContext(), kNativeExpressAdUnit,
341+
native_express_ad_size);
342+
343+
WaitForFutureCompletion(native_express_ad->InitializeLastResult());
344+
345+
// Set the listener.
346+
LoggingNativeExpressAdViewListener native_express_ad_listener;
347+
native_express_ad->SetListener(&native_express_ad_listener);
348+
349+
// Load the native express ad.
350+
LogMessage("Loading a native express ad.");
351+
native_express_ad->LoadAd(request);
352+
353+
WaitForFutureCompletion(native_express_ad->LoadAdLastResult());
354+
355+
// Make the NativeExpressAdView visible.
356+
LogMessage("Showing the native express ad.");
357+
native_express_ad->Show();
358+
359+
WaitForFutureCompletion(native_express_ad->ShowLastResult());
360+
361+
// Move to each of the six pre-defined positions.
362+
LogMessage("Moving the native express ad to top-center.");
363+
native_express_ad->MoveTo(firebase::admob::NativeExpressAdView::kPositionTop);
364+
365+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
366+
367+
LogMessage("Moving the native express ad to top-left.");
368+
native_express_ad->MoveTo(
369+
firebase::admob::NativeExpressAdView::kPositionTopLeft);
370+
371+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
372+
373+
LogMessage("Moving the native express ad to top-right.");
374+
native_express_ad->MoveTo(
375+
firebase::admob::NativeExpressAdView::kPositionTopRight);
376+
377+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
378+
379+
LogMessage("Moving the native express ad to bottom-center.");
380+
native_express_ad->MoveTo(
381+
firebase::admob::NativeExpressAdView::kPositionBottom);
382+
383+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
384+
385+
LogMessage("Moving the native express ad to bottom-left.");
386+
native_express_ad->MoveTo(
387+
firebase::admob::NativeExpressAdView::kPositionBottomLeft);
388+
389+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
390+
391+
LogMessage("Moving the native express ad to bottom-right.");
392+
native_express_ad->MoveTo(
393+
firebase::admob::NativeExpressAdView::kPositionBottomRight);
394+
395+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
396+
397+
// Try some coordinate moves.
398+
LogMessage("Moving the native express ad to (100, 300).");
399+
native_express_ad->MoveTo(100, 300);
400+
401+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
402+
403+
LogMessage("Moving the native express ad to (100, 400).");
404+
native_express_ad->MoveTo(100, 400);
405+
406+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
407+
408+
// Try hiding and showing the NativeExpressAdView.
409+
LogMessage("Hiding the native express ad.");
410+
native_express_ad->Hide();
411+
412+
WaitForFutureCompletion(native_express_ad->HideLastResult());
413+
414+
LogMessage("Showing the native express ad.");
415+
native_express_ad->Show();
416+
417+
WaitForFutureCompletion(native_express_ad->ShowLastResult());
418+
419+
// A few last moves after showing it again.
420+
LogMessage("Moving the native express ad to (100, 300).");
421+
native_express_ad->MoveTo(100, 300);
422+
423+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
424+
425+
LogMessage("Moving the native express ad to (100, 400).");
426+
native_express_ad->MoveTo(100, 400);
427+
428+
WaitForFutureCompletion(native_express_ad->MoveToLastResult());
429+
430+
LogMessage("Hiding the native express ad now that we're done with it.");
431+
native_express_ad->Hide();
432+
433+
WaitForFutureCompletion(native_express_ad->HideLastResult());
434+
304435
// Start up rewarded video ads and associated mediation adapters.
305436
LogMessage("Initializing rewarded video.");
306437
namespace rewarded_video = firebase::admob::rewarded_video;
@@ -355,6 +486,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
355486

356487
delete banner;
357488
delete interstitial;
489+
delete native_express_ad;
358490
rewarded_video::Destroy();
359491
firebase::admob::Terminate();
360492
delete app;

analytics/testapp/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ android {
9090

9191
dependencies {
9292
compile fileTree(dir: 'libs', include: ['*.jar'])
93-
compile 'com.google.firebase:firebase-analytics:9.6.0'
94-
compile 'com.google.android.gms:play-services-base:9.6.0'
93+
compile 'com.google.firebase:firebase-analytics:9.8.0'
94+
compile 'com.google.android.gms:play-services-base:9.8.0'
9595
}
9696

9797
apply plugin: 'com.google.gms.google-services'

analytics/testapp/src/common_main.cc

+2-11
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,12 @@ extern "C" int common_main(int argc, const char* argv[]) {
2727
::firebase::App* app;
2828

2929
LogMessage("Initialize the Analytics library");
30-
do {
3130
#if defined(__ANDROID__)
32-
app = ::firebase::App::Create(::firebase::AppOptions(), GetJniEnv(),
33-
GetActivity());
31+
app = ::firebase::App::Create(GetJniEnv(), GetActivity());
3432
#else
35-
app = ::firebase::App::Create(::firebase::AppOptions());
33+
app = ::firebase::App::Create();
3634
#endif // defined(__ANDROID__)
3735

38-
if (app == nullptr) {
39-
LogMessage("Couldn't create firebase app, try again.");
40-
// Wait a few moments, and try to create app again.
41-
ProcessEvents(1000);
42-
}
43-
} while (app == nullptr);
44-
4536
LogMessage("Created the firebase app %x",
4637
static_cast<int>(reinterpret_cast<intptr_t>(app)));
4738
analytics::Initialize(*app);

auth/testapp/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ android {
9090

9191
dependencies {
9292
compile fileTree(dir: 'libs', include: ['*.jar'])
93-
compile 'com.google.firebase:firebase-auth:9.6.0'
94-
compile 'com.google.android.gms:play-services-base:9.6.0'
93+
compile 'com.google.firebase:firebase-auth:9.8.0'
94+
compile 'com.google.android.gms:play-services-base:9.8.0'
9595
}
9696

9797
apply plugin: 'com.google.gms.google-services'

auth/testapp/src/common_main.cc

+58-5
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,38 @@ static void ExpectStringsEqual(const char* test, const char* expected,
155155
}
156156
}
157157

158+
class AuthStateChangeCounter : public firebase::auth::AuthStateListener {
159+
public:
160+
AuthStateChangeCounter() : num_state_changes_(0) {}
161+
162+
virtual void OnAuthStateChanged(Auth* auth) { num_state_changes_++; }
163+
164+
void CompleteTest(const char* test_name, int expected_state_changes) {
165+
CompleteTest(test_name, expected_state_changes, expected_state_changes);
166+
}
167+
168+
void CompleteTest(const char* test_name, int min_state_changes,
169+
int max_state_changes) {
170+
const bool success = min_state_changes <= num_state_changes_ &&
171+
num_state_changes_ <= max_state_changes;
172+
LogMessage("%sAuthStateListener called %d time%s on %s.",
173+
success ? "" : "ERROR: ", num_state_changes_,
174+
num_state_changes_ == 1 ? "" : "s", test_name);
175+
num_state_changes_ = 0;
176+
}
177+
178+
private:
179+
int num_state_changes_;
180+
};
181+
158182
// Utility class for holding a user's login credentials.
159183
class UserLogin {
160184
public:
161185
UserLogin(Auth* auth, const std::string& email, const std::string& password)
162-
: auth_(auth), email_(email), password_(password), user_(nullptr),
186+
: auth_(auth),
187+
email_(email),
188+
password_(password),
189+
user_(nullptr),
163190
log_errors_(true) {}
164191

165192
explicit UserLogin(Auth* auth) : auth_(auth) {
@@ -225,12 +252,11 @@ class UserLogin {
225252
extern "C" int common_main(int argc, const char* argv[]) {
226253
App* app;
227254
LogMessage("Starting Auth tests.");
228-
// Create the App wrapper.
229255

230256
#if defined(__ANDROID__)
231-
app = App::Create(AppOptions(), GetJniEnv(), GetActivity());
257+
app = App::Create(GetJniEnv(), GetActivity());
232258
#else
233-
app = App::Create(AppOptions());
259+
app = App::Create();
234260
#endif // defined(__ANDROID__)
235261

236262
LogMessage("Created the Firebase app %x.",
@@ -290,12 +316,39 @@ extern "C" int common_main(int argc, const char* argv[]) {
290316
}
291317
}
292318

319+
// --- StateChange tests -----------------------------------------------------
320+
{
321+
AuthStateChangeCounter counter;
322+
323+
// Test notification on registration.
324+
auth->AddAuthStateListener(&counter);
325+
counter.CompleteTest("registration", 0);
326+
327+
// Test notification on SignOut(), when already signed-out.
328+
auth->SignOut();
329+
counter.CompleteTest("SignOut() when already signed-out", 0);
330+
331+
// Test notification on SignIn().
332+
Future<User*> sign_in_future = auth->SignInAnonymously();
333+
WaitForSignInFuture(sign_in_future, "Auth::SignInAnonymously()",
334+
kAuthErrorNone, auth);
335+
counter.CompleteTest("SignInAnonymously()", 1, 4);
336+
337+
// Test notification on SignOut(), when signed-in.
338+
// TODO(jsanmiya): Change the minimum expected callbacks to 1 once
339+
// b/32179003 is fixed.
340+
auth->SignOut();
341+
counter.CompleteTest("SignOut()", 0, 4);
342+
343+
auth->RemoveAuthStateListener(&counter);
344+
}
345+
293346
// --- Auth tests ------------------------------------------------------------
294347
{
295348
UserLogin user_login(auth); // Generate a random name/password
296349
user_login.Register();
297350
if (!user_login.user()) {
298-
LogMessage("Error - Could not create in with user.");
351+
LogMessage("ERROR: Could not register new user.");
299352
} else {
300353
// Test Auth::SignInAnonymously().
301354
{

0 commit comments

Comments
 (0)