Skip to content

Commit ed6c14c

Browse files
authored
Clean up handling of GMA NoFill errors. (#1518)
* Clean up handling of tests that ignore NoFill errors. * Add NoFill checking for interstitial ads. * Format code. * Clean up additional usages of WaitForCompletionAnyResult * Fix compiler errors.
1 parent 0ce94bd commit ed6c14c

File tree

1 file changed

+77
-62
lines changed

1 file changed

+77
-62
lines changed

gma/integration_test/src/integration_test.cc

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -873,15 +873,27 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdLoad) {
873873
firebase::Future<firebase::gma::AdResult> load_ad_future =
874874
interstitial->LoadAd(kInterstitialAdUnit, GetAdRequest());
875875

876-
WaitForCompletion(load_ad_future, "LoadAd");
877-
const firebase::gma::AdResult* result_ptr = load_ad_future.result();
878-
ASSERT_NE(result_ptr, nullptr);
879-
EXPECT_TRUE(result_ptr->is_successful());
880-
EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty());
881-
EXPECT_FALSE(
882-
result_ptr->response_info().mediation_adapter_class_name().empty());
883-
EXPECT_FALSE(result_ptr->response_info().response_id().empty());
884-
EXPECT_FALSE(result_ptr->response_info().ToString().empty());
876+
// This test behaves differently if it's running in UI mode
877+
// (manually on a device) or in non-UI mode (via automated tests).
878+
if (ShouldRunUITests()) {
879+
// Run in manual mode: fail if any error occurs.
880+
WaitForCompletion(load_ad_future, "LoadAd");
881+
} else {
882+
// Run in automated test mode: don't fail if NoFill occurred.
883+
WaitForCompletion(
884+
load_ad_future, "LoadAd (ignoring NoFill error)",
885+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
886+
}
887+
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
888+
const firebase::gma::AdResult* result_ptr = load_ad_future.result();
889+
ASSERT_NE(result_ptr, nullptr);
890+
EXPECT_TRUE(result_ptr->is_successful());
891+
EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty());
892+
EXPECT_FALSE(
893+
result_ptr->response_info().mediation_adapter_class_name().empty());
894+
EXPECT_FALSE(result_ptr->response_info().response_id().empty());
895+
EXPECT_FALSE(result_ptr->response_info().ToString().empty());
896+
}
885897

886898
load_ad_future.Release();
887899
delete interstitial;
@@ -907,10 +919,9 @@ TEST_F(FirebaseGmaTest, TestRewardedAdLoad) {
907919
WaitForCompletion(load_ad_future, "LoadAd");
908920
} else {
909921
// Run in automated test mode: don't fail if NoFill occurred.
910-
WaitForCompletionAnyResult(load_ad_future,
911-
"LoadAd (ignoring NoFill error)");
912-
EXPECT_TRUE(load_ad_future.error() == firebase::gma::kAdErrorCodeNone ||
913-
load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill);
922+
WaitForCompletion(
923+
load_ad_future, "LoadAd (ignoring NoFill error)",
924+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
914925
}
915926
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
916927
// In UI mode, or in non-UI mode if a NoFill error didn't occur, check that
@@ -942,9 +953,9 @@ TEST_F(FirebaseGmaTest, TestNativeAdLoad) {
942953
native_ad->LoadAd(kNativeAdUnit, GetAdRequest());
943954

944955
// Don't fail loadAd, if NoFill occurred.
945-
WaitForCompletionAnyResult(load_ad_future, "LoadAd (ignoring NoFill error)");
946-
EXPECT_TRUE(load_ad_future.error() == firebase::gma::kAdErrorCodeNone ||
947-
load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill);
956+
WaitForCompletion(
957+
load_ad_future, "LoadAd (ignoring NoFill error)",
958+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
948959

949960
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
950961
const firebase::gma::AdResult* result_ptr = load_ad_future.result();
@@ -1759,16 +1770,27 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdLoadEmptyRequest) {
17591770
firebase::Future<firebase::gma::AdResult> load_ad_future =
17601771
interstitial->LoadAd(kInterstitialAdUnit, request);
17611772

1762-
WaitForCompletion(load_ad_future, "LoadAd");
1763-
const firebase::gma::AdResult* result_ptr = load_ad_future.result();
1764-
ASSERT_NE(result_ptr, nullptr);
1765-
EXPECT_TRUE(result_ptr->is_successful());
1766-
EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty());
1767-
EXPECT_FALSE(
1768-
result_ptr->response_info().mediation_adapter_class_name().empty());
1769-
EXPECT_FALSE(result_ptr->response_info().response_id().empty());
1770-
EXPECT_FALSE(result_ptr->response_info().ToString().empty());
1771-
1773+
// This test behaves differently if it's running in UI mode
1774+
// (manually on a device) or in non-UI mode (via automated tests).
1775+
if (ShouldRunUITests()) {
1776+
// Run in manual mode: fail if any error occurs.
1777+
WaitForCompletion(load_ad_future, "LoadAd");
1778+
} else {
1779+
// Run in automated test mode: don't fail if NoFill occurred.
1780+
WaitForCompletion(
1781+
load_ad_future, "LoadAd (ignoring NoFill error)",
1782+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
1783+
}
1784+
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
1785+
const firebase::gma::AdResult* result_ptr = load_ad_future.result();
1786+
ASSERT_NE(result_ptr, nullptr);
1787+
EXPECT_TRUE(result_ptr->is_successful());
1788+
EXPECT_FALSE(result_ptr->response_info().adapter_responses().empty());
1789+
EXPECT_FALSE(
1790+
result_ptr->response_info().mediation_adapter_class_name().empty());
1791+
EXPECT_FALSE(result_ptr->response_info().response_id().empty());
1792+
EXPECT_FALSE(result_ptr->response_info().ToString().empty());
1793+
}
17721794
load_ad_future.Release();
17731795
delete interstitial;
17741796
}
@@ -1943,10 +1965,9 @@ TEST_F(FirebaseGmaTest, TestRewardedAdLoadEmptyRequest) {
19431965
WaitForCompletion(load_ad_future, "LoadAd");
19441966
} else {
19451967
// Run in automated test mode: don't fail if NoFill occurred.
1946-
WaitForCompletionAnyResult(load_ad_future,
1947-
"LoadAd (ignoring NoFill error)");
1948-
EXPECT_TRUE(load_ad_future.error() == firebase::gma::kAdErrorCodeNone ||
1949-
load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill);
1968+
WaitForCompletion(
1969+
load_ad_future, "LoadAd (ignoring NoFill error)",
1970+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
19501971
}
19511972
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
19521973
// In UI mode, or in non-UI mode if a NoFill error didn't occur, check that
@@ -2120,10 +2141,9 @@ TEST_F(FirebaseGmaTest, TestNativeAdLoadEmptyRequest) {
21202141
native_ad->LoadAd(kNativeAdUnit, request);
21212142

21222143
// Don't fail loadAd, if NoFill occurred.
2123-
WaitForCompletionAnyResult(load_ad_future, "LoadAd (ignoring NoFill error)");
2124-
EXPECT_TRUE(load_ad_future.error() == firebase::gma::kAdErrorCodeNone ||
2125-
load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill);
2126-
2144+
WaitForCompletion(
2145+
load_ad_future, "LoadAd (ignoring NoFill error)",
2146+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
21272147
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
21282148
const firebase::gma::AdResult* result_ptr = load_ad_future.result();
21292149
ASSERT_NE(result_ptr, nullptr);
@@ -2155,9 +2175,9 @@ TEST_F(FirebaseGmaTest, TestNativeRecordImpression) {
21552175
native_ad->LoadAd(kNativeAdUnit, GetAdRequest());
21562176

21572177
// Don't fail loadAd, if NoFill occurred.
2158-
WaitForCompletionAnyResult(load_ad_future, "LoadAd (ignoring NoFill error)");
2159-
EXPECT_TRUE(load_ad_future.error() == firebase::gma::kAdErrorCodeNone ||
2160-
load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill);
2178+
WaitForCompletion(
2179+
load_ad_future, "LoadAd (ignoring NoFill error)",
2180+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
21612181

21622182
// Proceed verifying the RecordImpression, only when loadAd is successful.
21632183
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
@@ -2206,9 +2226,9 @@ TEST_F(FirebaseGmaTest, TestNativePerformClick) {
22062226
native_ad->LoadAd(kNativeAdUnit, GetAdRequest());
22072227

22082228
// Don't fail loadAd, if NoFill occurred.
2209-
WaitForCompletionAnyResult(load_ad_future, "LoadAd (ignoring NoFill error)");
2210-
EXPECT_TRUE(load_ad_future.error() == firebase::gma::kAdErrorCodeNone ||
2211-
load_ad_future.error() == firebase::gma::kAdErrorCodeNoFill);
2229+
WaitForCompletion(
2230+
load_ad_future, "LoadAd (ignoring NoFill error)",
2231+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
22122232

22132233
// Proceed verifying the PerformClick, only when loadAd is successful.
22142234
if (load_ad_future.error() == firebase::gma::kAdErrorCodeNone) {
@@ -2353,11 +2373,11 @@ TEST_F(FirebaseGmaTest, TestAdViewStress) {
23532373
// Load the AdView ad.
23542374
firebase::gma::AdRequest request = GetAdRequest();
23552375
firebase::Future<firebase::gma::AdResult> future = ad_view->LoadAd(request);
2356-
WaitForCompletionAnyResult(future, "TestAdViewStress LoadAd");
2376+
WaitForCompletion(
2377+
future, "TestAdViewStress LoadAd",
2378+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
23572379
// Stress tests may exhaust the ad pool. If so, loadAd will return
23582380
// kAdErrorCodeNoFill.
2359-
EXPECT_TRUE(future.error() == firebase::gma::kAdErrorCodeNone ||
2360-
future.error() == firebase::gma::kAdErrorCodeNoFill);
23612381
if (future.error() == firebase::gma::kAdErrorCodeNone) {
23622382
EXPECT_EQ(ad_view->ad_size().width(), kBannerWidth);
23632383
EXPECT_EQ(ad_view->ad_size().height(), kBannerHeight);
@@ -2387,11 +2407,11 @@ TEST_F(FirebaseGmaTest, TestInterstitialAdStress) {
23872407
firebase::gma::AdRequest request = GetAdRequest();
23882408
firebase::Future<firebase::gma::AdResult> future =
23892409
interstitial->LoadAd(kInterstitialAdUnit, request);
2390-
WaitForCompletionAnyResult(future, "TestInterstitialAdStress LoadAd");
2410+
WaitForCompletion(
2411+
future, "TestInterstitialAdStress LoadAd",
2412+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
23912413
// Stress tests may exhaust the ad pool. If so, loadAd will return
23922414
// kAdErrorCodeNoFill.
2393-
EXPECT_TRUE(future.error() == firebase::gma::kAdErrorCodeNone ||
2394-
future.error() == firebase::gma::kAdErrorCodeNoFill);
23952415
delete interstitial;
23962416
}
23972417
}
@@ -2414,11 +2434,11 @@ TEST_F(FirebaseGmaTest, TestRewardedAdStress) {
24142434
firebase::gma::AdRequest request = GetAdRequest();
24152435
firebase::Future<firebase::gma::AdResult> future =
24162436
rewarded->LoadAd(kRewardedAdUnit, request);
2417-
WaitForCompletionAnyResult(future, "TestRewardedAdStress LoadAd");
2437+
WaitForCompletion(
2438+
future, "TestRewardedAdStress LoadAd",
2439+
{firebase::gma::kAdErrorCodeNone, firebase::gma::kAdErrorCodeNoFill});
24182440
// Stress tests may exhaust the ad pool. If so, loadAd will return
24192441
// kAdErrorCodeNoFill.
2420-
EXPECT_TRUE(future.error() == firebase::gma::kAdErrorCodeNone ||
2421-
future.error() == firebase::gma::kAdErrorCodeNoFill);
24222442
delete rewarded;
24232443
}
24242444
}
@@ -2663,17 +2683,14 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadForm) {
26632683
firebase::gma::ump::kConsentFormStatusAvailable);
26642684

26652685
// Load the form. Run this step with retry in case of network timeout.
2666-
WaitForCompletionAnyResult(
2686+
WaitForCompletion(
26672687
RunWithRetry([&]() { return consent_info_->LoadConsentForm(); }),
2668-
"LoadConsentForm");
2688+
"LoadConsentForm",
2689+
{firebase::gma::ump::kConsentFormSuccess,
2690+
firebase::gma::ump::kConsentFormErrorTimeout});
26692691

26702692
firebase::Future<void> future = consent_info_->LoadConsentFormLastResult();
26712693

2672-
// If it still timed out after all the retries, let the test pass.
2673-
EXPECT_THAT(future.error(),
2674-
AnyOf(firebase::gma::ump::kConsentFormSuccess,
2675-
firebase::gma::ump::kConsentFormErrorTimeout));
2676-
26772694
EXPECT_EQ(consent_info_->GetConsentFormStatus(),
26782695
firebase::gma::ump::kConsentFormStatusAvailable);
26792696

@@ -2741,12 +2758,10 @@ TEST_F(FirebaseGmaUmpTest, TestUmpLoadFormUnderAgeOfConsent) {
27412758
"RequestConsentInfoUpdate");
27422759

27432760
firebase::Future<void> load_future = consent_info_->LoadConsentForm();
2744-
WaitForCompletionAnyResult(load_future, "LoadConsentForm");
2745-
2746-
EXPECT_THAT(load_future.error(),
2747-
AnyOf(Eq(firebase::gma::ump::kConsentFormErrorUnavailable),
2748-
Eq(firebase::gma::ump::kConsentFormErrorTimeout),
2749-
Eq(firebase::gma::ump::kConsentFormSuccess)));
2761+
WaitForCompletion(load_future, "LoadConsentForm",
2762+
{firebase::gma::ump::kConsentFormErrorUnavailable,
2763+
firebase::gma::ump::kConsentFormErrorTimeout,
2764+
firebase::gma::ump::kConsentFormSuccess});
27502765
}
27512766

27522767
TEST_F(FirebaseGmaUmpTest, TestUmpLoadFormUnavailableDebugNonEEA) {

0 commit comments

Comments
 (0)