-
Notifications
You must be signed in to change notification settings - Fork 124
RewardedAds for Android #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RewardedAds for Android #741
Conversation
@@ -489,6 +506,229 @@ TEST_F(FirebaseAdMobTest, TestRequestConfigurationSetGet) { | |||
retrieved_configuration.test_device_ids.end(), "3")); | |||
} | |||
|
|||
// Simple Load Tests as a sanity check. These don't show the ad, just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved some BannerView and Interstitial tests around. Will call out the new tests via comments below so that you need not waste your time reviewing unchanged tests.
delete interstitial; | ||
} | ||
|
||
TEST_F(FirebaseAdMobTest, TestRewardedAdLoad) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test.
delete interstitial; | ||
} | ||
|
||
TEST_F(FirebaseAdMobTest, TestRewardedAdLoadAndShow) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test.
@@ -1148,6 +1214,200 @@ TEST_F(FirebaseAdMobTest, TestInterstitialAdErrorBadExtrasClassName) { | |||
delete interstitial_ad; | |||
} | |||
|
|||
// Other RewardedAd Tests. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New tests from here downwards.
@@ -53,61 +50,6 @@ InterstitialAdInternal* InterstitialAdInternal::CreateInstance( | |||
// FIREBASE_PLATFORM_TVOS | |||
} | |||
|
|||
void InterstitialAdInternal::SetFullScreenContentListener( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a new internal full screen event listener base class which is shared with RewardedAds. This allows us to cast the nativepointer to a listener base class in the JNI callbacks, coalescing the two different JNI callback method sets into one.
@@ -0,0 +1,70 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stub implementation for now.
TestUserEarnedRewardListener user_earned_reward_listener; | ||
WaitForCompletion(rewarded->Show(&user_earned_reward_listener), "Show"); | ||
|
||
LogDebug( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you get credit for the ad even if you just watch it through, you don't have to install the thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you get the reward the ad doesn't produce the ad clicked event that we're also looking for.
Clicking Install just brings you to the app store. I'll update the comment that you don't actually have to go through with the installation of the app, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
// Stress tests. These take a while so run them near the end. | ||
TEST_F(FirebaseAdMobTest, TestBannerViewStress) { | ||
// AdMob cannot be tested on Firebase Test Lab, so disable tests on FTL. | ||
TEST_REQUIRES_USER_INTERACTION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AdMob cannot be tested on Firebase Test Lab, so disable tests on FTL.
What's the deal with this?
Also, even if we can't run this test on FTL, it would be better here to just ensure that you are specifically not running on FTL - the automated tests should still run on simulator, no?
Let's talk to @sunmou99 about seeing if there's a way to add a SKIP_TEST_ON_FIREBASE_TEST_LAB macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've enabled this test successfully in testing another PR, so I'll just remove it here.
I think that this TEST_REQUIRES_USER_INTERACTION was originally for the main BannerView tests that required you to click things but I was confused by the comment that was there, which seems to make it sound like the tests don't run at all. I hadn't tested this until recentlly and it works fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
admob/src/android/admob_android.cc
Outdated
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_com_google_firebase_admob_internal_cpp_InterstitialAdHelper_notifyAdImpressionEvent( // NOLINT | ||
extern "C" JNIEXPORT void JNICALL JNI_notifyAdImpressionEvent(JNIEnv* env, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you don't need any of the "extern "C" JNIEXPORT JNICALL stuff since we are registering natives directly - also it would probably be best to put these in an unnamed namespace. (along with the one I added!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
void FullScreenAdEventListener::NotifyListenerOfAdClickedFullScreenContent() { | ||
MutexLock lock(listener_mutex_); | ||
if (full_screen_content_listener_ != nullptr) { | ||
full_screen_content_listener_->OnAdClicked(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question: is it safe to keep the mutex locked the whole time the user's callback is running? This could potentially be a long time. Typically if there's any way to avoid locking a mutex while a user callback runs we try not to lock it. Not really sure how you'd safely do this here though, to avoid the listener itself being deleted, so maybe never mind,.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see your point.
I feel like tackling it this way: If this mutex lock is a problem then we'll have safe customer reports saying that it's in their way. But if we take the mutex out there, then we could have crazy crash reports due to corrupted memory somewhere later in the runtime. For now I'd like to play it safe and open up to dangers later, but only if we need to. WDYT?
admob/src/common/rewarded_ad.cc
Outdated
internal_ = internal::RewardedAdInternal::CreateInstance(this); | ||
|
||
GetOrCreateCleanupNotifier()->RegisterObject(this, [](void* object) { | ||
FIREBASE_ASSERT_MESSAGE( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of CleanupNotifier is to invalidate the objects and WARN the user they did the wrong thing, not assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. This was from the older implementation. Will fix it in banner and interstitial, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
private RewardedAd mRewarded; | ||
|
||
// Synchronization object for thread safe access to: | ||
// * mRewarded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't actually seem to be locking when mRewarded is used, is this because mRewarded is only ever used in the UI thread? If so you can mention that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it for other operations...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -937,6 +937,9 @@ TEST_F(FirebaseAdMobTest, TestBannerView) { | |||
bounding_box_listener.bounding_box_changes_.size()); | |||
|
|||
#if defined(ANDROID) || TARGET_OS_IPHONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of disabling this test, is it possible to just add some wiggle room to the aspect ratio check on simulator?
❌ Integration test FAILEDRequested by @DellaBitta on commit d852f3c
Add flaky tests to go/fpl-cpp-flake-tracker |
Description
Testing
iTest Run
Expanded AdMob integration tests.
Executed tests manually on Android phones.
Validated (via logs) that the SetServerSideVerificationOption strings are properly reaching the Android SDK space.
Type of Change
Place an
x
the applicable box: