Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 19 | import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 20 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
| 22 | import static android.app.NotificationManager.IMPORTANCE_NONE; |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 23 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 24 | import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 25 | import static android.view.View.GONE; |
| 26 | import static android.view.View.VISIBLE; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 27 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 28 | import static junit.framework.Assert.assertEquals; |
| 29 | import static junit.framework.Assert.assertFalse; |
| 30 | import static junit.framework.Assert.assertTrue; |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 31 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 32 | import static org.mockito.Mockito.any; |
| 33 | import static org.mockito.Mockito.anyBoolean; |
| 34 | import static org.mockito.Mockito.anyInt; |
| 35 | import static org.mockito.Mockito.anyString; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 36 | import static org.mockito.Mockito.doCallRealMethod; |
| 37 | import static org.mockito.Mockito.doNothing; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 38 | import static org.mockito.Mockito.eq; |
| 39 | import static org.mockito.Mockito.mock; |
| 40 | import static org.mockito.Mockito.never; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 41 | import static org.mockito.Mockito.spy; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 42 | import static org.mockito.Mockito.times; |
| 43 | import static org.mockito.Mockito.verify; |
| 44 | import static org.mockito.Mockito.when; |
| 45 | |
| 46 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 47 | import android.app.Notification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 48 | import android.app.NotificationChannel; |
| 49 | import android.app.NotificationChannelGroup; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 50 | import android.content.Intent; |
| 51 | import android.content.pm.ActivityInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 52 | import android.content.pm.ApplicationInfo; |
| 53 | import android.content.pm.PackageInfo; |
| 54 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 55 | import android.content.pm.ResolveInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 56 | import android.graphics.drawable.Drawable; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 57 | import android.os.IBinder; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 58 | import android.os.UserHandle; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 59 | import android.service.notification.StatusBarNotification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 60 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 61 | import android.testing.AndroidTestingRunner; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 62 | import android.testing.PollingCheck; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 63 | import android.testing.TestableLooper; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 64 | import android.testing.UiThreadTest; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 65 | import android.view.LayoutInflater; |
| 66 | import android.view.View; |
| 67 | import android.widget.ImageView; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 68 | import android.widget.TextView; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 69 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 70 | import com.android.internal.logging.MetricsLogger; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 71 | import com.android.systemui.Dependency; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 72 | import com.android.systemui.R; |
| 73 | import com.android.systemui.SysuiTestCase; |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 74 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 75 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 76 | import org.junit.Rule; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 77 | import org.junit.Test; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 78 | import org.junit.runner.RunWith; |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 79 | import org.mockito.ArgumentCaptor; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 80 | import org.mockito.Mock; |
| 81 | import org.mockito.junit.MockitoJUnit; |
| 82 | import org.mockito.junit.MockitoRule; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 83 | |
| 84 | import java.util.ArrayList; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 85 | import java.util.List; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 86 | import java.util.concurrent.CountDownLatch; |
| 87 | |
| 88 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 89 | @RunWith(AndroidTestingRunner.class) |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 90 | @TestableLooper.RunWithLooper |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 91 | public class NotificationInfoTest extends SysuiTestCase { |
| 92 | private static final String TEST_PACKAGE_NAME = "test_package"; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 93 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 94 | private static final int TEST_UID = 1; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 95 | private static final int MULTIPLE_CHANNEL_COUNT = 2; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 96 | private static final String TEST_CHANNEL = "test_channel"; |
| 97 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 98 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 99 | private TestableLooper mTestableLooper; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 100 | private NotificationInfo mNotificationInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 101 | private NotificationChannel mNotificationChannel; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 102 | private NotificationChannel mDefaultNotificationChannel; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 103 | private StatusBarNotification mSbn; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 104 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 105 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 106 | @Mock private MetricsLogger mMetricsLogger; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 107 | @Mock private INotificationManager mMockINotificationManager; |
| 108 | @Mock private PackageManager mMockPackageManager; |
| 109 | @Mock private NotificationBlockingHelperManager mBlockingHelperManager; |
| 110 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 111 | @Before |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 112 | public void setUp() throws Exception { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 113 | mDependency.injectTestDependency( |
| 114 | NotificationBlockingHelperManager.class, |
| 115 | mBlockingHelperManager); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 116 | mTestableLooper = TestableLooper.get(this); |
| 117 | mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper()); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 118 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 119 | // Inflate the layout |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 120 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 121 | mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, |
| 122 | null); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 123 | mNotificationInfo.setGutsParent(mock(NotificationGuts.class)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 124 | |
| 125 | // PackageManager must return a packageInfo and applicationInfo. |
| 126 | final PackageInfo packageInfo = new PackageInfo(); |
| 127 | packageInfo.packageName = TEST_PACKAGE_NAME; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 128 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 129 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 130 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 131 | applicationInfo.uid = TEST_UID; // non-zero |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 132 | when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn( |
| 133 | applicationInfo); |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 134 | 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 Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 140 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 141 | // Package has one channel by default. |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 142 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 143 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 144 | |
| 145 | // Some test channels. |
| 146 | mNotificationChannel = new NotificationChannel( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 147 | TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 148 | mDefaultNotificationChannel = new NotificationChannel( |
| 149 | NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 150 | IMPORTANCE_LOW); |
Julia Reynolds | 33bef2c | 2017-09-05 11:07:18 -0400 | [diff] [blame] | 151 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 152 | new Notification(), UserHandle.CURRENT, null, 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 153 | } |
| 154 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 155 | // 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 Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 160 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 161 | private void waitForStopButton() { |
| 162 | PollingCheck.waitFor(1000, |
| 163 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 166 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 167 | public void testBindNotification_SetsTextApplicationName() throws Exception { |
| 168 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
| 169 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 170 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 171 | final TextView textView = mNotificationInfo.findViewById(R.id.pkgname); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 172 | assertTrue(textView.getText().toString().contains("App Name")); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 173 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 177 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 182 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 183 | final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 184 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 185 | } |
| 186 | |
| 187 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 188 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
| 189 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 190 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 191 | 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 Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 198 | 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 Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 203 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 204 | .thenReturn(notificationChannelGroup); |
| 205 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 206 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 207 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 208 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 209 | assertEquals("Test Group Name", groupNameView.getText()); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 210 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 211 | assertEquals(View.VISIBLE, groupDividerView.getVisibility()); |
| 212 | } |
| 213 | |
| 214 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 215 | public void testBindNotification_SetsTextChannelName() throws Exception { |
| 216 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 217 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 218 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 219 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 220 | } |
| 221 | |
| 222 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 223 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
| 224 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 225 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 226 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 227 | assertEquals(GONE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | @Test |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 231 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 237 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false); |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 238 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 239 | assertEquals(VISIBLE, textView.getVisibility()); |
| 240 | } |
| 241 | |
| 242 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 243 | public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception { |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 244 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 245 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 246 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 247 | assertEquals(VISIBLE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 251 | public void testBindNotification_BlockButton() throws Exception { |
| 252 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 253 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 254 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 264 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 265 | 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 Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 272 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 273 | final CountDownLatch latch = new CountDownLatch(1); |
| 274 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 275 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 276 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 277 | assertEquals(mNotificationChannel, c); |
| 278 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 279 | }, null, false); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 280 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 281 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 282 | settingsButton.performClick(); |
| 283 | // Verify that listener was triggered. |
| 284 | assertEquals(0, latch.getCount()); |
| 285 | } |
| 286 | |
| 287 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 288 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
| 289 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 290 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 291 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 292 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 293 | } |
| 294 | |
| 295 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 296 | public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception { |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 297 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 298 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 299 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 300 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
| 301 | (View v, NotificationChannel c, int appUid) -> { |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 302 | }, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 303 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 304 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 305 | } |
| 306 | |
| 307 | @Test |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 308 | 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 Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 317 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 318 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, true, |
| 319 | true); |
| 320 | mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent"); |
Rohan Shah | c6b0d54 | 2018-05-10 13:00:54 -0700 | [diff] [blame] | 321 | verify(mMetricsLogger, times(1)).count(anyString(), anyInt()); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 325 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 326 | final CountDownLatch latch = new CountDownLatch(1); |
| 327 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 328 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 329 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 330 | assertEquals(null, c); |
| 331 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 332 | }, null, true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 333 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 334 | mNotificationInfo.findViewById(R.id.info).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 335 | // Verify that listener was triggered. |
| 336 | assertEquals(0, latch.getCount()); |
| 337 | } |
| 338 | |
| 339 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 340 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 341 | public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 342 | throws Exception { |
| 343 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 344 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null, |
| 345 | null, true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 346 | final TextView channelNameView = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 347 | mNotificationInfo.findViewById(R.id.channel_name); |
| 348 | assertEquals(GONE, channelNameView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | @Test |
| 352 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 353 | public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 354 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 355 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null, |
| 356 | null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 357 | final TextView blockView = mNotificationInfo.findViewById(R.id.block); |
| 358 | assertEquals(GONE, blockView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | @Test |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 362 | public void testbindNotification_BlockingHelper() throws Exception { |
| 363 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 364 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, false, |
| 365 | true); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 366 | 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 Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 372 | public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception { |
| 373 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 374 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 375 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 376 | assertEquals(View.VISIBLE, view.getVisibility()); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 377 | assertEquals(mContext.getString(R.string.notification_unblockable_desc), |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 378 | view.getText()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 382 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
| 383 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 384 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 385 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 386 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 387 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 391 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 392 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 393 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 394 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 395 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 396 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 397 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 398 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 399 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 403 | public void testDoesNotUpdateNotificationChannelAfterImportanceChangedMin() |
| 404 | throws Exception { |
| 405 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 406 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 407 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 408 | |
| 409 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 410 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 411 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 412 | anyString(), eq(TEST_UID), any()); |
| 413 | } |
| 414 | |
| 415 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 416 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 417 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 418 | int originalImportance = mNotificationChannel.getImportance(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 419 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 420 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 421 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 422 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 423 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 424 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 425 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 426 | assertEquals(originalImportance, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 430 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 431 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 432 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 433 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 434 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 435 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 436 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 437 | |
| 438 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 439 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 440 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 441 | assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | @Test |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 445 | 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 Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 495 | 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 Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 502 | 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 Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 511 | @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 Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 539 | @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 Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 576 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 577 | @Test |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 578 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 589 | false /* isNonblockable */, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 590 | true /* isForBlockingHelper */, |
| 591 | false /* isUserSentimentNegative */); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 592 | NotificationGuts guts = mock(NotificationGuts.class); |
| 593 | doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean()); |
| 594 | mNotificationInfo.setGutsParent(guts); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 595 | |
| 596 | mNotificationInfo.closeControls(mNotificationInfo); |
| 597 | |
| 598 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 599 | } |
| 600 | |
| 601 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 602 | public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 603 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 604 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 605 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 606 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 607 | waitForUndoButton(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 608 | |
| 609 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 610 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 611 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 615 | public void testBlockChangedCallsUpdateNotificationChannel() throws Exception { |
| 616 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 617 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 618 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 619 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 620 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 621 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 622 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 623 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 624 | mTestableLooper.processAllMessages(); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 625 | ArgumentCaptor<NotificationChannel> updated = |
| 626 | ArgumentCaptor.forClass(NotificationChannel.class); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 627 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 628 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 629 | assertTrue((updated.getValue().getUserLockedFields() |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 630 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 631 | assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance()); |
| 632 | } |
| 633 | |
| 634 | @Test |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 635 | 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 Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 667 | public void testNonBlockableAppDoesNotBecomeMin() throws Exception { |
| 668 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 669 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 670 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 671 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 672 | waitForUndoButton(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 673 | |
| 674 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 675 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 684 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 685 | |
| 686 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 687 | waitForUndoButton(); |
| 688 | mNotificationInfo.handleCloseControls(true, false); |
| 689 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 690 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 691 | 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 Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | @Test |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 701 | public void testKeepUpdatesNotificationChannel() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 702 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 703 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 704 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 705 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 706 | mNotificationInfo.handleCloseControls(true, false); |
| 707 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 708 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 709 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 721 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 722 | |
| 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 Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 729 | mTestableLooper.processAllMessages(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 730 | ArgumentCaptor<NotificationChannel> updated = |
| 731 | ArgumentCaptor.forClass(NotificationChannel.class); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 732 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 733 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 734 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 735 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 736 | } |
| 737 | |
| 738 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 739 | public void testMinUndoDoesNotMinNotificationChannel() throws Exception { |
| 740 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 741 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 742 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 743 | |
| 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 Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 750 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 751 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 763 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 764 | |
| 765 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 766 | waitForUndoButton(); |
| 767 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 768 | |
| 769 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 770 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 771 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 772 | } |
| 773 | |
| 774 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 775 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 776 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 777 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 778 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 779 | |
| 780 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 781 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 782 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 783 | |
| 784 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 785 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 786 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 787 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 788 | |
| 789 | @Test |
| 790 | public void testCloseControlsDoesNotUpdateIfCheckSaveListenerIsNoOp() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 791 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 792 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 793 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 794 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 795 | }, null, null, true); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 796 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 797 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 798 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 799 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 800 | |
| 801 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 802 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 803 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | @Test |
| 807 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 808 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 809 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 810 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 811 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 812 | saveImportance.run(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 813 | }, null, null, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 814 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 815 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 816 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 817 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 818 | |
| 819 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 820 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 821 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 822 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 823 | |
| 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 Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 835 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 836 | 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 Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 842 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 843 | (View v, Intent intent) -> { |
| 844 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 845 | }, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 846 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 847 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 848 | 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 Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 863 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 864 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 870 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 871 | (View v, Intent intent) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 872 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 873 | }, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 874 | 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 Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 884 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 885 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 891 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
| 892 | null, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 893 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 894 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 895 | } |
| 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 Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 906 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 907 | 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 912 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 913 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 914 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 915 | } |
| 916 | |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 917 | @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 Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 940 | |
| 941 | @Test |
| 942 | public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception { |
| 943 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 944 | } |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 945 | |
| 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 951 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 952 | |
| 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 963 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 964 | |
| 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 975 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 976 | |
| 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 Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 986 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 987 | |
| 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 Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 994 | } |