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 | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 19 | import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; |
| 20 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 21 | import static junit.framework.Assert.assertEquals; |
| 22 | import static junit.framework.Assert.assertFalse; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 23 | import static junit.framework.Assert.assertNull; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 24 | import static junit.framework.Assert.assertTrue; |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 25 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 26 | import static org.mockito.Mockito.any; |
| 27 | import static org.mockito.Mockito.anyBoolean; |
| 28 | import static org.mockito.Mockito.anyInt; |
| 29 | import static org.mockito.Mockito.anyString; |
| 30 | import static org.mockito.Mockito.eq; |
| 31 | import static org.mockito.Mockito.mock; |
| 32 | import static org.mockito.Mockito.never; |
| 33 | import static org.mockito.Mockito.times; |
| 34 | import static org.mockito.Mockito.verify; |
| 35 | import static org.mockito.Mockito.when; |
| 36 | |
| 37 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 38 | import android.app.Notification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 39 | import android.app.NotificationChannel; |
| 40 | import android.app.NotificationChannelGroup; |
| 41 | import android.app.NotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 42 | import android.content.Intent; |
| 43 | import android.content.pm.ActivityInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 44 | import android.content.pm.ApplicationInfo; |
| 45 | import android.content.pm.PackageInfo; |
| 46 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 47 | import android.content.pm.ResolveInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 48 | import android.graphics.drawable.Drawable; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 49 | import android.os.UserHandle; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 50 | import android.service.notification.StatusBarNotification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 51 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 52 | import android.testing.AndroidTestingRunner; |
| 53 | import android.testing.UiThreadTest; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 54 | import android.view.LayoutInflater; |
| 55 | import android.view.View; |
| 56 | import android.widget.ImageView; |
| 57 | import android.widget.Switch; |
| 58 | import android.widget.TextView; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 59 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 60 | import com.android.systemui.R; |
| 61 | import com.android.systemui.SysuiTestCase; |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 62 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 63 | import org.junit.Before; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 64 | import org.junit.Test; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 65 | import org.junit.runner.RunWith; |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 66 | import org.mockito.ArgumentCaptor; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 67 | |
| 68 | import java.util.ArrayList; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 69 | import java.util.Arrays; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 70 | import java.util.Collections; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 71 | import java.util.List; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 72 | import java.util.concurrent.CountDownLatch; |
| 73 | |
| 74 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 75 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 76 | @UiThreadTest |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 77 | public class NotificationInfoTest extends SysuiTestCase { |
| 78 | private static final String TEST_PACKAGE_NAME = "test_package"; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 79 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 80 | private static final int TEST_UID = 1; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 81 | private static final String TEST_CHANNEL = "test_channel"; |
| 82 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 83 | |
| 84 | private NotificationInfo mNotificationInfo; |
| 85 | private final INotificationManager mMockINotificationManager = mock(INotificationManager.class); |
| 86 | private final PackageManager mMockPackageManager = mock(PackageManager.class); |
| 87 | private NotificationChannel mNotificationChannel; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 88 | private NotificationChannel mDefaultNotificationChannel; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 89 | private StatusBarNotification mSbn; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 90 | |
| 91 | @Before |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 92 | public void setUp() throws Exception { |
| 93 | // Inflate the layout |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 94 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 95 | mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, |
| 96 | null); |
| 97 | |
| 98 | // PackageManager must return a packageInfo and applicationInfo. |
| 99 | final PackageInfo packageInfo = new PackageInfo(); |
| 100 | packageInfo.packageName = TEST_PACKAGE_NAME; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 101 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 102 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 103 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 104 | applicationInfo.uid = TEST_UID; // non-zero |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 105 | when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn( |
| 106 | applicationInfo); |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 107 | final PackageInfo systemPackageInfo = new PackageInfo(); |
| 108 | systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; |
| 109 | when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) |
| 110 | .thenReturn(systemPackageInfo); |
| 111 | when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) |
| 112 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 113 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 114 | // Package has one channel by default. |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 115 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 116 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 117 | |
| 118 | // Some test channels. |
| 119 | mNotificationChannel = new NotificationChannel( |
| 120 | TEST_CHANNEL, TEST_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); |
| 121 | mDefaultNotificationChannel = new NotificationChannel( |
| 122 | NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, |
| 123 | NotificationManager.IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 124 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, 0, 0, |
| 125 | new Notification(), UserHandle.CURRENT, null, 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | private CharSequence getStringById(int resId) { |
| 129 | return mContext.getString(resId); |
| 130 | } |
| 131 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 132 | private CharSequence getNumChannelsDescString(int numChannels) { |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 133 | return String.format( |
| 134 | mContext.getResources().getQuantityString( |
| 135 | R.plurals.notification_num_channels_desc, numChannels), |
| 136 | numChannels); |
| 137 | } |
| 138 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 139 | private CharSequence getChannelsListDescString(NotificationChannel... channels) { |
| 140 | if (channels.length == 2) { |
| 141 | return mContext.getString(R.string.notification_channels_list_desc_2, |
| 142 | channels[0].getName(), channels[1].getName()); |
| 143 | } else { |
| 144 | final int numOthers = channels.length - 2; |
| 145 | return String.format( |
| 146 | mContext.getResources().getQuantityString( |
| 147 | R.plurals.notification_channels_list_desc_2_and_others, numOthers), |
| 148 | channels[0].getName(), channels[1].getName(), numOthers); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | private CharSequence getNumChannelsString(int numChannels) { |
| 153 | return mContext.getString(R.string.notification_num_channels, numChannels); |
| 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, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 160 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 161 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 162 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 163 | final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.pkgname); |
| 164 | assertTrue(textView.getText().toString().contains("App Name")); |
| 165 | } |
| 166 | |
| 167 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 168 | public void testBindNotification_SetsPackageIcon() throws Exception { |
| 169 | final Drawable iconDrawable = mock(Drawable.class); |
| 170 | when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) |
| 171 | .thenReturn(iconDrawable); |
| 172 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 173 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 174 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 175 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 176 | final ImageView iconView = (ImageView) mNotificationInfo.findViewById(R.id.pkgicon); |
| 177 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 178 | } |
| 179 | |
| 180 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 181 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
| 182 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 183 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 184 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 185 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 186 | final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name); |
| 187 | assertEquals(View.GONE, groupNameView.getVisibility()); |
| 188 | final TextView groupDividerView = |
| 189 | (TextView) mNotificationInfo.findViewById(R.id.pkg_group_divider); |
| 190 | assertEquals(View.GONE, groupDividerView.getVisibility()); |
| 191 | } |
| 192 | |
| 193 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 194 | public void testBindNotification_SetsGroupNameIfNonNull() throws Exception { |
| 195 | mNotificationChannel.setGroup("test_group_id"); |
| 196 | final NotificationChannelGroup notificationChannelGroup = |
| 197 | new NotificationChannelGroup("test_group_id", "Test Group Name"); |
| 198 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 199 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 200 | .thenReturn(notificationChannelGroup); |
| 201 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 202 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 203 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 204 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 205 | final TextView groupNameView = (TextView) mNotificationInfo.findViewById(R.id.group_name); |
| 206 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 207 | assertEquals("Test Group Name", groupNameView.getText()); |
| 208 | final TextView groupDividerView = |
| 209 | (TextView) mNotificationInfo.findViewById(R.id.pkg_group_divider); |
| 210 | assertEquals(View.VISIBLE, groupDividerView.getVisibility()); |
| 211 | } |
| 212 | |
| 213 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 214 | public void testBindNotification_SetsTextChannelName() throws Exception { |
| 215 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 216 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 217 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 218 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 219 | final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name); |
| 220 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 221 | } |
| 222 | |
| 223 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 224 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
| 225 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 226 | TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), |
| 227 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 228 | null, null); |
| 229 | final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name); |
| 230 | assertEquals(mContext.getString(R.string.notification_header_default_channel), |
| 231 | textView.getText()); |
| 232 | } |
| 233 | |
| 234 | @Test |
| 235 | public void testBindNotification_DefaultChannelUsesNameWhenMoreThanOneChannelExists() |
| 236 | throws Exception { |
| 237 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 238 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 239 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 240 | TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), |
| 241 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 242 | null, null); |
| 243 | final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name); |
| 244 | assertEquals(mDefaultNotificationChannel.getName(), textView.getText()); |
| 245 | } |
| 246 | |
| 247 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 248 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 249 | final CountDownLatch latch = new CountDownLatch(1); |
| 250 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 251 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 252 | mNotificationChannel.getImportance(), mSbn, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 253 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 254 | assertEquals(mNotificationChannel, c); |
| 255 | latch.countDown(); |
| 256 | }, null, null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 257 | |
| 258 | final TextView settingsButton = |
| 259 | (TextView) mNotificationInfo.findViewById(R.id.more_settings); |
| 260 | settingsButton.performClick(); |
| 261 | // Verify that listener was triggered. |
| 262 | assertEquals(0, latch.getCount()); |
| 263 | } |
| 264 | |
| 265 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 266 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
| 267 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 268 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 269 | mNotificationChannel.getImportance(), mSbn, null, null, null, null, null); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 270 | final TextView settingsButton = |
| 271 | (TextView) mNotificationInfo.findViewById(R.id.more_settings); |
| 272 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 273 | } |
| 274 | |
| 275 | @Test |
| 276 | public void testBindNotification_SettingsButtonReappersAfterSecondBind() throws Exception { |
| 277 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 278 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
Julia Reynolds | 4740b61 | 2017-04-06 12:31:56 -0400 | [diff] [blame] | 279 | mNotificationChannel.getImportance(), mSbn, null, null, null, null, null); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 280 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 281 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 282 | mNotificationChannel.getImportance(), mSbn, |
| 283 | (View v, NotificationChannel c, int appUid) -> {}, null, null, null, null); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 284 | final TextView settingsButton = |
| 285 | (TextView) mNotificationInfo.findViewById(R.id.more_settings); |
| 286 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 287 | } |
| 288 | |
| 289 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 290 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 291 | final CountDownLatch latch = new CountDownLatch(1); |
| 292 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 293 | TEST_PACKAGE_NAME, |
| 294 | Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 295 | mNotificationChannel.getImportance(), mSbn, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 296 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 297 | assertEquals(null, c); |
| 298 | latch.countDown(); |
| 299 | }, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 300 | |
| 301 | final TextView settingsButton = |
| 302 | (TextView) mNotificationInfo.findViewById(R.id.more_settings); |
| 303 | settingsButton.performClick(); |
| 304 | // Verify that listener was triggered. |
| 305 | assertEquals(0, latch.getCount()); |
| 306 | } |
| 307 | |
| 308 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 309 | public void testBindNotification_SettingsTextWithOneChannel() throws Exception { |
| 310 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 311 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 312 | mNotificationChannel.getImportance(), mSbn, |
| 313 | (View v, NotificationChannel c, int appUid) -> { |
| 314 | }, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 315 | final TextView settingsButton = |
| 316 | (TextView) mNotificationInfo.findViewById(R.id.more_settings); |
| 317 | assertEquals(getStringById(R.string.notification_more_settings), settingsButton.getText()); |
| 318 | } |
| 319 | |
| 320 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 321 | public void testBindNotification_SettingsTextWithMultipleChannels() throws Exception { |
| 322 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 323 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 324 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 325 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 326 | mNotificationChannel.getImportance(), mSbn, |
| 327 | (View v, NotificationChannel c, int appUid) -> { |
| 328 | }, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 329 | final TextView settingsButton = |
| 330 | (TextView) mNotificationInfo.findViewById(R.id.more_settings); |
| 331 | assertEquals(getStringById(R.string.notification_all_categories), settingsButton.getText()); |
| 332 | } |
| 333 | |
| 334 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 335 | public void testBindNotification_SetsOnClickListenerForDone() throws Exception { |
| 336 | final CountDownLatch latch = new CountDownLatch(1); |
| 337 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 338 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 339 | mNotificationChannel.getImportance(), mSbn, null, |
| 340 | null, (View v) -> { |
| 341 | latch.countDown(); |
| 342 | }, |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 343 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 344 | |
| 345 | final TextView doneButton = (TextView) mNotificationInfo.findViewById(R.id.done); |
| 346 | doneButton.performClick(); |
| 347 | // Verify that listener was triggered. |
| 348 | assertEquals(0, latch.getCount()); |
| 349 | } |
| 350 | |
| 351 | @Test |
Geoffrey Pitsch | 0a8f055 | 2017-04-20 13:56:40 -0400 | [diff] [blame] | 352 | public void testBindNotification_NumChannelsTextHiddenWhenDefaultChannel() throws Exception { |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 353 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 354 | TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 355 | mNotificationChannel.getImportance(), mSbn, null, null, |
| 356 | null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 357 | final TextView numChannelsView = |
| 358 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
Geoffrey Pitsch | 0a8f055 | 2017-04-20 13:56:40 -0400 | [diff] [blame] | 359 | assertEquals(View.INVISIBLE, numChannelsView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 363 | public void testBindNotification_NumChannelsTextDisplaysWhenMoreThanOneChannelExists() |
| 364 | throws Exception { |
| 365 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 366 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 367 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 368 | TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), |
| 369 | mNotificationChannel.getImportance(), mSbn, null, null, |
| 370 | null, null, null); |
| 371 | final TextView numChannelsView = |
| 372 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
| 373 | assertEquals(numChannelsView.getVisibility(), View.VISIBLE); |
| 374 | assertEquals(getNumChannelsDescString(2), numChannelsView.getText()); |
| 375 | } |
| 376 | |
| 377 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 378 | public void testBindNotification_NumChannelsTextDisplaysWhenNotDefaultChannel() |
| 379 | throws Exception { |
| 380 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 381 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 382 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 383 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 384 | final TextView numChannelsView = |
| 385 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
| 386 | assertEquals(numChannelsView.getVisibility(), View.VISIBLE); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 387 | assertEquals(getNumChannelsDescString(1), numChannelsView.getText()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 391 | public void testBindNotification_NumChannelsTextScalesWithNumberOfChannels() |
| 392 | throws Exception { |
| 393 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 394 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 395 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 396 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 397 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 398 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 399 | final TextView numChannelsView = |
| 400 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 401 | assertEquals(getNumChannelsDescString(2), numChannelsView.getText()); |
| 402 | } |
| 403 | |
| 404 | @Test |
| 405 | @UiThreadTest |
| 406 | public void testBindNotification_NumChannelsTextListsChannelsWhenTwoInBundle() |
| 407 | throws Exception { |
| 408 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 409 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 410 | mNotificationChannel.getImportance(), mSbn, null, null, null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 411 | final TextView numChannelsView = |
| 412 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
| 413 | assertEquals(getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel), |
| 414 | numChannelsView.getText()); |
| 415 | } |
| 416 | |
| 417 | @Test |
| 418 | @UiThreadTest |
| 419 | public void testBindNotification_NumChannelsTextListsChannelsWhenThreeInBundle() |
| 420 | throws Exception { |
| 421 | NotificationChannel thirdChannel = new NotificationChannel( |
| 422 | "third_channel", "third_channel", NotificationManager.IMPORTANCE_LOW); |
| 423 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 424 | TEST_PACKAGE_NAME, |
| 425 | Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 426 | mNotificationChannel.getImportance(), mSbn, null, null, null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 427 | final TextView numChannelsView = |
| 428 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
| 429 | assertEquals( |
| 430 | getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel, |
| 431 | thirdChannel), |
| 432 | numChannelsView.getText()); |
| 433 | } |
| 434 | |
| 435 | @Test |
| 436 | @UiThreadTest |
| 437 | public void testBindNotification_NumChannelsTextListsChannelsWhenFourInBundle() |
| 438 | throws Exception { |
| 439 | NotificationChannel thirdChannel = new NotificationChannel( |
| 440 | "third_channel", "third_channel", NotificationManager.IMPORTANCE_LOW); |
| 441 | NotificationChannel fourthChannel = new NotificationChannel( |
| 442 | "fourth_channel", "fourth_channel", NotificationManager.IMPORTANCE_LOW); |
| 443 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 444 | TEST_PACKAGE_NAME, |
| 445 | Arrays.asList(mNotificationChannel, mDefaultNotificationChannel, thirdChannel, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 446 | fourthChannel), mNotificationChannel.getImportance(), mSbn, null, null, |
| 447 | null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 448 | final TextView numChannelsView = |
| 449 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
| 450 | assertEquals( |
| 451 | getChannelsListDescString(mNotificationChannel, mDefaultNotificationChannel, |
| 452 | thirdChannel, fourthChannel), |
| 453 | numChannelsView.getText()); |
| 454 | } |
| 455 | |
| 456 | @Test |
| 457 | @UiThreadTest |
| 458 | public void testBindNotification_ChannelNameChangesWhenBundleFromDifferentChannels() |
| 459 | throws Exception { |
| 460 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 461 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 462 | mNotificationChannel.getImportance(), mSbn, null, null, null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 463 | final TextView channelNameView = |
| 464 | (TextView) mNotificationInfo.findViewById(R.id.channel_name); |
| 465 | assertEquals(getNumChannelsString(2), channelNameView.getText()); |
| 466 | } |
| 467 | |
| 468 | @Test |
| 469 | @UiThreadTest |
| 470 | public void testEnabledSwitchInvisibleIfBundleFromDifferentChannels() throws Exception { |
| 471 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 472 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 473 | mNotificationChannel.getImportance(), mSbn, null, null, null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 474 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 475 | assertEquals(View.INVISIBLE, enabledSwitch.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 479 | public void testbindNotification_ChannelDisabledTextGoneWhenNotDisabled() throws Exception { |
| 480 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 481 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 482 | mNotificationChannel.getImportance(), mSbn, null, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 483 | final TextView channelDisabledView = |
| 484 | (TextView) mNotificationInfo.findViewById(R.id.channel_disabled); |
| 485 | assertEquals(channelDisabledView.getVisibility(), View.GONE); |
| 486 | } |
| 487 | |
| 488 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 489 | public void testbindNotification_ChannelDisabledTextVisibleWhenDisabled() throws Exception { |
| 490 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); |
| 491 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 492 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 493 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 494 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 495 | final TextView channelDisabledView = |
| 496 | (TextView) mNotificationInfo.findViewById(R.id.channel_disabled); |
| 497 | assertEquals(channelDisabledView.getVisibility(), View.VISIBLE); |
| 498 | // Replaces the numChannelsView |
| 499 | final TextView numChannelsView = |
| 500 | (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); |
| 501 | assertEquals(numChannelsView.getVisibility(), View.GONE); |
| 502 | } |
| 503 | |
| 504 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 505 | @UiThreadTest |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 506 | public void testBindNotification_ChannelDisabledTextShowsForDefaultChannel() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 507 | throws Exception { |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 508 | mDefaultNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 509 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 510 | TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 511 | mDefaultNotificationChannel.getImportance(), mSbn, null, null, |
| 512 | null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 513 | final TextView channelDisabledView = |
| 514 | (TextView) mNotificationInfo.findViewById(R.id.channel_disabled); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 515 | assertEquals(View.VISIBLE, channelDisabledView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 519 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
| 520 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 521 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 522 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 523 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 524 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 525 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 529 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
| 530 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 531 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 532 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 533 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 534 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 535 | |
| 536 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 537 | enabledSwitch.setChecked(false); |
| 538 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 539 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 543 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 544 | throws Exception { |
| 545 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 546 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 547 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 548 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 549 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 550 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 551 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 552 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 556 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 557 | throws Exception { |
| 558 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED); |
| 559 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 560 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 561 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 562 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 563 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 564 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 565 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 566 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 570 | public void testEnabledSwitchOnByDefault() throws Exception { |
| 571 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 572 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 573 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 574 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 575 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 576 | |
| 577 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 578 | assertTrue(enabledSwitch.isChecked()); |
| 579 | } |
| 580 | |
| 581 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 582 | public void testEnabledButtonOffWhenAlreadyBanned() throws Exception { |
| 583 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); |
| 584 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 585 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 586 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 587 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 588 | |
| 589 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 590 | assertFalse(enabledSwitch.isChecked()); |
| 591 | } |
| 592 | |
| 593 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 594 | public void testEnabledSwitchVisibleByDefault() throws Exception { |
| 595 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 596 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 597 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 598 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 599 | null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 600 | |
| 601 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 602 | assertEquals(View.VISIBLE, enabledSwitch.getVisibility()); |
| 603 | } |
| 604 | |
| 605 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 606 | public void testEnabledSwitchInvisibleIfNonBlockable() throws Exception { |
| 607 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 608 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 609 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 610 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 611 | null, Collections.singleton(TEST_PACKAGE_NAME)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 612 | |
| 613 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 614 | assertEquals(View.INVISIBLE, enabledSwitch.getVisibility()); |
| 615 | } |
| 616 | |
| 617 | @Test |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 618 | public void testEnabledSwitchInvisibleIfNonBlockableSystemChannel() throws Exception { |
| 619 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 620 | mNotificationChannel.setBlockableSystem(false); |
| 621 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 622 | TEST_SYSTEM_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 623 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 624 | null, null); |
| 625 | |
| 626 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 627 | assertEquals(View.INVISIBLE, enabledSwitch.getVisibility()); |
| 628 | } |
| 629 | |
| 630 | @Test |
| 631 | public void testEnabledSwitchVisibleIfBlockableSystemChannel() throws Exception { |
| 632 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 633 | mNotificationChannel.setBlockableSystem(true); |
| 634 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 635 | TEST_SYSTEM_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 636 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 637 | null, null); |
| 638 | |
| 639 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 640 | assertEquals(View.VISIBLE, enabledSwitch.getVisibility()); |
| 641 | } |
| 642 | |
| 643 | @Test |
| 644 | public void testEnabledSwitchInvisibleIfMultiChannelSummary() throws Exception { |
| 645 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 646 | mNotificationChannel.setBlockableSystem(true); |
| 647 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 648 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), |
| 649 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 650 | null, Collections.singleton(TEST_PACKAGE_NAME)); |
| 651 | |
| 652 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 653 | assertEquals(View.INVISIBLE, enabledSwitch.getVisibility()); |
| 654 | } |
| 655 | |
| 656 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 657 | public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception { |
| 658 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 659 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 660 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 661 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 662 | null, Collections.singleton(TEST_PACKAGE_NAME)); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 663 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 664 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 665 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 669 | public void testEnabledSwitchChangedCallsUpdateNotificationChannel() throws Exception { |
| 670 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 671 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 672 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 673 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 674 | null, Collections.singleton(TEST_PACKAGE_NAME)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 675 | |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 676 | Switch enabledSwitch = mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 677 | enabledSwitch.setChecked(false); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 678 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 679 | |
| 680 | ArgumentCaptor<NotificationChannel> updated = |
| 681 | ArgumentCaptor.forClass(NotificationChannel.class); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 682 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 683 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 684 | assertTrue((updated.getValue().getUserLockedFields() |
| 685 | & NotificationChannel.USER_LOCKED_IMPORTANCE) != 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 689 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 690 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 691 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 692 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 693 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 694 | null, Collections.singleton(TEST_PACKAGE_NAME)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 695 | |
| 696 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 697 | enabledSwitch.setChecked(false); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 698 | mNotificationInfo.handleCloseControls(false, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 699 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 700 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 701 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 702 | |
| 703 | @Test |
| 704 | public void testCloseControlsDoesNotUpdateIfCheckSaveListenerIsNoOp() throws Exception { |
| 705 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 706 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 707 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 708 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 709 | (Runnable saveImportance) -> { |
| 710 | }, |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 711 | Collections.singleton(TEST_PACKAGE_NAME)); |
| 712 | |
| 713 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 714 | enabledSwitch.setChecked(false); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 715 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 716 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 717 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | @Test |
| 721 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
| 722 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 723 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 724 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 725 | mNotificationChannel.getImportance(), mSbn, null, null, null, |
| 726 | (Runnable saveImportance) -> { |
| 727 | saveImportance.run(); |
| 728 | }, |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 729 | Collections.singleton(TEST_PACKAGE_NAME)); |
| 730 | |
| 731 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 732 | enabledSwitch.setChecked(false); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 733 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 734 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 735 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 736 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 737 | |
| 738 | @Test |
| 739 | public void testDisplaySettingsLink() throws Exception { |
| 740 | final CountDownLatch latch = new CountDownLatch(1); |
| 741 | final String settingsText = "work chats"; |
| 742 | final ResolveInfo ri = new ResolveInfo(); |
| 743 | ri.activityInfo = new ActivityInfo(); |
| 744 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 745 | ri.activityInfo.name = "something"; |
| 746 | List<ResolveInfo> ris = new ArrayList<>(); |
| 747 | ris.add(ri); |
| 748 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
| 749 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 750 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 751 | .setSettingsText(settingsText).build(); |
| 752 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 753 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 754 | |
| 755 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 756 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 757 | mNotificationChannel.getImportance(), sbn, null, |
| 758 | (View v, Intent intent) -> { |
| 759 | latch.countDown(); |
| 760 | }, null, null, null); |
| 761 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 762 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 763 | assertTrue(settingsLink.getText().toString().length() > settingsText.length()); |
| 764 | assertTrue(settingsLink.getText().toString().contains(settingsText)); |
| 765 | settingsLink.performClick(); |
| 766 | assertEquals(0, latch.getCount()); |
| 767 | } |
| 768 | |
| 769 | @Test |
| 770 | public void testDisplaySettingsLink_multipleChannels() throws Exception { |
| 771 | final CountDownLatch latch = new CountDownLatch(1); |
| 772 | final String settingsText = "work chats"; |
| 773 | final ResolveInfo ri = new ResolveInfo(); |
| 774 | ri.activityInfo = new ActivityInfo(); |
| 775 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 776 | ri.activityInfo.name = "something"; |
| 777 | List<ResolveInfo> ris = new ArrayList<>(); |
| 778 | ris.add(ri); |
| 779 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
| 780 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 781 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 782 | .setSettingsText(settingsText).build(); |
| 783 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 784 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 785 | |
| 786 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 787 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel, mDefaultNotificationChannel), |
| 788 | mNotificationChannel.getImportance(), sbn, null, (View v, Intent intent) -> { |
| 789 | latch.countDown(); |
| 790 | }, null, null, null); |
| 791 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 792 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 793 | settingsLink.performClick(); |
| 794 | assertEquals(0, latch.getCount()); |
| 795 | } |
| 796 | |
| 797 | @Test |
| 798 | public void testNoSettingsLink_noHandlingActivity() throws Exception { |
| 799 | final String settingsText = "work chats"; |
| 800 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(null); |
| 801 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 802 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 803 | .setSettingsText(settingsText).build(); |
| 804 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 805 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 806 | |
| 807 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 808 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 809 | mNotificationChannel.getImportance(), sbn, null, null, null, |
| 810 | null, null); |
| 811 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 812 | assertEquals(View.GONE, settingsLink.getVisibility()); |
| 813 | } |
| 814 | |
| 815 | @Test |
| 816 | public void testNoSettingsLink_noLinkText() throws Exception { |
| 817 | final ResolveInfo ri = new ResolveInfo(); |
| 818 | ri.activityInfo = new ActivityInfo(); |
| 819 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 820 | ri.activityInfo.name = "something"; |
| 821 | List<ResolveInfo> ris = new ArrayList<>(); |
| 822 | ris.add(ri); |
| 823 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
| 824 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 825 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()).build(); |
| 826 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 827 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 828 | |
| 829 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 830 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 831 | mNotificationChannel.getImportance(), sbn, null, null, null, |
| 832 | null, null); |
| 833 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 834 | assertEquals(View.GONE, settingsLink.getVisibility()); |
| 835 | } |
| 836 | |
| 837 | @Test |
| 838 | public void testNoSettingsLink_afterBlockingChannel() throws Exception { |
| 839 | final String settingsText = "work chats"; |
| 840 | final ResolveInfo ri = new ResolveInfo(); |
| 841 | ri.activityInfo = new ActivityInfo(); |
| 842 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 843 | ri.activityInfo.name = "something"; |
| 844 | List<ResolveInfo> ris = new ArrayList<>(); |
| 845 | ris.add(ri); |
| 846 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
| 847 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW); |
| 848 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 849 | .setSettingsText(settingsText).build(); |
| 850 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 851 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 852 | |
| 853 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 854 | TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel), |
| 855 | mNotificationChannel.getImportance(), sbn, null, null, null, |
| 856 | null, null); |
| 857 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 858 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 859 | |
| 860 | // Block channel |
| 861 | Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch); |
| 862 | enabledSwitch.setChecked(false); |
| 863 | |
| 864 | assertEquals(View.GONE, settingsLink.getVisibility()); |
| 865 | |
| 866 | //unblock |
| 867 | enabledSwitch.setChecked(true); |
| 868 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 869 | } |
Geoffrey Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 870 | |
| 871 | @Test |
| 872 | public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception { |
| 873 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 874 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 875 | } |