Skip to content

Commit

Permalink
🔧 Make prefetch false by default
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-rasevych-criteo committed Sep 14, 2023
1 parent 04bb8af commit 557625a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -32,9 +33,11 @@
import com.criteo.publisher.mock.MockedDependenciesRule;
import com.criteo.publisher.mock.SpyBean;
import com.criteo.publisher.model.CdbRequest;
import com.criteo.publisher.model.Config;
import com.criteo.publisher.network.PubSdkApi;
import com.criteo.publisher.util.SharedPreferencesFactory;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
Expand All @@ -55,6 +58,15 @@ public class UserPrivacyFunctionalTest {
@Inject
private SharedPreferencesFactory sharedPreferencesFactory;

@SpyBean
private Config config;

@Before
public void setUp() {
doReturn(true).when(config).isPrefetchOnInitEnabled();
doReturn(false).when(config).isLiveBiddingEnabled();
}

@Test
public void whenCriteoInit_GivenUspIabNotEmpty_VerifyItIsPassedToCdb() throws Exception {
writeIntoDefaultSharedPrefs("IABUSPrivacy_String", "fake_iab_usp");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -46,6 +47,7 @@
import com.criteo.publisher.mock.MockedDependenciesRule;
import com.criteo.publisher.mock.SpyBean;
import com.criteo.publisher.model.AdUnit;
import com.criteo.publisher.model.Config;
import com.criteo.publisher.network.CdbMock;
import com.criteo.publisher.network.PubSdkApi;
import com.criteo.publisher.util.BuildConfigWrapper;
Expand Down Expand Up @@ -87,8 +89,13 @@ public class CsmFunctionalTest {
@Inject
private CdbMock cdbMock;

@SpyBean
private Config config;

@Before
public void setUp() throws Exception {
doReturn(true).when(config).isPrefetchOnInitEnabled();
doReturn(false).when(config).isLiveBiddingEnabled();
integrationRegistry.declare(Integration.IN_HOUSE);
givenConsentGiven();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -50,13 +51,15 @@
import com.criteo.publisher.model.AdUnit;
import com.criteo.publisher.model.BannerAdUnit;
import com.criteo.publisher.model.CdbResponse;
import com.criteo.publisher.model.Config;
import com.criteo.publisher.model.InterstitialAdUnit;
import com.criteo.publisher.network.PubSdkApi;
import com.criteo.publisher.test.activity.DummyActivity;
import com.criteo.publisher.util.BuildConfigWrapper;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.junit.MockitoJUnit;
Expand Down Expand Up @@ -98,6 +101,15 @@ public class CriteoFunctionalTest {
@SpyBean
private Logger logger;

@SpyBean
private Config config;

@Before
public void setUp() {
doReturn(true).when(config).isPrefetchOnInitEnabled();
doReturn(false).when(config).isLiveBiddingEnabled();
}

@Test
@SuppressWarnings("deprecation")
public void setMoPubConsent_LogThatDeprecatedMethodIsCalled() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public static Iterable<?> data() {
@Before
public void setUp() {
doReturn(isLiveBiddingEnabled).when(config).isLiveBiddingEnabled();
doReturn(true).when(config).isPrefetchOnInitEnabled();

RequestConfiguration requestConfiguration = new RequestConfiguration.Builder().setTestDeviceIds(Collections.singletonList(AdRequest.DEVICE_ID_EMULATOR)).build();
MobileAds.setRequestConfiguration(requestConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static Iterable<?> data() {
@Before
public void setUp() throws Exception {
doReturn(isLiveBiddingEnabled).when(config).isLiveBiddingEnabled();
doReturn(true).when(config).isPrefetchOnInitEnabled();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.criteo.publisher.TestAdUnits.BANNER_320_480
import com.criteo.publisher.TestAdUnits.INTERSTITIAL
import com.criteo.publisher.TestAdUnits.NATIVE
import com.criteo.publisher.advancednative.CriteoNativeLoader
import com.criteo.publisher.concurrent.ThreadingUtil.callOnMainThreadAndWait
import com.criteo.publisher.concurrent.ThreadingUtil.runOnMainThreadAndWait
import com.criteo.publisher.context.ContextData
import com.criteo.publisher.csm.MetricHelper
Expand All @@ -34,10 +33,12 @@ import com.criteo.publisher.csm.MetricSendingQueueConsumer
import com.criteo.publisher.csm.MetricSendingQueueProducer
import com.criteo.publisher.mock.MockedDependenciesRule
import com.criteo.publisher.mock.SpyBean
import com.criteo.publisher.model.Config
import com.criteo.publisher.network.PubSdkApi
import com.criteo.publisher.privacy.ConsentData
import com.google.android.gms.ads.admanager.AdManagerAdRequest
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.kotlin.any
Expand All @@ -46,6 +47,7 @@ import org.mockito.kotlin.check
import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.doCallRealMethod
import org.mockito.kotlin.doNothing
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
Expand Down Expand Up @@ -75,6 +77,15 @@ class ProfileIdFunctionalTest {
@SpyBean
private lateinit var consentData: ConsentData

@SpyBean
private lateinit var config: Config

@Before
fun setUp() {
doReturn(true).whenever(config).isPrefetchOnInitEnabled()
doReturn(false).whenever(config).isLiveBiddingEnabled()
}

@Test
fun prefetch_GivenSdkUsedForTheFirstTime_UseFallbackProfileId() {
givenInitializedCriteo(BANNER_320_480)
Expand Down Expand Up @@ -331,12 +342,14 @@ class ProfileIdFunctionalTest {
givenInitializedCriteo()
bidInHouseInterstitial()
mockedDependenciesRule.resetAllDependencies()
setUp()
}

private fun givenPreviousStandaloneIntegrationWithResetDependencies() {
givenInitializedCriteo()
bidStandaloneInterstitial()
mockedDependenciesRule.resetAllDependencies()
setUp()
}

private fun triggerMetricRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static com.criteo.publisher.concurrent.ThreadingUtil.runOnMainThreadAndWait;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -32,8 +34,10 @@
import com.criteo.publisher.model.AdSize;
import com.criteo.publisher.model.BannerAdUnit;
import com.criteo.publisher.model.CdbRequest;
import com.criteo.publisher.model.Config;
import com.criteo.publisher.util.AdvertisingInfo;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
Expand All @@ -60,6 +64,15 @@ public class AdvertisingInfoFunctionalTest {
@Inject
private Context context;

@SpyBean
private Config config;

@Before
public void setUp() {
doReturn(true).when(config).isPrefetchOnInitEnabled();
doReturn(false).when(config).isLiveBiddingEnabled();
}

@Test
public void testBearcatCall_LimitedGAID() throws Exception {
when(advertisingInfo.getAdvertisingId()).thenReturn(DEVICE_ID_LIMITED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public static class DefaultConfig {
public static final String AD_TAG_DATA_MACRO = "%%adTagData%%";
public static final String AD_TAG_DATA_MODE = "<html><body style='text-align:center; margin:0px; padding:0px; horizontal-align:center;'><script>%%adTagData%%</script></body></html>";
public static final boolean CSM_ENABLED = true;
public static final boolean LIVE_BIDDING_ENABLED = false;
public static final boolean LIVE_BIDDING_ENABLED = true;
public static final int LIVE_BIDDING_TIME_BUDGET_IN_MILLIS = 8_000;
public static final boolean PREFETCH_ON_INIT_ENABLED = true;
public static final boolean PREFETCH_ON_INIT_ENABLED = false;
public static final RemoteLogLevel REMOTE_LOG_LEVEL = RemoteLogLevel.WARNING;
public static final boolean IS_MRAID_ENABLED = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private void assertConfigContainsDefaultValues() {
"<html><body style='text-align:center; margin:0px; padding:0px; horizontal-align:center;'><script>%%adTagData%%</script></body></html>",
config.getAdTagDataMode());
assertTrue(config.isCsmEnabled());
assertFalse(config.isLiveBiddingEnabled());
assertTrue(config.isLiveBiddingEnabled());
assertEquals(8000, config.getLiveBiddingTimeBudgetInMillis());
assertFalse(config.isMraidEnabled());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ class CdbMock(private val jsonSerializer: JsonSerializer) {
"iOSWidthMacro": "%%width%%",
"iOSAdTagUrlMode": "<!doctype html><html><head><meta charset=\"utf-8\"><style>body{margin:0;padding:0}</style><meta name=\"viewport\" content=\"width=%%width%%, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\" ></head><body><script src=\"%%displayUrl%%\"></script></body></html>",
"csmEnabled": true,
"liveBiddingEnabled": false,
"liveBiddingEnabled": true,
"liveBiddingTimeBudgetInMillis": 8000,
"prefetchOnInitEnabled": true,
"prefetchOnInitEnabled": false,
"remoteLogLevel": "Warning",
"mraidEnabled": false
}
Expand Down

0 comments on commit 557625a

Please sign in to comment.