• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("eu_notif_flow_change_enabled")
48 @SetFlagDisabled(KEY_IS_EEA_DEVICE)
49 @SetFlagEnabled(KEY_ENABLE_AD_SERVICES_SYSTEM_API)
50 public final class ExtGaUxDebugChannelRowTest extends AdExtServicesGaUxDebugChannelTestCase {
51 
52     private AdServicesCommonManager mCommonManager;
53 
54     private UiDevice mDevice;
55 
56     private String mTestName;
57 
58     private OutcomeReceiver<Boolean, Exception> mCallback;
59 
60     @Rule public final ScreenRecordRule sScreenRecordRule = new ScreenRecordRule();
61 
62     @Before
setUp()63     public void setUp() throws Exception {
64         mTestName = getTestName();
65 
66         UiUtils.resetAdServicesConsentData(sContext, flags);
67 
68         mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
69 
70         UiUtils.enableNotificationPermission();
71 
72         mCommonManager = AdServicesCommonManager.get(sContext);
73 
74         // consent debug mode is turned on for this test class as we only care about the
75         // first trigger (API call).
76         UiUtils.enableConsentDebugMode(flags);
77         UiUtils.disableNotificationFlowV2(flags);
78         UiUtils.disableOtaStrings(flags);
79 
80         mCallback =
81                 new OutcomeReceiver<>() {
82                     @Override
83                     public void onResult(Boolean result) {
84                         assertThat(result).isTrue();
85                     }
86 
87                     @Override
88                     public void onError(Exception exception) {
89                         Assert.fail();
90                     }
91                 };
92 
93         mDevice.pressHome();
94     }
95 
96     @After
tearDown()97     public void tearDown() throws Exception {
98         UiUtils.takeScreenshot(mDevice, getClass().getSimpleName() + "_" + mTestName + "_");
99 
100         mDevice.pressHome();
101     }
102 
103     /** Verify that entry point disabled can not trigger consent notification. */
104     @Test
testEntryPointDisabled()105     public void testEntryPointDisabled() throws Exception {
106         mCommonManager.enableAdServices(
107                 new AdServicesStates.Builder()
108                         .setAdIdEnabled(true)
109                         .setAdultAccount(true)
110                         .setPrivacySandboxUiEnabled(false)
111                         .build(),
112                 Executors.newCachedThreadPool(),
113                 mCallback);
114 
115         AdservicesWorkflows.verifyNotification(
116                 sContext,
117                 mDevice, /* isDisplayed */
118                 false, /* isEuTest */
119                 false, /* isGa */
120                 UiConstants.UX.GA_UX,
121                 true);
122     }
123 
124     /** Verify that when request sent from entry point, we won't trigger notification. */
125     @Test
testFromEntryPointRequest()126     public void testFromEntryPointRequest() throws Exception {
127         mCommonManager.enableAdServices(
128                 new AdServicesStates.Builder()
129                         .setAdIdEnabled(false)
130                         .setAdultAccount(true)
131                         .setPrivacySandboxUiEnabled(true)
132                         .setPrivacySandboxUiRequest(true)
133                         .build(),
134                 Executors.newCachedThreadPool(),
135                 mCallback);
136 
137         AdservicesWorkflows.verifyNotification(
138                 sContext,
139                 mDevice, /* isDisplayed */
140                 false, /* isEuTest */
141                 false,
142                 UiConstants.UX.GA_UX,
143                 true);
144     }
145 
146     /** Verify that non-adult account can not trigger consent notification. */
147     @Test
testNonAdultAccount()148     public void testNonAdultAccount() throws Exception {
149         mCommonManager.enableAdServices(
150                 new AdServicesStates.Builder()
151                         .setAdIdEnabled(true)
152                         .setAdultAccount(false)
153                         .setPrivacySandboxUiEnabled(true)
154                         .build(),
155                 Executors.newCachedThreadPool(),
156                 mCallback);
157 
158         AdservicesWorkflows.verifyNotification(
159                 sContext,
160                 mDevice, /* isDisplayed */
161                 false, /* isEuTest */
162                 false,
163                 UiConstants.UX.GA_UX,
164                 true);
165     }
166 
167     /**
168      * Verify that for GA, ROW devices with non zeroed-out AdId, the GA ROW notification is
169      * displayed.
170      */
171     @Test
testGaRowAdIdEnabled()172     public void testGaRowAdIdEnabled() throws Exception {
173         mCommonManager.enableAdServices(
174                 new AdServicesStates.Builder()
175                         .setAdIdEnabled(true)
176                         .setAdultAccount(true)
177                         .setPrivacySandboxUiEnabled(true)
178                         .build(),
179                 Executors.newCachedThreadPool(),
180                 mCallback);
181 
182         AdservicesWorkflows.verifyNotification(
183                 sContext,
184                 mDevice, /* isDisplayed */
185                 true, /* isEuTest */
186                 false,
187                 UiConstants.UX.GA_UX,
188                 true);
189     }
190 
191     /**
192      * Verify that for GA, ROW devices with zeroed-out AdId, the GA EU notification is displayed.
193      */
194     @Test
testGaRowAdIdDisabled()195     public void testGaRowAdIdDisabled() throws Exception {
196         mCommonManager.enableAdServices(
197                 new AdServicesStates.Builder()
198                         .setAdIdEnabled(false)
199                         .setAdultAccount(true)
200                         .setPrivacySandboxUiEnabled(true)
201                         .build(),
202                 Executors.newCachedThreadPool(),
203                 mCallback);
204 
205         AdservicesWorkflows.verifyNotification(
206                 sContext,
207                 mDevice, /* isDisplayed */
208                 true, /* isEuTest */
209                 true,
210                 UiConstants.UX.GA_UX,
211                 true);
212     }
213 }
214