Skip to content

Commit 521a3a3

Browse files
committed
Integrate Latest @ 201086911
Changes to all ... - Update Android dependency versions. Changes to analytics/testapp ... - Added support for reading the instance ID. Changes to auth/testapp ... - Add additional logging and SignInAndRetrieveDataWithCredential test. Changes to functions/testapp ... - Add Functions testapp for C++. Changes to storage/testapp ... - Add additional Metadata-related tests. CL: 201086911
1 parent 27201e2 commit 521a3a3

File tree

41 files changed

+10861
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+10861
-18
lines changed

admob/testapp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ android {
9191
}
9292

9393
dependencies {
94-
compile 'com.google.firebase:firebase-core:16.0.0'
94+
compile 'com.google.firebase:firebase-core:16.0.1'
9595
compile 'com.google.firebase:firebase-ads:15.0.1'
9696
compile 'com.google.firebase:firebase-common:16.0.0'
9797
}

analytics/testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ android {
9191
}
9292

9393
dependencies {
94-
compile 'com.google.firebase:firebase-core:16.0.0'
95-
compile 'com.google.firebase:firebase-analytics:16.0.0'
94+
compile 'com.google.firebase:firebase-core:16.0.1'
95+
compile 'com.google.firebase:firebase-analytics:16.0.1'
9696
compile 'com.google.firebase:firebase-common:16.0.0'
9797
}
9898

analytics/testapp/src/common_main.cc

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,24 @@ extern "C" int common_main(int argc, const char* argv[]) {
4040

4141
LogMessage("Enabling data collection.");
4242
analytics::SetAnalyticsCollectionEnabled(true);
43-
// App needs to be open at least 1s before logging a valid session.
44-
analytics::SetMinimumSessionDuration(1000);
45-
// App session times out after 5s.
46-
analytics::SetSessionTimeoutDuration(5000);
43+
// App needs to be open at least 10s before logging a valid session.
44+
analytics::SetMinimumSessionDuration(1000 * 10);
45+
// App session times out after 30 minutes.
46+
// If the app is placed in the background and returns to the foreground after
47+
// the timeout is expired analytics will log a new session.
48+
analytics::SetSessionTimeoutDuration(1000 * 60 * 30);
49+
50+
LogMessage("Get App Instance ID...");
51+
auto future_result = analytics::GetAnalyticsInstanceId();
52+
while (future_result.status() == firebase::kFutureStatusPending) {
53+
if (ProcessEvents(1000)) break;
54+
}
55+
if (future_result.status() == firebase::kFutureStatusComplete) {
56+
LogMessage("Analytics Instance ID %s", future_result.result()->c_str());
57+
} else {
58+
LogMessage("ERROR: Failed to fetch Analytics Instance ID %s (%d)",
59+
future_result.error_message(), future_result.error());
60+
}
4761

4862
LogMessage("Set user properties.");
4963
// Set the user's sign up method.

auth/testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ android {
9191
}
9292

9393
dependencies {
94-
compile 'com.google.firebase:firebase-core:16.0.0'
95-
compile 'com.google.firebase:firebase-auth:16.0.1'
94+
compile 'com.google.firebase:firebase-core:16.0.1'
95+
compile 'com.google.firebase:firebase-auth:16.0.2'
9696
compile 'com.google.firebase:firebase-common:16.0.0'
9797
}
9898

auth/testapp/src/common_main.cc

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ using ::firebase::App;
2727
using ::firebase::AppOptions;
2828
using ::firebase::Future;
2929
using ::firebase::FutureBase;
30+
using ::firebase::Variant;
31+
using ::firebase::auth::AdditionalUserInfo;
3032
using ::firebase::auth::Auth;
3133
using ::firebase::auth::AuthError;
3234
using ::firebase::auth::Credential;
@@ -39,8 +41,10 @@ using ::firebase::auth::kAuthErrorNone;
3941
using ::firebase::auth::OAuthProvider;
4042
using ::firebase::auth::PhoneAuthProvider;
4143
using ::firebase::auth::PlayGamesAuthProvider;
44+
using ::firebase::auth::SignInResult;
4245
using ::firebase::auth::TwitterAuthProvider;
4346
using ::firebase::auth::User;
47+
using ::firebase::auth::UserMetadata;
4448
using ::firebase::auth::UserInfoInterface;
4549

4650
// Set this to true, and set the email/password, to test a custom email address.
@@ -73,7 +77,7 @@ static const char kFirebaseProviderId[] =
7377
// Don't return until `future` is complete.
7478
// Print a message for whether the result mathes our expectations.
7579
// Returns true if the application should exit.
76-
static bool WaitForFuture(FutureBase future, const char* fn,
80+
static bool WaitForFuture(const FutureBase& future, const char* fn,
7781
AuthError expected_error, bool log_error = true) {
7882
// Note if the future has not be started properly.
7983
if (future.status() == ::firebase::kFutureStatusInvalid) {
@@ -125,6 +129,25 @@ static bool WaitForSignInFuture(Future<User*> sign_in_future, const char* fn,
125129
return false;
126130
}
127131

132+
static bool WaitForSignInFuture(const Future<SignInResult>& sign_in_future,
133+
const char* fn, AuthError expected_error,
134+
Auth* auth) {
135+
if (WaitForFuture(sign_in_future, fn, expected_error)) return true;
136+
137+
const SignInResult* sign_in_result = sign_in_future.result();
138+
const User* sign_in_user = sign_in_result ? sign_in_result->user : nullptr;
139+
const User* auth_user = auth->current_user();
140+
141+
if (expected_error == ::firebase::auth::kAuthErrorNone &&
142+
sign_in_user != auth_user) {
143+
LogMessage("ERROR: future's user (%x) and current_user (%x) don't match",
144+
static_cast<int>(reinterpret_cast<intptr_t>(sign_in_user)),
145+
static_cast<int>(reinterpret_cast<intptr_t>(auth_user)));
146+
}
147+
148+
return false;
149+
}
150+
128151
// Wait for the current user to sign out. Typically you should use the
129152
// state listener to determine whether the user has signed out.
130153
static bool WaitForSignOut(firebase::auth::Auth* auth) {
@@ -170,6 +193,77 @@ static void ExpectStringsEqual(const char* test, const char* expected,
170193
}
171194
}
172195

196+
static void LogVariantMap(const std::map<Variant, Variant>& variant_map,
197+
int indent);
198+
199+
// Log a vector of variants.
200+
static void LogVariantVector(const std::vector<Variant>& variants,
201+
int indent) {
202+
std::string indent_string(indent * 2, ' ');
203+
LogMessage("%s[", indent_string.c_str());
204+
for (auto it = variants.begin(); it != variants.end(); ++it) {
205+
const Variant& item = *it;
206+
if (item.is_fundamental_type()) {
207+
const Variant& string_value = item.AsString();
208+
LogMessage("%s %s,", indent_string.c_str(),
209+
string_value.string_value());
210+
} else if (item.is_vector()) {
211+
LogVariantVector(item.vector(), indent + 2);
212+
} else if (item.is_map()) {
213+
LogVariantMap(item.map(), indent + 2);
214+
} else {
215+
LogMessage("%s ERROR: unknown type %d", indent_string.c_str(),
216+
static_cast<int>(item.type()));
217+
}
218+
}
219+
LogMessage("%s]", indent_string.c_str());
220+
}
221+
222+
// Log a map of variants.
223+
static void LogVariantMap(const std::map<Variant, Variant>& variant_map,
224+
int indent) {
225+
std::string indent_string(indent * 2, ' ');
226+
for (auto it = variant_map.begin(); it != variant_map.end(); ++it) {
227+
const Variant& key_string = it->first.AsString();
228+
const Variant& value = it->second;
229+
if (value.is_fundamental_type()) {
230+
const Variant& string_value = value.AsString();
231+
LogMessage("%s%s: %s,", indent_string.c_str(),
232+
key_string.string_value(),
233+
string_value.string_value());
234+
} else {
235+
LogMessage("%s%s:", indent_string.c_str(),
236+
key_string.string_value());
237+
if (value.is_vector()) {
238+
LogVariantVector(value.vector(), indent + 1);
239+
} else if (value.is_map()) {
240+
LogVariantMap(value.map(), indent + 1);
241+
} else {
242+
LogMessage("%s ERROR: unknown type %d", indent_string.c_str(),
243+
static_cast<int>(value.type()));
244+
}
245+
}
246+
}
247+
}
248+
249+
// Display the sign-in result.
250+
static void LogSignInResult(const SignInResult& result) {
251+
if (!result.user) {
252+
LogMessage("ERROR: User not signed in");
253+
return;
254+
}
255+
LogMessage("* User ID %s", result.user->uid().c_str());
256+
const AdditionalUserInfo& info = result.info;
257+
LogMessage("* Provider ID %s", info.provider_id.c_str());
258+
LogMessage("* User Name %s", info.user_name.c_str());
259+
LogVariantMap(info.profile, 0);
260+
const UserMetadata& metadata = result.meta;
261+
LogMessage("* Sign in timestamp %d",
262+
static_cast<int>(metadata.last_sign_in_timestamp));
263+
LogMessage("* Creation timestamp %d",
264+
static_cast<int>(metadata.creation_timestamp));
265+
}
266+
173267
class AuthStateChangeCounter : public firebase::auth::AuthStateListener {
174268
public:
175269
AuthStateChangeCounter() : num_state_changes_(0) {}
@@ -622,6 +716,43 @@ extern "C" int common_main(int argc, const char* argv[]) {
622716
}
623717
}
624718

719+
// Sign in anonymously, link an email credential, reauthenticate with the
720+
// credential, unlink the credential and finally sign out.
721+
{
722+
Future<User*> sign_in_anonymously_future = auth->SignInAnonymously();
723+
WaitForSignInFuture(sign_in_anonymously_future,
724+
"Auth::SignInAnonymously", kAuthErrorNone, auth);
725+
if (sign_in_anonymously_future.error() == kAuthErrorNone) {
726+
User* user = *sign_in_anonymously_future.result();
727+
std::string email = CreateNewEmail();
728+
Credential credential = EmailAuthProvider::GetCredential(
729+
email.c_str(), kTestPassword);
730+
// Link with an email / password credential.
731+
Future<SignInResult> link_future =
732+
user->LinkAndRetrieveDataWithCredential(credential);
733+
WaitForSignInFuture(link_future,
734+
"User::LinkAndRetrieveDataWithCredential",
735+
kAuthErrorNone, auth);
736+
if (link_future.error() == kAuthErrorNone) {
737+
LogSignInResult(*link_future.result());
738+
Future<SignInResult> reauth_future =
739+
user->ReauthenticateAndRetrieveData(credential);
740+
WaitForSignInFuture(reauth_future,
741+
"User::ReauthenticateAndRetrieveData",
742+
kAuthErrorNone, auth);
743+
if (reauth_future.error() == kAuthErrorNone) {
744+
LogSignInResult(*reauth_future.result());
745+
}
746+
// Unlink email / password from credential.
747+
Future<User*> unlink_future = user->Unlink(
748+
credential.provider().c_str());
749+
WaitForSignInFuture(unlink_future, "User::Unlink",
750+
kAuthErrorNone, auth);
751+
}
752+
auth->SignOut();
753+
}
754+
}
755+
625756
// Sign in user with bad email. Should fail.
626757
{
627758
Future<User*> sign_in_future_bad_email =
@@ -669,6 +800,32 @@ extern "C" int common_main(int argc, const char* argv[]) {
669800
sign_in_cred_ok == auth->SignInWithCredentialLastResult());
670801
}
671802

803+
// Test Auth::SignInAndRetrieveDataWithCredential using email & password.
804+
// Use existing email. Should succeed.
805+
{
806+
Credential email_cred = EmailAuthProvider::GetCredential(
807+
user_login.email(), user_login.password());
808+
Future<SignInResult> sign_in_future =
809+
auth->SignInAndRetrieveDataWithCredential(email_cred);
810+
WaitForSignInFuture(sign_in_future,
811+
"Auth::SignInAndRetrieveDataWithCredential "
812+
"existing email", kAuthErrorNone, auth);
813+
ExpectTrue("SignInAndRetrieveDataWithCredentialLastResult matches "
814+
"returned Future",
815+
sign_in_future ==
816+
auth->SignInAndRetrieveDataWithCredentialLastResult());
817+
if (sign_in_future.error() == kAuthErrorNone) {
818+
const SignInResult* sign_in_result = sign_in_future.result();
819+
if (sign_in_result != nullptr && sign_in_result->user) {
820+
LogMessage("SignInAndRetrieveDataWithCredential");
821+
LogSignInResult(*sign_in_result);
822+
} else {
823+
LogMessage("ERROR: SignInAndRetrieveDataWithCredential returned no "
824+
"result");
825+
}
826+
}
827+
}
828+
672829
// Use bad Facebook credentials. Should fail.
673830
{
674831
Credential facebook_cred_bad =

database/testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ android {
9292
}
9393

9494
dependencies {
95-
compile 'com.google.firebase:firebase-core:16.0.0'
96-
compile 'com.google.firebase:firebase-auth:16.0.1'
95+
compile 'com.google.firebase:firebase-core:16.0.1'
96+
compile 'com.google.firebase:firebase-auth:16.0.2'
9797
compile 'com.google.firebase:firebase-database:16.0.1'
9898
}
9999

dynamic_links/testapp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ android {
9191
}
9292

9393
dependencies {
94-
compile 'com.google.firebase:firebase-core:16.0.0'
94+
compile 'com.google.firebase:firebase-core:16.0.1'
9595
compile 'com.google.firebase:firebase-invites:16.0.0'
9696
compile 'com.google.firebase:firebase-common:16.0.0'
9797
}

functions/testapp/AndroidManifest.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.firebase.cpp.functions.testapp"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
8+
<uses-permission android:name="android.permission.WAKE_LOCK" />
9+
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="24" />
10+
<application android:label="@string/app_name">
11+
<activity android:name="android.app.NativeActivity"
12+
android:screenOrientation="portrait"
13+
android:configChanges="orientation|screenSize">
14+
<meta-data android:name="android.app.lib_name"
15+
android:value="android_main" />
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
</manifest>

0 commit comments

Comments
 (0)