Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 14 | * limitations under the License |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 18 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 19 | import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 20 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 22 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 23 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 24 | import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 25 | import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 26 | import static android.view.View.GONE; |
| 27 | import static android.view.View.VISIBLE; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 28 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 29 | import static junit.framework.Assert.assertEquals; |
| 30 | import static junit.framework.Assert.assertFalse; |
| 31 | import static junit.framework.Assert.assertTrue; |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 32 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 33 | import static org.mockito.Mockito.any; |
| 34 | import static org.mockito.Mockito.anyBoolean; |
| 35 | import static org.mockito.Mockito.anyInt; |
| 36 | import static org.mockito.Mockito.anyString; |
| 37 | import static org.mockito.Mockito.eq; |
| 38 | import static org.mockito.Mockito.mock; |
| 39 | import static org.mockito.Mockito.never; |
| 40 | import static org.mockito.Mockito.times; |
| 41 | import static org.mockito.Mockito.verify; |
| 42 | import static org.mockito.Mockito.when; |
| 43 | |
| 44 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 45 | import android.app.Notification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 46 | import android.app.NotificationChannel; |
| 47 | import android.app.NotificationChannelGroup; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 48 | import android.content.pm.ApplicationInfo; |
| 49 | import android.content.pm.PackageInfo; |
| 50 | import android.content.pm.PackageManager; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 51 | import android.graphics.drawable.Drawable; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 52 | import android.os.UserHandle; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 53 | import android.provider.Settings; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 54 | import android.service.notification.StatusBarNotification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 55 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 56 | import android.testing.AndroidTestingRunner; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 57 | import android.testing.TestableLooper; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 58 | import android.testing.UiThreadTest; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 59 | import android.view.LayoutInflater; |
| 60 | import android.view.View; |
| 61 | import android.widget.ImageView; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 62 | import android.widget.TextView; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 63 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 64 | import com.android.internal.logging.MetricsLogger; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 65 | import com.android.systemui.Dependency; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 66 | import com.android.systemui.R; |
| 67 | import com.android.systemui.SysuiTestCase; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Beverly | 79c89ec | 2019-12-13 10:33:01 -0500 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 71 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 72 | import org.junit.After; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 73 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 74 | import org.junit.Rule; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 75 | import org.junit.Test; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 76 | import org.junit.runner.RunWith; |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 77 | import org.mockito.ArgumentCaptor; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 78 | import org.mockito.Mock; |
| 79 | import org.mockito.junit.MockitoJUnit; |
| 80 | import org.mockito.junit.MockitoRule; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 81 | |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 82 | import java.util.HashSet; |
| 83 | import java.util.Set; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 84 | import java.util.concurrent.CountDownLatch; |
| 85 | |
| 86 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 87 | @RunWith(AndroidTestingRunner.class) |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 88 | @TestableLooper.RunWithLooper |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 89 | public class NotificationInfoTest extends SysuiTestCase { |
| 90 | private static final String TEST_PACKAGE_NAME = "test_package"; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 91 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 92 | private static final int TEST_UID = 1; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 93 | private static final int MULTIPLE_CHANNEL_COUNT = 2; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 94 | private static final String TEST_CHANNEL = "test_channel"; |
| 95 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 96 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 97 | private TestableLooper mTestableLooper; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 98 | private NotificationInfo mNotificationInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 99 | private NotificationChannel mNotificationChannel; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 100 | private NotificationChannel mDefaultNotificationChannel; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 101 | private Set<NotificationChannel> mNotificationChannelSet = new HashSet<>(); |
| 102 | private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 103 | private StatusBarNotification mSbn; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 104 | private NotificationEntry mEntry; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 105 | |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 106 | @Rule |
| 107 | public MockitoRule mockito = MockitoJUnit.rule(); |
| 108 | @Mock |
| 109 | private MetricsLogger mMetricsLogger; |
| 110 | @Mock |
| 111 | private INotificationManager mMockINotificationManager; |
| 112 | @Mock |
| 113 | private PackageManager mMockPackageManager; |
| 114 | @Mock |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 115 | private VisualStabilityManager mVisualStabilityManager; |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 116 | @Mock |
| 117 | private ChannelEditorDialogController mChannelEditorDialogController; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 118 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 119 | @Before |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 120 | public void setUp() throws Exception { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 121 | mTestableLooper = TestableLooper.get(this); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 122 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 123 | mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper()); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 124 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 125 | // Inflate the layout |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 126 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 127 | mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, |
| 128 | null); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 129 | mNotificationInfo.setGutsParent(mock(NotificationGuts.class)); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 130 | // Our view is never attached to a window so the View#post methods in NotificationInfo never |
| 131 | // get called. Setting this will skip the post and do the action immediately. |
| 132 | mNotificationInfo.mSkipPost = true; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 133 | |
| 134 | // PackageManager must return a packageInfo and applicationInfo. |
| 135 | final PackageInfo packageInfo = new PackageInfo(); |
| 136 | packageInfo.packageName = TEST_PACKAGE_NAME; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 137 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 138 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 139 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 140 | applicationInfo.uid = TEST_UID; // non-zero |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 141 | when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn( |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 142 | applicationInfo); |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 143 | final PackageInfo systemPackageInfo = new PackageInfo(); |
| 144 | systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; |
| 145 | when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) |
| 146 | .thenReturn(systemPackageInfo); |
| 147 | when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) |
| 148 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 149 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 150 | // Package has one channel by default. |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 151 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 152 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 153 | |
| 154 | // Some test channels. |
| 155 | mNotificationChannel = new NotificationChannel( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 156 | TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 157 | mNotificationChannelSet.add(mNotificationChannel); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 158 | mDefaultNotificationChannel = new NotificationChannel( |
| 159 | NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 160 | IMPORTANCE_LOW); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 161 | mDefaultNotificationChannelSet.add(mDefaultNotificationChannel); |
Julia Reynolds | 33bef2c | 2017-09-05 11:07:18 -0400 | [diff] [blame] | 162 | 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] | 163 | new Notification(), UserHandle.CURRENT, null, 0); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 164 | mEntry = new NotificationEntryBuilder().setSbn(mSbn).build(); |
| 165 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 166 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 167 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); |
| 168 | } |
| 169 | |
| 170 | @After |
| 171 | public void tearDown() { |
| 172 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 173 | NOTIFICATION_NEW_INTERRUPTION_MODEL, 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 174 | } |
| 175 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 176 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 177 | public void testBindNotification_SetsTextApplicationName() throws Exception { |
| 178 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 179 | mNotificationInfo.bindNotification( |
| 180 | mMockPackageManager, |
| 181 | mMockINotificationManager, |
| 182 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 183 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 184 | TEST_PACKAGE_NAME, |
| 185 | mNotificationChannel, |
| 186 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 187 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 188 | null, |
| 189 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 190 | true, |
| 191 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 192 | true); |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 193 | final TextView textView = mNotificationInfo.findViewById(R.id.pkg_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 194 | assertTrue(textView.getText().toString().contains("App Name")); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 195 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 199 | public void testBindNotification_SetsPackageIcon() throws Exception { |
| 200 | final Drawable iconDrawable = mock(Drawable.class); |
| 201 | when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) |
| 202 | .thenReturn(iconDrawable); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 203 | mNotificationInfo.bindNotification( |
| 204 | mMockPackageManager, |
| 205 | mMockINotificationManager, |
| 206 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 207 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 208 | TEST_PACKAGE_NAME, |
| 209 | mNotificationChannel, |
| 210 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 211 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 212 | null, |
| 213 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 214 | true, |
| 215 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 216 | true); |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 217 | final ImageView iconView = mNotificationInfo.findViewById(R.id.pkg_icon); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 218 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 219 | } |
| 220 | |
| 221 | @Test |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 222 | public void testBindNotification_noDelegate() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 223 | mNotificationInfo.bindNotification( |
| 224 | mMockPackageManager, |
| 225 | mMockINotificationManager, |
| 226 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 227 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 228 | TEST_PACKAGE_NAME, |
| 229 | mNotificationChannel, |
| 230 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 231 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 232 | null, |
| 233 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 234 | true, |
| 235 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 236 | true); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 237 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 238 | assertEquals(GONE, nameView.getVisibility()); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Test |
| 242 | public void testBindNotification_delegate() throws Exception { |
| 243 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, "other", 0, null, TEST_UID, 0, |
| 244 | new Notification(), UserHandle.CURRENT, null, 0); |
| 245 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 246 | applicationInfo.uid = 7; // non-zero |
| 247 | when(mMockPackageManager.getApplicationInfo(eq("other"), anyInt())).thenReturn( |
| 248 | applicationInfo); |
| 249 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Other"); |
| 250 | |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 251 | NotificationEntry entry = new NotificationEntryBuilder().setSbn(mSbn).build(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 252 | mNotificationInfo.bindNotification( |
| 253 | mMockPackageManager, |
| 254 | mMockINotificationManager, |
| 255 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 256 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 257 | TEST_PACKAGE_NAME, |
| 258 | mNotificationChannel, |
| 259 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 260 | entry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 261 | null, |
| 262 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 263 | true, |
| 264 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 265 | true); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 266 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 267 | assertEquals(VISIBLE, nameView.getVisibility()); |
Julia Reynolds | 25b27f5 | 2019-04-24 11:58:38 -0400 | [diff] [blame] | 268 | assertTrue(nameView.getText().toString().contains("Proxied")); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 272 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 273 | mNotificationInfo.bindNotification( |
| 274 | mMockPackageManager, |
| 275 | mMockINotificationManager, |
| 276 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 277 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 278 | TEST_PACKAGE_NAME, |
| 279 | mNotificationChannel, |
| 280 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 281 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 282 | null, |
| 283 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 284 | true, |
| 285 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 286 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 287 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
| 288 | assertEquals(GONE, groupNameView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 292 | public void testBindNotification_SetsGroupNameIfNonNull() throws Exception { |
| 293 | mNotificationChannel.setGroup("test_group_id"); |
| 294 | final NotificationChannelGroup notificationChannelGroup = |
| 295 | new NotificationChannelGroup("test_group_id", "Test Group Name"); |
| 296 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 297 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 298 | .thenReturn(notificationChannelGroup); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 299 | mNotificationInfo.bindNotification( |
| 300 | mMockPackageManager, |
| 301 | mMockINotificationManager, |
| 302 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 303 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 304 | TEST_PACKAGE_NAME, |
| 305 | mNotificationChannel, |
| 306 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 307 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 308 | null, |
| 309 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 310 | true, |
| 311 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 312 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 313 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 314 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 315 | assertEquals("Test Group Name", groupNameView.getText()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 319 | public void testBindNotification_SetsTextChannelName() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 320 | mNotificationInfo.bindNotification( |
| 321 | mMockPackageManager, |
| 322 | mMockINotificationManager, |
| 323 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 324 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 325 | TEST_PACKAGE_NAME, |
| 326 | mNotificationChannel, |
| 327 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 328 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 329 | null, |
| 330 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 331 | true, |
| 332 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 333 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 334 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 335 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 336 | } |
| 337 | |
| 338 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 339 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 340 | mNotificationInfo.bindNotification( |
| 341 | mMockPackageManager, |
| 342 | mMockINotificationManager, |
| 343 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 344 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 345 | TEST_PACKAGE_NAME, |
| 346 | mDefaultNotificationChannel, |
| 347 | mDefaultNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 348 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 349 | null, |
| 350 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 351 | true, |
| 352 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 353 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 354 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 355 | assertEquals(GONE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | @Test |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 359 | public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist() |
| 360 | throws Exception { |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 361 | // Package has more than one channel by default. |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 362 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
| 363 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 364 | mNotificationInfo.bindNotification( |
| 365 | mMockPackageManager, |
| 366 | mMockINotificationManager, |
| 367 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 368 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 369 | TEST_PACKAGE_NAME, |
| 370 | mDefaultNotificationChannel, |
| 371 | mDefaultNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 372 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 373 | null, |
| 374 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 375 | true, |
| 376 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 377 | true); |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 378 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 379 | assertEquals(VISIBLE, textView.getVisibility()); |
| 380 | } |
| 381 | |
| 382 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 383 | public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 384 | mNotificationInfo.bindNotification( |
| 385 | mMockPackageManager, |
| 386 | mMockINotificationManager, |
| 387 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 388 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 389 | TEST_PACKAGE_NAME, |
| 390 | mNotificationChannel, |
| 391 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 392 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 393 | null, |
| 394 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 395 | true, |
| 396 | true, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 397 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 398 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 399 | assertEquals(VISIBLE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 403 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 404 | final CountDownLatch latch = new CountDownLatch(1); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 405 | mNotificationInfo.bindNotification( |
| 406 | mMockPackageManager, |
| 407 | mMockINotificationManager, |
| 408 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 409 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 410 | TEST_PACKAGE_NAME, |
| 411 | mNotificationChannel, |
| 412 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 413 | mEntry, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 414 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 415 | assertEquals(mNotificationChannel, c); |
| 416 | latch.countDown(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 417 | }, |
| 418 | null, |
| 419 | true, |
| 420 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 421 | true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 422 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 423 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 424 | settingsButton.performClick(); |
| 425 | // Verify that listener was triggered. |
| 426 | assertEquals(0, latch.getCount()); |
| 427 | } |
| 428 | |
| 429 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 430 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 431 | mNotificationInfo.bindNotification( |
| 432 | mMockPackageManager, |
| 433 | mMockINotificationManager, |
| 434 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 435 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 436 | TEST_PACKAGE_NAME, |
| 437 | mNotificationChannel, |
| 438 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 439 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 440 | null, |
| 441 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 442 | true, |
| 443 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 444 | true); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 445 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
| 446 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 447 | } |
| 448 | |
| 449 | @Test |
| 450 | public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned() |
| 451 | throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 452 | mNotificationInfo.bindNotification( |
| 453 | mMockPackageManager, |
| 454 | mMockINotificationManager, |
| 455 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 456 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 457 | TEST_PACKAGE_NAME, |
| 458 | mNotificationChannel, |
| 459 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 460 | mEntry, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 461 | (View v, NotificationChannel c, int appUid) -> { |
| 462 | assertEquals(mNotificationChannel, c); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 463 | }, |
| 464 | null, |
| 465 | false, |
| 466 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 467 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 468 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 469 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 470 | } |
| 471 | |
| 472 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 473 | public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 474 | mNotificationInfo.bindNotification( |
| 475 | mMockPackageManager, |
| 476 | mMockINotificationManager, |
| 477 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 478 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 479 | TEST_PACKAGE_NAME, |
| 480 | mNotificationChannel, |
| 481 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 482 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 483 | null, |
| 484 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 485 | true, |
| 486 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 487 | true); |
| 488 | mNotificationInfo.bindNotification( |
| 489 | mMockPackageManager, |
| 490 | mMockINotificationManager, |
| 491 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 492 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 493 | TEST_PACKAGE_NAME, |
| 494 | mNotificationChannel, |
| 495 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 496 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 497 | (View v, NotificationChannel c, int appUid) -> { }, |
| 498 | null, |
| 499 | true, |
| 500 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 501 | true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 502 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 503 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 504 | } |
| 505 | |
| 506 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 507 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 508 | final CountDownLatch latch = new CountDownLatch(1); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 509 | mNotificationInfo.bindNotification( |
| 510 | mMockPackageManager, |
| 511 | mMockINotificationManager, |
| 512 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 513 | mChannelEditorDialogController, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 514 | TEST_PACKAGE_NAME, mNotificationChannel, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 515 | createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 516 | mEntry, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 517 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 518 | assertEquals(null, c); |
| 519 | latch.countDown(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 520 | }, |
| 521 | null, |
| 522 | true, |
| 523 | true, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 524 | true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 525 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 526 | mNotificationInfo.findViewById(R.id.info).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 527 | // Verify that listener was triggered. |
| 528 | assertEquals(0, latch.getCount()); |
| 529 | } |
| 530 | |
| 531 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 532 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 533 | public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 534 | throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 535 | mNotificationInfo.bindNotification( |
| 536 | mMockPackageManager, |
| 537 | mMockINotificationManager, |
| 538 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 539 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 540 | TEST_PACKAGE_NAME, |
| 541 | mNotificationChannel, |
| 542 | createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 543 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 544 | null, |
| 545 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 546 | true, |
| 547 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 548 | true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 549 | final TextView channelNameView = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 550 | mNotificationInfo.findViewById(R.id.channel_name); |
| 551 | assertEquals(GONE, channelNameView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | @Test |
| 555 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 556 | public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 557 | mNotificationInfo.bindNotification( |
| 558 | mMockPackageManager, |
| 559 | mMockINotificationManager, |
| 560 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 561 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 562 | TEST_PACKAGE_NAME, |
| 563 | mNotificationChannel, |
| 564 | createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT), |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 565 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 566 | null, |
| 567 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 568 | true, |
| 569 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 570 | true); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 571 | assertEquals(GONE, mNotificationInfo.findViewById( |
| 572 | R.id.interruptiveness_settings).getVisibility()); |
| 573 | assertEquals(VISIBLE, mNotificationInfo.findViewById( |
| 574 | R.id.non_configurable_multichannel_text).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | @Test |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 578 | public void testBindNotification_whenAppUnblockable() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 579 | mNotificationInfo.bindNotification( |
| 580 | mMockPackageManager, |
| 581 | mMockINotificationManager, |
| 582 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 583 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 584 | TEST_PACKAGE_NAME, |
| 585 | mNotificationChannel, |
| 586 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 587 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 588 | null, |
| 589 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 590 | true, |
| 591 | true, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 592 | true); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 593 | final TextView view = mNotificationInfo.findViewById(R.id.non_configurable_text); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 594 | assertEquals(View.VISIBLE, view.getVisibility()); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 595 | assertEquals(mContext.getString(R.string.notification_unblockable_desc), |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 596 | view.getText()); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 597 | assertEquals(GONE, |
| 598 | mNotificationInfo.findViewById(R.id.interruptiveness_settings).getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | @Test |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 602 | public void testBindNotification_alertIsSelected() throws Exception { |
| 603 | mNotificationInfo.bindNotification( |
| 604 | mMockPackageManager, |
| 605 | mMockINotificationManager, |
| 606 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 607 | mChannelEditorDialogController, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 608 | TEST_PACKAGE_NAME, |
| 609 | mNotificationChannel, |
| 610 | mNotificationChannelSet, |
Julia Reynolds | c3e922b | 2020-01-16 16:12:56 -0500 | [diff] [blame] | 611 | mEntry, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 612 | null, |
| 613 | null, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 614 | true, |
| 615 | false, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 616 | true); |
| 617 | assertTrue(mNotificationInfo.findViewById(R.id.alert).isSelected()); |
| 618 | } |
| 619 | |
| 620 | @Test |
| 621 | public void testBindNotification_silenceIsSelected() throws Exception { |
| 622 | mNotificationInfo.bindNotification( |
| 623 | mMockPackageManager, |
| 624 | mMockINotificationManager, |
| 625 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 626 | mChannelEditorDialogController, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 627 | TEST_PACKAGE_NAME, |
| 628 | mNotificationChannel, |
| 629 | mNotificationChannelSet, |
Julia Reynolds | c3e922b | 2020-01-16 16:12:56 -0500 | [diff] [blame] | 630 | mEntry, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 631 | null, |
| 632 | null, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 633 | true, |
| 634 | false, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 635 | false); |
| 636 | assertTrue(mNotificationInfo.findViewById(R.id.silence).isSelected()); |
| 637 | } |
| 638 | |
| 639 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 640 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 641 | mNotificationInfo.bindNotification( |
| 642 | mMockPackageManager, |
| 643 | mMockINotificationManager, |
| 644 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 645 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 646 | TEST_PACKAGE_NAME, |
| 647 | mNotificationChannel, |
| 648 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 649 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 650 | null, |
| 651 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 652 | true, |
| 653 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 654 | true); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 655 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 656 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 657 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 661 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 662 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 663 | mNotificationInfo.bindNotification( |
| 664 | mMockPackageManager, |
| 665 | mMockINotificationManager, |
| 666 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 667 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 668 | TEST_PACKAGE_NAME, |
| 669 | mNotificationChannel, |
| 670 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 671 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 672 | null, |
| 673 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 674 | true, |
| 675 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 676 | false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 677 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 678 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 679 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 680 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 681 | anyString(), eq(TEST_UID), any()); |
| 682 | } |
| 683 | |
| 684 | @Test |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 685 | public void testDoesNotUpdateNotificationChannelAfterImportanceChangedSilenced() |
| 686 | throws Exception { |
| 687 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 688 | mNotificationInfo.bindNotification( |
| 689 | mMockPackageManager, |
| 690 | mMockINotificationManager, |
| 691 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 692 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 693 | TEST_PACKAGE_NAME, |
| 694 | mNotificationChannel, |
| 695 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 696 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 697 | null, |
| 698 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 699 | true, |
| 700 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 701 | true); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 702 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 703 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 704 | mTestableLooper.processAllMessages(); |
| 705 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 706 | anyString(), eq(TEST_UID), any()); |
| 707 | } |
| 708 | |
| 709 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 710 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 711 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 712 | int originalImportance = mNotificationChannel.getImportance(); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 713 | mNotificationInfo.bindNotification( |
| 714 | mMockPackageManager, |
| 715 | mMockINotificationManager, |
| 716 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 717 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 718 | TEST_PACKAGE_NAME, |
| 719 | mNotificationChannel, |
| 720 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 721 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 722 | null, |
| 723 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 724 | true, |
| 725 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 726 | true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 727 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 728 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 729 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 730 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 731 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 732 | assertEquals(originalImportance, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 736 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 737 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 738 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 739 | mNotificationInfo.bindNotification( |
| 740 | mMockPackageManager, |
| 741 | mMockINotificationManager, |
| 742 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 743 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 744 | TEST_PACKAGE_NAME, |
| 745 | mNotificationChannel, |
| 746 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 747 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 748 | null, |
| 749 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 750 | true, |
| 751 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 752 | true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 753 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 754 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 755 | |
| 756 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 757 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 758 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 759 | assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | @Test |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 763 | public void testSilenceCallsUpdateNotificationChannel() throws Exception { |
| 764 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 765 | mNotificationInfo.bindNotification( |
| 766 | mMockPackageManager, |
| 767 | mMockINotificationManager, |
| 768 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 769 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 770 | TEST_PACKAGE_NAME, |
| 771 | mNotificationChannel, |
| 772 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 773 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 774 | null, |
| 775 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 776 | true, |
| 777 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 778 | true); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 779 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 780 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 781 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 782 | mNotificationInfo.handleCloseControls(true, false); |
| 783 | |
| 784 | mTestableLooper.processAllMessages(); |
| 785 | ArgumentCaptor<NotificationChannel> updated = |
| 786 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 787 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 788 | anyString(), eq(TEST_UID), updated.capture()); |
| 789 | assertTrue((updated.getValue().getUserLockedFields() |
| 790 | & USER_LOCKED_IMPORTANCE) != 0); |
| 791 | assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance()); |
| 792 | } |
| 793 | |
| 794 | @Test |
| 795 | public void testUnSilenceCallsUpdateNotificationChannel() throws Exception { |
| 796 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 797 | mNotificationInfo.bindNotification( |
| 798 | mMockPackageManager, |
| 799 | mMockINotificationManager, |
| 800 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 801 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 802 | TEST_PACKAGE_NAME, |
| 803 | mNotificationChannel, |
| 804 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 805 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 806 | null, |
| 807 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 808 | true, |
| 809 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 810 | false); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 811 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 812 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 813 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 814 | mNotificationInfo.handleCloseControls(true, false); |
| 815 | |
| 816 | mTestableLooper.processAllMessages(); |
| 817 | ArgumentCaptor<NotificationChannel> updated = |
| 818 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 819 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 820 | anyString(), eq(TEST_UID), updated.capture()); |
| 821 | assertTrue((updated.getValue().getUserLockedFields() |
| 822 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 9ae5e64 | 2019-02-06 10:19:22 -0500 | [diff] [blame] | 823 | assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | @Test |
| 827 | public void testSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified() |
| 828 | throws Exception { |
| 829 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 830 | mNotificationInfo.bindNotification( |
| 831 | mMockPackageManager, |
| 832 | mMockINotificationManager, |
| 833 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 834 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 835 | TEST_PACKAGE_NAME, |
| 836 | mNotificationChannel, |
| 837 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 838 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 839 | null, |
| 840 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 841 | true, |
| 842 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 843 | true); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 844 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 845 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 846 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 847 | mNotificationInfo.handleCloseControls(true, false); |
| 848 | |
| 849 | mTestableLooper.processAllMessages(); |
| 850 | ArgumentCaptor<NotificationChannel> updated = |
| 851 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 852 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 853 | anyString(), eq(TEST_UID), updated.capture()); |
| 854 | assertTrue((updated.getValue().getUserLockedFields() |
| 855 | & USER_LOCKED_IMPORTANCE) != 0); |
| 856 | assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance()); |
| 857 | } |
| 858 | |
| 859 | @Test |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 860 | public void testSilenceCallsUpdateNotificationChannel_channelImportanceMin() |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 861 | throws Exception { |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 862 | mNotificationChannel.setImportance(IMPORTANCE_MIN); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 863 | mNotificationInfo.bindNotification( |
| 864 | mMockPackageManager, |
| 865 | mMockINotificationManager, |
| 866 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 867 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 868 | TEST_PACKAGE_NAME, |
| 869 | mNotificationChannel, |
| 870 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 871 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 872 | null, |
| 873 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 874 | true, |
| 875 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 876 | false); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 877 | |
| 878 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 879 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 880 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
| 881 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 882 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 883 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 884 | mNotificationInfo.handleCloseControls(true, false); |
| 885 | |
| 886 | mTestableLooper.processAllMessages(); |
| 887 | ArgumentCaptor<NotificationChannel> updated = |
| 888 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 889 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 890 | anyString(), eq(TEST_UID), updated.capture()); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 891 | assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 892 | assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance()); |
| 893 | } |
| 894 | |
| 895 | @Test |
| 896 | public void testAlertCallsUpdateNotificationChannel_channelImportanceMin() |
| 897 | throws Exception { |
| 898 | mNotificationChannel.setImportance(IMPORTANCE_MIN); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 899 | mNotificationInfo.bindNotification( |
| 900 | mMockPackageManager, |
| 901 | mMockINotificationManager, |
| 902 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 903 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 904 | TEST_PACKAGE_NAME, |
| 905 | mNotificationChannel, |
| 906 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 907 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 908 | null, |
| 909 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 910 | true, |
| 911 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 912 | false); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 913 | |
| 914 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 915 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 916 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
| 917 | assertEquals(mContext.getString(R.string.inline_ok_button), |
| 918 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 919 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 920 | mNotificationInfo.handleCloseControls(true, false); |
| 921 | |
| 922 | mTestableLooper.processAllMessages(); |
| 923 | ArgumentCaptor<NotificationChannel> updated = |
| 924 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 925 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 926 | anyString(), eq(TEST_UID), updated.capture()); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 927 | assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 928 | assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); |
| 929 | } |
| 930 | |
| 931 | @Test |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 932 | public void testAdjustImportanceTemporarilyAllowsReordering() throws Exception { |
| 933 | mNotificationChannel.setImportance(IMPORTANCE_DEFAULT); |
| 934 | mNotificationInfo.bindNotification( |
| 935 | mMockPackageManager, |
| 936 | mMockINotificationManager, |
| 937 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 938 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 939 | TEST_PACKAGE_NAME, |
| 940 | mNotificationChannel, |
| 941 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 942 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 943 | null, |
| 944 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 945 | true, |
| 946 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 947 | true); |
| 948 | |
| 949 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
| 950 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 951 | mNotificationInfo.handleCloseControls(true, false); |
| 952 | |
| 953 | verify(mVisualStabilityManager).temporarilyAllowReordering(); |
| 954 | } |
| 955 | |
| 956 | @Test |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 957 | public void testDoneText() |
| 958 | throws Exception { |
| 959 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 960 | mNotificationInfo.bindNotification( |
| 961 | mMockPackageManager, |
| 962 | mMockINotificationManager, |
| 963 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 964 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 965 | TEST_PACKAGE_NAME, |
| 966 | mNotificationChannel, |
| 967 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 968 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 969 | null, |
| 970 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 971 | true, |
| 972 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 973 | false); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 974 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 975 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 976 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 977 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
| 978 | assertEquals(mContext.getString(R.string.inline_ok_button), |
| 979 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 980 | mNotificationInfo.findViewById(R.id.silence).performClick(); |
| 981 | assertEquals(mContext.getString(R.string.inline_done_button), |
| 982 | ((TextView) mNotificationInfo.findViewById(R.id.done)).getText()); |
| 983 | } |
| 984 | |
| 985 | @Test |
| 986 | public void testUnSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified() |
| 987 | throws Exception { |
| 988 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 989 | mNotificationInfo.bindNotification( |
| 990 | mMockPackageManager, |
| 991 | mMockINotificationManager, |
| 992 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 993 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 994 | TEST_PACKAGE_NAME, |
| 995 | mNotificationChannel, |
| 996 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 997 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 998 | null, |
| 999 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1000 | true, |
| 1001 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1002 | false); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1003 | |
| 1004 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1005 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1006 | mNotificationInfo.handleCloseControls(true, false); |
| 1007 | |
| 1008 | mTestableLooper.processAllMessages(); |
| 1009 | ArgumentCaptor<NotificationChannel> updated = |
| 1010 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 1011 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 1012 | anyString(), eq(TEST_UID), updated.capture()); |
| 1013 | assertTrue((updated.getValue().getUserLockedFields() |
| 1014 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | 9ae5e64 | 2019-02-06 10:19:22 -0500 | [diff] [blame] | 1015 | assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance()); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 1019 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 1020 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1021 | mNotificationInfo.bindNotification( |
| 1022 | mMockPackageManager, |
| 1023 | mMockINotificationManager, |
| 1024 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 1025 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1026 | TEST_PACKAGE_NAME, |
| 1027 | mNotificationChannel, |
| 1028 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1029 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1030 | null, |
| 1031 | null, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1032 | true, |
| 1033 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1034 | false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 1035 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1036 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1037 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1038 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 1039 | |
| 1040 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1041 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 1042 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1043 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1044 | |
| 1045 | @Test |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1046 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 1047 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1048 | mNotificationInfo.bindNotification( |
| 1049 | mMockPackageManager, |
| 1050 | mMockINotificationManager, |
| 1051 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 1052 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1053 | TEST_PACKAGE_NAME, |
| 1054 | mNotificationChannel, |
| 1055 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1056 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1057 | null, |
| 1058 | null, |
| 1059 | true, |
| 1060 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1061 | false |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 1062 | ); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1063 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 1064 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 1065 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 1066 | mTestableLooper.processAllMessages(); |
| 1067 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 1068 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 1069 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 1070 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 1071 | |
| 1072 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1073 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 1074 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 1075 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 1076 | |
| 1077 | @Test |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1078 | public void testCloseControls_withoutHittingApply() throws Exception { |
| 1079 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1080 | mNotificationInfo.bindNotification( |
| 1081 | mMockPackageManager, |
| 1082 | mMockINotificationManager, |
| 1083 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 1084 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1085 | TEST_PACKAGE_NAME, |
| 1086 | mNotificationChannel, |
| 1087 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1088 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1089 | null, |
| 1090 | null, |
| 1091 | true, |
| 1092 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1093 | false |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1094 | ); |
| 1095 | |
| 1096 | mNotificationInfo.findViewById(R.id.alert).performClick(); |
| 1097 | |
| 1098 | assertFalse(mNotificationInfo.shouldBeSaved()); |
| 1099 | } |
| 1100 | |
| 1101 | @Test |
| 1102 | public void testWillBeRemovedReturnsFalse() throws Exception { |
| 1103 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 1104 | |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1105 | mNotificationInfo.bindNotification( |
| 1106 | mMockPackageManager, |
| 1107 | mMockINotificationManager, |
| 1108 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 1109 | mChannelEditorDialogController, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1110 | TEST_PACKAGE_NAME, |
| 1111 | mNotificationChannel, |
| 1112 | mNotificationChannelSet, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 1113 | mEntry, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1114 | null, |
| 1115 | null, |
| 1116 | true, |
| 1117 | false, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 1118 | false |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 1119 | ); |
| 1120 | |
Geoffrey Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 1121 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 1122 | } |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 1123 | |
| 1124 | private Set<NotificationChannel> createMultipleChannelSet(int howMany) { |
| 1125 | Set<NotificationChannel> multiChannelSet = new HashSet<>(); |
| 1126 | for (int i = 0; i < howMany; i++) { |
| 1127 | if (i == 0) { |
| 1128 | multiChannelSet.add(mNotificationChannel); |
| 1129 | continue; |
| 1130 | } |
| 1131 | |
| 1132 | NotificationChannel channel = new NotificationChannel( |
| 1133 | TEST_CHANNEL, TEST_CHANNEL_NAME + i, IMPORTANCE_LOW); |
| 1134 | |
| 1135 | multiChannelSet.add(channel); |
| 1136 | } |
| 1137 | |
| 1138 | return multiChannelSet; |
| 1139 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1140 | } |