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; |
| 36 | import static org.mockito.Mockito.eq; |
| 37 | import static org.mockito.Mockito.mock; |
| 38 | import static org.mockito.Mockito.never; |
| 39 | import static org.mockito.Mockito.times; |
| 40 | import static org.mockito.Mockito.verify; |
| 41 | import static org.mockito.Mockito.when; |
| 42 | |
| 43 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 44 | import android.app.Notification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 45 | import android.app.NotificationChannel; |
| 46 | import android.app.NotificationChannelGroup; |
| 47 | import android.app.NotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 48 | import android.content.Intent; |
| 49 | import android.content.pm.ActivityInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 50 | import android.content.pm.ApplicationInfo; |
| 51 | import android.content.pm.PackageInfo; |
| 52 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 53 | import android.content.pm.ResolveInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 54 | import android.graphics.drawable.Drawable; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 55 | import android.os.UserHandle; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 56 | import android.service.notification.StatusBarNotification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 57 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 58 | import android.testing.AndroidTestingRunner; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 59 | import android.testing.PollingCheck; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 60 | import android.testing.UiThreadTest; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 61 | import android.view.LayoutInflater; |
| 62 | import android.view.View; |
| 63 | import android.widget.ImageView; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 64 | import android.widget.TextView; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 65 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 66 | import com.android.systemui.R; |
| 67 | import com.android.systemui.SysuiTestCase; |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 68 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 69 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 70 | import org.junit.Rule; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 71 | import org.junit.Test; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 72 | import org.junit.runner.RunWith; |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 73 | import org.mockito.ArgumentCaptor; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 74 | import org.mockito.Mock; |
| 75 | import org.mockito.junit.MockitoJUnit; |
| 76 | import org.mockito.junit.MockitoRule; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 77 | |
| 78 | import java.util.ArrayList; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 79 | import java.util.List; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 80 | import java.util.concurrent.CountDownLatch; |
| 81 | |
| 82 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 83 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 84 | @UiThreadTest |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 85 | public class NotificationInfoTest extends SysuiTestCase { |
| 86 | private static final String TEST_PACKAGE_NAME = "test_package"; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 87 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 88 | private static final int TEST_UID = 1; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 89 | private static final int MULTIPLE_CHANNEL_COUNT = 2; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 90 | private static final String TEST_CHANNEL = "test_channel"; |
| 91 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 92 | |
| 93 | private NotificationInfo mNotificationInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 94 | private NotificationChannel mNotificationChannel; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 95 | private NotificationChannel mDefaultNotificationChannel; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 96 | private StatusBarNotification mSbn; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 97 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 98 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
| 99 | @Mock private INotificationManager mMockINotificationManager; |
| 100 | @Mock private PackageManager mMockPackageManager; |
| 101 | @Mock private NotificationBlockingHelperManager mBlockingHelperManager; |
| 102 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 103 | @Before |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 104 | public void setUp() throws Exception { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 105 | mDependency.injectTestDependency( |
| 106 | NotificationBlockingHelperManager.class, |
| 107 | mBlockingHelperManager); |
| 108 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 109 | // Inflate the layout |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 110 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 111 | mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, |
| 112 | null); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 113 | mNotificationInfo.setGutsParent(mock(NotificationGuts.class)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 114 | |
| 115 | // PackageManager must return a packageInfo and applicationInfo. |
| 116 | final PackageInfo packageInfo = new PackageInfo(); |
| 117 | packageInfo.packageName = TEST_PACKAGE_NAME; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 118 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 119 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 120 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 121 | applicationInfo.uid = TEST_UID; // non-zero |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 122 | when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn( |
| 123 | applicationInfo); |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 124 | final PackageInfo systemPackageInfo = new PackageInfo(); |
| 125 | systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; |
| 126 | when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) |
| 127 | .thenReturn(systemPackageInfo); |
| 128 | when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) |
| 129 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 130 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 131 | // Package has one channel by default. |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 132 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 133 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 134 | |
| 135 | // Some test channels. |
| 136 | mNotificationChannel = new NotificationChannel( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 137 | TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 138 | mDefaultNotificationChannel = new NotificationChannel( |
| 139 | NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 140 | IMPORTANCE_LOW); |
Julia Reynolds | 33bef2c | 2017-09-05 11:07:18 -0400 | [diff] [blame] | 141 | 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] | 142 | new Notification(), UserHandle.CURRENT, null, 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 143 | } |
| 144 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 145 | // TODO: if tests are taking too long replace this with something that makes the animation |
| 146 | // finish instantly. |
| 147 | private void waitForUndoButton() { |
| 148 | PollingCheck.waitFor(1000, |
| 149 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 150 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 151 | private void waitForStopButton() { |
| 152 | PollingCheck.waitFor(1000, |
| 153 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 154 | } |
| 155 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 156 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 157 | public void testBindNotification_SetsTextApplicationName() throws Exception { |
| 158 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
| 159 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 160 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 161 | final TextView textView = mNotificationInfo.findViewById(R.id.pkgname); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 162 | assertTrue(textView.getText().toString().contains("App Name")); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 163 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 167 | public void testBindNotification_SetsPackageIcon() throws Exception { |
| 168 | final Drawable iconDrawable = mock(Drawable.class); |
| 169 | when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) |
| 170 | .thenReturn(iconDrawable); |
| 171 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 172 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 173 | final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 174 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 175 | } |
| 176 | |
| 177 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 178 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
| 179 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 180 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 181 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
| 182 | assertEquals(GONE, groupNameView.getVisibility()); |
| 183 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
| 184 | assertEquals(GONE, groupDividerView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 188 | public void testBindNotification_SetsGroupNameIfNonNull() throws Exception { |
| 189 | mNotificationChannel.setGroup("test_group_id"); |
| 190 | final NotificationChannelGroup notificationChannelGroup = |
| 191 | new NotificationChannelGroup("test_group_id", "Test Group Name"); |
| 192 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 193 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 194 | .thenReturn(notificationChannelGroup); |
| 195 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 196 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 197 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 198 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 199 | assertEquals("Test Group Name", groupNameView.getText()); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 200 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 201 | assertEquals(View.VISIBLE, groupDividerView.getVisibility()); |
| 202 | } |
| 203 | |
| 204 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 205 | public void testBindNotification_SetsTextChannelName() throws Exception { |
| 206 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 207 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 208 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 209 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 210 | } |
| 211 | |
| 212 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 213 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
| 214 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 215 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 216 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 217 | assertEquals(GONE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | @Test |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 221 | public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist() |
| 222 | throws Exception { |
| 223 | // Package has one channel by default. |
| 224 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
| 225 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10); |
| 226 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 227 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false); |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 228 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 229 | assertEquals(VISIBLE, textView.getVisibility()); |
| 230 | } |
| 231 | |
| 232 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 233 | public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception { |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 234 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 235 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 236 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 237 | assertEquals(VISIBLE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 241 | public void testBindNotification_BlockButton() throws Exception { |
| 242 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 243 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 244 | final View block = mNotificationInfo.findViewById(R.id.block); |
| 245 | final View minimize = mNotificationInfo.findViewById(R.id.minimize); |
| 246 | assertEquals(VISIBLE, block.getVisibility()); |
| 247 | assertEquals(GONE, minimize.getVisibility()); |
| 248 | } |
| 249 | |
| 250 | @Test |
| 251 | public void testBindNotification_MinButton() throws Exception { |
| 252 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 253 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 254 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 255 | final View block = mNotificationInfo.findViewById(R.id.block); |
| 256 | final View minimize = mNotificationInfo.findViewById(R.id.minimize); |
| 257 | assertEquals(GONE, block.getVisibility()); |
| 258 | assertEquals(VISIBLE, minimize.getVisibility()); |
| 259 | } |
| 260 | |
| 261 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 262 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 263 | final CountDownLatch latch = new CountDownLatch(1); |
| 264 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 265 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 266 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 267 | assertEquals(mNotificationChannel, c); |
| 268 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 269 | }, null, false); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 270 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 271 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 272 | settingsButton.performClick(); |
| 273 | // Verify that listener was triggered. |
| 274 | assertEquals(0, latch.getCount()); |
| 275 | } |
| 276 | |
| 277 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 278 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
| 279 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 280 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 281 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 282 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 283 | } |
| 284 | |
| 285 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 286 | public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception { |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 287 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 288 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 289 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 290 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
| 291 | (View v, NotificationChannel c, int appUid) -> { |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 292 | }, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 293 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 294 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 295 | } |
| 296 | |
| 297 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 298 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 299 | final CountDownLatch latch = new CountDownLatch(1); |
| 300 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 301 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 302 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 303 | assertEquals(null, c); |
| 304 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 305 | }, null, true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 306 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 307 | mNotificationInfo.findViewById(R.id.info).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 308 | // Verify that listener was triggered. |
| 309 | assertEquals(0, latch.getCount()); |
| 310 | } |
| 311 | |
| 312 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 313 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 314 | public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 315 | throws Exception { |
| 316 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 317 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null, |
| 318 | null, true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 319 | final TextView channelNameView = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 320 | mNotificationInfo.findViewById(R.id.channel_name); |
| 321 | assertEquals(GONE, channelNameView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Test |
| 325 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 326 | public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 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, null, |
| 329 | null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 330 | final TextView blockView = mNotificationInfo.findViewById(R.id.block); |
| 331 | assertEquals(GONE, blockView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | @Test |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 335 | public void testbindNotification_BlockingHelper() throws Exception { |
| 336 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 337 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, false, |
| 338 | true); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 339 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 340 | assertEquals(View.VISIBLE, view.getVisibility()); |
| 341 | assertEquals(mContext.getString(R.string.inline_blocking_helper), view.getText()); |
| 342 | } |
| 343 | |
| 344 | @Test |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 345 | public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception { |
| 346 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 347 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 348 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 349 | assertEquals(View.VISIBLE, view.getVisibility()); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 350 | assertEquals(mContext.getString(R.string.notification_unblockable_desc), |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 351 | view.getText()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 355 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
| 356 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 357 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 358 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 359 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 363 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 364 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 365 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 366 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 367 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 368 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 369 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 370 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 374 | public void testDoesNotUpdateNotificationChannelAfterImportanceChangedMin() |
| 375 | throws Exception { |
| 376 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 377 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 378 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 379 | |
| 380 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 381 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 382 | anyString(), eq(TEST_UID), any()); |
| 383 | } |
| 384 | |
| 385 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 386 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 387 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 388 | int originalImportance = mNotificationChannel.getImportance(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 389 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 390 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 391 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 392 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 393 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 394 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 395 | assertEquals(originalImportance, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 399 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 400 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 401 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -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, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 404 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 405 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 406 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 407 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 408 | assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | @Test |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 412 | public void testCloseControls_blockingHelperDismissedIfShown() throws Exception { |
| 413 | mNotificationInfo.bindNotification( |
| 414 | mMockPackageManager, |
| 415 | mMockINotificationManager, |
| 416 | TEST_PACKAGE_NAME, |
| 417 | mNotificationChannel, |
| 418 | 1 /* numChannels */, |
| 419 | mSbn, |
| 420 | null /* checkSaveListener */, |
| 421 | null /* onSettingsClick */, |
| 422 | null /* onAppSettingsClick */, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 423 | false /* isNonblockable */, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 424 | true /* isForBlockingHelper */, |
| 425 | false /* isUserSentimentNegative */); |
| 426 | |
| 427 | mNotificationInfo.closeControls(mNotificationInfo); |
| 428 | |
| 429 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 430 | } |
| 431 | |
| 432 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 433 | public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 434 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 435 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 436 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 437 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 438 | waitForUndoButton(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 439 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 440 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 444 | public void testBlockChangedCallsUpdateNotificationChannel() throws Exception { |
| 445 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 446 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 447 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 448 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 449 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 450 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 451 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 452 | |
| 453 | ArgumentCaptor<NotificationChannel> updated = |
| 454 | ArgumentCaptor.forClass(NotificationChannel.class); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 455 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 456 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 457 | assertTrue((updated.getValue().getUserLockedFields() |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 458 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 459 | assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance()); |
| 460 | } |
| 461 | |
| 462 | @Test |
| 463 | public void testNonBlockableAppDoesNotBecomeMin() throws Exception { |
| 464 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 465 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 466 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 467 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 468 | waitForUndoButton(); |
| 469 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 470 | anyString(), eq(TEST_UID), any()); |
| 471 | } |
| 472 | |
| 473 | @Test |
| 474 | public void testMinChangedCallsUpdateNotificationChannel() throws Exception { |
| 475 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 476 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 477 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 478 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 479 | |
| 480 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 481 | waitForUndoButton(); |
| 482 | mNotificationInfo.handleCloseControls(true, false); |
| 483 | |
| 484 | ArgumentCaptor<NotificationChannel> updated = |
| 485 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 486 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 487 | anyString(), eq(TEST_UID), updated.capture()); |
| 488 | assertTrue((updated.getValue().getUserLockedFields() |
| 489 | & USER_LOCKED_IMPORTANCE) != 0); |
| 490 | assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | @Test |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 494 | public void testKeepUpdatesNotificationChannel() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 495 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 496 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 497 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 498 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 499 | mNotificationInfo.handleCloseControls(true, false); |
| 500 | |
| 501 | ArgumentCaptor<NotificationChannel> updated = |
| 502 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 503 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 504 | anyString(), eq(TEST_UID), updated.capture()); |
| 505 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 506 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 507 | } |
| 508 | |
| 509 | @Test |
| 510 | public void testBlockUndoDoesNotBlockNotificationChannel() throws Exception { |
| 511 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 512 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 513 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 514 | |
| 515 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 516 | waitForUndoButton(); |
| 517 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 518 | waitForStopButton(); |
| 519 | mNotificationInfo.handleCloseControls(true, false); |
| 520 | |
| 521 | ArgumentCaptor<NotificationChannel> updated = |
| 522 | ArgumentCaptor.forClass(NotificationChannel.class); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 523 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 524 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 525 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 526 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 527 | } |
| 528 | |
| 529 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 530 | public void testMinUndoDoesNotMinNotificationChannel() throws Exception { |
| 531 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 532 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 533 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 534 | |
| 535 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 536 | waitForUndoButton(); |
| 537 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 538 | waitForStopButton(); |
| 539 | mNotificationInfo.handleCloseControls(true, false); |
| 540 | |
| 541 | ArgumentCaptor<NotificationChannel> updated = |
| 542 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 543 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 544 | anyString(), eq(TEST_UID), updated.capture()); |
| 545 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 546 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 547 | } |
| 548 | |
| 549 | @Test |
| 550 | public void testCloseControlsDoesNotUpdateiMinIfSaveIsFalse() throws Exception { |
| 551 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 552 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 553 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 554 | |
| 555 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 556 | waitForUndoButton(); |
| 557 | mNotificationInfo.handleCloseControls(false, false); |
| 558 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 559 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 560 | } |
| 561 | |
| 562 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 563 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 564 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 565 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 566 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 567 | |
| 568 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 569 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 570 | mNotificationInfo.handleCloseControls(false, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 571 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 572 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 573 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 574 | |
| 575 | @Test |
| 576 | public void testCloseControlsDoesNotUpdateIfCheckSaveListenerIsNoOp() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 577 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 578 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 579 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 580 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 581 | }, null, null, true); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 582 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 583 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 584 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 585 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 586 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 587 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | @Test |
| 591 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 592 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 593 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 594 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 595 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 596 | saveImportance.run(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 597 | }, null, null, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 598 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 599 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 600 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 601 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 602 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 603 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 604 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 605 | |
| 606 | @Test |
| 607 | public void testDisplaySettingsLink() throws Exception { |
| 608 | final CountDownLatch latch = new CountDownLatch(1); |
| 609 | final String settingsText = "work chats"; |
| 610 | final ResolveInfo ri = new ResolveInfo(); |
| 611 | ri.activityInfo = new ActivityInfo(); |
| 612 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 613 | ri.activityInfo.name = "something"; |
| 614 | List<ResolveInfo> ris = new ArrayList<>(); |
| 615 | ris.add(ri); |
| 616 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 617 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 618 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 619 | .setSettingsText(settingsText).build(); |
| 620 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 621 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 622 | |
| 623 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 624 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 625 | (View v, Intent intent) -> { |
| 626 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 627 | }, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 628 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 629 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 630 | settingsLink.performClick(); |
| 631 | assertEquals(0, latch.getCount()); |
| 632 | } |
| 633 | |
| 634 | @Test |
| 635 | public void testDisplaySettingsLink_multipleChannels() throws Exception { |
| 636 | final CountDownLatch latch = new CountDownLatch(1); |
| 637 | final String settingsText = "work chats"; |
| 638 | final ResolveInfo ri = new ResolveInfo(); |
| 639 | ri.activityInfo = new ActivityInfo(); |
| 640 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 641 | ri.activityInfo.name = "something"; |
| 642 | List<ResolveInfo> ris = new ArrayList<>(); |
| 643 | ris.add(ri); |
| 644 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 645 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 646 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 647 | .setSettingsText(settingsText).build(); |
| 648 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 649 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 650 | |
| 651 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 652 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 653 | (View v, Intent intent) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 654 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 655 | }, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 656 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 657 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 658 | settingsLink.performClick(); |
| 659 | assertEquals(0, latch.getCount()); |
| 660 | } |
| 661 | |
| 662 | @Test |
| 663 | public void testNoSettingsLink_noHandlingActivity() throws Exception { |
| 664 | final String settingsText = "work chats"; |
| 665 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(null); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 666 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 667 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 668 | .setSettingsText(settingsText).build(); |
| 669 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 670 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 671 | |
| 672 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 673 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
| 674 | null, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 675 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 676 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | @Test |
| 680 | public void testNoSettingsLink_noLinkText() throws Exception { |
| 681 | final ResolveInfo ri = new ResolveInfo(); |
| 682 | ri.activityInfo = new ActivityInfo(); |
| 683 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 684 | ri.activityInfo.name = "something"; |
| 685 | List<ResolveInfo> ris = new ArrayList<>(); |
| 686 | ris.add(ri); |
| 687 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 688 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 689 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()).build(); |
| 690 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 691 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 692 | |
| 693 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 694 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 695 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 696 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 697 | } |
| 698 | |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 699 | @Test |
| 700 | public void testBindHeader_noSettingsLinkWhenIsForBlockingHelper() throws Exception { |
| 701 | final String settingsText = "work chats"; |
| 702 | final ResolveInfo ri = new ResolveInfo(); |
| 703 | ri.activityInfo = new ActivityInfo(); |
| 704 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 705 | ri.activityInfo.name = "something"; |
| 706 | List<ResolveInfo> ris = new ArrayList<>(); |
| 707 | ris.add(ri); |
| 708 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
| 709 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 710 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 711 | .setSettingsText(settingsText).build(); |
| 712 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 713 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 714 | |
| 715 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 716 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false, true, |
| 717 | true); |
| 718 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 719 | assertEquals(GONE, settingsLink.getVisibility()); |
| 720 | } |
| 721 | |
Geoffrey Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 722 | |
| 723 | @Test |
| 724 | public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception { |
| 725 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 726 | } |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 727 | |
| 728 | @Test |
| 729 | public void testUndoText_min() throws Exception { |
| 730 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 731 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 732 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 733 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 734 | |
| 735 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 736 | waitForUndoButton(); |
| 737 | TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text); |
| 738 | assertTrue(confirmationText.getText().toString().contains("minimized")); |
| 739 | } |
| 740 | |
| 741 | @Test |
| 742 | public void testUndoText_block() throws Exception { |
| 743 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 744 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 745 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 746 | |
| 747 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 748 | waitForUndoButton(); |
| 749 | TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text); |
| 750 | assertTrue(confirmationText.getText().toString().contains("won't see")); |
| 751 | } |
| 752 | |
| 753 | @Test |
| 754 | public void testNoHeaderOnConfirmation() throws Exception { |
| 755 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 756 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 757 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 758 | |
| 759 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 760 | waitForUndoButton(); |
| 761 | assertEquals(GONE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 762 | } |
| 763 | |
| 764 | @Test |
| 765 | public void testHeaderOnUndo() throws Exception { |
| 766 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 767 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 768 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 769 | |
| 770 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 771 | waitForUndoButton(); |
| 772 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 773 | waitForStopButton(); |
| 774 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 775 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 776 | } |