1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.adservices.tests.ui.gaux.debugchannel; 17 18 import static com.android.adservices.service.FlagsConstants.KEY_ENABLE_AD_SERVICES_SYSTEM_API; 19 import static com.android.adservices.service.FlagsConstants.KEY_IS_EEA_DEVICE; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import android.adservices.common.AdServicesCommonManager; 24 import android.adservices.common.AdServicesStates; 25 import android.os.OutcomeReceiver; 26 import android.platform.test.rule.ScreenRecordRule; 27 28 import androidx.test.platform.app.InstrumentationRegistry; 29 import androidx.test.uiautomator.UiDevice; 30 31 import com.android.adservices.shared.testing.annotations.SetFlagDisabled; 32 import com.android.adservices.shared.testing.annotations.SetFlagEnabled; 33 import com.android.adservices.tests.ui.libs.AdservicesWorkflows; 34 import com.android.adservices.tests.ui.libs.UiConstants; 35 import com.android.adservices.tests.ui.libs.UiUtils; 36 37 import org.junit.After; 38 import org.junit.Assert; 39 import org.junit.Before; 40 import org.junit.Rule; 41 import org.junit.Test; 42 43 import java.util.concurrent.Executors; 44 45 /** Test for verifying user consent notification trigger behaviors. */ 46 @ScreenRecordRule.ScreenRecord 47 @SetFlagDisabled(KEY_ENABLE_AD_SERVICES_SYSTEM_API) 48 @SetFlagEnabled(KEY_IS_EEA_DEVICE) 49 public final class ExtGaUxDebugChannelApiOffTest extends AdExtServicesGaUxDebugChannelTestCase { 50 51 private AdServicesCommonManager mCommonManager; 52 53 private UiDevice mDevice; 54 55 private String mTestName; 56 57 @Rule public final ScreenRecordRule sScreenRecordRule = new ScreenRecordRule(); 58 59 @Before setUp()60 public void setUp() throws Exception { 61 mTestName = getTestName(); 62 63 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 64 65 UiUtils.enableNotificationPermission(); 66 67 mCommonManager = AdServicesCommonManager.get(sContext); 68 69 // consent debug mode is turned on for this test class as we only care about the 70 // first trigger (API call). 71 UiUtils.enableConsentDebugMode(flags); 72 UiUtils.disableNotificationFlowV2(flags); 73 UiUtils.disableOtaStrings(flags); 74 75 mDevice.pressHome(); 76 } 77 78 @After tearDown()79 public void tearDown() throws Exception { 80 UiUtils.takeScreenshot(mDevice, getClass().getSimpleName() + "_" + mTestName + "_"); 81 82 mDevice.pressHome(); 83 } 84 85 /** Verify that the API returns false when API is disabled. */ 86 @Test testApiDisabled()87 public void testApiDisabled() throws Exception { 88 mCommonManager.enableAdServices( 89 new AdServicesStates.Builder() 90 .setAdIdEnabled(true) 91 .setAdultAccount(true) 92 .setPrivacySandboxUiEnabled(true) 93 .build(), 94 Executors.newCachedThreadPool(), 95 new OutcomeReceiver<>() { 96 @Override 97 public void onResult(Boolean result) { 98 assertThat(result).isFalse(); 99 } 100 101 @Override 102 public void onError(Exception exception) { 103 Assert.fail(); 104 } 105 }); 106 107 AdservicesWorkflows.verifyNotification( 108 sContext, 109 mDevice, /* isDisplayed */ 110 false, /* isEuTest */ 111 false, 112 UiConstants.UX.GA_UX, 113 true); 114 } 115 } 116