@@ -98,6 +98,8 @@ const char* kErrorDomain = "com.google.admob";
9898#endif
9999
100100// Sample test device IDs to use in making the request.
101+ // You can replace these with actual device IDs for certain tests (e.g. UMP)
102+ // to work on hardware devices.
101103const std::vector<std::string> kTestDeviceIDs = {
102104 " 2077ef9a63d2b398840261c8221a0c9b" , " 098fe087d987c9a878965454a65654d7" };
103105
@@ -136,6 +138,7 @@ static const std::vector<std::string> kNeighboringContentURLs = {
136138 " test_url1" , " test_url2" , " test_url3" };
137139
138140using app_framework::LogDebug;
141+ using app_framework::LogInfo;
139142using app_framework::LogWarning;
140143using app_framework::ProcessEvents;
141144
@@ -2498,6 +2501,7 @@ void FirebaseGmaUmpTest::InitializeUmp(ResetOption reset) {
24982501
24992502void FirebaseGmaUmpTest::TerminateUmp () {
25002503 if (consent_info_) {
2504+ consent_info_->Reset ();
25012505 delete consent_info_;
25022506 consent_info_ = nullptr ;
25032507 }
@@ -2591,6 +2595,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpRequestConsentInfoUpdateDebugEEA) {
25912595 params.tag_for_under_age_of_consent = false ;
25922596 params.debug_settings .debug_geography =
25932597 firebase::gma::ump::kConsentDebugGeographyEEA ;
2598+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2599+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
25942600
25952601 firebase::Future<void > future =
25962602 consent_info_->RequestConsentInfoUpdate (params);
@@ -2610,6 +2616,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpRequestConsentInfoUpdateDebugNonEEA) {
26102616 params.tag_for_under_age_of_consent = false ;
26112617 params.debug_settings .debug_geography =
26122618 firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2619+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2620+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
26132621
26142622 firebase::Future<void > future =
26152623 consent_info_->RequestConsentInfoUpdate (params);
@@ -2630,6 +2638,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadForm) {
26302638 params.tag_for_under_age_of_consent = false ;
26312639 params.debug_settings .debug_geography =
26322640 firebase::gma::ump::kConsentDebugGeographyEEA ;
2641+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2642+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
26332643
26342644 WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
26352645 " RequestConsentInfoUpdate" );
@@ -2663,6 +2673,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpShowForm) {
26632673 params.tag_for_under_age_of_consent = false ;
26642674 params.debug_settings .debug_geography =
26652675 firebase::gma::ump::kConsentDebugGeographyEEA ;
2676+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2677+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
26662678
26672679 WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
26682680 " RequestConsentInfoUpdate" );
@@ -2678,7 +2690,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpShowForm) {
26782690 EXPECT_EQ (consent_info_->GetConsentFormStatus (),
26792691 firebase::gma::ump::kConsentFormStatusAvailable );
26802692
2681- firebase::Future<void > future = consent_info_->ShowConsentForm (nullptr );
2693+ firebase::Future<void > future =
2694+ consent_info_->ShowConsentForm (app_framework::GetWindowController ());
26822695
26832696 EXPECT_TRUE (future == consent_info_->ShowConsentFormLastResult ());
26842697
@@ -2688,9 +2701,7 @@ TEST_F(FirebaseGmaUmpTest, TestUmpShowForm) {
26882701 firebase::gma::ump::kConsentStatusObtained );
26892702}
26902703
2691- TEST_F (FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDueUnderAgeOfConsent) {
2692- TEST_REQUIRES_USER_INTERACTION;
2693-
2704+ TEST_F (FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDueToUnderAgeOfConsent) {
26942705 using firebase::gma::ump::ConsentDebugSettings;
26952706 using firebase::gma::ump::ConsentFormStatus;
26962707 using firebase::gma::ump::ConsentRequestParameters;
@@ -2700,24 +2711,65 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDueUnderAgeOfConsent) {
27002711 params.tag_for_under_age_of_consent = true ;
27012712 params.debug_settings .debug_geography =
27022713 firebase::gma::ump::kConsentDebugGeographyEEA ;
2714+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2715+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
27032716
27042717 WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
27052718 " RequestConsentInfoUpdate" );
27062719
2707- EXPECT_EQ (consent_info_->GetConsentStatus (),
2708- firebase::gma::ump::kConsentStatusRequired );
2720+ WaitForCompletion (consent_info_->LoadConsentForm (), " LoadConsentForm" ,
2721+ firebase::gma::ump::kConsentFormErrorUnavailable );
2722+ }
27092723
2710- EXPECT_EQ (consent_info_->GetConsentFormStatus (),
2711- firebase::gma::ump::kConsentFormStatusUnavailable );
2724+ TEST_F (FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDebugNonEEA) {
2725+ using firebase::gma::ump::ConsentDebugSettings;
2726+ using firebase::gma::ump::ConsentFormStatus;
2727+ using firebase::gma::ump::ConsentRequestParameters;
2728+ using firebase::gma::ump::ConsentStatus;
2729+
2730+ ConsentRequestParameters params;
2731+ params.tag_for_under_age_of_consent = false ;
2732+ params.debug_settings .debug_geography =
2733+ firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2734+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2735+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2736+
2737+ WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2738+ " RequestConsentInfoUpdate" );
27122739
27132740 WaitForCompletion (consent_info_->LoadConsentForm (), " LoadConsentForm" ,
27142741 firebase::gma::ump::kConsentFormErrorUnavailable );
2742+ }
27152743
2716- EXPECT_EQ (consent_info_->GetConsentFormStatus (),
2717- firebase::gma::ump::kConsentFormStatusUnavailable );
2744+ TEST_F (FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequiredDebugNonEEA) {
2745+ using firebase::gma::ump::ConsentDebugSettings;
2746+ using firebase::gma::ump::ConsentRequestParameters;
2747+ using firebase::gma::ump::ConsentStatus;
2748+
2749+ ConsentRequestParameters params;
2750+ params.tag_for_under_age_of_consent = false ;
2751+ params.debug_settings .debug_geography =
2752+ firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2753+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2754+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2755+
2756+ WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2757+ " RequestConsentInfoUpdate" );
2758+
2759+ EXPECT_EQ (consent_info_->GetConsentStatus (),
2760+ firebase::gma::ump::kConsentStatusNotRequired );
2761+
2762+ firebase::Future<void > future =
2763+ consent_info_->LoadAndShowConsentFormIfRequired (
2764+ app_framework::GetWindowController ());
2765+
2766+ EXPECT_TRUE (future ==
2767+ consent_info_->LoadAndShowConsentFormIfRequiredLastResult ());
2768+
2769+ WaitForCompletion (future, " LoadAndShowConsentFormIfRequired" );
27182770}
27192771
2720- TEST_F (FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequired ) {
2772+ TEST_F (FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequiredDebugEEA ) {
27212773 using firebase::gma::ump::ConsentDebugSettings;
27222774 using firebase::gma::ump::ConsentRequestParameters;
27232775 using firebase::gma::ump::ConsentStatus;
@@ -2728,6 +2780,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequired) {
27282780 params.tag_for_under_age_of_consent = false ;
27292781 params.debug_settings .debug_geography =
27302782 firebase::gma::ump::kConsentDebugGeographyEEA ;
2783+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2784+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
27312785
27322786 WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
27332787 " RequestConsentInfoUpdate" );
@@ -2736,7 +2790,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequired) {
27362790 firebase::gma::ump::kConsentStatusRequired );
27372791
27382792 firebase::Future<void > future =
2739- consent_info_->LoadAndShowConsentFormIfRequired (nullptr );
2793+ consent_info_->LoadAndShowConsentFormIfRequired (
2794+ app_framework::GetWindowController ());
27402795
27412796 EXPECT_TRUE (future ==
27422797 consent_info_->LoadAndShowConsentFormIfRequiredLastResult ());
@@ -2759,6 +2814,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpPrivacyOptions) {
27592814 params.tag_for_under_age_of_consent = false ;
27602815 params.debug_settings .debug_geography =
27612816 firebase::gma::ump::kConsentDebugGeographyEEA ;
2817+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2818+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
27622819
27632820 WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
27642821 " RequestConsentInfoUpdate" );
@@ -2768,41 +2825,43 @@ TEST_F(FirebaseGmaUmpTest, TestUmpPrivacyOptions) {
27682825
27692826 EXPECT_FALSE (consent_info_->CanRequestAds ());
27702827
2771- WaitForCompletion (consent_info_->LoadAndShowConsentFormIfRequired (nullptr ),
2828+ WaitForCompletion (consent_info_->LoadAndShowConsentFormIfRequired (
2829+ app_framework::GetWindowController ()),
27722830 " LoadAndShowConsentFormIfRequired" );
27732831
27742832 EXPECT_EQ (consent_info_->GetConsentStatus (),
27752833 firebase::gma::ump::kConsentStatusObtained );
27762834
2777- EXPECT_TRUE (consent_info_->CanRequestAds ());
2835+ EXPECT_TRUE (consent_info_->CanRequestAds ()) << " After consent obtained" ;
2836+
2837+ LogInfo (
2838+ " ******** On the Privacy Options screen that is about to appear, please "
2839+ " select DO NOT CONSENT." );
2840+
2841+ ProcessEvents (5000 );
27782842
27792843 EXPECT_EQ (consent_info_->GetPrivacyOptionsRequirementStatus (),
27802844 firebase::gma::ump::kPrivacyOptionsRequirementStatusRequired );
27812845
2782- firebase::Future<void > future =
2783- consent_info_-> ShowPrivacyOptionsForm ( nullptr );
2846+ firebase::Future<void > future = consent_info_-> ShowPrivacyOptionsForm (
2847+ app_framework::GetWindowController () );
27842848
27852849 EXPECT_TRUE (future == consent_info_->ShowPrivacyOptionsFormLastResult ());
27862850
27872851 WaitForCompletion (future, " ShowPrivacyOptionsForm" );
2788-
2789- EXPECT_EQ (consent_info_->GetConsentStatus (),
2790- firebase::gma::ump::kConsentStatusRequired );
2791-
2792- EXPECT_FALSE (consent_info_->CanRequestAds ());
27932852}
27942853
27952854TEST_F (FirebaseGmaUmpTest, TestCanRequestAdsNonEEA) {
27962855 using firebase::gma::ump::ConsentDebugSettings;
27972856 using firebase::gma::ump::ConsentRequestParameters;
27982857 using firebase::gma::ump::ConsentStatus;
27992858
2800- TEST_REQUIRES_USER_INTERACTION;
2801-
28022859 ConsentRequestParameters params;
28032860 params.tag_for_under_age_of_consent = false ;
28042861 params.debug_settings .debug_geography =
28052862 firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2863+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2864+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
28062865
28072866 WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
28082867 " RequestConsentInfoUpdate" );
@@ -2818,12 +2877,12 @@ TEST_F(FirebaseGmaUmpTest, TestCanRequestAdsEEA) {
28182877 using firebase::gma::ump::ConsentRequestParameters;
28192878 using firebase::gma::ump::ConsentStatus;
28202879
2821- TEST_REQUIRES_USER_INTERACTION;
2822-
28232880 ConsentRequestParameters params;
28242881 params.tag_for_under_age_of_consent = false ;
28252882 params.debug_settings .debug_geography =
28262883 firebase::gma::ump::kConsentDebugGeographyEEA ;
2884+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2885+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
28272886
28282887 WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
28292888 " RequestConsentInfoUpdate" );
@@ -2834,7 +2893,30 @@ TEST_F(FirebaseGmaUmpTest, TestCanRequestAdsEEA) {
28342893 EXPECT_FALSE (consent_info_->CanRequestAds ());
28352894}
28362895
2837- TEST_F (FirebaseGmaUmpTest, TestUmpCleanup) {
2896+ TEST_F (FirebaseGmaUmpTest, TestUmpCleanupWithDelay) {
2897+ using firebase::gma::ump::ConsentFormStatus;
2898+ using firebase::gma::ump::ConsentRequestParameters;
2899+ using firebase::gma::ump::ConsentStatus;
2900+
2901+ ConsentRequestParameters params;
2902+ params.tag_for_under_age_of_consent = false ;
2903+ firebase::Future<void > future_request =
2904+ consent_info_->RequestConsentInfoUpdate (params);
2905+ firebase::Future<void > future_load = consent_info_->LoadConsentForm ();
2906+ firebase::Future<void > future_show =
2907+ consent_info_->ShowConsentForm (app_framework::GetWindowController ());
2908+
2909+ ProcessEvents (5000 );
2910+
2911+ delete consent_info_;
2912+ consent_info_ = nullptr ;
2913+
2914+ EXPECT_EQ (future_request.status (), firebase::kFutureStatusInvalid );
2915+ EXPECT_EQ (future_load.status (), firebase::kFutureStatusInvalid );
2916+ EXPECT_EQ (future_show.status (), firebase::kFutureStatusInvalid );
2917+ }
2918+
2919+ TEST_F (FirebaseGmaUmpTest, TestUmpCleanupRaceCondition) {
28382920 using firebase::gma::ump::ConsentFormStatus;
28392921 using firebase::gma::ump::ConsentRequestParameters;
28402922 using firebase::gma::ump::ConsentStatus;
@@ -2844,7 +2926,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpCleanup) {
28442926 firebase::Future<void > future_request =
28452927 consent_info_->RequestConsentInfoUpdate (params);
28462928 firebase::Future<void > future_load = consent_info_->LoadConsentForm ();
2847- firebase::Future<void > future_show = consent_info_->ShowConsentForm (nullptr );
2929+ firebase::Future<void > future_show =
2930+ consent_info_->ShowConsentForm (app_framework::GetWindowController ());
28482931
28492932 delete consent_info_;
28502933 consent_info_ = nullptr ;
0 commit comments