diff --git a/analytics/integration_test/src/integration_test.cc b/analytics/integration_test/src/integration_test.cc index e950415599..5f7942dc2a 100644 --- a/analytics/integration_test/src/integration_test.cc +++ b/analytics/integration_test/src/integration_test.cc @@ -100,6 +100,21 @@ TEST_F(FirebaseAnalyticsTest, TestSetSessionTimeoutDuraction) { } TEST_F(FirebaseAnalyticsTest, TestGetAnalyticsInstanceID) { + // On Android, if SetConsent was tested, this test will fail, since the app + // needs to be restarted after consent is denied or it won't generate a new + // sessionID. To not break the tests, skip this test in that case. +#if defined(__ANDROID__) + // Log the Google Play services version for debugging in case this test fails. + LogInfo("Google Play services version: %d", GetGooglePlayServicesVersion()); + if (did_test_setconsent_) { + LogInfo( + "Skipping %s after TestSetConsent, as the test may fail until the app is restarted.", + ::testing::UnitTest::GetInstance()->current_test_info()->name()); + GTEST_SKIP(); + return; + } +#endif + FLAKY_TEST_SECTION_BEGIN(); firebase::Future future = @@ -124,11 +139,10 @@ TEST_F(FirebaseAnalyticsTest, TestGetSessionID) { #if defined(__ANDROID__) // Log the Google Play services version for debugging in case this test fails. LogInfo("Google Play services version: %d", GetGooglePlayServicesVersion()); - if (did_test_setconsent_) { LogInfo( - "Skipping TestGetSessionID after TestSetConsent, as GetSessionId() " - "will fail until the app is restarted."); + "Skipping %s after TestSetConsent, as the test may fail until the app is restarted.", + ::testing::UnitTest::GetInstance()->current_test_info()->name()); GTEST_SKIP(); return; } @@ -158,39 +172,38 @@ TEST_F(FirebaseAnalyticsTest, TestGetSessionID) { } } -TEST_F(FirebaseAnalyticsTest, TestSetConsent) { - // Can't confirm that these do anything but just run them all to ensure the - // app doesn't crash. - std::map - consent_settings_allow = { - {firebase::analytics::kConsentTypeAnalyticsStorage, - firebase::analytics::kConsentStatusGranted}, - {firebase::analytics::kConsentTypeAdStorage, - firebase::analytics::kConsentStatusGranted}, - {firebase::analytics::kConsentTypeAdUserData, - firebase::analytics::kConsentStatusGranted}, - {firebase::analytics::kConsentTypeAdPersonalization, - firebase::analytics::kConsentStatusGranted}}; - std::map - consent_settings_deny = { - {firebase::analytics::kConsentTypeAnalyticsStorage, - firebase::analytics::kConsentStatusDenied}, - {firebase::analytics::kConsentTypeAdStorage, - firebase::analytics::kConsentStatusDenied}, - {firebase::analytics::kConsentTypeAdUserData, - firebase::analytics::kConsentStatusDenied}, - {firebase::analytics::kConsentTypeAdPersonalization, - firebase::analytics::kConsentStatusDenied}}; - std::map - consent_settings_empty; - firebase::analytics::SetConsent(consent_settings_empty); - ProcessEvents(1000); - firebase::analytics::SetConsent(consent_settings_deny); - ProcessEvents(1000); - firebase::analytics::SetConsent(consent_settings_allow); - ProcessEvents(1000); +TEST_F(FirebaseAnalyticsTest, TestResettingGivesNewInstanceId) { + // On Android, if SetConsent was tested, this test will fail, since the app + // needs to be restarted after consent is denied or it won't generate a new + // sessionID. To not break the tests, skip this test in that case. +#if defined(__ANDROID__) + // Log the Google Play services version for debugging in case this test fails. + LogInfo("Google Play services version: %d", GetGooglePlayServicesVersion()); + if (did_test_setconsent_) { + LogInfo( + "Skipping %s after TestSetConsent, as the test may fail until the app is restarted.", + ::testing::UnitTest::GetInstance()->current_test_info()->name()); + GTEST_SKIP(); + return; + } +#endif + FLAKY_TEST_SECTION_BEGIN(); - did_test_setconsent_ = true; + firebase::Future future = + firebase::analytics::GetAnalyticsInstanceId(); + WaitForCompletion(future, "GetAnalyticsInstanceId"); + EXPECT_FALSE(future.result()->empty()); + std::string instance_id = *future.result(); + + firebase::analytics::ResetAnalyticsData(); + + future = firebase::analytics::GetAnalyticsInstanceId(); + WaitForCompletion(future, "GetAnalyticsInstanceId after ResetAnalyticsData"); + std::string new_instance_id = *future.result(); + EXPECT_FALSE(future.result()->empty()); + EXPECT_NE(instance_id, new_instance_id); + + FLAKY_TEST_SECTION_END(); } TEST_F(FirebaseAnalyticsTest, TestSetProperties) { @@ -235,24 +248,39 @@ TEST_F(FirebaseAnalyticsTest, TestLogEventWithMultipleParameters) { sizeof(kLevelUpParameters) / sizeof(kLevelUpParameters[0])); } -TEST_F(FirebaseAnalyticsTest, TestResettingGivesNewInstanceId) { - FLAKY_TEST_SECTION_BEGIN(); - - firebase::Future future = - firebase::analytics::GetAnalyticsInstanceId(); - WaitForCompletion(future, "GetAnalyticsInstanceId"); - EXPECT_FALSE(future.result()->empty()); - std::string instance_id = *future.result(); - - firebase::analytics::ResetAnalyticsData(); - - future = firebase::analytics::GetAnalyticsInstanceId(); - WaitForCompletion(future, "GetAnalyticsInstanceId after ResetAnalyticsData"); - std::string new_instance_id = *future.result(); - EXPECT_FALSE(future.result()->empty()); - EXPECT_NE(instance_id, new_instance_id); +TEST_F(FirebaseAnalyticsTest, TestSetConsent) { + // Can't confirm that these do anything but just run them all to ensure the + // app doesn't crash. + std::map + consent_settings_allow = { + {firebase::analytics::kConsentTypeAnalyticsStorage, + firebase::analytics::kConsentStatusGranted}, + {firebase::analytics::kConsentTypeAdStorage, + firebase::analytics::kConsentStatusGranted}, + {firebase::analytics::kConsentTypeAdUserData, + firebase::analytics::kConsentStatusGranted}, + {firebase::analytics::kConsentTypeAdPersonalization, + firebase::analytics::kConsentStatusGranted}}; + std::map + consent_settings_deny = { + {firebase::analytics::kConsentTypeAnalyticsStorage, + firebase::analytics::kConsentStatusDenied}, + {firebase::analytics::kConsentTypeAdStorage, + firebase::analytics::kConsentStatusDenied}, + {firebase::analytics::kConsentTypeAdUserData, + firebase::analytics::kConsentStatusDenied}, + {firebase::analytics::kConsentTypeAdPersonalization, + firebase::analytics::kConsentStatusDenied}}; + std::map + consent_settings_empty; + firebase::analytics::SetConsent(consent_settings_empty); + ProcessEvents(1000); + firebase::analytics::SetConsent(consent_settings_deny); + ProcessEvents(1000); + firebase::analytics::SetConsent(consent_settings_allow); + ProcessEvents(1000); - FLAKY_TEST_SECTION_END(); + did_test_setconsent_ = true; } } // namespace firebase_testapp_automated