blob: a72fed4a2b41d0348a999217a8eceab2a916cae1 [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 }
Julia Reynolds437cdb12018-01-03 12:27:24 -0500161 private void waitForStopButton() {
162 PollingCheck.waitFor(1000,
163 () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500164 }
165
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500166 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500167 public void testBindNotification_SetsTextApplicationName() throws Exception {
168 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
169 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700170 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500171 final TextView textView = mNotificationInfo.findViewById(R.id.pkgname);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500172 assertTrue(textView.getText().toString().contains("App Name"));
Julia Reynoldse0341482018-03-08 14:42:50 -0500173 assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500174 }
175
176 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500177 public void testBindNotification_SetsPackageIcon() throws Exception {
178 final Drawable iconDrawable = mock(Drawable.class);
179 when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
180 .thenReturn(iconDrawable);
181 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700182 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500183 final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500184 assertEquals(iconDrawable, iconView.getDrawable());
185 }
186
187 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500188 public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
189 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700190 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500191 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
192 assertEquals(GONE, groupNameView.getVisibility());
193 final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider);
194 assertEquals(GONE, groupDividerView.getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500195 }
196
197 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500198 public void testBindNotification_SetsGroupNameIfNonNull() throws Exception {
199 mNotificationChannel.setGroup("test_group_id");
200 final NotificationChannelGroup notificationChannelGroup =
201 new NotificationChannelGroup("test_group_id", "Test Group Name");
202 when(mMockINotificationManager.getNotificationChannelGroupForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400203 eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID)))
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500204 .thenReturn(notificationChannelGroup);
205 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700206 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500207 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500208 assertEquals(View.VISIBLE, groupNameView.getVisibility());
209 assertEquals("Test Group Name", groupNameView.getText());
Julia Reynolds437cdb12018-01-03 12:27:24 -0500210 final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500211 assertEquals(View.VISIBLE, groupDividerView.getVisibility());
212 }
213
214 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500215 public void testBindNotification_SetsTextChannelName() throws Exception {
216 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700217 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500218 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500219 assertEquals(TEST_CHANNEL_NAME, textView.getText());
220 }
221
222 @Test
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400223 public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception {
224 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700225 TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500226 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
227 assertEquals(GONE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400228 }
229
230 @Test
Rohan Shahdbd64e72018-03-28 14:46:50 -0700231 public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist()
232 throws Exception {
233 // Package has one channel by default.
234 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
235 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10);
236 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700237 TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false);
Rohan Shahdbd64e72018-03-28 14:46:50 -0700238 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
239 assertEquals(VISIBLE, textView.getVisibility());
240 }
241
242 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500243 public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception {
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400244 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700245 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500246 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
247 assertEquals(VISIBLE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400248 }
249
250 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500251 public void testBindNotification_BlockButton() throws Exception {
252 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700253 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500254 final View block = mNotificationInfo.findViewById(R.id.block);
255 final View minimize = mNotificationInfo.findViewById(R.id.minimize);
256 assertEquals(VISIBLE, block.getVisibility());
257 assertEquals(GONE, minimize.getVisibility());
258 }
259
260 @Test
261 public void testBindNotification_MinButton() throws Exception {
262 mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
263 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700264 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500265 final View block = mNotificationInfo.findViewById(R.id.block);
266 final View minimize = mNotificationInfo.findViewById(R.id.minimize);
267 assertEquals(GONE, block.getVisibility());
268 assertEquals(VISIBLE, minimize.getVisibility());
269 }
270
271 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500272 public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
273 final CountDownLatch latch = new CountDownLatch(1);
274 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500275 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500276 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400277 assertEquals(mNotificationChannel, c);
278 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700279 }, null, false);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500280
Julia Reynolds437cdb12018-01-03 12:27:24 -0500281 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500282 settingsButton.performClick();
283 // Verify that listener was triggered.
284 assertEquals(0, latch.getCount());
285 }
286
287 @Test
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400288 public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception {
289 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700290 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500291 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400292 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
293 }
294
295 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500296 public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception {
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400297 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700298 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400299 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500300 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null,
301 (View v, NotificationChannel c, int appUid) -> {
Rohan Shah63411fc2018-03-28 19:05:52 -0700302 }, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500303 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400304 assertEquals(View.VISIBLE, settingsButton.getVisibility());
305 }
306
307 @Test
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700308 public void testLogBlockingHelperCounter_doesntLogForNormalGutsView() throws Exception {
309 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
310 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
311 mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent");
312 verify(mMetricsLogger, times(0)).count(anyString(), anyInt());
313 }
314
315 @Test
316 public void testLogBlockingHelperCounter_logsForBlockingHelper() throws Exception {
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700317 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
318 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, true,
319 true);
320 mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent");
Rohan Shahc6b0d542018-05-10 13:00:54 -0700321 verify(mMetricsLogger, times(1)).count(anyString(), anyInt());
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700322 }
323
324 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500325 public void testOnClickListenerPassesNullChannelForBundle() throws Exception {
326 final CountDownLatch latch = new CountDownLatch(1);
327 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700328 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500329 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400330 assertEquals(null, c);
331 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700332 }, null, true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500333
Julia Reynolds437cdb12018-01-03 12:27:24 -0500334 mNotificationInfo.findViewById(R.id.info).performClick();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500335 // Verify that listener was triggered.
336 assertEquals(0, latch.getCount());
337 }
338
339 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500340 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500341 public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels()
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500342 throws Exception {
343 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700344 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null,
345 null, true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500346 final TextView channelNameView =
Julia Reynolds437cdb12018-01-03 12:27:24 -0500347 mNotificationInfo.findViewById(R.id.channel_name);
348 assertEquals(GONE, channelNameView.getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500349 }
350
351 @Test
352 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500353 public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception {
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500354 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700355 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null,
356 null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500357 final TextView blockView = mNotificationInfo.findViewById(R.id.block);
358 assertEquals(GONE, blockView.getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500359 }
360
361 @Test
Julia Reynolds0ef7d842018-01-24 17:50:31 -0500362 public void testbindNotification_BlockingHelper() throws Exception {
363 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700364 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, false,
365 true);
Julia Reynolds0ef7d842018-01-24 17:50:31 -0500366 final TextView view = mNotificationInfo.findViewById(R.id.block_prompt);
367 assertEquals(View.VISIBLE, view.getVisibility());
368 assertEquals(mContext.getString(R.string.inline_blocking_helper), view.getText());
369 }
370
371 @Test
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400372 public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception {
373 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700374 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500375 final TextView view = mNotificationInfo.findViewById(R.id.block_prompt);
376 assertEquals(View.VISIBLE, view.getVisibility());
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400377 assertEquals(mContext.getString(R.string.notification_unblockable_desc),
Julia Reynolds437cdb12018-01-03 12:27:24 -0500378 view.getText());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500379 }
380
381 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500382 public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception {
383 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700384 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700385 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500386 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400387 anyString(), eq(TEST_UID), any());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500388 }
389
390 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500391 public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500392 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500393 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700394 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500395
Julia Reynolds437cdb12018-01-03 12:27:24 -0500396 mNotificationInfo.findViewById(R.id.block).performClick();
Rohan Shahca0447e2018-03-30 15:18:27 -0700397 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500398 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400399 anyString(), eq(TEST_UID), any());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500400 }
401
402 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500403 public void testDoesNotUpdateNotificationChannelAfterImportanceChangedMin()
404 throws Exception {
405 mNotificationChannel.setImportance(IMPORTANCE_LOW);
406 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700407 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500408
409 mNotificationInfo.findViewById(R.id.minimize).performClick();
Rohan Shahca0447e2018-03-30 15:18:27 -0700410 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500411 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
412 anyString(), eq(TEST_UID), any());
413 }
414
415 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500416 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
417 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500418 int originalImportance = mNotificationChannel.getImportance();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500419 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700420 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500421
Mady Mellorc2dbe492017-03-30 13:22:03 -0700422 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700423 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500424 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400425 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500426 assertEquals(originalImportance, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500427 }
428
429 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500430 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified()
431 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500432 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500433 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700434 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500435
Mady Mellorc2dbe492017-03-30 13:22:03 -0700436 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700437
438 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500439 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400440 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500441 assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500442 }
443
444 @Test
Rohan Shah590e1b22018-04-10 23:48:47 -0400445 public void testHandleCloseControls_setsNotificationsDisabledForMultipleChannelNotifications()
446 throws Exception {
447 mNotificationChannel.setImportance(IMPORTANCE_LOW);
448 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
449 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
450 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */,
451 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
452 false /* isNonblockable */);
453
454 mNotificationInfo.findViewById(R.id.block).performClick();
455 waitForUndoButton();
456 mNotificationInfo.handleCloseControls(true, false);
457
458 mTestableLooper.processAllMessages();
459 verify(mMockINotificationManager, times(1))
460 .setNotificationsEnabledWithImportanceLockForPackage(
461 anyString(), eq(TEST_UID), eq(false));
462 }
463
464
465 @Test
466 public void testHandleCloseControls_keepsNotificationsEnabledForMultipleChannelNotifications()
467 throws Exception {
468 mNotificationChannel.setImportance(IMPORTANCE_LOW);
469 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
470 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
471 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */,
472 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
473 false /* isNonblockable */);
474
475 mNotificationInfo.findViewById(R.id.block).performClick();
476 waitForUndoButton();
477 mNotificationInfo.handleCloseControls(true, false);
478
479 mTestableLooper.processAllMessages();
480 verify(mMockINotificationManager, times(1))
481 .setNotificationsEnabledWithImportanceLockForPackage(
482 anyString(), eq(TEST_UID), eq(false));
483 }
484
485 @Test
486 public void testCloseControls_blockingHelperSavesImportanceForMultipleChannelNotifications()
487 throws Exception {
488 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
489 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
490 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */,
491 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
492 false /* isNonblockable */, true /* isForBlockingHelper */,
493 true /* isUserSentimentNegative */);
494
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700495 NotificationGuts guts = spy(new NotificationGuts(mContext, null));
496 when(guts.getWindowToken()).thenReturn(mock(IBinder.class));
497 doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean());
498 doNothing().when(guts).setExposed(anyBoolean(), anyBoolean());
499 guts.setGutsContent(mNotificationInfo);
500 mNotificationInfo.setGutsParent(guts);
501
Rohan Shah590e1b22018-04-10 23:48:47 -0400502 mNotificationInfo.findViewById(R.id.keep).performClick();
503
504 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
505 mTestableLooper.processAllMessages();
506 verify(mMockINotificationManager, times(1))
507 .setNotificationsEnabledWithImportanceLockForPackage(
508 anyString(), eq(TEST_UID), eq(true));
509 }
510
Rohan Shahdd588c72018-05-09 20:32:15 -0700511 @Test
512 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayKeepShowing()
513 throws Exception {
514 NotificationInfo.CheckSaveListener listener =
515 mock(NotificationInfo.CheckSaveListener.class);
516 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
517 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
518 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */,
519 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
520 false /* isNonblockable */, true /* isForBlockingHelper */,
521 true /* isUserSentimentNegative */);
522
523 NotificationGuts guts = spy(new NotificationGuts(mContext, null));
524 when(guts.getWindowToken()).thenReturn(mock(IBinder.class));
525 doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean());
526 doNothing().when(guts).setExposed(anyBoolean(), anyBoolean());
527 guts.setGutsContent(mNotificationInfo);
528 mNotificationInfo.setGutsParent(guts);
529
530 mNotificationInfo.findViewById(R.id.keep).performClick();
531
532 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
533 mTestableLooper.processAllMessages();
534 verify(mMockINotificationManager, times(1))
535 .setNotificationsEnabledWithImportanceLockForPackage(
536 anyString(), eq(TEST_UID), eq(true));
537 }
538
Rohan Shah593e8f12018-05-22 10:06:23 -0700539 @Test
540 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayDismiss()
541 throws Exception {
542 NotificationInfo.CheckSaveListener listener =
543 mock(NotificationInfo.CheckSaveListener.class);
544 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
545 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
546 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */,
547 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
548 false /* isNonblockable */, true /* isForBlockingHelper */,
549 true /* isUserSentimentNegative */);
550
551 mNotificationInfo.handleCloseControls(true /* save */, false /* force */);
552
553 mTestableLooper.processAllMessages();
554 verify(listener, times(0)).checkSave(any(Runnable.class), eq(mSbn));
555 }
556
557 @Test
558 public void testCloseControls_checkSaveListenerDelaysStopNotifications()
559 throws Exception {
560 NotificationInfo.CheckSaveListener listener =
561 mock(NotificationInfo.CheckSaveListener.class);
562 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
563 TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */,
564 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */,
565 null /* onSettingsClick */, null /* onAppSettingsClick */ ,
566 false /* isNonblockable */, true /* isForBlockingHelper */,
567 true /* isUserSentimentNegative */);
568
569 mNotificationInfo.findViewById(R.id.block).performClick();
570 waitForUndoButton();
571 mNotificationInfo.handleCloseControls(true /* save */, false /* force */);
572
573 mTestableLooper.processAllMessages();
574 verify(listener).checkSave(any(Runnable.class), eq(mSbn));
575 }
Rohan Shahdd588c72018-05-09 20:32:15 -0700576
Rohan Shah590e1b22018-04-10 23:48:47 -0400577 @Test
Rohan Shah524cf7b2018-03-15 14:40:02 -0700578 public void testCloseControls_blockingHelperDismissedIfShown() throws Exception {
579 mNotificationInfo.bindNotification(
580 mMockPackageManager,
581 mMockINotificationManager,
582 TEST_PACKAGE_NAME,
583 mNotificationChannel,
584 1 /* numChannels */,
585 mSbn,
586 null /* checkSaveListener */,
587 null /* onSettingsClick */,
588 null /* onAppSettingsClick */,
Rohan Shah63411fc2018-03-28 19:05:52 -0700589 false /* isNonblockable */,
Rohan Shah524cf7b2018-03-15 14:40:02 -0700590 true /* isForBlockingHelper */,
591 false /* isUserSentimentNegative */);
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700592 NotificationGuts guts = mock(NotificationGuts.class);
593 doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean());
594 mNotificationInfo.setGutsParent(guts);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700595
596 mNotificationInfo.closeControls(mNotificationInfo);
597
598 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
599 }
600
601 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500602 public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500603 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500604 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700605 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500606 mNotificationInfo.findViewById(R.id.block).performClick();
607 waitForUndoButton();
Rohan Shahca0447e2018-03-30 15:18:27 -0700608
609 mTestableLooper.processAllMessages();
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500610 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400611 anyString(), eq(TEST_UID), any());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500612 }
613
614 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500615 public void testBlockChangedCallsUpdateNotificationChannel() throws Exception {
616 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500617 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700618 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500619
Julia Reynolds437cdb12018-01-03 12:27:24 -0500620 mNotificationInfo.findViewById(R.id.block).performClick();
621 waitForUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700622 mNotificationInfo.handleCloseControls(true, false);
Julia Reynolds8ceb5792017-04-11 11:32:44 -0400623
Rohan Shahca0447e2018-03-30 15:18:27 -0700624 mTestableLooper.processAllMessages();
Julia Reynolds8ceb5792017-04-11 11:32:44 -0400625 ArgumentCaptor<NotificationChannel> updated =
626 ArgumentCaptor.forClass(NotificationChannel.class);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500627 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400628 anyString(), eq(TEST_UID), updated.capture());
Julia Reynolds8ceb5792017-04-11 11:32:44 -0400629 assertTrue((updated.getValue().getUserLockedFields()
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500630 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynoldse0341482018-03-08 14:42:50 -0500631 assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance());
632 }
633
634 @Test
Rohan Shahca0447e2018-03-30 15:18:27 -0700635 public void testBlockChangedCallsUpdateNotificationChannel_blockingHelper() throws Exception {
636 mNotificationChannel.setImportance(IMPORTANCE_LOW);
637 mNotificationInfo.bindNotification(
638 mMockPackageManager,
639 mMockINotificationManager,
640 TEST_PACKAGE_NAME,
641 mNotificationChannel,
642 1 /* numChannels */,
643 mSbn,
644 null /* checkSaveListener */,
645 null /* onSettingsClick */,
646 null /* onAppSettingsClick */,
647 false /* isNonblockable */,
648 true /* isForBlockingHelper */,
649 true /* isUserSentimentNegative */);
650
651 mNotificationInfo.findViewById(R.id.block).performClick();
652 waitForUndoButton();
653 mNotificationInfo.handleCloseControls(true, false);
654
655 mTestableLooper.processAllMessages();
656 ArgumentCaptor<NotificationChannel> updated =
657 ArgumentCaptor.forClass(NotificationChannel.class);
658 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
659 anyString(), eq(TEST_UID), updated.capture());
660 assertTrue((updated.getValue().getUserLockedFields()
661 & USER_LOCKED_IMPORTANCE) != 0);
662 assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance());
663 }
664
665
666 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500667 public void testNonBlockableAppDoesNotBecomeMin() throws Exception {
668 mNotificationChannel.setImportance(IMPORTANCE_LOW);
669 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700670 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500671 mNotificationInfo.findViewById(R.id.minimize).performClick();
672 waitForUndoButton();
Rohan Shahca0447e2018-03-30 15:18:27 -0700673
674 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500675 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
676 anyString(), eq(TEST_UID), any());
677 }
678
679 @Test
680 public void testMinChangedCallsUpdateNotificationChannel() throws Exception {
681 mNotificationChannel.setImportance(IMPORTANCE_LOW);
682 mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
683 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700684 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500685
686 mNotificationInfo.findViewById(R.id.minimize).performClick();
687 waitForUndoButton();
688 mNotificationInfo.handleCloseControls(true, false);
689
Rohan Shahca0447e2018-03-30 15:18:27 -0700690 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500691 ArgumentCaptor<NotificationChannel> updated =
692 ArgumentCaptor.forClass(NotificationChannel.class);
693 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
694 anyString(), eq(TEST_UID), updated.capture());
695 assertTrue((updated.getValue().getUserLockedFields()
696 & USER_LOCKED_IMPORTANCE) != 0);
697 assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500698 }
699
700 @Test
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500701 public void testKeepUpdatesNotificationChannel() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500702 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500703 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700704 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500705
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500706 mNotificationInfo.handleCloseControls(true, false);
707
Rohan Shahca0447e2018-03-30 15:18:27 -0700708 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500709 ArgumentCaptor<NotificationChannel> updated =
710 ArgumentCaptor.forClass(NotificationChannel.class);
711 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
712 anyString(), eq(TEST_UID), updated.capture());
713 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
714 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
715 }
716
717 @Test
718 public void testBlockUndoDoesNotBlockNotificationChannel() throws Exception {
719 mNotificationChannel.setImportance(IMPORTANCE_LOW);
720 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700721 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500722
723 mNotificationInfo.findViewById(R.id.block).performClick();
724 waitForUndoButton();
725 mNotificationInfo.findViewById(R.id.undo).performClick();
726 waitForStopButton();
727 mNotificationInfo.handleCloseControls(true, false);
728
Rohan Shahca0447e2018-03-30 15:18:27 -0700729 mTestableLooper.processAllMessages();
Julia Reynolds437cdb12018-01-03 12:27:24 -0500730 ArgumentCaptor<NotificationChannel> updated =
731 ArgumentCaptor.forClass(NotificationChannel.class);
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500732 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Julia Reynolds437cdb12018-01-03 12:27:24 -0500733 anyString(), eq(TEST_UID), updated.capture());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500734 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
Julia Reynolds437cdb12018-01-03 12:27:24 -0500735 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
736 }
737
738 @Test
Julia Reynoldse0341482018-03-08 14:42:50 -0500739 public void testMinUndoDoesNotMinNotificationChannel() throws Exception {
740 mNotificationChannel.setImportance(IMPORTANCE_LOW);
741 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700742 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false);
Julia Reynoldse0341482018-03-08 14:42:50 -0500743
744 mNotificationInfo.findViewById(R.id.minimize).performClick();
745 waitForUndoButton();
746 mNotificationInfo.findViewById(R.id.undo).performClick();
747 waitForStopButton();
748 mNotificationInfo.handleCloseControls(true, false);
749
Rohan Shahca0447e2018-03-30 15:18:27 -0700750 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500751 ArgumentCaptor<NotificationChannel> updated =
752 ArgumentCaptor.forClass(NotificationChannel.class);
753 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
754 anyString(), eq(TEST_UID), updated.capture());
755 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
756 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
757 }
758
759 @Test
760 public void testCloseControlsDoesNotUpdateiMinIfSaveIsFalse() throws Exception {
761 mNotificationChannel.setImportance(IMPORTANCE_LOW);
762 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700763 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500764
765 mNotificationInfo.findViewById(R.id.minimize).performClick();
766 waitForUndoButton();
767 mNotificationInfo.handleCloseControls(false, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700768
769 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500770 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
771 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
772 }
773
774 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500775 public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception {
776 mNotificationChannel.setImportance(IMPORTANCE_LOW);
777 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700778 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500779
780 mNotificationInfo.findViewById(R.id.block).performClick();
781 waitForUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700782 mNotificationInfo.handleCloseControls(false, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700783
784 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500785 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400786 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500787 }
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400788
789 @Test
790 public void testCloseControlsDoesNotUpdateIfCheckSaveListenerIsNoOp() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500791 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400792 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500793 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn,
Eliot Courtney47098cb2017-10-18 17:30:30 +0900794 (Runnable saveImportance, StatusBarNotification sbn) -> {
Rohan Shah63411fc2018-03-28 19:05:52 -0700795 }, null, null, true);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400796
Julia Reynolds437cdb12018-01-03 12:27:24 -0500797 mNotificationInfo.findViewById(R.id.block).performClick();
798 waitForUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700799 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700800
801 mTestableLooper.processAllMessages();
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400802 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400803 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400804 }
805
806 @Test
807 public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500808 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400809 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500810 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn,
Eliot Courtney47098cb2017-10-18 17:30:30 +0900811 (Runnable saveImportance, StatusBarNotification sbn) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400812 saveImportance.run();
Rohan Shah63411fc2018-03-28 19:05:52 -0700813 }, null, null, false);
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400814
Julia Reynolds437cdb12018-01-03 12:27:24 -0500815 mNotificationInfo.findViewById(R.id.block).performClick();
816 waitForUndoButton();
Mady Mellorc2dbe492017-03-30 13:22:03 -0700817 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700818
819 mTestableLooper.processAllMessages();
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400820 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400821 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -0400822 }
Julia Reynolds3aedded2017-03-31 14:42:09 -0400823
824 @Test
825 public void testDisplaySettingsLink() throws Exception {
826 final CountDownLatch latch = new CountDownLatch(1);
827 final String settingsText = "work chats";
828 final ResolveInfo ri = new ResolveInfo();
829 ri.activityInfo = new ActivityInfo();
830 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
831 ri.activityInfo.name = "something";
832 List<ResolveInfo> ris = new ArrayList<>();
833 ris.add(ri);
834 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500835 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400836 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
837 .setSettingsText(settingsText).build();
838 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
839 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
840
841 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500842 TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400843 (View v, Intent intent) -> {
844 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700845 }, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400846 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
847 assertEquals(View.VISIBLE, settingsLink.getVisibility());
Julia Reynolds3aedded2017-03-31 14:42:09 -0400848 settingsLink.performClick();
849 assertEquals(0, latch.getCount());
850 }
851
852 @Test
853 public void testDisplaySettingsLink_multipleChannels() throws Exception {
854 final CountDownLatch latch = new CountDownLatch(1);
855 final String settingsText = "work chats";
856 final ResolveInfo ri = new ResolveInfo();
857 ri.activityInfo = new ActivityInfo();
858 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
859 ri.activityInfo.name = "something";
860 List<ResolveInfo> ris = new ArrayList<>();
861 ris.add(ri);
862 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500863 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400864 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
865 .setSettingsText(settingsText).build();
866 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
867 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
868
869 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700870 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500871 (View v, Intent intent) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400872 latch.countDown();
Rohan Shah63411fc2018-03-28 19:05:52 -0700873 }, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400874 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
875 assertEquals(View.VISIBLE, settingsLink.getVisibility());
876 settingsLink.performClick();
877 assertEquals(0, latch.getCount());
878 }
879
880 @Test
881 public void testNoSettingsLink_noHandlingActivity() throws Exception {
882 final String settingsText = "work chats";
883 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(null);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500884 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400885 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
886 .setSettingsText(settingsText).build();
887 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
888 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
889
890 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700891 TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null,
892 null, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400893 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500894 assertEquals(GONE, settingsLink.getVisibility());
Julia Reynolds3aedded2017-03-31 14:42:09 -0400895 }
896
897 @Test
898 public void testNoSettingsLink_noLinkText() throws Exception {
899 final ResolveInfo ri = new ResolveInfo();
900 ri.activityInfo = new ActivityInfo();
901 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
902 ri.activityInfo.name = "something";
903 List<ResolveInfo> ris = new ArrayList<>();
904 ris.add(ri);
905 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500906 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400907 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()).build();
908 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
909 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
910
911 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700912 TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false);
Julia Reynolds3aedded2017-03-31 14:42:09 -0400913 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500914 assertEquals(GONE, settingsLink.getVisibility());
Julia Reynolds3aedded2017-03-31 14:42:09 -0400915 }
916
Rohan Shah7c6b37a2018-03-30 21:07:45 +0000917 @Test
918 public void testBindHeader_noSettingsLinkWhenIsForBlockingHelper() throws Exception {
919 final String settingsText = "work chats";
920 final ResolveInfo ri = new ResolveInfo();
921 ri.activityInfo = new ActivityInfo();
922 ri.activityInfo.packageName = TEST_PACKAGE_NAME;
923 ri.activityInfo.name = "something";
924 List<ResolveInfo> ris = new ArrayList<>();
925 ris.add(ri);
926 when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris);
927 mNotificationChannel.setImportance(IMPORTANCE_LOW);
928 Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
929 .setSettingsText(settingsText).build();
930 StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME,
931 0, null, 0, 0, n, UserHandle.CURRENT, null, 0);
932
933 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
934 TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false, true,
935 true);
936 final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings);
937 assertEquals(GONE, settingsLink.getVisibility());
938 }
939
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -0400940
941 @Test
942 public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception {
943 assertFalse(mNotificationInfo.willBeRemoved());
944 }
Julia Reynoldse0341482018-03-08 14:42:50 -0500945
946 @Test
947 public void testUndoText_min() throws Exception {
948 mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE;
949 mNotificationChannel.setImportance(IMPORTANCE_LOW);
950 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700951 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500952
953 mNotificationInfo.findViewById(R.id.minimize).performClick();
954 waitForUndoButton();
955 TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text);
956 assertTrue(confirmationText.getText().toString().contains("minimized"));
957 }
958
959 @Test
960 public void testUndoText_block() throws Exception {
961 mNotificationChannel.setImportance(IMPORTANCE_LOW);
962 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700963 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500964
965 mNotificationInfo.findViewById(R.id.block).performClick();
966 waitForUndoButton();
967 TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text);
968 assertTrue(confirmationText.getText().toString().contains("won't see"));
969 }
970
971 @Test
972 public void testNoHeaderOnConfirmation() throws Exception {
973 mNotificationChannel.setImportance(IMPORTANCE_LOW);
974 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700975 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500976
977 mNotificationInfo.findViewById(R.id.block).performClick();
978 waitForUndoButton();
979 assertEquals(GONE, mNotificationInfo.findViewById(R.id.header).getVisibility());
980 }
981
982 @Test
983 public void testHeaderOnUndo() throws Exception {
984 mNotificationChannel.setImportance(IMPORTANCE_LOW);
985 mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
Rohan Shah63411fc2018-03-28 19:05:52 -0700986 TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true);
Julia Reynoldse0341482018-03-08 14:42:50 -0500987
988 mNotificationInfo.findViewById(R.id.block).performClick();
989 waitForUndoButton();
990 mNotificationInfo.findViewById(R.id.undo).performClick();
991 waitForStopButton();
992 assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility());
993 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500994}