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 |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 14 | * limitations under the License |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 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 |
Julia Reynolds | ac98aea | 2018-10-25 16:54:27 -0400 | [diff] [blame^] | 132 | when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn( |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 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 | } |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 161 | private void ensureNoUndoButton() { |
| 162 | PollingCheck.waitFor(1000, |
| 163 | () -> GONE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility() |
| 164 | && !mNotificationInfo.isAnimating()); |
| 165 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 166 | private void waitForStopButton() { |
| 167 | PollingCheck.waitFor(1000, |
| 168 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 171 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 172 | public void testBindNotification_SetsTextApplicationName() throws Exception { |
| 173 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
| 174 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 175 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 176 | final TextView textView = mNotificationInfo.findViewById(R.id.pkgname); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 177 | assertTrue(textView.getText().toString().contains("App Name")); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 178 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 182 | public void testBindNotification_SetsPackageIcon() throws Exception { |
| 183 | final Drawable iconDrawable = mock(Drawable.class); |
| 184 | when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) |
| 185 | .thenReturn(iconDrawable); |
| 186 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 187 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 188 | final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 189 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 190 | } |
| 191 | |
| 192 | @Test |
Julia Reynolds | ac98aea | 2018-10-25 16:54:27 -0400 | [diff] [blame^] | 193 | public void testBindNotification_noDelegate() throws Exception { |
| 194 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 195 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
| 196 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 197 | assertEquals(GONE, nameView.getVisibility()); |
| 198 | final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider); |
| 199 | assertEquals(GONE, dividerView.getVisibility()); |
| 200 | } |
| 201 | |
| 202 | @Test |
| 203 | public void testBindNotification_delegate() throws Exception { |
| 204 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, "other", 0, null, TEST_UID, 0, |
| 205 | new Notification(), UserHandle.CURRENT, null, 0); |
| 206 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 207 | applicationInfo.uid = 7; // non-zero |
| 208 | when(mMockPackageManager.getApplicationInfo(eq("other"), anyInt())).thenReturn( |
| 209 | applicationInfo); |
| 210 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Other"); |
| 211 | |
| 212 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 213 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
| 214 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 215 | assertEquals(VISIBLE, nameView.getVisibility()); |
| 216 | assertTrue(nameView.getText().toString().contains("Other")); |
| 217 | final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider); |
| 218 | assertEquals(VISIBLE, dividerView.getVisibility()); |
| 219 | } |
| 220 | |
| 221 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 222 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
| 223 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 224 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 225 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
| 226 | assertEquals(GONE, groupNameView.getVisibility()); |
| 227 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
| 228 | assertEquals(GONE, groupDividerView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 232 | public void testBindNotification_SetsGroupNameIfNonNull() throws Exception { |
| 233 | mNotificationChannel.setGroup("test_group_id"); |
| 234 | final NotificationChannelGroup notificationChannelGroup = |
| 235 | new NotificationChannelGroup("test_group_id", "Test Group Name"); |
| 236 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 237 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 238 | .thenReturn(notificationChannelGroup); |
| 239 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 240 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 241 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 242 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 243 | assertEquals("Test Group Name", groupNameView.getText()); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 244 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 245 | assertEquals(View.VISIBLE, groupDividerView.getVisibility()); |
| 246 | } |
| 247 | |
| 248 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 249 | public void testBindNotification_SetsTextChannelName() throws Exception { |
| 250 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 251 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 252 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 253 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 254 | } |
| 255 | |
| 256 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 257 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
| 258 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 259 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, true, |
| 260 | false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 261 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 262 | assertEquals(GONE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | @Test |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 266 | public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist() |
| 267 | throws Exception { |
| 268 | // Package has one channel by default. |
| 269 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
| 270 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10); |
| 271 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 272 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, true, |
| 273 | false); |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 274 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 275 | assertEquals(VISIBLE, textView.getVisibility()); |
| 276 | } |
| 277 | |
| 278 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 279 | public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception { |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 280 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 281 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 282 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 283 | assertEquals(VISIBLE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 287 | public void testBindNotification_BlockButton() throws Exception { |
| 288 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 289 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 290 | final View block = mNotificationInfo.findViewById(R.id.block); |
| 291 | final View minimize = mNotificationInfo.findViewById(R.id.minimize); |
| 292 | assertEquals(VISIBLE, block.getVisibility()); |
| 293 | assertEquals(GONE, minimize.getVisibility()); |
| 294 | } |
| 295 | |
| 296 | @Test |
| 297 | public void testBindNotification_MinButton() throws Exception { |
| 298 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 299 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 300 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 301 | final View block = mNotificationInfo.findViewById(R.id.block); |
| 302 | final View minimize = mNotificationInfo.findViewById(R.id.minimize); |
| 303 | assertEquals(GONE, block.getVisibility()); |
| 304 | assertEquals(VISIBLE, minimize.getVisibility()); |
| 305 | } |
| 306 | |
| 307 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 308 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 309 | final CountDownLatch latch = new CountDownLatch(1); |
| 310 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 311 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 312 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 313 | assertEquals(mNotificationChannel, c); |
| 314 | latch.countDown(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 315 | }, null, true, false); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 316 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 317 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 318 | settingsButton.performClick(); |
| 319 | // Verify that listener was triggered. |
| 320 | assertEquals(0, latch.getCount()); |
| 321 | } |
| 322 | |
| 323 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 324 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
| 325 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 326 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
| 327 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
| 328 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 329 | } |
| 330 | |
| 331 | @Test |
| 332 | public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned() |
| 333 | throws Exception { |
| 334 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 335 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
| 336 | (View v, NotificationChannel c, int appUid) -> { |
| 337 | assertEquals(mNotificationChannel, c); |
| 338 | }, null, false, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 339 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 340 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 341 | } |
| 342 | |
| 343 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 344 | public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception { |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 345 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 346 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 347 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 348 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
| 349 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 350 | }, null, true, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 351 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 352 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 353 | } |
| 354 | |
| 355 | @Test |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 356 | public void testLogBlockingHelperCounter_doesntLogForNormalGutsView() throws Exception { |
| 357 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 358 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 359 | mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent"); |
| 360 | verify(mMetricsLogger, times(0)).count(anyString(), anyInt()); |
| 361 | } |
| 362 | |
| 363 | @Test |
| 364 | public void testLogBlockingHelperCounter_logsForBlockingHelper() throws Exception { |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 365 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 366 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, true, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 367 | true, true); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 368 | mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent"); |
Rohan Shah | c6b0d54 | 2018-05-10 13:00:54 -0700 | [diff] [blame] | 369 | verify(mMetricsLogger, times(1)).count(anyString(), anyInt()); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 373 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 374 | final CountDownLatch latch = new CountDownLatch(1); |
| 375 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 376 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 377 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 378 | assertEquals(null, c); |
| 379 | latch.countDown(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 380 | }, null, true, true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 381 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 382 | mNotificationInfo.findViewById(R.id.info).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 383 | // Verify that listener was triggered. |
| 384 | assertEquals(0, latch.getCount()); |
| 385 | } |
| 386 | |
| 387 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 388 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 389 | public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 390 | throws Exception { |
| 391 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 392 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 393 | null, true, true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 394 | final TextView channelNameView = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 395 | mNotificationInfo.findViewById(R.id.channel_name); |
| 396 | assertEquals(GONE, channelNameView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | @Test |
| 400 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 401 | public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 402 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 403 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 404 | null, true, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 405 | final TextView blockView = mNotificationInfo.findViewById(R.id.block); |
| 406 | assertEquals(GONE, blockView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | @Test |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 410 | public void testbindNotification_BlockingHelper() throws Exception { |
| 411 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 412 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, false, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 413 | true, true); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 414 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 415 | assertEquals(View.VISIBLE, view.getVisibility()); |
| 416 | assertEquals(mContext.getString(R.string.inline_blocking_helper), view.getText()); |
| 417 | } |
| 418 | |
| 419 | @Test |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 420 | public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception { |
| 421 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 422 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 423 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 424 | assertEquals(View.VISIBLE, view.getVisibility()); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 425 | assertEquals(mContext.getString(R.string.notification_unblockable_desc), |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 426 | view.getText()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 430 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
| 431 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 432 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 433 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 434 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 435 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 439 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 440 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 441 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 442 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 443 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 444 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 445 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 446 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 447 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 451 | public void testDoesNotUpdateNotificationChannelAfterImportanceChangedMin() |
| 452 | throws Exception { |
| 453 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 454 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 455 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 456 | |
| 457 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 458 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 459 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 460 | anyString(), eq(TEST_UID), any()); |
| 461 | } |
| 462 | |
| 463 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 464 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 465 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 466 | int originalImportance = mNotificationChannel.getImportance(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 467 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 468 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 469 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 470 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 471 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 472 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 473 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 474 | assertEquals(originalImportance, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 478 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 479 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 480 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 481 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 482 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 483 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 484 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 485 | |
| 486 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 487 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 488 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 489 | assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | @Test |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 493 | public void testHandleCloseControls_setsNotificationsDisabledForMultipleChannelNotifications() |
| 494 | throws Exception { |
| 495 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 496 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 497 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 498 | 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */, |
| 499 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 500 | true, false /* isNonblockable */); |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 501 | |
| 502 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 503 | waitForUndoButton(); |
| 504 | mNotificationInfo.handleCloseControls(true, false); |
| 505 | |
| 506 | mTestableLooper.processAllMessages(); |
| 507 | verify(mMockINotificationManager, times(1)) |
| 508 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 509 | anyString(), eq(TEST_UID), eq(false)); |
| 510 | } |
| 511 | |
| 512 | |
| 513 | @Test |
| 514 | public void testHandleCloseControls_keepsNotificationsEnabledForMultipleChannelNotifications() |
| 515 | throws Exception { |
| 516 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 517 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 518 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 519 | 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */, |
| 520 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 521 | true, false /* isNonblockable */); |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 522 | |
| 523 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 524 | waitForUndoButton(); |
| 525 | mNotificationInfo.handleCloseControls(true, false); |
| 526 | |
| 527 | mTestableLooper.processAllMessages(); |
| 528 | verify(mMockINotificationManager, times(1)) |
| 529 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 530 | anyString(), eq(TEST_UID), eq(false)); |
| 531 | } |
| 532 | |
| 533 | @Test |
| 534 | public void testCloseControls_blockingHelperSavesImportanceForMultipleChannelNotifications() |
| 535 | throws Exception { |
| 536 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 537 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 538 | 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */, |
| 539 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 540 | true /* provisioned */, |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 541 | false /* isNonblockable */, true /* isForBlockingHelper */, |
| 542 | true /* isUserSentimentNegative */); |
| 543 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 544 | NotificationGuts guts = spy(new NotificationGuts(mContext, null)); |
| 545 | when(guts.getWindowToken()).thenReturn(mock(IBinder.class)); |
| 546 | doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean()); |
| 547 | doNothing().when(guts).setExposed(anyBoolean(), anyBoolean()); |
| 548 | guts.setGutsContent(mNotificationInfo); |
| 549 | mNotificationInfo.setGutsParent(guts); |
| 550 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 551 | mNotificationInfo.findViewById(R.id.keep).performClick(); |
| 552 | |
| 553 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 554 | mTestableLooper.processAllMessages(); |
| 555 | verify(mMockINotificationManager, times(1)) |
| 556 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 557 | anyString(), eq(TEST_UID), eq(true)); |
| 558 | } |
| 559 | |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 560 | @Test |
| 561 | public void testCloseControls_nonNullCheckSaveListenerDoesntDelayKeepShowing() |
| 562 | throws Exception { |
| 563 | NotificationInfo.CheckSaveListener listener = |
| 564 | mock(NotificationInfo.CheckSaveListener.class); |
| 565 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 566 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 567 | 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 568 | null /* onSettingsClick */, null /* onAppSettingsClick */ , true /* provisioned */, |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 569 | false /* isNonblockable */, true /* isForBlockingHelper */, |
| 570 | true /* isUserSentimentNegative */); |
| 571 | |
| 572 | NotificationGuts guts = spy(new NotificationGuts(mContext, null)); |
| 573 | when(guts.getWindowToken()).thenReturn(mock(IBinder.class)); |
| 574 | doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean()); |
| 575 | doNothing().when(guts).setExposed(anyBoolean(), anyBoolean()); |
| 576 | guts.setGutsContent(mNotificationInfo); |
| 577 | mNotificationInfo.setGutsParent(guts); |
| 578 | |
| 579 | mNotificationInfo.findViewById(R.id.keep).performClick(); |
| 580 | |
| 581 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 582 | mTestableLooper.processAllMessages(); |
| 583 | verify(mMockINotificationManager, times(1)) |
| 584 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 585 | anyString(), eq(TEST_UID), eq(true)); |
| 586 | } |
| 587 | |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 588 | @Test |
| 589 | public void testCloseControls_nonNullCheckSaveListenerDoesntDelayDismiss() |
| 590 | throws Exception { |
| 591 | NotificationInfo.CheckSaveListener listener = |
| 592 | mock(NotificationInfo.CheckSaveListener.class); |
| 593 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 594 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 595 | 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */, |
| 596 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
| 597 | false /* isNonblockable */, true /* isForBlockingHelper */, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 598 | true, true /* isUserSentimentNegative */); |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 599 | |
| 600 | mNotificationInfo.handleCloseControls(true /* save */, false /* force */); |
| 601 | |
| 602 | mTestableLooper.processAllMessages(); |
| 603 | verify(listener, times(0)).checkSave(any(Runnable.class), eq(mSbn)); |
| 604 | } |
| 605 | |
| 606 | @Test |
| 607 | public void testCloseControls_checkSaveListenerDelaysStopNotifications() |
| 608 | throws Exception { |
| 609 | NotificationInfo.CheckSaveListener listener = |
| 610 | mock(NotificationInfo.CheckSaveListener.class); |
| 611 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 612 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 613 | 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 614 | null /* onSettingsClick */, null /* onAppSettingsClick */, |
| 615 | true /* provisioned */, |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 616 | false /* isNonblockable */, true /* isForBlockingHelper */, |
| 617 | true /* isUserSentimentNegative */); |
| 618 | |
| 619 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 620 | mTestableLooper.processAllMessages(); |
| 621 | verify(listener).checkSave(any(Runnable.class), eq(mSbn)); |
| 622 | } |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 623 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 624 | @Test |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 625 | public void testCloseControls_blockingHelperDismissedIfShown() throws Exception { |
| 626 | mNotificationInfo.bindNotification( |
| 627 | mMockPackageManager, |
| 628 | mMockINotificationManager, |
| 629 | TEST_PACKAGE_NAME, |
| 630 | mNotificationChannel, |
| 631 | 1 /* numChannels */, |
| 632 | mSbn, |
| 633 | null /* checkSaveListener */, |
| 634 | null /* onSettingsClick */, |
| 635 | null /* onAppSettingsClick */, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 636 | false /* isNonblockable */, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 637 | true /* isForBlockingHelper */, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 638 | true, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 639 | false /* isUserSentimentNegative */); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 640 | NotificationGuts guts = mock(NotificationGuts.class); |
| 641 | doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean()); |
| 642 | mNotificationInfo.setGutsParent(guts); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 643 | |
| 644 | mNotificationInfo.closeControls(mNotificationInfo); |
| 645 | |
| 646 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 647 | } |
| 648 | |
| 649 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 650 | public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 651 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 652 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 653 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 654 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 655 | waitForUndoButton(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 656 | |
| 657 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 658 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 659 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 663 | public void testBlockChangedCallsUpdateNotificationChannel() throws Exception { |
| 664 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 665 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 666 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 667 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 668 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 669 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 670 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 671 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 672 | mTestableLooper.processAllMessages(); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 673 | ArgumentCaptor<NotificationChannel> updated = |
| 674 | ArgumentCaptor.forClass(NotificationChannel.class); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 675 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 676 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 677 | assertTrue((updated.getValue().getUserLockedFields() |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 678 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 679 | assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance()); |
| 680 | } |
| 681 | |
| 682 | @Test |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 683 | public void testBlockChangedCallsUpdateNotificationChannel_blockingHelper() throws Exception { |
| 684 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 685 | mNotificationInfo.bindNotification( |
| 686 | mMockPackageManager, |
| 687 | mMockINotificationManager, |
| 688 | TEST_PACKAGE_NAME, |
| 689 | mNotificationChannel, |
| 690 | 1 /* numChannels */, |
| 691 | mSbn, |
| 692 | null /* checkSaveListener */, |
| 693 | null /* onSettingsClick */, |
| 694 | null /* onAppSettingsClick */, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 695 | true /*provisioned */, |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 696 | false /* isNonblockable */, |
| 697 | true /* isForBlockingHelper */, |
| 698 | true /* isUserSentimentNegative */); |
| 699 | |
| 700 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 701 | waitForUndoButton(); |
| 702 | mNotificationInfo.handleCloseControls(true, false); |
| 703 | |
| 704 | mTestableLooper.processAllMessages(); |
| 705 | ArgumentCaptor<NotificationChannel> updated = |
| 706 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 707 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 708 | anyString(), eq(TEST_UID), updated.capture()); |
| 709 | assertTrue((updated.getValue().getUserLockedFields() |
| 710 | & USER_LOCKED_IMPORTANCE) != 0); |
| 711 | assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance()); |
| 712 | } |
| 713 | |
| 714 | |
| 715 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 716 | public void testNonBlockableAppDoesNotBecomeMin() throws Exception { |
| 717 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 718 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 719 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 720 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 721 | waitForUndoButton(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 722 | |
| 723 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 724 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 725 | anyString(), eq(TEST_UID), any()); |
| 726 | } |
| 727 | |
| 728 | @Test |
| 729 | public void testMinChangedCallsUpdateNotificationChannel() throws Exception { |
| 730 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 731 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 732 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 733 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 734 | |
| 735 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 736 | waitForUndoButton(); |
| 737 | mNotificationInfo.handleCloseControls(true, false); |
| 738 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 739 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 740 | ArgumentCaptor<NotificationChannel> updated = |
| 741 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 742 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 743 | anyString(), eq(TEST_UID), updated.capture()); |
| 744 | assertTrue((updated.getValue().getUserLockedFields() |
| 745 | & USER_LOCKED_IMPORTANCE) != 0); |
| 746 | assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | @Test |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 750 | public void testKeepUpdatesNotificationChannel() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 751 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 752 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 753 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 754 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 755 | mNotificationInfo.handleCloseControls(true, false); |
| 756 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 757 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 758 | ArgumentCaptor<NotificationChannel> updated = |
| 759 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 760 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 761 | anyString(), eq(TEST_UID), updated.capture()); |
| 762 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 763 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 764 | } |
| 765 | |
| 766 | @Test |
| 767 | public void testBlockUndoDoesNotBlockNotificationChannel() throws Exception { |
| 768 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 769 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 770 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 771 | |
| 772 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 773 | waitForUndoButton(); |
| 774 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 775 | waitForStopButton(); |
| 776 | mNotificationInfo.handleCloseControls(true, false); |
| 777 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 778 | mTestableLooper.processAllMessages(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 779 | ArgumentCaptor<NotificationChannel> updated = |
| 780 | ArgumentCaptor.forClass(NotificationChannel.class); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 781 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 782 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 783 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 784 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 785 | } |
| 786 | |
| 787 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 788 | public void testMinUndoDoesNotMinNotificationChannel() throws Exception { |
| 789 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 790 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 791 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 792 | |
| 793 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 794 | waitForUndoButton(); |
| 795 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 796 | waitForStopButton(); |
| 797 | mNotificationInfo.handleCloseControls(true, false); |
| 798 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 799 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 800 | ArgumentCaptor<NotificationChannel> updated = |
| 801 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 802 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 803 | anyString(), eq(TEST_UID), updated.capture()); |
| 804 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 805 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 806 | } |
| 807 | |
| 808 | @Test |
| 809 | public void testCloseControlsDoesNotUpdateiMinIfSaveIsFalse() throws Exception { |
| 810 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 811 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 812 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 813 | |
| 814 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 815 | waitForUndoButton(); |
| 816 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 817 | |
| 818 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 819 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 820 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 821 | } |
| 822 | |
| 823 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 824 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 825 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 826 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 827 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 828 | |
| 829 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 830 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 831 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 832 | |
| 833 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 834 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 835 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 836 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 837 | |
| 838 | @Test |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 839 | public void testBlockDoesNothingIfCheckSaveListenerIsNoOp() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 840 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 841 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 842 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 843 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 844 | }, null, null, true, true); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 845 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 846 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 847 | mTestableLooper.processAllMessages(); |
| 848 | ensureNoUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 849 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 850 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 851 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 852 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | @Test |
| 856 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 857 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 858 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 859 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 860 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 861 | saveImportance.run(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 862 | }, null, null, true, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 863 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 864 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 865 | mTestableLooper.processAllMessages(); |
| 866 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 867 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 868 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 869 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 870 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 871 | |
| 872 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 873 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 874 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 875 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 876 | |
| 877 | @Test |
| 878 | public void testDisplaySettingsLink() throws Exception { |
| 879 | final CountDownLatch latch = new CountDownLatch(1); |
| 880 | final String settingsText = "work chats"; |
| 881 | final ResolveInfo ri = new ResolveInfo(); |
| 882 | ri.activityInfo = new ActivityInfo(); |
| 883 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 884 | ri.activityInfo.name = "something"; |
| 885 | List<ResolveInfo> ris = new ArrayList<>(); |
| 886 | ris.add(ri); |
| 887 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 888 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 889 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 890 | .setSettingsText(settingsText).build(); |
| 891 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 892 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 893 | |
| 894 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 895 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 896 | (View v, Intent intent) -> { |
| 897 | latch.countDown(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 898 | }, true, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 899 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 900 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 901 | settingsLink.performClick(); |
| 902 | assertEquals(0, latch.getCount()); |
| 903 | } |
| 904 | |
| 905 | @Test |
| 906 | public void testDisplaySettingsLink_multipleChannels() throws Exception { |
| 907 | final CountDownLatch latch = new CountDownLatch(1); |
| 908 | final String settingsText = "work chats"; |
| 909 | final ResolveInfo ri = new ResolveInfo(); |
| 910 | ri.activityInfo = new ActivityInfo(); |
| 911 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 912 | ri.activityInfo.name = "something"; |
| 913 | List<ResolveInfo> ris = new ArrayList<>(); |
| 914 | ris.add(ri); |
| 915 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 916 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 917 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 918 | .setSettingsText(settingsText).build(); |
| 919 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 920 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 921 | |
| 922 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 923 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 924 | (View v, Intent intent) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 925 | latch.countDown(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 926 | }, true, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 927 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 928 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 929 | settingsLink.performClick(); |
| 930 | assertEquals(0, latch.getCount()); |
| 931 | } |
| 932 | |
| 933 | @Test |
| 934 | public void testNoSettingsLink_noHandlingActivity() throws Exception { |
| 935 | final String settingsText = "work chats"; |
| 936 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(null); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 937 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 938 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 939 | .setSettingsText(settingsText).build(); |
| 940 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 941 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 942 | |
| 943 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 944 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 945 | null, true, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 946 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 947 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | @Test |
| 951 | public void testNoSettingsLink_noLinkText() throws Exception { |
| 952 | final ResolveInfo ri = new ResolveInfo(); |
| 953 | ri.activityInfo = new ActivityInfo(); |
| 954 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 955 | ri.activityInfo.name = "something"; |
| 956 | List<ResolveInfo> ris = new ArrayList<>(); |
| 957 | ris.add(ri); |
| 958 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 959 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 960 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()).build(); |
| 961 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 962 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 963 | |
| 964 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 965 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, true, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 966 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 967 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 968 | } |
| 969 | |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 970 | @Test |
| 971 | public void testBindHeader_noSettingsLinkWhenIsForBlockingHelper() throws Exception { |
| 972 | final String settingsText = "work chats"; |
| 973 | final ResolveInfo ri = new ResolveInfo(); |
| 974 | ri.activityInfo = new ActivityInfo(); |
| 975 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 976 | ri.activityInfo.name = "something"; |
| 977 | List<ResolveInfo> ris = new ArrayList<>(); |
| 978 | ris.add(ri); |
| 979 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
| 980 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 981 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 982 | .setSettingsText(settingsText).build(); |
| 983 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 984 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 985 | |
| 986 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 987 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false, true, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 988 | true, true); |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 989 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 990 | assertEquals(GONE, settingsLink.getVisibility()); |
| 991 | } |
| 992 | |
Geoffrey Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 993 | |
| 994 | @Test |
| 995 | public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception { |
| 996 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 997 | } |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 998 | |
| 999 | @Test |
| 1000 | public void testUndoText_min() throws Exception { |
| 1001 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 1002 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 1003 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 1004 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 1005 | |
| 1006 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 1007 | waitForUndoButton(); |
| 1008 | TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text); |
| 1009 | assertTrue(confirmationText.getText().toString().contains("minimized")); |
| 1010 | } |
| 1011 | |
| 1012 | @Test |
| 1013 | public void testUndoText_block() throws Exception { |
| 1014 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 1015 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 1016 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 1017 | |
| 1018 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 1019 | waitForUndoButton(); |
| 1020 | TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text); |
| 1021 | assertTrue(confirmationText.getText().toString().contains("won't see")); |
| 1022 | } |
| 1023 | |
| 1024 | @Test |
| 1025 | public void testNoHeaderOnConfirmation() throws Exception { |
| 1026 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 1027 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 1028 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 1029 | |
| 1030 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 1031 | waitForUndoButton(); |
| 1032 | assertEquals(GONE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 1033 | } |
| 1034 | |
| 1035 | @Test |
| 1036 | public void testHeaderOnUndo() throws Exception { |
| 1037 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 1038 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 1039 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 1040 | |
| 1041 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 1042 | waitForUndoButton(); |
| 1043 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 1044 | waitForStopButton(); |
| 1045 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 1046 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1047 | } |