summaryrefslogtreecommitdiff
path: root/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdBidGeneratorImplTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdBidGeneratorImplTest.java')
-rw-r--r--adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdBidGeneratorImplTest.java150
1 files changed, 104 insertions, 46 deletions
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdBidGeneratorImplTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdBidGeneratorImplTest.java
index 618fd879e5..fa70f438ad 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdBidGeneratorImplTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/adselection/AdBidGeneratorImplTest.java
@@ -17,7 +17,6 @@
package com.android.adservices.service.adselection;
import static com.android.adservices.service.adselection.AdBidGeneratorImpl.BIDDING_TIMED_OUT;
-import static com.android.adservices.service.adselection.AdBidGeneratorImpl.MISSING_BIDDING_LOGIC;
import static com.android.adservices.service.adselection.AdBidGeneratorImpl.MISSING_TRUSTED_BIDDING_SIGNALS;
import static org.junit.Assert.assertEquals;
@@ -83,6 +82,7 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
public class AdBidGeneratorImplTest {
public static final List<Double> BIDS =
@@ -106,7 +106,6 @@ public class AdBidGeneratorImplTest {
private static final AdSelectionSignals EMPTY_AD_SELECTION_SIGNALS = AdSelectionSignals.EMPTY;
private static final AdSelectionSignals EMPTY_BUYER_SIGNALS = AdSelectionSignals.EMPTY;
private static final AdSelectionSignals EMPTY_CONTEXTUAL_SIGNALS = AdSelectionSignals.EMPTY;
- private static final AdSelectionSignals EMPTY_USER_SIGNALS = AdSelectionSignals.EMPTY;
private static final AdSelectionSignals TRUSTED_BIDDING_SIGNALS =
AdSelectionSignals.fromString(
"{\n" + "\t\"max_bid_limit\": 20,\n" + "\t\"ad_type\": \"retail\"\n" + "}");
@@ -121,9 +120,11 @@ public class AdBidGeneratorImplTest {
private ListeningExecutorService mLightweightExecutorService;
private ListeningExecutorService mBackgroundExecutorService;
private ListeningExecutorService mBlockingExecutorService;
+ private ScheduledThreadPoolExecutor mScheduledExecutor;
private final Context mContext = ApplicationProvider.getApplicationContext();
@Rule public MockWebServerRule mMockWebServerRule = MockWebServerRuleFactory.createForHttps();
@Mock AdSelectionScriptEngine mAdSelectionScriptEngine;
+ private JsFetcher mJsFetcher;
private Uri mDecisionLogicUri;
private Dispatcher mDefaultDispatcher;
private AdBidGeneratorImpl mAdBidGenerator;
@@ -150,6 +151,7 @@ public class AdBidGeneratorImplTest {
mLightweightExecutorService = AdServicesExecutors.getLightWeightExecutor();
mBackgroundExecutorService = AdServicesExecutors.getBackgroundExecutor();
mBlockingExecutorService = AdServicesExecutors.getBlockingExecutor();
+ mScheduledExecutor = AdServicesExecutors.getScheduler();
mAdServicesHttpsClient =
new AdServicesHttpsClient(AdServicesExecutors.getBlockingExecutor());
mCustomAudienceDao =
@@ -221,17 +223,24 @@ public class AdBidGeneratorImplTest {
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
-
+ mIsolateSettings,
+ mJsFetcher);
Mockito.when(
mAdSelectionScriptEngine.generateBids(
mBuyerDecisionLogicJs,
@@ -240,7 +249,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals))
.thenReturn(FluentFuture.from(Futures.immediateFuture(AD_WITH_BIDS)));
// When the call to runAdBiddingPerCA, and the computation of future is complete,
@@ -249,8 +257,7 @@ public class AdBidGeneratorImplTest {
mCustomAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
AdBiddingOutcome expectedAdBiddingOutcome =
AdBiddingOutcome.builder()
.setAdWithBid(AD_WITH_BIDS.get(2))
@@ -266,7 +273,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals);
mMockWebServerRule.verifyMockServerRequests(
mServer,
@@ -313,16 +319,24 @@ public class AdBidGeneratorImplTest {
// Resetting adBidGenerator to use the new dev context
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
// Given we are using a direct executor and mock the returned result from the
// AdSelectionScriptEngine.generateBids for preparing the test,
@@ -334,7 +348,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals))
.thenReturn(FluentFuture.from(Futures.immediateFuture(AD_WITH_BIDS)));
// When the call to runAdBiddingPerCA, and the computation of future is complete,
@@ -343,8 +356,7 @@ public class AdBidGeneratorImplTest {
mCustomAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- adSelectionConfig);
+ EMPTY_CONTEXTUAL_SIGNALS);
AdBiddingOutcome expectedAdBiddingOutcome =
AdBiddingOutcome.builder()
.setAdWithBid(AD_WITH_BIDS.get(2))
@@ -361,7 +373,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals);
mMockWebServerRule.verifyMockServerRequests(
mServer, 0, Collections.emptyList(), mRequestMatcherExactMatch);
@@ -375,16 +386,24 @@ public class AdBidGeneratorImplTest {
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
Mockito.when(
mAdSelectionScriptEngine.generateBids(
@@ -394,7 +413,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals))
.thenReturn(FluentFuture.from(Futures.immediateFuture(AD_WITH_NON_POSITIVE_BIDS)));
// When the call to runAdBiddingPerCA, and the computation of future is complete,
@@ -403,8 +421,7 @@ public class AdBidGeneratorImplTest {
mCustomAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
// Then we can test the result by assertion,
assertNull(result.get());
Mockito.verify(mAdSelectionScriptEngine)
@@ -415,7 +432,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals);
mMockWebServerRule.verifyMockServerRequests(
mServer,
@@ -433,7 +449,12 @@ public class AdBidGeneratorImplTest {
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
-
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
Flags flagsWithSmallerLimits =
new Flags() {
@Override
@@ -446,11 +467,13 @@ public class AdBidGeneratorImplTest {
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
flagsWithSmallerLimits,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
Mockito.when(
mAdSelectionScriptEngine.generateBids(
mBuyerDecisionLogicJs,
@@ -459,7 +482,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals))
.thenAnswer((invocation) -> generateBidsWithDelay(flagsWithSmallerLimits));
// When the call to runAdBiddingPerCA, and the computation of future is complete,
@@ -468,8 +490,7 @@ public class AdBidGeneratorImplTest {
mCustomAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
// Then we can test the result by assertion
ExecutionException thrown = assertThrows(ExecutionException.class, result::get);
assertTrue(thrown.getMessage().contains(BIDDING_TIMED_OUT));
@@ -481,7 +502,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals);
mMockWebServerRule.verifyMockServerRequests(
mServer,
@@ -498,16 +518,24 @@ public class AdBidGeneratorImplTest {
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
JSONException jsonException = new JSONException("");
Mockito.when(
@@ -518,7 +546,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals))
.thenThrow(jsonException);
// When the call to runBidding, and the computation of future is complete.
@@ -529,7 +556,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
mCustomAudienceSignals,
- EMPTY_USER_SIGNALS,
EMPTY_AD_SELECTION_SIGNALS);
ExecutionException outException = assertThrows(ExecutionException.class, result::get);
@@ -562,6 +588,12 @@ public class AdBidGeneratorImplTest {
mServer = mMockWebServerRule.startMockWebServer(dispatcher);
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
List<String> emptyTrustedBiddingKeys = Collections.EMPTY_LIST;
DBTrustedBiddingData trustedBiddingData =
new DBTrustedBiddingData.Builder()
@@ -587,11 +619,13 @@ public class AdBidGeneratorImplTest {
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
Mockito.when(
mAdSelectionScriptEngine.generateBids(
@@ -601,7 +635,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
customAudienceSignals))
.thenReturn(FluentFuture.from(Futures.immediateFuture(AD_WITH_BIDS)));
// When the call to runAdBiddingPerCA, and the computation of future is complete,
@@ -610,8 +643,7 @@ public class AdBidGeneratorImplTest {
customAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
AdBiddingOutcome expectedAdBiddingOutcome =
AdBiddingOutcome.builder()
.setAdWithBid(AD_WITH_BIDS.get(2))
@@ -627,7 +659,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
customAudienceSignals);
mMockWebServerRule.verifyMockServerRequests(
mServer,
@@ -655,20 +686,28 @@ public class AdBidGeneratorImplTest {
};
mServer = mMockWebServerRule.startMockWebServer(dispatcher);
IllegalStateException missingJSLogicException =
- new IllegalStateException(MISSING_BIDDING_LOGIC);
+ new IllegalStateException(JsFetcher.MISSING_BIDDING_LOGIC);
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
// When the call to runAdBiddingPerCA, and the computation of future is complete,
FluentFuture<AdBiddingOutcome> result =
@@ -676,8 +715,7 @@ public class AdBidGeneratorImplTest {
mCustomAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
ExecutionException outException = assertThrows(ExecutionException.class, result::get);
assertEquals(outException.getCause().getMessage(), missingJSLogicException.getMessage());
mMockWebServerRule.verifyMockServerRequests(
@@ -707,16 +745,24 @@ public class AdBidGeneratorImplTest {
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
// When the call to runAdBiddingPerCA, and the computation of future is complete,
FluentFuture<AdBiddingOutcome> result =
@@ -724,8 +770,7 @@ public class AdBidGeneratorImplTest {
mCustomAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
ExecutionException outException = assertThrows(ExecutionException.class, result::get);
assertEquals(outException.getCause().getMessage(), missingSignalsException.getMessage());
mMockWebServerRule.verifyMockServerRequests(
@@ -741,16 +786,24 @@ public class AdBidGeneratorImplTest {
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
// Given we are using a direct executor and mock the returned result from the
// AdSelectionScriptEngine.generateBids for preparing the test,
@@ -762,7 +815,6 @@ public class AdBidGeneratorImplTest {
EMPTY_BUYER_SIGNALS,
TRUSTED_BIDDING_SIGNALS,
EMPTY_CONTEXTUAL_SIGNALS,
- EMPTY_USER_SIGNALS,
mCustomAudienceSignals))
.thenThrow(new JSONException(""));
// When the call to runBidding, and the computation of future is complete.
@@ -771,8 +823,7 @@ public class AdBidGeneratorImplTest {
mCustomAudienceWithAds,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
assertNull(result.get());
mMockWebServerRule.verifyMockServerRequests(
mServer,
@@ -787,24 +838,31 @@ public class AdBidGeneratorImplTest {
CustomAudienceDevOverridesHelper customAudienceDevOverridesHelper =
new CustomAudienceDevOverridesHelper(mDevContext, mCustomAudienceDao);
+ mJsFetcher =
+ new JsFetcher(
+ mBackgroundExecutorService,
+ mLightweightExecutorService,
+ customAudienceDevOverridesHelper,
+ mAdServicesHttpsClient);
mAdBidGenerator =
new AdBidGeneratorImpl(
mContext,
mLightweightExecutorService,
mBackgroundExecutorService,
+ mScheduledExecutor,
mAdSelectionScriptEngine,
mAdServicesHttpsClient,
customAudienceDevOverridesHelper,
mFlags,
- mIsolateSettings);
+ mIsolateSettings,
+ mJsFetcher);
FluentFuture<AdBiddingOutcome> result =
mAdBidGenerator.runAdBiddingPerCA(
CUSTOM_AUDIENCE_WITH_EMPTY_ADS,
EMPTY_AD_SELECTION_SIGNALS,
EMPTY_BUYER_SIGNALS,
- EMPTY_CONTEXTUAL_SIGNALS,
- AdSelectionConfigFixture.anAdSelectionConfig());
+ EMPTY_CONTEXTUAL_SIGNALS);
// The result is an early return with a FluentFuture of Null, after checking the Ads list is
// empty.
assertNull(result.get());