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 | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 19 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 20 | import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 21 | import static android.view.View.GONE; |
| 22 | import static android.view.View.VISIBLE; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 23 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 24 | import static junit.framework.Assert.assertEquals; |
| 25 | import static junit.framework.Assert.assertFalse; |
| 26 | import static junit.framework.Assert.assertTrue; |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 27 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 28 | import static org.mockito.Mockito.any; |
| 29 | import static org.mockito.Mockito.anyBoolean; |
| 30 | import static org.mockito.Mockito.anyInt; |
| 31 | import static org.mockito.Mockito.anyString; |
| 32 | import static org.mockito.Mockito.eq; |
| 33 | import static org.mockito.Mockito.mock; |
| 34 | import static org.mockito.Mockito.never; |
| 35 | import static org.mockito.Mockito.times; |
| 36 | import static org.mockito.Mockito.verify; |
| 37 | import static org.mockito.Mockito.when; |
| 38 | |
| 39 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 40 | import android.app.Notification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 41 | import android.app.NotificationChannel; |
| 42 | import android.app.NotificationChannelGroup; |
| 43 | import android.app.NotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 44 | import android.content.Intent; |
| 45 | import android.content.pm.ActivityInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 46 | import android.content.pm.ApplicationInfo; |
| 47 | import android.content.pm.PackageInfo; |
| 48 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 49 | import android.content.pm.ResolveInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 50 | import android.graphics.drawable.Drawable; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 51 | import android.os.UserHandle; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 52 | import android.service.notification.StatusBarNotification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 53 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 54 | import android.testing.AndroidTestingRunner; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 55 | import android.testing.PollingCheck; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 56 | import android.testing.UiThreadTest; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 57 | import android.view.LayoutInflater; |
| 58 | import android.view.View; |
| 59 | import android.widget.ImageView; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 60 | import android.widget.TextView; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 61 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 62 | import com.android.systemui.R; |
| 63 | import com.android.systemui.SysuiTestCase; |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 64 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 65 | import org.junit.Before; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 66 | import org.junit.Test; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 67 | import org.junit.runner.RunWith; |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 68 | import org.mockito.ArgumentCaptor; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 69 | |
| 70 | import java.util.ArrayList; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 71 | import java.util.Collections; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 72 | import java.util.List; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 73 | import java.util.concurrent.CountDownLatch; |
| 74 | |
| 75 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 76 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 77 | @UiThreadTest |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 78 | public class NotificationInfoTest extends SysuiTestCase { |
| 79 | private static final String TEST_PACKAGE_NAME = "test_package"; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 80 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 81 | private static final int TEST_UID = 1; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 82 | private static final String TEST_CHANNEL = "test_channel"; |
| 83 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 84 | |
| 85 | private NotificationInfo mNotificationInfo; |
| 86 | private final INotificationManager mMockINotificationManager = mock(INotificationManager.class); |
| 87 | private final PackageManager mMockPackageManager = mock(PackageManager.class); |
| 88 | private NotificationChannel mNotificationChannel; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 89 | private NotificationChannel mDefaultNotificationChannel; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 90 | private StatusBarNotification mSbn; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 91 | |
| 92 | @Before |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 93 | public void setUp() throws Exception { |
| 94 | // Inflate the layout |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 95 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 96 | mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, |
| 97 | null); |
| 98 | |
| 99 | // PackageManager must return a packageInfo and applicationInfo. |
| 100 | final PackageInfo packageInfo = new PackageInfo(); |
| 101 | packageInfo.packageName = TEST_PACKAGE_NAME; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 102 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 103 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 104 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 105 | applicationInfo.uid = TEST_UID; // non-zero |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 106 | when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn( |
| 107 | applicationInfo); |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 108 | final PackageInfo systemPackageInfo = new PackageInfo(); |
| 109 | systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; |
| 110 | when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) |
| 111 | .thenReturn(systemPackageInfo); |
| 112 | when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) |
| 113 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 114 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 115 | // Package has one channel by default. |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 116 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 117 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 118 | |
| 119 | // Some test channels. |
| 120 | mNotificationChannel = new NotificationChannel( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 121 | TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 122 | mDefaultNotificationChannel = new NotificationChannel( |
| 123 | NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 124 | IMPORTANCE_LOW); |
Julia Reynolds | 33bef2c | 2017-09-05 11:07:18 -0400 | [diff] [blame] | 125 | 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] | 126 | new Notification(), UserHandle.CURRENT, null, 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 127 | } |
| 128 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 129 | // TODO: if tests are taking too long replace this with something that makes the animation |
| 130 | // finish instantly. |
| 131 | private void waitForUndoButton() { |
| 132 | PollingCheck.waitFor(1000, |
| 133 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 134 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 135 | private void waitForStopButton() { |
| 136 | PollingCheck.waitFor(1000, |
| 137 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 138 | } |
| 139 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 140 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 141 | public void testBindNotification_SetsTextApplicationName() throws Exception { |
| 142 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
| 143 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 144 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
| 145 | final TextView textView = mNotificationInfo.findViewById(R.id.pkgname); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 146 | assertTrue(textView.getText().toString().contains("App Name")); |
| 147 | } |
| 148 | |
| 149 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 150 | public void testBindNotification_SetsPackageIcon() throws Exception { |
| 151 | final Drawable iconDrawable = mock(Drawable.class); |
| 152 | when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) |
| 153 | .thenReturn(iconDrawable); |
| 154 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 155 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
| 156 | final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 157 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 158 | } |
| 159 | |
| 160 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 161 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
| 162 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 163 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
| 164 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
| 165 | assertEquals(GONE, groupNameView.getVisibility()); |
| 166 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
| 167 | assertEquals(GONE, groupDividerView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 171 | public void testBindNotification_SetsGroupNameIfNonNull() throws Exception { |
| 172 | mNotificationChannel.setGroup("test_group_id"); |
| 173 | final NotificationChannelGroup notificationChannelGroup = |
| 174 | new NotificationChannelGroup("test_group_id", "Test Group Name"); |
| 175 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 176 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 177 | .thenReturn(notificationChannelGroup); |
| 178 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 179 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
| 180 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 181 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 182 | assertEquals("Test Group Name", groupNameView.getText()); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 183 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 184 | assertEquals(View.VISIBLE, groupDividerView.getVisibility()); |
| 185 | } |
| 186 | |
| 187 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 188 | public void testBindNotification_SetsTextChannelName() throws Exception { |
| 189 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 190 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
| 191 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 192 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 193 | } |
| 194 | |
| 195 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 196 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
| 197 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 198 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, null); |
| 199 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 200 | assertEquals(GONE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 204 | public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception { |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 205 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 206 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, |
| 207 | Collections.singleton(TEST_PACKAGE_NAME)); |
| 208 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 209 | assertEquals(VISIBLE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 213 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 214 | final CountDownLatch latch = new CountDownLatch(1); |
| 215 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 216 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 217 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 218 | assertEquals(mNotificationChannel, c); |
| 219 | latch.countDown(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 220 | }, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 221 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 222 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 223 | settingsButton.performClick(); |
| 224 | // Verify that listener was triggered. |
| 225 | assertEquals(0, latch.getCount()); |
| 226 | } |
| 227 | |
| 228 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 229 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
| 230 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 231 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
| 232 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 233 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 234 | } |
| 235 | |
| 236 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 237 | public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception { |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 238 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 239 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 240 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 241 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
| 242 | (View v, NotificationChannel c, int appUid) -> { |
| 243 | }, null, null); |
| 244 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 245 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 246 | } |
| 247 | |
| 248 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 249 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 250 | final CountDownLatch latch = new CountDownLatch(1); |
| 251 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 252 | TEST_PACKAGE_NAME, mNotificationChannel, 2, mSbn, null, |
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(null, c); |
| 255 | latch.countDown(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 256 | }, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 257 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 258 | mNotificationInfo.findViewById(R.id.info).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 259 | // Verify that listener was triggered. |
| 260 | assertEquals(0, latch.getCount()); |
| 261 | } |
| 262 | |
| 263 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 264 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 265 | public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 266 | throws Exception { |
| 267 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 268 | TEST_PACKAGE_NAME, mNotificationChannel, 2, mSbn, null, null, null, null); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 269 | final TextView channelNameView = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 270 | mNotificationInfo.findViewById(R.id.channel_name); |
| 271 | assertEquals(GONE, channelNameView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | @Test |
| 275 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 276 | public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 277 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 278 | TEST_PACKAGE_NAME, mNotificationChannel, 2, mSbn, null, null, null, null); |
| 279 | final TextView blockView = mNotificationInfo.findViewById(R.id.block); |
| 280 | assertEquals(GONE, blockView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | @Test |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 284 | public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception { |
| 285 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 286 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 287 | null, Collections.singleton(TEST_PACKAGE_NAME)); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 288 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 289 | assertEquals(View.VISIBLE, view.getVisibility()); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 290 | assertEquals(mContext.getString(R.string.notification_unblockable_desc), |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 291 | view.getText()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 295 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
| 296 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 297 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 298 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 299 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 303 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 304 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 305 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 306 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 307 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 308 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 309 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 310 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 314 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 315 | throws Exception { |
| 316 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 317 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 318 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 319 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 320 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 321 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 325 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 326 | throws Exception { |
| 327 | mNotificationChannel.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED); |
| 328 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 329 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 330 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 331 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 332 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 333 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 337 | public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 338 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 339 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 340 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 341 | null, Collections.singleton(TEST_PACKAGE_NAME)); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 342 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 343 | waitForUndoButton(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 344 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 345 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 349 | public void testBlockChangedCallsUpdateNotificationChannel() throws Exception { |
| 350 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 351 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 352 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, null); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 353 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 354 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 355 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 356 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 357 | |
| 358 | ArgumentCaptor<NotificationChannel> updated = |
| 359 | ArgumentCaptor.forClass(NotificationChannel.class); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 360 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 361 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 362 | assertTrue((updated.getValue().getUserLockedFields() |
| 363 | & NotificationChannel.USER_LOCKED_IMPORTANCE) != 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 367 | public void testBlockUndoDoesNotCallUpdateNotificationChannel() throws Exception { |
| 368 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 369 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 370 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, |
| 371 | Collections.singleton(TEST_PACKAGE_NAME)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 372 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 373 | |
| 374 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 375 | waitForUndoButton(); |
| 376 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 377 | waitForStopButton(); |
| 378 | mNotificationInfo.handleCloseControls(true, false); |
| 379 | |
| 380 | ArgumentCaptor<NotificationChannel> updated = |
| 381 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 382 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 383 | anyString(), eq(TEST_UID), updated.capture()); |
| 384 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 385 | } |
| 386 | |
| 387 | @Test |
| 388 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 389 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 390 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 391 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, |
| 392 | Collections.singleton(TEST_PACKAGE_NAME)); |
| 393 | |
| 394 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 395 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 396 | mNotificationInfo.handleCloseControls(false, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 397 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 398 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 399 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 400 | |
| 401 | @Test |
| 402 | public void testCloseControlsDoesNotUpdateIfCheckSaveListenerIsNoOp() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 403 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 404 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 405 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 406 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 407 | }, null, null, Collections.singleton(TEST_PACKAGE_NAME)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 408 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 409 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 410 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 411 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 412 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 413 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | @Test |
| 417 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 418 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 419 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 420 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 421 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 422 | saveImportance.run(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 423 | }, null, null, null); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 424 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 425 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 426 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 427 | mNotificationInfo.handleCloseControls(true, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 428 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 429 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 430 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 431 | |
| 432 | @Test |
| 433 | public void testDisplaySettingsLink() throws Exception { |
| 434 | final CountDownLatch latch = new CountDownLatch(1); |
| 435 | final String settingsText = "work chats"; |
| 436 | final ResolveInfo ri = new ResolveInfo(); |
| 437 | ri.activityInfo = new ActivityInfo(); |
| 438 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 439 | ri.activityInfo.name = "something"; |
| 440 | List<ResolveInfo> ris = new ArrayList<>(); |
| 441 | ris.add(ri); |
| 442 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 443 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 444 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 445 | .setSettingsText(settingsText).build(); |
| 446 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 447 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 448 | |
| 449 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 450 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 451 | (View v, Intent intent) -> { |
| 452 | latch.countDown(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 453 | }, null); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 454 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 455 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 456 | settingsLink.performClick(); |
| 457 | assertEquals(0, latch.getCount()); |
| 458 | } |
| 459 | |
| 460 | @Test |
| 461 | public void testDisplaySettingsLink_multipleChannels() throws Exception { |
| 462 | final CountDownLatch latch = new CountDownLatch(1); |
| 463 | final String settingsText = "work chats"; |
| 464 | final ResolveInfo ri = new ResolveInfo(); |
| 465 | ri.activityInfo = new ActivityInfo(); |
| 466 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 467 | ri.activityInfo.name = "something"; |
| 468 | List<ResolveInfo> ris = new ArrayList<>(); |
| 469 | ris.add(ri); |
| 470 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 471 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 472 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 473 | .setSettingsText(settingsText).build(); |
| 474 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 475 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 476 | |
| 477 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 478 | TEST_PACKAGE_NAME, mNotificationChannel, 2, sbn, null, null, |
| 479 | (View v, Intent intent) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 480 | latch.countDown(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 481 | }, null); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 482 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 483 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 484 | settingsLink.performClick(); |
| 485 | assertEquals(0, latch.getCount()); |
| 486 | } |
| 487 | |
| 488 | @Test |
| 489 | public void testNoSettingsLink_noHandlingActivity() throws Exception { |
| 490 | final String settingsText = "work chats"; |
| 491 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(null); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 492 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 493 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 494 | .setSettingsText(settingsText).build(); |
| 495 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 496 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 497 | |
| 498 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 499 | TEST_PACKAGE_NAME, mNotificationChannel, 2, sbn, null, null, null, null); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 500 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 501 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | @Test |
| 505 | public void testNoSettingsLink_noLinkText() throws Exception { |
| 506 | final ResolveInfo ri = new ResolveInfo(); |
| 507 | ri.activityInfo = new ActivityInfo(); |
| 508 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 509 | ri.activityInfo.name = "something"; |
| 510 | List<ResolveInfo> ris = new ArrayList<>(); |
| 511 | ris.add(ri); |
| 512 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 513 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 514 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()).build(); |
| 515 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 516 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 517 | |
| 518 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 519 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, null); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 520 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 521 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 522 | } |
| 523 | |
Geoffrey Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 524 | |
| 525 | @Test |
| 526 | public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception { |
| 527 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 528 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 529 | } |