@@ -256,6 +256,7 @@ FirebaseGmaTest::~FirebaseGmaTest() {}
256
256
257
257
void FirebaseGmaTest::SetUp () {
258
258
TEST_DOES_NOT_REQUIRE_USER_INTERACTION;
259
+ ProcessEvents (100 ); // Flush main thread queue.
259
260
FirebaseTest::SetUp ();
260
261
261
262
// This example uses ad units that are specially configured to return test ads
@@ -2484,7 +2485,7 @@ class FirebaseGmaUmpTest : public FirebaseGmaTest {
2484
2485
enum ResetOption { kReset , kNoReset };
2485
2486
2486
2487
void InitializeUmp (ResetOption reset = kReset );
2487
- void TerminateUmp ();
2488
+ void TerminateUmp (ResetOption reset = kReset );
2488
2489
2489
2490
void SetUp () override ;
2490
2491
void TearDown () override ;
@@ -2506,9 +2507,11 @@ void FirebaseGmaUmpTest::InitializeUmp(ResetOption reset) {
2506
2507
}
2507
2508
}
2508
2509
2509
- void FirebaseGmaUmpTest::TerminateUmp () {
2510
+ void FirebaseGmaUmpTest::TerminateUmp (ResetOption reset ) {
2510
2511
if (consent_info_) {
2511
- consent_info_->Reset ();
2512
+ if (reset == kReset ) {
2513
+ consent_info_->Reset ();
2514
+ }
2512
2515
delete consent_info_;
2513
2516
consent_info_ = nullptr ;
2514
2517
}
@@ -2901,47 +2904,121 @@ TEST_F(FirebaseGmaUmpTest, TestCanRequestAdsEEA) {
2901
2904
}
2902
2905
2903
2906
TEST_F (FirebaseGmaUmpTest, TestUmpCleanupWithDelay) {
2907
+ // Ensure that if ConsentInfo is deleted after a delay, Futures are
2908
+ // properly invalidated.
2904
2909
using firebase::gma::ump::ConsentFormStatus;
2905
2910
using firebase::gma::ump::ConsentRequestParameters;
2906
2911
using firebase::gma::ump::ConsentStatus;
2907
2912
2908
2913
ConsentRequestParameters params;
2909
2914
params.tag_for_under_age_of_consent = false ;
2915
+ params.debug_settings .debug_geography =
2916
+ firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2917
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2918
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2919
+
2910
2920
firebase::Future<void > future_request =
2911
2921
consent_info_->RequestConsentInfoUpdate (params);
2912
2922
firebase::Future<void > future_load = consent_info_->LoadConsentForm ();
2913
2923
firebase::Future<void > future_show =
2914
2924
consent_info_->ShowConsentForm (app_framework::GetWindowController ());
2925
+ firebase::Future<void > future_load_and_show =
2926
+ consent_info_->LoadAndShowConsentFormIfRequired (
2927
+ app_framework::GetWindowController ());
2928
+ firebase::Future<void > future_privacy = consent_info_->ShowPrivacyOptionsForm (
2929
+ app_framework::GetWindowController ());
2915
2930
2916
2931
ProcessEvents (5000 );
2917
2932
2918
- delete consent_info_;
2919
- consent_info_ = nullptr ;
2933
+ TerminateUmp (kNoReset );
2920
2934
2921
2935
EXPECT_EQ (future_request.status (), firebase::kFutureStatusInvalid );
2922
2936
EXPECT_EQ (future_load.status (), firebase::kFutureStatusInvalid );
2923
2937
EXPECT_EQ (future_show.status (), firebase::kFutureStatusInvalid );
2938
+ EXPECT_EQ (future_load_and_show.status (), firebase::kFutureStatusInvalid );
2939
+ EXPECT_EQ (future_privacy.status (), firebase::kFutureStatusInvalid );
2924
2940
}
2925
2941
2926
2942
TEST_F (FirebaseGmaUmpTest, TestUmpCleanupRaceCondition) {
2943
+ // Ensure that if ConsentInfo is deleted immediately, operations
2944
+ // (and their Futures) are properly invalidated.
2945
+
2927
2946
using firebase::gma::ump::ConsentFormStatus;
2928
2947
using firebase::gma::ump::ConsentRequestParameters;
2929
2948
using firebase::gma::ump::ConsentStatus;
2930
2949
2931
2950
ConsentRequestParameters params;
2932
2951
params.tag_for_under_age_of_consent = false ;
2952
+ params.debug_settings .debug_geography =
2953
+ firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2954
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2955
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2956
+
2933
2957
firebase::Future<void > future_request =
2934
2958
consent_info_->RequestConsentInfoUpdate (params);
2935
2959
firebase::Future<void > future_load = consent_info_->LoadConsentForm ();
2936
2960
firebase::Future<void > future_show =
2937
2961
consent_info_->ShowConsentForm (app_framework::GetWindowController ());
2962
+ firebase::Future<void > future_load_and_show =
2963
+ consent_info_->LoadAndShowConsentFormIfRequired (
2964
+ app_framework::GetWindowController ());
2965
+ firebase::Future<void > future_privacy = consent_info_->ShowPrivacyOptionsForm (
2966
+ app_framework::GetWindowController ());
2938
2967
2939
- delete consent_info_;
2940
- consent_info_ = nullptr ;
2968
+ TerminateUmp (kNoReset );
2941
2969
2942
2970
EXPECT_EQ (future_request.status (), firebase::kFutureStatusInvalid );
2943
2971
EXPECT_EQ (future_load.status (), firebase::kFutureStatusInvalid );
2944
2972
EXPECT_EQ (future_show.status (), firebase::kFutureStatusInvalid );
2973
+ EXPECT_EQ (future_load_and_show.status (), firebase::kFutureStatusInvalid );
2974
+ EXPECT_EQ (future_privacy.status (), firebase::kFutureStatusInvalid );
2975
+
2976
+ ProcessEvents (5000 );
2977
+ }
2978
+
2979
+ TEST_F (FirebaseGmaUmpTest, TestUmpCallbacksOnWrongInstance) {
2980
+ // Ensure that if ConsentInfo is deleted and then recreated, stale
2981
+ // callbacks don't call into the new instance.
2982
+ using firebase::gma::ump::ConsentFormStatus;
2983
+ using firebase::gma::ump::ConsentRequestParameters;
2984
+ using firebase::gma::ump::ConsentStatus;
2985
+
2986
+ ConsentRequestParameters params;
2987
+ params.tag_for_under_age_of_consent = false ;
2988
+ params.debug_settings .debug_geography =
2989
+ firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2990
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2991
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2992
+
2993
+ firebase::Future<void > future_request =
2994
+ consent_info_->RequestConsentInfoUpdate (params);
2995
+ firebase::Future<void > future_load = consent_info_->LoadConsentForm ();
2996
+ firebase::Future<void > future_show =
2997
+ consent_info_->ShowConsentForm (app_framework::GetWindowController ());
2998
+ firebase::Future<void > future_load_and_show =
2999
+ consent_info_->LoadAndShowConsentFormIfRequired (
3000
+ app_framework::GetWindowController ());
3001
+ firebase::Future<void > future_privacy = consent_info_->ShowPrivacyOptionsForm (
3002
+ app_framework::GetWindowController ());
3003
+
3004
+ TerminateUmp (kNoReset );
3005
+
3006
+ EXPECT_EQ (future_request.status (), firebase::kFutureStatusInvalid );
3007
+ EXPECT_EQ (future_load.status (), firebase::kFutureStatusInvalid );
3008
+ EXPECT_EQ (future_show.status (), firebase::kFutureStatusInvalid );
3009
+ EXPECT_EQ (future_load_and_show.status (), firebase::kFutureStatusInvalid );
3010
+ EXPECT_EQ (future_privacy.status (), firebase::kFutureStatusInvalid );
3011
+
3012
+ InitializeUmp (kNoReset );
3013
+
3014
+ EXPECT_EQ (future_request.status (), firebase::kFutureStatusInvalid );
3015
+ EXPECT_EQ (future_load.status (), firebase::kFutureStatusInvalid );
3016
+ EXPECT_EQ (future_show.status (), firebase::kFutureStatusInvalid );
3017
+ EXPECT_EQ (future_load_and_show.status (), firebase::kFutureStatusInvalid );
3018
+ EXPECT_EQ (future_privacy.status (), firebase::kFutureStatusInvalid );
3019
+
3020
+ // Give the operations time to complete.
3021
+ ProcessEvents (5000 );
2945
3022
}
2946
3023
2947
3024
TEST_F (FirebaseGmaUmpTest, TestUmpMethodsReturnOperationInProgress) {
@@ -2952,18 +3029,15 @@ TEST_F(FirebaseGmaUmpTest, TestUmpMethodsReturnOperationInProgress) {
2952
3029
using firebase::gma::ump::ConsentStatus;
2953
3030
2954
3031
// Check that all of the UMP operations properly return an OperationInProgress
2955
- // error if called more than once at the same time. Each step of this test is
2956
- // inherently flaky, so add flaky test blocks all over.
3032
+ // error if called more than once at the same time.
2957
3033
2958
3034
ConsentRequestParameters params;
2959
3035
params.tag_for_under_age_of_consent = false ;
2960
3036
params.debug_settings .debug_geography =
2961
- ShouldRunUITests () ? firebase::gma::ump::kConsentDebugGeographyEEA
2962
- : firebase::gma::ump::kConsentDebugGeographyNonEEA ;
3037
+ firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2963
3038
params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2964
3039
params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2965
3040
2966
- FLAKY_TEST_SECTION_BEGIN ();
2967
3041
firebase::Future<void > future_request_1 =
2968
3042
consent_info_->RequestConsentInfoUpdate (params);
2969
3043
firebase::Future<void > future_request_2 =
@@ -2972,62 +3046,88 @@ TEST_F(FirebaseGmaUmpTest, TestUmpMethodsReturnOperationInProgress) {
2972
3046
future_request_2, " RequestConsentInfoUpdate second" ,
2973
3047
firebase::gma::ump::kConsentRequestErrorOperationInProgress );
2974
3048
WaitForCompletion (future_request_1, " RequestConsentInfoUpdate first" );
2975
- FLAKY_TEST_SECTION_END ();
2976
3049
2977
- if (ShouldRunUITests ()) {
2978
- // The below should only be checked if UI tests are enabled, as they
2979
- // require some interaction.
2980
- FLAKY_TEST_SECTION_BEGIN ();
2981
- firebase::Future<void > future_load_1 = consent_info_->LoadConsentForm ();
2982
- firebase::Future<void > future_load_2 = consent_info_->LoadConsentForm ();
2983
- WaitForCompletion (future_load_2, " LoadConsentForm second" ,
2984
- firebase::gma::ump::kConsentFormErrorOperationInProgress );
2985
- WaitForCompletion (future_load_1, " LoadConsentForm first" );
2986
- FLAKY_TEST_SECTION_END ();
2987
-
2988
- FLAKY_TEST_SECTION_BEGIN ();
2989
- firebase::Future<void > future_show_1 =
2990
- consent_info_->ShowConsentForm (app_framework::GetWindowController ());
2991
- firebase::Future<void > future_show_2 =
2992
- consent_info_->ShowConsentForm (app_framework::GetWindowController ());
2993
- WaitForCompletion (future_show_2, " ShowConsentForm second" ,
2994
- firebase::gma::ump::kConsentFormErrorOperationInProgress );
2995
- WaitForCompletion (future_show_1, " ShowConsentForm first" );
2996
- FLAKY_TEST_SECTION_END ();
2997
-
2998
- FLAKY_TEST_SECTION_BEGIN ();
2999
- firebase::Future<void > future_privacy_1 =
3000
- consent_info_->ShowPrivacyOptionsForm (
3001
- app_framework::GetWindowController ());
3002
- firebase::Future<void > future_privacy_2 =
3003
- consent_info_->ShowPrivacyOptionsForm (
3004
- app_framework::GetWindowController ());
3005
- WaitForCompletion (future_privacy_2, " ShowPrivacyOptionsForm second" ,
3006
- firebase::gma::ump::kConsentFormErrorOperationInProgress );
3007
- WaitForCompletion (future_privacy_1, " ShowPrivacyOptionsForm first" );
3008
- FLAKY_TEST_SECTION_END ();
3050
+ firebase::Future<void > future_load_and_show_1 =
3051
+ consent_info_->LoadAndShowConsentFormIfRequired (
3052
+ app_framework::GetWindowController ());
3053
+ firebase::Future<void > future_load_and_show_2 =
3054
+ consent_info_->LoadAndShowConsentFormIfRequired (
3055
+ app_framework::GetWindowController ());
3056
+ WaitForCompletion (future_load_and_show_2,
3057
+ " LoadAndShowConsentFormIfRequired second" ,
3058
+ firebase::gma::ump::kConsentFormErrorOperationInProgress );
3059
+ WaitForCompletion (future_load_and_show_1,
3060
+ " LoadAndShowConsentFormIfRequired first" );
3061
+ }
3009
3062
3010
- consent_info_->Reset ();
3011
- // Request again so we can test LoadAndShowConsentFormIfRequired.
3012
- WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
3013
- " RequestConsentInfoUpdate" );
3014
-
3015
- FLAKY_TEST_SECTION_BEGIN ();
3016
- firebase::Future<void > future_load_and_show_1 =
3017
- consent_info_->LoadAndShowConsentFormIfRequired (
3018
- app_framework::GetWindowController ());
3019
- firebase::Future<void > future_load_and_show_2 =
3020
- consent_info_->LoadAndShowConsentFormIfRequired (
3021
- app_framework::GetWindowController ());
3022
- WaitForCompletion (future_load_and_show_2,
3023
- " LoadAndShowConsentFormIfRequired second" ,
3024
- firebase::gma::ump::kConsentFormErrorOperationInProgress );
3025
- WaitForCompletion (future_load_and_show_1,
3026
- " LoadAndShowConsentFormIfRequired first" );
3027
- FLAKY_TEST_SECTION_END ();
3028
- } else {
3029
- LogInfo (" Skipping methods that require user interaction." );
3030
- }
3063
+ TEST_F (FirebaseGmaUmpTest, TestUmpMethodsReturnOperationInProgressWithUI) {
3064
+ SKIP_TEST_ON_DESKTOP;
3065
+ TEST_REQUIRES_USER_INTERACTION;
3066
+
3067
+ using firebase::gma::ump::ConsentFormStatus;
3068
+ using firebase::gma::ump::ConsentRequestParameters;
3069
+ using firebase::gma::ump::ConsentStatus;
3070
+
3071
+ // Check that all of the UMP operations properly return an OperationInProgress
3072
+ // error if called more than once at the same time. This test include methods
3073
+ // with UI interaction.
3074
+
3075
+ ConsentRequestParameters params;
3076
+ params.tag_for_under_age_of_consent = false ;
3077
+ params.debug_settings .debug_geography =
3078
+ firebase::gma::ump::kConsentDebugGeographyEEA ;
3079
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
3080
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
3081
+
3082
+ firebase::Future<void > future_request_1 =
3083
+ consent_info_->RequestConsentInfoUpdate (params);
3084
+ firebase::Future<void > future_request_2 =
3085
+ consent_info_->RequestConsentInfoUpdate (params);
3086
+ WaitForCompletion (
3087
+ future_request_2, " RequestConsentInfoUpdate second" ,
3088
+ firebase::gma::ump::kConsentRequestErrorOperationInProgress );
3089
+ WaitForCompletion (future_request_1, " RequestConsentInfoUpdate first" );
3090
+
3091
+ firebase::Future<void > future_load_1 = consent_info_->LoadConsentForm ();
3092
+ firebase::Future<void > future_load_2 = consent_info_->LoadConsentForm ();
3093
+ WaitForCompletion (future_load_2, " LoadConsentForm second" ,
3094
+ firebase::gma::ump::kConsentFormErrorOperationInProgress );
3095
+ WaitForCompletion (future_load_1, " LoadConsentForm first" );
3096
+
3097
+ firebase::Future<void > future_show_1 =
3098
+ consent_info_->ShowConsentForm (app_framework::GetWindowController ());
3099
+ firebase::Future<void > future_show_2 =
3100
+ consent_info_->ShowConsentForm (app_framework::GetWindowController ());
3101
+ WaitForCompletion (future_show_2, " ShowConsentForm second" ,
3102
+ firebase::gma::ump::kConsentFormErrorOperationInProgress );
3103
+ WaitForCompletion (future_show_1, " ShowConsentForm first" );
3104
+
3105
+ firebase::Future<void > future_privacy_1 =
3106
+ consent_info_->ShowPrivacyOptionsForm (
3107
+ app_framework::GetWindowController ());
3108
+ firebase::Future<void > future_privacy_2 =
3109
+ consent_info_->ShowPrivacyOptionsForm (
3110
+ app_framework::GetWindowController ());
3111
+ WaitForCompletion (future_privacy_2, " ShowPrivacyOptionsForm second" ,
3112
+ firebase::gma::ump::kConsentFormErrorOperationInProgress );
3113
+ WaitForCompletion (future_privacy_1, " ShowPrivacyOptionsForm first" );
3114
+
3115
+ consent_info_->Reset ();
3116
+ // Request again so we can test LoadAndShowConsentFormIfRequired.
3117
+ WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
3118
+ " RequestConsentInfoUpdate" );
3119
+
3120
+ firebase::Future<void > future_load_and_show_1 =
3121
+ consent_info_->LoadAndShowConsentFormIfRequired (
3122
+ app_framework::GetWindowController ());
3123
+ firebase::Future<void > future_load_and_show_2 =
3124
+ consent_info_->LoadAndShowConsentFormIfRequired (
3125
+ app_framework::GetWindowController ());
3126
+ WaitForCompletion (future_load_and_show_2,
3127
+ " LoadAndShowConsentFormIfRequired second" ,
3128
+ firebase::gma::ump::kConsentFormErrorOperationInProgress );
3129
+ WaitForCompletion (future_load_and_show_1,
3130
+ " LoadAndShowConsentFormIfRequired first" );
3031
3131
}
3032
3132
3033
3133
} // namespace firebase_testapp_automated
0 commit comments