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.google.common.truth.Truth.assertThat; 19 20 import android.adservices.common.AdServicesCommonManager; 21 import android.adservices.common.AdServicesStates; 22 import android.content.Context; 23 import android.os.OutcomeReceiver; 24 import android.platform.test.rule.ScreenRecordRule; 25 26 import androidx.test.platform.app.InstrumentationRegistry; 27 import androidx.test.runner.AndroidJUnit4; 28 import androidx.test.uiautomator.UiDevice; 29 30 import com.android.adservices.common.AdservicesTestHelper; 31 import com.android.adservices.tests.ui.libs.AdservicesWorkflows; 32 import com.android.adservices.tests.ui.libs.UiConstants; 33 import com.android.adservices.tests.ui.libs.UiUtils; 34 35 import org.junit.After; 36 import org.junit.Assert; 37 import org.junit.Assume; 38 import org.junit.Before; 39 import org.junit.Rule; 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 43 import java.util.concurrent.Executors; 44 45 /** Test for verifying user consent notification trigger behaviors. */ 46 @RunWith(AndroidJUnit4.class) 47 @ScreenRecordRule.ScreenRecord 48 public class ExtGaUxDebugChannelApiOffTest { 49 50 private AdServicesCommonManager mCommonManager; 51 52 private UiDevice mDevice; 53 54 private String mTestName; 55 56 private static final Context sContext = 57 InstrumentationRegistry.getInstrumentation().getContext(); 58 59 @Rule public final ScreenRecordRule sScreenRecordRule = new ScreenRecordRule(); 60 61 @Before setUp()62 public void setUp() throws Exception { 63 // Skip the test if it runs on unsupported platforms. 64 Assume.assumeTrue(AdservicesTestHelper.isDeviceSupported()); 65 66 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 67 68 UiUtils.enableNotificationPermission(); 69 70 mCommonManager = AdServicesCommonManager.get(sContext); 71 72 // consent debug mode is turned on for this test class as we only care about the 73 // first trigger (API call). 74 UiUtils.enableConsentDebugMode(); 75 UiUtils.disableNotificationFlowV2(); 76 UiUtils.disableOtaStrings(); 77 78 mDevice.pressHome(); 79 } 80 81 @After tearDown()82 public void tearDown() throws Exception { 83 if (!AdservicesTestHelper.isDeviceSupported()) return; 84 85 UiUtils.takeScreenshot(mDevice, getClass().getSimpleName() + "_" + mTestName + "_"); 86 87 mDevice.pressHome(); 88 } 89 90 /** Verify that the API returns false when API is disabled. */ 91 @Test testApiDisabled()92 public void testApiDisabled() throws Exception { 93 mTestName = new Object() {}.getClass().getEnclosingMethod().getName(); 94 95 mCommonManager.enableAdServices( 96 new AdServicesStates.Builder() 97 .setAdIdEnabled(true) 98 .setAdultAccount(true) 99 .setPrivacySandboxUiEnabled(true) 100 .build(), 101 Executors.newCachedThreadPool(), 102 new OutcomeReceiver<>() { 103 @Override 104 public void onResult(Boolean result) { 105 assertThat(result).isFalse(); 106 } 107 108 @Override 109 public void onError(Exception exception) { 110 Assert.fail(); 111 } 112 }); 113 114 AdservicesWorkflows.verifyNotification( 115 sContext, 116 mDevice, /* isDisplayed */ 117 false, /* isEuTest */ 118 false, 119 UiConstants.UX.GA_UX, 120 true); 121 } 122 } 123