blob: 0017943cfc986c5d1b3e7d03bf5e81b8cb0a2d8f [file] [log] [blame]
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001/*
2 * Copyright (C) 2016 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
17package com.android.systemui.statusbar;
18
Julia Reynoldsc65656a2018-02-12 09:55:14 -050019import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE;
Julia Reynolds437cdb12018-01-03 12:27:24 -050020import static android.app.NotificationManager.IMPORTANCE_LOW;
Julia Reynoldse0341482018-03-08 14:42:50 -050021import static android.app.NotificationManager.IMPORTANCE_MIN;
22import static android.app.NotificationManager.IMPORTANCE_NONE;
Julia Reynoldsc65656a2018-02-12 09:55:14 -050023import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
Julia Reynoldsf7321592017-05-24 16:09:19 -040024import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME;
Julia Reynolds437cdb12018-01-03 12:27:24 -050025import static android.view.View.GONE;
26import static android.view.View.VISIBLE;
Julia Reynoldsf7321592017-05-24 16:09:19 -040027
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050028import static junit.framework.Assert.assertEquals;
29import static junit.framework.Assert.assertFalse;
30import static junit.framework.Assert.assertTrue;
Julia Reynolds5a311932017-03-01 16:33:44 -050031
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050032import static org.mockito.Mockito.any;
33import static org.mockito.Mockito.anyBoolean;
34import static org.mockito.Mockito.anyInt;
35import static org.mockito.Mockito.anyString;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070036import static org.mockito.Mockito.doCallRealMethod;
37import static org.mockito.Mockito.doNothing;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050038import static org.mockito.Mockito.eq;
39import static org.mockito.Mockito.mock;
40import static org.mockito.Mockito.never;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070041import static org.mockito.Mockito.spy;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050042import static org.mockito.Mockito.times;
43import static org.mockito.Mockito.verify;
44import static org.mockito.Mockito.when;
45
46import android.app.INotificationManager;
Julia Reynolds3aedded2017-03-31 14:42:09 -040047import android.app.Notification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050048import android.app.NotificationChannel;
49import android.app.NotificationChannelGroup;
Julia Reynolds3aedded2017-03-31 14:42:09 -040050import android.content.Intent;
51import android.content.pm.ActivityInfo;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050052import android.content.pm.ApplicationInfo;
53import android.content.pm.PackageInfo;
54import android.content.pm.PackageManager;
Julia Reynolds3aedded2017-03-31 14:42:09 -040055import android.content.pm.ResolveInfo;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050056import android.graphics.drawable.Drawable;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070057import android.os.IBinder;
Julia Reynolds3aedded2017-03-31 14:42:09 -040058import android.os.UserHandle;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050059import android.service.notification.StatusBarNotification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050060import android.test.suitebuilder.annotation.SmallTest;
Jason Monk340b0e52017-03-08 14:57:56 -050061import android.testing.AndroidTestingRunner;
Julia Reynolds437cdb12018-01-03 12:27:24 -050062import android.testing.PollingCheck;
Rohan Shahca0447e2018-03-30 15:18:27 -070063import android.testing.TestableLooper;
Jason Monk340b0e52017-03-08 14:57:56 -050064import android.testing.UiThreadTest;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050065import android.view.LayoutInflater;
66import android.view.View;
67import android.widget.ImageView;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050068import android.widget.TextView;
Jason Monk340b0e52017-03-08 14:57:56 -050069
Rohan Shahda5dcdd2018-04-27 17:21:50 -070070import com.android.internal.logging.MetricsLogger;
Rohan Shahca0447e2018-03-30 15:18:27 -070071import com.android.systemui.Dependency;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050072import com.android.systemui.R;
73import com.android.systemui.SysuiTestCase;
Jason Monkba364322017-03-06 11:19:20 -050074
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050075import org.junit.Before;
Rohan Shah524cf7b2018-03-15 14:40:02 -070076import org.junit.Rule;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050077import org.junit.Test;
Jason Monk340b0e52017-03-08 14:57:56 -050078import org.junit.runner.RunWith;
Julia Reynolds8ceb5792017-04-11 11:32:44 -040079import org.mockito.ArgumentCaptor;
Rohan Shah524cf7b2018-03-15 14:40:02 -070080import org.mockito.Mock;
81import org.mockito.junit.MockitoJUnit;
82import org.mockito.junit.MockitoRule;
Julia Reynolds3aedded2017-03-31 14:42:09 -040083
84import java.util.ArrayList;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -050085import java.util.List;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050086import java.util.concurrent.CountDownLatch;
87
88@SmallTest
Jason Monk340b0e52017-03-08 14:57:56 -050089@RunWith(AndroidTestingRunner.class)
Rohan Shahca0447e2018-03-30 15:18:27 -070090@TestableLooper.RunWithLooper
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050091public class NotificationInfoTest extends SysuiTestCase {
92 private static final String TEST_PACKAGE_NAME = "test_package";
Julia Reynoldsf7321592017-05-24 16:09:19 -040093 private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME;
Geoffrey Pitschd034d292017-05-12 11:59:20 -040094 private static final int TEST_UID = 1;
Rohan Shah63411fc2018-03-28 19:05:52 -070095 private static final int MULTIPLE_CHANNEL_COUNT = 2;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050096 private static final String TEST_CHANNEL = "test_channel";
97 private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME";
98
Rohan Shahca0447e2018-03-30 15:18:27 -070099 private TestableLooper mTestableLooper;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500100 private NotificationInfo mNotificationInfo;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500101 private NotificationChannel mNotificationChannel;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500102 private NotificationChannel mDefaultNotificationChannel;
Julia Reynolds3aedded2017-03-31 14:42:09 -0400103 private StatusBarNotification mSbn;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500104
Rohan Shah524cf7b2018-03-15 14:40:02 -0700105 @Rule public MockitoRule mockito = MockitoJUnit.rule();
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700106 @Mock private MetricsLogger mMetricsLogger;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700107 @Mock private INotificationManager mMockINotificationManager;
108 @Mock private PackageManager mMockPackageManager;
109 @Mock private NotificationBlockingHelperManager mBlockingHelperManager;
110
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500111 @Before
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500112 public void setUp() throws Exception {
Rohan Shah524cf7b2018-03-15 14:40:02 -0700113 mDependency.injectTestDependency(
114 NotificationBlockingHelperManager.class,
115 mBlockingHelperManager);
Rohan Shahca0447e2018-03-30 15:18:27 -0700116 mTestableLooper = TestableLooper.get(this);
117 mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper());
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700118 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500119 // Inflate the layout
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500120 final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500121 mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info,
122 null);
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500123 mNotificationInfo.setGutsParent(mock(NotificationGuts.class));
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500124
125 // PackageManager must return a packageInfo and applicationInfo.
126 final PackageInfo packageInfo = new PackageInfo();
127 packageInfo.packageName = TEST_PACKAGE_NAME;
Julia Reynoldsf7321592017-05-24 16:09:19 -0400128 when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt()))
129 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500130 final ApplicationInfo applicationInfo = new ApplicationInfo();
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400131 applicationInfo.uid = TEST_UID; // non-zero
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500132 when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn(
133 applicationInfo);
Julia Reynoldsf7321592017-05-24 16:09:19 -0400134 final PackageInfo systemPackageInfo = new PackageInfo();
135 systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME;
136 when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt()))
137 .thenReturn(systemPackageInfo);
138 when(mMockPackageManager.getPackageInfo(eq("android"), anyInt()))
139 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500140
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500141 // Package has one channel by default.
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500142 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400143 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500144
145 // Some test channels.
146 mNotificationChannel = new NotificationChannel(
Julia Reynolds437cdb12018-01-03 12:27:24 -0500147 TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500148 mDefaultNotificationChannel = new NotificationChannel(
149 NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500150 IMPORTANCE_LOW);
Julia Reynolds33bef2c2017-09-05 11:07:18 -0400151 mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400152 new Notification(), UserHandle.CURRENT, null, 0);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500153 }
154
Julia Reynolds437cdb12018-01-03 12:27:24 -0500155 // TODO: if tests are taking too long replace this with something that makes the animation
156 // finish instantly.
157 private void waitForUndoButton() {
158 PollingCheck.waitFor(1000,
159 () -> VISIBLE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500160 }
Gus Prevasf4f0b062018-09-24 17:15:32 -0400161 private void ensureNoUndoButton() {
162 PollingCheck.waitFor(1000,
163 () -> GONE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility()
164 && !mNotificationInfo.isAnimating());
165 }
Julia Reynolds437cdb12018-01-03 12:27:24 -0500166 private void waitForStopButton() {
167 PollingCheck.waitFor(1000,
168 () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500169 }
170
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500171 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500172 public void testBindNotification_SetsTextApplicationName() throws Exception {
173 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
174 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700175 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500176 final TextView textView = mNotificationInfo.findViewById(R.id.pkgname);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500177 assertTrue(textView.getText().toString().contains("App Name"));
Julia Reynoldse0341482018-03-08 14:42:50 -0500178 assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500179 }
180
181 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500182 public void testBindNotification_SetsPackageIcon() throws Exception {
183 final Drawable iconDrawable = mock(Drawable.class);
184 when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
185 .thenReturn(iconDrawable);
186 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700187 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500188 final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500189 assertEquals(iconDrawable, iconView.getDrawable());
190 }
191
192 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500193 public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
194 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700195 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500196 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
197 assertEquals(GONE, groupNameView.getVisibility());
198 final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider);
199 assertEquals(GONE, groupDividerView.getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500200 }
201
202 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500203 public void testBindNotification_SetsGroupNameIfNonNull() throws Exception {
204 mNotificationChannel.setGroup("test_group_id");
205 final NotificationChannelGroup notificationChannelGroup =
206 new NotificationChannelGroup("test_group_id", "Test Group Name");
207 when(mMockINotificationManager.getNotificationChannelGroupForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400208 eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID)))
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500209 .thenReturn(notificationChannelGroup);
210 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700211 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500212 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500213 assertEquals(View.VISIBLE, groupNameView.getVisibility());
214 assertEquals("Test Group Name", groupNameView.getText());
Julia Reynolds437cdb12018-01-03 12:27:24 -0500215 final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500216 assertEquals(View.VISIBLE, groupDividerView.getVisibility());
217 }
218
219 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500220 public void testBindNotification_SetsTextChannelName() throws Exception {
221 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700222 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500223 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500224 assertEquals(TEST_CHANNEL_NAME, textView.getText());
225 }
226
227 @Test
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400228 public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception {
229 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700230 TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500231 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
232 assertEquals(GONE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400233 }
234
235 @Test
Rohan Shahdbd64e72018-03-28 14:46:50 -0700236 public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist()
237 throws Exception {
238 // Package has one channel by default.
239 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
240 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10);
241 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700242 TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false);
Rohan Shahdbd64e72018-03-28 14:46:50 -0700243 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
244 assertEquals(VISIBLE, textView.getVisibility());
245 }
246
247 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500248 public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception {
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400249 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700250 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500251 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
252 assertEquals(VISIBLE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400253 }
254
255 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500256 public void testBindNotification_BlockButton() throws Exception {
257 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700258 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500259 final View block = mNotificationInfo.findViewById(R.id.block);
260 final View minimize = mNotificationInfo.findViewById(R.id.minimize);
261 assertEquals(VISIBLE, block.getVisibility());
262 assertEquals(GONE, minimize.getVisibility());
263 }
264
265 @Test
266 public void testBindNotification_MinButton() throws Exception {
267 mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
268 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700269 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500270 final View block = mNotificationInfo.findViewById(R.id.block);
271 final View minimize = mNotificationInfo.findViewById(R.id.minimize);
272 assertEquals(GONE, block.getVisibility());
273 assertEquals(VISIBLE, minimize.getVisibility());
274 }
275
276 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500277 public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
278 final CountDownLatch latch = new CountDownLatch(1);
279 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500280 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500281 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400282 assertEquals(mNotificationChannel, c);
283 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700284 }, null, false);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500285
Julia Reynolds437cdb12018-01-03 12:27:24 -0500286 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500287 settingsButton.performClick();
288 // Verify that listener was triggered.
289 assertEquals(0, latch.getCount());
290 }
291
292 @Test
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400293 public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception {
294 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700295 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500296 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400297 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
298 }
299
300 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500301 public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception {
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400302 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700303 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400304 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500305 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null,
306 (View v, NotificationChannel c, int appUid) -> {
Rohan Shah63411fc2018-03-28 19:05:52 -0700307 }, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500308 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400309 assertEquals(View.VISIBLE, settingsButton.getVisibility());
310 }
311
312 @Test
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700313 public void testLogBlockingHelperCounter_doesntLogForNormalGutsView() throws Exception {
314 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
315 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
316 mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent");
317 verify(mMetricsLogger, times(0)).count(anyString(), anyInt());
318 }
319
320 @Test
321 public void testLogBlockingHelperCounter_logsForBlockingHelper() throws Exception {
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700322 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
323 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, true,
324 true);
325 mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent");
Rohan Shahc6b0d542018-05-10 13:00:54 -0700326 verify(mMetricsLogger, times(1)).count(anyString(), anyInt());
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700327 }
328
329 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500330 public void testOnClickListenerPassesNullChannelForBundle() throws Exception {
331 final CountDownLatch latch = new CountDownLatch(1);
332 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700333 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500334 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400335 assertEquals(null, c);
336 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700337 }, null, true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500338
Julia Reynolds437cdb12018-01-03 12:27:24 -0500339 mNotificationInfo.findViewById(R.id.info).performClick();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500340 // Verify that listener was triggered.
341 assertEquals(0, latch.getCount());
342 }
343
344 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500345 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500346 public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels()
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500347 throws Exception {
348 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700349 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null,
350 null, true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500351 final TextView channelNameView =
Julia Reynolds437cdb12018-01-03 12:27:24 -0500352 mNotificationInfo.findViewById(R.id.channel_name);
353 assertEquals(GONE, channelNameView.getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500354 }
355
356 @Test
357 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500358 public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500359 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700360 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null,
361 null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500362 final TextView blockView = mNotificationInfo.findViewById(R.id.block);
363 assertEquals(GONE, blockView.getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500364 }
365
366 @Test
Julia Reynolds0ef7d842018-01-24 17:50:31 -0500367 public void testbindNotification_BlockingHelper() throws Exception {
368 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700369 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, false,
370 true);
Julia Reynolds0ef7d842018-01-24 17:50:31 -0500371 final TextView view = mNotificationInfo.findViewById(R.id.block_prompt);
372 assertEquals(View.VISIBLE, view.getVisibility());
373 assertEquals(mContext.getString(R.string.inline_blocking_helper), view.getText());
374 }
375
376 @Test
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400377 public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception {
378 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700379 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500380 final TextView view = mNotificationInfo.findViewById(R.id.block_prompt);
381 assertEquals(View.VISIBLE, view.getVisibility());
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400382 assertEquals(mContext.getString(R.string.notification_unblockable_desc),
Julia Reynolds437cdb12018-01-03 12:27:24 -0500383 view.getText());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500384 }
385
386 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500387 public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception {
388 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700389 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700390 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500391 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400392 anyString(), eq(TEST_UID), any());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500393 }
394
395 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500396 public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500397 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500398 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700399 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500400
Julia Reynolds437cdb12018-01-03 12:27:24 -0500401 mNotificationInfo.findViewById(R.id.block).performClick();
Rohan Shahca0447e2018-03-30 15:18:27 -0700402 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500403 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400404 anyString(), eq(TEST_UID), any());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500405 }
406
407 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500408 public void testDoesNotUpdateNotificationChannelAfterImportanceChangedMin()
409 throws Exception {
410 mNotificationChannel.setImportance(IMPORTANCE_LOW);
411 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700412 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500413
414 mNotificationInfo.findViewById(R.id.minimize).performClick();
Rohan Shahca0447e2018-03-30 15:18:27 -0700415 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500416 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
417 anyString(), eq(TEST_UID), any());
418 }
419
420 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500421 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
422 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500423 int originalImportance = mNotificationChannel.getImportance();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500424 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700425 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500426
Mady Mellorc2dbe492017-03-30 13:22:03 -0700427 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700428 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500429 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400430 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500431 assertEquals(originalImportance, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500432 }
433
434 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500435 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified()
436 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500437 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500438 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700439 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500440
Mady Mellorc2dbe492017-03-30 13:22:03 -0700441 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700442
443 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500444 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400445 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500446 assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500447 }
448
449 @Test
Rohan Shah590e1b22018-04-10 23:48:47 -0400450 public void testHandleCloseControls_setsNotificationsDisabledForMultipleChannelNotifications()
451 throws Exception {
452 mNotificationChannel.setImportance(IMPORTANCE_LOW);
453 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
454 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
455 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */,
456 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
457 false /* isNonblockable */);
458
459 mNotificationInfo.findViewById(R.id.block).performClick();
460 waitForUndoButton();
461 mNotificationInfo.handleCloseControls(true, false);
462
463 mTestableLooper.processAllMessages();
464 verify(mMockINotificationManager, times(1))
465 .setNotificationsEnabledWithImportanceLockForPackage(
466 anyString(), eq(TEST_UID), eq(false));
467 }
468
469
470 @Test
471 public void testHandleCloseControls_keepsNotificationsEnabledForMultipleChannelNotifications()
472 throws Exception {
473 mNotificationChannel.setImportance(IMPORTANCE_LOW);
474 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
475 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
476 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */,
477 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
478 false /* isNonblockable */);
479
480 mNotificationInfo.findViewById(R.id.block).performClick();
481 waitForUndoButton();
482 mNotificationInfo.handleCloseControls(true, false);
483
484 mTestableLooper.processAllMessages();
485 verify(mMockINotificationManager, times(1))
486 .setNotificationsEnabledWithImportanceLockForPackage(
487 anyString(), eq(TEST_UID), eq(false));
488 }
489
490 @Test
491 public void testCloseControls_blockingHelperSavesImportanceForMultipleChannelNotifications()
492 throws Exception {
493 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
494 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
495 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */,
496 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
497 false /* isNonblockable */, true /* isForBlockingHelper */,
498 true /* isUserSentimentNegative */);
499
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700500 NotificationGuts guts = spy(new NotificationGuts(mContext, null));
501 when(guts.getWindowToken()).thenReturn(mock(IBinder.class));
502 doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean());
503 doNothing().when(guts).setExposed(anyBoolean(), anyBoolean());
504 guts.setGutsContent(mNotificationInfo);
505 mNotificationInfo.setGutsParent(guts);
506
Rohan Shah590e1b22018-04-10 23:48:47 -0400507 mNotificationInfo.findViewById(R.id.keep).performClick();
508
509 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
510 mTestableLooper.processAllMessages();
511 verify(mMockINotificationManager, times(1))
512 .setNotificationsEnabledWithImportanceLockForPackage(
513 anyString(), eq(TEST_UID), eq(true));
514 }
515
Rohan Shahdd588c72018-05-09 20:32:15 -0700516 @Test
517 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayKeepShowing()
518 throws Exception {
519 NotificationInfo.CheckSaveListener listener =
520 mock(NotificationInfo.CheckSaveListener.class);
521 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
522 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
523 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */,
524 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
525 false /* isNonblockable */, true /* isForBlockingHelper */,
526 true /* isUserSentimentNegative */);
527
528 NotificationGuts guts = spy(new NotificationGuts(mContext, null));
529 when(guts.getWindowToken()).thenReturn(mock(IBinder.class));
530 doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean());
531 doNothing().when(guts).setExposed(anyBoolean(), anyBoolean());
532 guts.setGutsContent(mNotificationInfo);
533 mNotificationInfo.setGutsParent(guts);
534
535 mNotificationInfo.findViewById(R.id.keep).performClick();
536
537 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
538 mTestableLooper.processAllMessages();
539 verify(mMockINotificationManager, times(1))
540 .setNotificationsEnabledWithImportanceLockForPackage(
541 anyString(), eq(TEST_UID), eq(true));
542 }
543
Rohan Shah593e8f12018-05-22 10:06:23 -0700544 @Test
545 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayDismiss()
546 throws Exception {
547 NotificationInfo.CheckSaveListener listener =
548 mock(NotificationInfo.CheckSaveListener.class);
549 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
550 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
551 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */,
552 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
553 false /* isNonblockable */, true /* isForBlockingHelper */,
554 true /* isUserSentimentNegative */);
555
556 mNotificationInfo.handleCloseControls(true /* save */, false /* force */);
557
558 mTestableLooper.processAllMessages();
559 verify(listener, times(0)).checkSave(any(Runnable.class), eq(mSbn));
560 }
561
562 @Test
563 public void testCloseControls_checkSaveListenerDelaysStopNotifications()
564 throws Exception {
565 NotificationInfo.CheckSaveListener listener =
566 mock(NotificationInfo.CheckSaveListener.class);
567 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
568 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
569 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */,
570 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
571 false /* isNonblockable */, true /* isForBlockingHelper */,
572 true /* isUserSentimentNegative */);
573
574 mNotificationInfo.findViewById(R.id.block).performClick();
Rohan Shah593e8f12018-05-22 10:06:23 -0700575 mTestableLooper.processAllMessages();
576 verify(listener).checkSave(any(Runnable.class), eq(mSbn));
577 }
Rohan Shahdd588c72018-05-09 20:32:15 -0700578
Rohan Shah590e1b22018-04-10 23:48:47 -0400579 @Test
Rohan Shah524cf7b2018-03-15 14:40:02 -0700580 public void testCloseControls_blockingHelperDismissedIfShown() throws Exception {
581 mNotificationInfo.bindNotification(
582 mMockPackageManager,
583 mMockINotificationManager,
584 TEST_PACKAGE_NAME,
585 mNotificationChannel,
586 1 /* numChannels */,
587 mSbn,
588 null /* checkSaveListener */,
589 null /* onSettingsClick */,
590 null /* onAppSettingsClick */,
Rohan Shah63411fc2018-03-28 19:05:52 -0700591 false /* isNonblockable */,
Rohan Shah524cf7b2018-03-15 14:40:02 -0700592 true /* isForBlockingHelper */,
593 false /* isUserSentimentNegative */);
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700594 NotificationGuts guts = mock(NotificationGuts.class);
595 doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean());
596 mNotificationInfo.setGutsParent(guts);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700597
598 mNotificationInfo.closeControls(mNotificationInfo);
599
600 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
601 }
602
603 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500604 public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500605 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500606 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700607 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500608 mNotificationInfo.findViewById(R.id.block).performClick();
609 waitForUndoButton();
Rohan Shahca0447e2018-03-30 15:18:27 -0700610
611 mTestableLooper.processAllMessages();
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500612 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400613 anyString(), eq(TEST_UID), any());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500614 }
615
616 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500617 public void testBlockChangedCallsUpdateNotificationChannel() throws Exception {
618 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500619 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700620 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500621
Julia Reynolds437cdb12018-01-03 12:27:24 -0500622 mNotificationInfo.findViewById(R.id.block).performClick();
623 waitForUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700624 mNotificationInfo.handleCloseControls(true, false);
Julia Reynolds8ceb5792017-04-11 11:32:44 -0400625
Rohan Shahca0447e2018-03-30 15:18:27 -0700626 mTestableLooper.processAllMessages();
Julia Reynolds8ceb5792017-04-11 11:32:44 -0400627 ArgumentCaptor<NotificationChannel> updated =
628 ArgumentCaptor.forClass(NotificationChannel.class);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500629 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400630 anyString(), eq(TEST_UID), updated.capture());
Julia Reynolds8ceb5792017-04-11 11:32:44 -0400631 assertTrue((updated.getValue().getUserLockedFields()
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500632 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynoldse0341482018-03-08 14:42:50 -0500633 assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance());
634 }
635
636 @Test
Rohan Shahca0447e2018-03-30 15:18:27 -0700637 public void testBlockChangedCallsUpdateNotificationChannel_blockingHelper() throws Exception {
638 mNotificationChannel.setImportance(IMPORTANCE_LOW);
639 mNotificationInfo.bindNotification(
640 mMockPackageManager,
641 mMockINotificationManager,
642 TEST_PACKAGE_NAME,
643 mNotificationChannel,
644 1 /* numChannels */,
645 mSbn,
646 null /* checkSaveListener */,
647 null /* onSettingsClick */,
648 null /* onAppSettingsClick */,
649 false /* isNonblockable */,
650 true /* isForBlockingHelper */,
651 true /* isUserSentimentNegative */);
652
653 mNotificationInfo.findViewById(R.id.block).performClick();
654 waitForUndoButton();
655 mNotificationInfo.handleCloseControls(true, false);
656
657 mTestableLooper.processAllMessages();
658 ArgumentCaptor<NotificationChannel> updated =
659 ArgumentCaptor.forClass(NotificationChannel.class);
660 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
661 anyString(), eq(TEST_UID), updated.capture());
662 assertTrue((updated.getValue().getUserLockedFields()
663 & USER_LOCKED_IMPORTANCE) != 0);
664 assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance());
665 }
666
667
668 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500669 public void testNonBlockableAppDoesNotBecomeMin() throws Exception {
670 mNotificationChannel.setImportance(IMPORTANCE_LOW);
671 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700672 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500673 mNotificationInfo.findViewById(R.id.minimize).performClick();
674 waitForUndoButton();
Rohan Shahca0447e2018-03-30 15:18:27 -0700675
676 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500677 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
678 anyString(), eq(TEST_UID), any());
679 }
680
681 @Test
682 public void testMinChangedCallsUpdateNotificationChannel() throws Exception {
683 mNotificationChannel.setImportance(IMPORTANCE_LOW);
684 mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
685 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700686 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500687
688 mNotificationInfo.findViewById(R.id.minimize).performClick();
689 waitForUndoButton();
690 mNotificationInfo.handleCloseControls(true, false);
691
Rohan Shahca0447e2018-03-30 15:18:27 -0700692 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500693 ArgumentCaptor<NotificationChannel> updated =
694 ArgumentCaptor.forClass(NotificationChannel.class);
695 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
696 anyString(), eq(TEST_UID), updated.capture());
697 assertTrue((updated.getValue().getUserLockedFields()
698 & USER_LOCKED_IMPORTANCE) != 0);
699 assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500700 }
701
702 @Test
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500703 public void testKeepUpdatesNotificationChannel() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500704 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500705 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700706 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500707
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500708 mNotificationInfo.handleCloseControls(true, false);
709
Rohan Shahca0447e2018-03-30 15:18:27 -0700710 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500711 ArgumentCaptor<NotificationChannel> updated =
712 ArgumentCaptor.forClass(NotificationChannel.class);
713 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
714 anyString(), eq(TEST_UID), updated.capture());
715 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
716 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
717 }
718
719 @Test
720 public void testBlockUndoDoesNotBlockNotificationChannel() throws Exception {
721 mNotificationChannel.setImportance(IMPORTANCE_LOW);
722 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700723 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500724
725 mNotificationInfo.findViewById(R.id.block).performClick();
726 waitForUndoButton();
727 mNotificationInfo.findViewById(R.id.undo).performClick();
728 waitForStopButton();
729 mNotificationInfo.handleCloseControls(true, false);
730
Rohan Shahca0447e2018-03-30 15:18:27 -0700731 mTestableLooper.processAllMessages();
Julia Reynolds437cdb12018-01-03 12:27:24 -0500732 ArgumentCaptor<NotificationChannel> updated =
733 ArgumentCaptor.forClass(NotificationChannel.class);
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500734 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Julia Reynolds437cdb12018-01-03 12:27:24 -0500735 anyString(), eq(TEST_UID), updated.capture());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500736 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
Julia Reynolds437cdb12018-01-03 12:27:24 -0500737 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
738 }
739
740 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500741 public void testMinUndoDoesNotMinNotificationChannel() throws Exception {
742 mNotificationChannel.setImportance(IMPORTANCE_LOW);
743 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700744 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500745
746 mNotificationInfo.findViewById(R.id.minimize).performClick();
747 waitForUndoButton();
748 mNotificationInfo.findViewById(R.id.undo).performClick();
749 waitForStopButton();
750 mNotificationInfo.handleCloseControls(true, false);
751
Rohan Shahca0447e2018-03-30 15:18:27 -0700752 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500753 ArgumentCaptor<NotificationChannel> updated =
754 ArgumentCaptor.forClass(NotificationChannel.class);
755 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
756 anyString(), eq(TEST_UID), updated.capture());
757 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
758 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
759 }
760
761 @Test
762 public void testCloseControlsDoesNotUpdateiMinIfSaveIsFalse() throws Exception {
763 mNotificationChannel.setImportance(IMPORTANCE_LOW);
764 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700765 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500766
767 mNotificationInfo.findViewById(R.id.minimize).performClick();
768 waitForUndoButton();
769 mNotificationInfo.handleCloseControls(false, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700770
771 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500772 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
773 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
774 }
775
776 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500777 public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception {
778 mNotificationChannel.setImportance(IMPORTANCE_LOW);
779 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700780 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500781
782 mNotificationInfo.findViewById(R.id.block).performClick();
783 waitForUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700784 mNotificationInfo.handleCloseControls(false, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700785
786 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500787 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400788 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500789 }
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400790
791 @Test
Gus Prevasf4f0b062018-09-24 17:15:32 -0400792 public void testBlockDoesNothingIfCheckSaveListenerIsNoOp() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500793 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400794 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500795 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn,
Eliot Courtney47098cb2017-10-18 17:30:30 +0900796 (Runnable saveImportance, StatusBarNotification sbn) -> {
Rohan Shah63411fc2018-03-28 19:05:52 -0700797 }, null, null, true);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400798
Julia Reynolds437cdb12018-01-03 12:27:24 -0500799 mNotificationInfo.findViewById(R.id.block).performClick();
Gus Prevasf4f0b062018-09-24 17:15:32 -0400800 mTestableLooper.processAllMessages();
801 ensureNoUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700802 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700803
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400804 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400805 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400806 }
807
808 @Test
809 public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500810 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400811 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500812 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn,
Eliot Courtney47098cb2017-10-18 17:30:30 +0900813 (Runnable saveImportance, StatusBarNotification sbn) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400814 saveImportance.run();
Rohan Shah63411fc2018-03-28 19:05:52 -0700815 }, null, null, false);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400816
Julia Reynolds437cdb12018-01-03 12:27:24 -0500817 mNotificationInfo.findViewById(R.id.block).performClick();
Gus Prevasf4f0b062018-09-24 17:15:32 -0400818 mTestableLooper.processAllMessages();
819 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
820 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
821
Julia Reynolds437cdb12018-01-03 12:27:24 -0500822 waitForUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700823 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700824
825 mTestableLooper.processAllMessages();
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400826 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400827 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400828 }
Julia Reynolds3aedded2017-03-31 14:42:09 -0400829
830 @Test
831 public void testDisplaySettingsLink() throws Exception {
832 final CountDownLatch latch = new CountDownLatch(1);
833 final String settingsText = "work chats";
834 final ResolveInfo ri = new ResolveInfo();
835 ri.activityInfo = new ActivityInfo();
836 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
837 ri.activityInfo.name = "something";
838 List<ResolveInfo> ris = new ArrayList<>();
839 ris.add(ri);
840 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500841 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400842 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
843 .setSettingsText(settingsText).build();
844 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
845 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
846
847 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500848 TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400849 (View v, Intent intent) -> {
850 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700851 }, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400852 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
853 assertEquals(View.VISIBLE, settingsLink.getVisibility());
Julia Reynolds3aedded2017-03-31 14:42:09 -0400854 settingsLink.performClick();
855 assertEquals(0, latch.getCount());
856 }
857
858 @Test
859 public void testDisplaySettingsLink_multipleChannels() throws Exception {
860 final CountDownLatch latch = new CountDownLatch(1);
861 final String settingsText = "work chats";
862 final ResolveInfo ri = new ResolveInfo();
863 ri.activityInfo = new ActivityInfo();
864 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
865 ri.activityInfo.name = "something";
866 List<ResolveInfo> ris = new ArrayList<>();
867 ris.add(ri);
868 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500869 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400870 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
871 .setSettingsText(settingsText).build();
872 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
873 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
874
875 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700876 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500877 (View v, Intent intent) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400878 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700879 }, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400880 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
881 assertEquals(View.VISIBLE, settingsLink.getVisibility());
882 settingsLink.performClick();
883 assertEquals(0, latch.getCount());
884 }
885
886 @Test
887 public void testNoSettingsLink_noHandlingActivity() throws Exception {
888 final String settingsText = "work chats";
889 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(null);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500890 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400891 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
892 .setSettingsText(settingsText).build();
893 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
894 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
895
896 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700897 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null,
898 null, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400899 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500900 assertEquals(GONE, settingsLink.getVisibility());
Julia Reynolds3aedded2017-03-31 14:42:09 -0400901 }
902
903 @Test
904 public void testNoSettingsLink_noLinkText() throws Exception {
905 final ResolveInfo ri = new ResolveInfo();
906 ri.activityInfo = new ActivityInfo();
907 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
908 ri.activityInfo.name = "something";
909 List<ResolveInfo> ris = new ArrayList<>();
910 ris.add(ri);
911 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500912 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400913 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()).build();
914 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
915 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
916
917 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700918 TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400919 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500920 assertEquals(GONE, settingsLink.getVisibility());
Julia Reynolds3aedded2017-03-31 14:42:09 -0400921 }
922
Rohan Shah7c6b37a2018-03-30 21:07:45 +0000923 @Test
924 public void testBindHeader_noSettingsLinkWhenIsForBlockingHelper() throws Exception {
925 final String settingsText = "work chats";
926 final ResolveInfo ri = new ResolveInfo();
927 ri.activityInfo = new ActivityInfo();
928 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
929 ri.activityInfo.name = "something";
930 List<ResolveInfo> ris = new ArrayList<>();
931 ris.add(ri);
932 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
933 mNotificationChannel.setImportance(IMPORTANCE_LOW);
934 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
935 .setSettingsText(settingsText).build();
936 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
937 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
938
939 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
940 TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false, true,
941 true);
942 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
943 assertEquals(GONE, settingsLink.getVisibility());
944 }
945
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -0400946
947 @Test
948 public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception {
949 assertFalse(mNotificationInfo.willBeRemoved());
950 }
Julia Reynoldse0341482018-03-08 14:42:50 -0500951
952 @Test
953 public void testUndoText_min() throws Exception {
954 mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
955 mNotificationChannel.setImportance(IMPORTANCE_LOW);
956 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700957 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500958
959 mNotificationInfo.findViewById(R.id.minimize).performClick();
960 waitForUndoButton();
961 TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text);
962 assertTrue(confirmationText.getText().toString().contains("minimized"));
963 }
964
965 @Test
966 public void testUndoText_block() throws Exception {
967 mNotificationChannel.setImportance(IMPORTANCE_LOW);
968 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700969 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500970
971 mNotificationInfo.findViewById(R.id.block).performClick();
972 waitForUndoButton();
973 TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text);
974 assertTrue(confirmationText.getText().toString().contains("won't see"));
975 }
976
977 @Test
978 public void testNoHeaderOnConfirmation() throws Exception {
979 mNotificationChannel.setImportance(IMPORTANCE_LOW);
980 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700981 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500982
983 mNotificationInfo.findViewById(R.id.block).performClick();
984 waitForUndoButton();
985 assertEquals(GONE, mNotificationInfo.findViewById(R.id.header).getVisibility());
986 }
987
988 @Test
989 public void testHeaderOnUndo() throws Exception {
990 mNotificationChannel.setImportance(IMPORTANCE_LOW);
991 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700992 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500993
994 mNotificationInfo.findViewById(R.id.block).performClick();
995 waitForUndoButton();
996 mNotificationInfo.findViewById(R.id.undo).performClick();
997 waitForStopButton();
998 assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility());
999 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001000}