@@ -98,6 +98,8 @@ const char* kErrorDomain = "com.google.admob";
98
98
#endif
99
99
100
100
// 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.
101
103
const std::vector<std::string> kTestDeviceIDs = {
102
104
" 2077ef9a63d2b398840261c8221a0c9b" , " 098fe087d987c9a878965454a65654d7" };
103
105
@@ -136,6 +138,7 @@ static const std::vector<std::string> kNeighboringContentURLs = {
136
138
" test_url1" , " test_url2" , " test_url3" };
137
139
138
140
using app_framework::LogDebug;
141
+ using app_framework::LogInfo;
139
142
using app_framework::LogWarning;
140
143
using app_framework::ProcessEvents;
141
144
@@ -2498,6 +2501,7 @@ void FirebaseGmaUmpTest::InitializeUmp(ResetOption reset) {
2498
2501
2499
2502
void FirebaseGmaUmpTest::TerminateUmp () {
2500
2503
if (consent_info_) {
2504
+ consent_info_->Reset ();
2501
2505
delete consent_info_;
2502
2506
consent_info_ = nullptr ;
2503
2507
}
@@ -2591,6 +2595,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpRequestConsentInfoUpdateDebugEEA) {
2591
2595
params.tag_for_under_age_of_consent = false ;
2592
2596
params.debug_settings .debug_geography =
2593
2597
firebase::gma::ump::kConsentDebugGeographyEEA ;
2598
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2599
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2594
2600
2595
2601
firebase::Future<void > future =
2596
2602
consent_info_->RequestConsentInfoUpdate (params);
@@ -2610,6 +2616,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpRequestConsentInfoUpdateDebugNonEEA) {
2610
2616
params.tag_for_under_age_of_consent = false ;
2611
2617
params.debug_settings .debug_geography =
2612
2618
firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2619
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2620
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2613
2621
2614
2622
firebase::Future<void > future =
2615
2623
consent_info_->RequestConsentInfoUpdate (params);
@@ -2630,6 +2638,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadForm) {
2630
2638
params.tag_for_under_age_of_consent = false ;
2631
2639
params.debug_settings .debug_geography =
2632
2640
firebase::gma::ump::kConsentDebugGeographyEEA ;
2641
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2642
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2633
2643
2634
2644
WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2635
2645
" RequestConsentInfoUpdate" );
@@ -2663,6 +2673,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpShowForm) {
2663
2673
params.tag_for_under_age_of_consent = false ;
2664
2674
params.debug_settings .debug_geography =
2665
2675
firebase::gma::ump::kConsentDebugGeographyEEA ;
2676
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2677
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2666
2678
2667
2679
WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2668
2680
" RequestConsentInfoUpdate" );
@@ -2678,7 +2690,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpShowForm) {
2678
2690
EXPECT_EQ (consent_info_->GetConsentFormStatus (),
2679
2691
firebase::gma::ump::kConsentFormStatusAvailable );
2680
2692
2681
- firebase::Future<void > future = consent_info_->ShowConsentForm (nullptr );
2693
+ firebase::Future<void > future =
2694
+ consent_info_->ShowConsentForm (app_framework::GetWindowController ());
2682
2695
2683
2696
EXPECT_TRUE (future == consent_info_->ShowConsentFormLastResult ());
2684
2697
@@ -2688,9 +2701,7 @@ TEST_F(FirebaseGmaUmpTest, TestUmpShowForm) {
2688
2701
firebase::gma::ump::kConsentStatusObtained );
2689
2702
}
2690
2703
2691
- TEST_F (FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDueUnderAgeOfConsent) {
2692
- TEST_REQUIRES_USER_INTERACTION;
2693
-
2704
+ TEST_F (FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDueToUnderAgeOfConsent) {
2694
2705
using firebase::gma::ump::ConsentDebugSettings;
2695
2706
using firebase::gma::ump::ConsentFormStatus;
2696
2707
using firebase::gma::ump::ConsentRequestParameters;
@@ -2700,24 +2711,65 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDueUnderAgeOfConsent) {
2700
2711
params.tag_for_under_age_of_consent = true ;
2701
2712
params.debug_settings .debug_geography =
2702
2713
firebase::gma::ump::kConsentDebugGeographyEEA ;
2714
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2715
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2703
2716
2704
2717
WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2705
2718
" RequestConsentInfoUpdate" );
2706
2719
2707
- EXPECT_EQ (consent_info_->GetConsentStatus (),
2708
- firebase::gma::ump::kConsentStatusRequired );
2720
+ WaitForCompletion (consent_info_->LoadConsentForm (), " LoadConsentForm" ,
2721
+ firebase::gma::ump::kConsentFormErrorUnavailable );
2722
+ }
2709
2723
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" );
2712
2739
2713
2740
WaitForCompletion (consent_info_->LoadConsentForm (), " LoadConsentForm" ,
2714
2741
firebase::gma::ump::kConsentFormErrorUnavailable );
2742
+ }
2715
2743
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" );
2718
2770
}
2719
2771
2720
- TEST_F (FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequired ) {
2772
+ TEST_F (FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequiredDebugEEA ) {
2721
2773
using firebase::gma::ump::ConsentDebugSettings;
2722
2774
using firebase::gma::ump::ConsentRequestParameters;
2723
2775
using firebase::gma::ump::ConsentStatus;
@@ -2728,6 +2780,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequired) {
2728
2780
params.tag_for_under_age_of_consent = false ;
2729
2781
params.debug_settings .debug_geography =
2730
2782
firebase::gma::ump::kConsentDebugGeographyEEA ;
2783
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2784
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2731
2785
2732
2786
WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2733
2787
" RequestConsentInfoUpdate" );
@@ -2736,7 +2790,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadAndShowIfRequired) {
2736
2790
firebase::gma::ump::kConsentStatusRequired );
2737
2791
2738
2792
firebase::Future<void > future =
2739
- consent_info_->LoadAndShowConsentFormIfRequired (nullptr );
2793
+ consent_info_->LoadAndShowConsentFormIfRequired (
2794
+ app_framework::GetWindowController ());
2740
2795
2741
2796
EXPECT_TRUE (future ==
2742
2797
consent_info_->LoadAndShowConsentFormIfRequiredLastResult ());
@@ -2759,6 +2814,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpPrivacyOptions) {
2759
2814
params.tag_for_under_age_of_consent = false ;
2760
2815
params.debug_settings .debug_geography =
2761
2816
firebase::gma::ump::kConsentDebugGeographyEEA ;
2817
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2818
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2762
2819
2763
2820
WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2764
2821
" RequestConsentInfoUpdate" );
@@ -2768,41 +2825,43 @@ TEST_F(FirebaseGmaUmpTest, TestUmpPrivacyOptions) {
2768
2825
2769
2826
EXPECT_FALSE (consent_info_->CanRequestAds ());
2770
2827
2771
- WaitForCompletion (consent_info_->LoadAndShowConsentFormIfRequired (nullptr ),
2828
+ WaitForCompletion (consent_info_->LoadAndShowConsentFormIfRequired (
2829
+ app_framework::GetWindowController ()),
2772
2830
" LoadAndShowConsentFormIfRequired" );
2773
2831
2774
2832
EXPECT_EQ (consent_info_->GetConsentStatus (),
2775
2833
firebase::gma::ump::kConsentStatusObtained );
2776
2834
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 );
2778
2842
2779
2843
EXPECT_EQ (consent_info_->GetPrivacyOptionsRequirementStatus (),
2780
2844
firebase::gma::ump::kPrivacyOptionsRequirementStatusRequired );
2781
2845
2782
- firebase::Future<void > future =
2783
- consent_info_-> ShowPrivacyOptionsForm ( nullptr );
2846
+ firebase::Future<void > future = consent_info_-> ShowPrivacyOptionsForm (
2847
+ app_framework::GetWindowController () );
2784
2848
2785
2849
EXPECT_TRUE (future == consent_info_->ShowPrivacyOptionsFormLastResult ());
2786
2850
2787
2851
WaitForCompletion (future, " ShowPrivacyOptionsForm" );
2788
-
2789
- EXPECT_EQ (consent_info_->GetConsentStatus (),
2790
- firebase::gma::ump::kConsentStatusRequired );
2791
-
2792
- EXPECT_FALSE (consent_info_->CanRequestAds ());
2793
2852
}
2794
2853
2795
2854
TEST_F (FirebaseGmaUmpTest, TestCanRequestAdsNonEEA) {
2796
2855
using firebase::gma::ump::ConsentDebugSettings;
2797
2856
using firebase::gma::ump::ConsentRequestParameters;
2798
2857
using firebase::gma::ump::ConsentStatus;
2799
2858
2800
- TEST_REQUIRES_USER_INTERACTION;
2801
-
2802
2859
ConsentRequestParameters params;
2803
2860
params.tag_for_under_age_of_consent = false ;
2804
2861
params.debug_settings .debug_geography =
2805
2862
firebase::gma::ump::kConsentDebugGeographyNonEEA ;
2863
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2864
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2806
2865
2807
2866
WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2808
2867
" RequestConsentInfoUpdate" );
@@ -2818,12 +2877,12 @@ TEST_F(FirebaseGmaUmpTest, TestCanRequestAdsEEA) {
2818
2877
using firebase::gma::ump::ConsentRequestParameters;
2819
2878
using firebase::gma::ump::ConsentStatus;
2820
2879
2821
- TEST_REQUIRES_USER_INTERACTION;
2822
-
2823
2880
ConsentRequestParameters params;
2824
2881
params.tag_for_under_age_of_consent = false ;
2825
2882
params.debug_settings .debug_geography =
2826
2883
firebase::gma::ump::kConsentDebugGeographyEEA ;
2884
+ params.debug_settings .debug_device_ids = kTestDeviceIDs ;
2885
+ params.debug_settings .debug_device_ids .push_back (GetDebugDeviceId ());
2827
2886
2828
2887
WaitForCompletion (consent_info_->RequestConsentInfoUpdate (params),
2829
2888
" RequestConsentInfoUpdate" );
@@ -2834,7 +2893,30 @@ TEST_F(FirebaseGmaUmpTest, TestCanRequestAdsEEA) {
2834
2893
EXPECT_FALSE (consent_info_->CanRequestAds ());
2835
2894
}
2836
2895
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) {
2838
2920
using firebase::gma::ump::ConsentFormStatus;
2839
2921
using firebase::gma::ump::ConsentRequestParameters;
2840
2922
using firebase::gma::ump::ConsentStatus;
@@ -2844,7 +2926,8 @@ TEST_F(FirebaseGmaUmpTest, TestUmpCleanup) {
2844
2926
firebase::Future<void > future_request =
2845
2927
consent_info_->RequestConsentInfoUpdate (params);
2846
2928
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 ());
2848
2931
2849
2932
delete consent_info_;
2850
2933
consent_info_ = nullptr ;
0 commit comments