Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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.notification.row; |
| 18 | |
Julia Reynolds | 8d25709 | 2020-04-15 15:57:21 -0400 | [diff] [blame] | 19 | import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; |
| 20 | import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
| 22 | import static android.app.NotificationManager.IMPORTANCE_HIGH; |
| 23 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
| 24 | import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; |
| 25 | import static android.view.View.GONE; |
| 26 | import static android.view.View.VISIBLE; |
| 27 | |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 28 | import static com.google.common.truth.Truth.assertThat; |
| 29 | |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 30 | import static junit.framework.Assert.assertEquals; |
| 31 | import static junit.framework.Assert.assertFalse; |
| 32 | import static junit.framework.Assert.assertTrue; |
| 33 | |
Dan Sandler | b11f2de | 2020-02-19 13:18:24 -0500 | [diff] [blame] | 34 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 35 | import static org.mockito.Mockito.any; |
| 36 | import static org.mockito.Mockito.anyInt; |
| 37 | import static org.mockito.Mockito.anyString; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 38 | import static org.mockito.Mockito.atLeastOnce; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 39 | import static org.mockito.Mockito.doAnswer; |
| 40 | import static org.mockito.Mockito.eq; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 41 | import static org.mockito.Mockito.mock; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 42 | import static org.mockito.Mockito.never; |
| 43 | import static org.mockito.Mockito.times; |
| 44 | import static org.mockito.Mockito.verify; |
| 45 | import static org.mockito.Mockito.when; |
| 46 | |
| 47 | import android.app.INotificationManager; |
| 48 | import android.app.Notification; |
| 49 | import android.app.NotificationChannel; |
| 50 | import android.app.NotificationChannelGroup; |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 51 | import android.app.NotificationManager; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 52 | import android.app.PendingIntent; |
| 53 | import android.app.Person; |
| 54 | import android.content.Intent; |
| 55 | import android.content.pm.ApplicationInfo; |
| 56 | import android.content.pm.LauncherApps; |
| 57 | import android.content.pm.PackageInfo; |
| 58 | import android.content.pm.PackageManager; |
| 59 | import android.content.pm.ShortcutInfo; |
| 60 | import android.content.pm.ShortcutManager; |
Dan Sandler | b11f2de | 2020-02-19 13:18:24 -0500 | [diff] [blame] | 61 | import android.graphics.drawable.Drawable; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 62 | import android.graphics.drawable.Icon; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 63 | import android.os.Handler; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 64 | import android.os.UserHandle; |
| 65 | import android.service.notification.StatusBarNotification; |
| 66 | import android.test.suitebuilder.annotation.SmallTest; |
| 67 | import android.testing.AndroidTestingRunner; |
| 68 | import android.testing.TestableLooper; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 69 | import android.view.LayoutInflater; |
| 70 | import android.view.View; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 71 | import android.widget.ImageView; |
| 72 | import android.widget.TextView; |
| 73 | |
| 74 | import com.android.internal.logging.MetricsLogger; |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 75 | import com.android.settingslib.notification.ConversationIconFactory; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 76 | import com.android.systemui.Prefs; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 77 | import com.android.systemui.R; |
| 78 | import com.android.systemui.SysuiTestCase; |
| 79 | import com.android.systemui.bubbles.BubbleController; |
| 80 | import com.android.systemui.bubbles.BubblesTestActivity; |
| 81 | import com.android.systemui.statusbar.SbnBuilder; |
| 82 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
| 83 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
| 84 | import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; |
Julia Reynolds | e6fed50 | 2020-02-07 14:41:02 -0500 | [diff] [blame] | 85 | import com.android.systemui.statusbar.phone.ShadeController; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 86 | |
| 87 | import org.junit.Before; |
| 88 | import org.junit.Rule; |
| 89 | import org.junit.Test; |
| 90 | import org.junit.runner.RunWith; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 91 | import org.mockito.Answers; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 92 | import org.mockito.ArgumentCaptor; |
| 93 | import org.mockito.Mock; |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 94 | import org.mockito.MockitoAnnotations; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 95 | import org.mockito.junit.MockitoJUnit; |
| 96 | import org.mockito.junit.MockitoRule; |
| 97 | import org.mockito.stubbing.Answer; |
| 98 | |
| 99 | import java.util.Arrays; |
| 100 | import java.util.List; |
| 101 | import java.util.concurrent.CountDownLatch; |
| 102 | |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 103 | import javax.inject.Provider; |
| 104 | |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 105 | @SmallTest |
| 106 | @RunWith(AndroidTestingRunner.class) |
| 107 | @TestableLooper.RunWithLooper |
| 108 | public class NotificationConversationInfoTest extends SysuiTestCase { |
| 109 | private static final String TEST_PACKAGE_NAME = "test_package"; |
| 110 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
| 111 | private static final int TEST_UID = 1; |
| 112 | private static final String TEST_CHANNEL = "test_channel"; |
| 113 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 114 | private static final String CONVERSATION_ID = "convo"; |
| 115 | |
| 116 | private TestableLooper mTestableLooper; |
| 117 | private NotificationConversationInfo mNotificationInfo; |
| 118 | private NotificationChannel mNotificationChannel; |
| 119 | private NotificationChannel mConversationChannel; |
| 120 | private StatusBarNotification mSbn; |
| 121 | private NotificationEntry mEntry; |
| 122 | private StatusBarNotification mBubbleSbn; |
| 123 | private NotificationEntry mBubbleEntry; |
| 124 | @Mock |
| 125 | private ShortcutInfo mShortcutInfo; |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 126 | @Mock |
Dan Sandler | b11f2de | 2020-02-19 13:18:24 -0500 | [diff] [blame] | 127 | private Drawable mIconDrawable; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 128 | |
| 129 | @Rule |
| 130 | public MockitoRule mockito = MockitoJUnit.rule(); |
| 131 | @Mock |
| 132 | private MetricsLogger mMetricsLogger; |
| 133 | @Mock |
| 134 | private INotificationManager mMockINotificationManager; |
| 135 | @Mock |
| 136 | private PackageManager mMockPackageManager; |
| 137 | @Mock |
| 138 | private VisualStabilityManager mVisualStabilityManager; |
| 139 | @Mock |
| 140 | private BubbleController mBubbleController; |
| 141 | @Mock |
| 142 | private LauncherApps mLauncherApps; |
| 143 | @Mock |
| 144 | private ShortcutManager mShortcutManager; |
| 145 | @Mock |
| 146 | private NotificationGuts mNotificationGuts; |
Julia Reynolds | e6fed50 | 2020-02-07 14:41:02 -0500 | [diff] [blame] | 147 | @Mock |
| 148 | private ShadeController mShadeController; |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 149 | @Mock |
| 150 | private ConversationIconFactory mIconFactory; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 151 | @Mock(answer = Answers.RETURNS_SELF) |
| 152 | private PriorityOnboardingDialogController.Builder mBuilder; |
| 153 | private Provider<PriorityOnboardingDialogController.Builder> mBuilderProvider = () -> mBuilder; |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 154 | @Mock |
| 155 | private Notification.BubbleMetadata mBubbleMetadata; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 156 | private Handler mTestHandler; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 157 | |
| 158 | @Before |
| 159 | public void setUp() throws Exception { |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 160 | MockitoAnnotations.initMocks(this); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 161 | mTestableLooper = TestableLooper.get(this); |
| 162 | |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 163 | mTestHandler = new Handler(mTestableLooper.getLooper()); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 164 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
| 165 | mDependency.injectTestDependency(BubbleController.class, mBubbleController); |
Julia Reynolds | e6fed50 | 2020-02-07 14:41:02 -0500 | [diff] [blame] | 166 | mDependency.injectTestDependency(ShadeController.class, mShadeController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 167 | // Inflate the layout |
| 168 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
| 169 | mNotificationInfo = (NotificationConversationInfo) layoutInflater.inflate( |
| 170 | R.layout.notification_conversation_info, |
| 171 | null); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 172 | mNotificationInfo.setGutsParent(mNotificationGuts); |
| 173 | doAnswer((Answer<Object>) invocation -> { |
| 174 | mNotificationInfo.handleCloseControls(true, false); |
| 175 | return null; |
Dave Mankoff | c97a0e6 | 2020-06-01 12:13:05 -0400 | [diff] [blame] | 176 | }).when(mNotificationGuts).closeControls(any(View.class), eq(true)); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 177 | // Our view is never attached to a window so the View#post methods in NotificationInfo never |
| 178 | // get called. Setting this will skip the post and do the action immediately. |
| 179 | mNotificationInfo.mSkipPost = true; |
| 180 | |
| 181 | // PackageManager must return a packageInfo and applicationInfo. |
| 182 | final PackageInfo packageInfo = new PackageInfo(); |
| 183 | packageInfo.packageName = TEST_PACKAGE_NAME; |
| 184 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 185 | .thenReturn(packageInfo); |
| 186 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 187 | applicationInfo.uid = TEST_UID; // non-zero |
| 188 | when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn( |
| 189 | applicationInfo); |
| 190 | final PackageInfo systemPackageInfo = new PackageInfo(); |
| 191 | systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; |
| 192 | when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) |
| 193 | .thenReturn(systemPackageInfo); |
| 194 | when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) |
| 195 | .thenReturn(packageInfo); |
| 196 | |
Julia Reynolds | 8d34af8 | 2020-05-20 14:24:36 -0400 | [diff] [blame] | 197 | when(mShortcutInfo.getLabel()).thenReturn("Convo name"); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 198 | List<ShortcutInfo> shortcuts = Arrays.asList(mShortcutInfo); |
| 199 | when(mLauncherApps.getShortcuts(any(), any())).thenReturn(shortcuts); |
Dan Sandler | b11f2de | 2020-02-19 13:18:24 -0500 | [diff] [blame] | 200 | when(mIconFactory.getConversationDrawable( |
| 201 | any(ShortcutInfo.class), anyString(), anyInt(), anyBoolean())) |
| 202 | .thenReturn(mIconDrawable); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 203 | |
| 204 | mNotificationChannel = new NotificationChannel( |
| 205 | TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
| 206 | |
| 207 | Notification notification = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 208 | .setShortcutId(CONVERSATION_ID) |
| 209 | .setStyle(new Notification.MessagingStyle(new Person.Builder().setName("m").build()) |
| 210 | .addMessage(new Notification.MessagingStyle.Message( |
| 211 | "hello!", 1000, new Person.Builder().setName("other").build()))) |
| 212 | .build(); |
| 213 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, |
| 214 | notification, UserHandle.CURRENT, null, 0); |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 215 | mEntry = new NotificationEntryBuilder().setSbn(mSbn).setShortcutInfo(mShortcutInfo).build(); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 216 | |
| 217 | PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, |
| 218 | new Intent(mContext, BubblesTestActivity.class), 0); |
| 219 | mBubbleSbn = new SbnBuilder(mSbn).setBubbleMetadata( |
Mady Mellor | aa9ce17 | 2020-03-17 10:34:20 -0700 | [diff] [blame] | 220 | new Notification.BubbleMetadata.Builder(bubbleIntent, |
| 221 | Icon.createWithResource(mContext, R.drawable.android)).build()) |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 222 | .build(); |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 223 | mBubbleEntry = new NotificationEntryBuilder() |
| 224 | .setSbn(mBubbleSbn) |
| 225 | .setShortcutInfo(mShortcutInfo) |
| 226 | .build(); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 227 | |
| 228 | mConversationChannel = new NotificationChannel( |
| 229 | TEST_CHANNEL + " : " + CONVERSATION_ID, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
| 230 | mConversationChannel.setConversationId(TEST_CHANNEL, CONVERSATION_ID); |
| 231 | when(mMockINotificationManager.getConversationNotificationChannel(anyString(), anyInt(), |
| 232 | anyString(), eq(TEST_CHANNEL), eq(false), eq(CONVERSATION_ID))) |
| 233 | .thenReturn(mConversationChannel); |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 234 | |
| 235 | when(mMockINotificationManager.getConsolidatedNotificationPolicy()) |
| 236 | .thenReturn(mock(NotificationManager.Policy.class)); |
| 237 | |
| 238 | when(mBuilder.build()).thenReturn(mock(PriorityOnboardingDialogController.class)); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Test |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 242 | public void testBindNotification_SetsShortcutIcon() { |
| 243 | mNotificationInfo.bindNotification( |
| 244 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 245 | mMockPackageManager, |
| 246 | mMockINotificationManager, |
| 247 | mVisualStabilityManager, |
| 248 | TEST_PACKAGE_NAME, |
| 249 | mNotificationChannel, |
| 250 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 251 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 252 | null, |
| 253 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 254 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 255 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 256 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 257 | true, |
| 258 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 259 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 260 | final ImageView view = mNotificationInfo.findViewById(R.id.conversation_icon); |
Dan Sandler | b11f2de | 2020-02-19 13:18:24 -0500 | [diff] [blame] | 261 | assertEquals(mIconDrawable, view.getDrawable()); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | @Test |
| 265 | public void testBindNotification_SetsTextApplicationName() { |
| 266 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
| 267 | mNotificationInfo.bindNotification( |
| 268 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 269 | mMockPackageManager, |
| 270 | mMockINotificationManager, |
| 271 | mVisualStabilityManager, |
| 272 | TEST_PACKAGE_NAME, |
| 273 | mNotificationChannel, |
| 274 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 275 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 276 | null, |
| 277 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 278 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 279 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 280 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 281 | true, |
| 282 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 283 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 284 | final TextView textView = mNotificationInfo.findViewById(R.id.pkg_name); |
| 285 | assertTrue(textView.getText().toString().contains("App Name")); |
| 286 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 287 | } |
Julia Reynolds | f2acd60 | 2020-01-21 16:01:25 -0500 | [diff] [blame] | 288 | /** |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 289 | @Test |
| 290 | public void testBindNotification_SetsTextChannelName() { |
| 291 | mNotificationInfo.bindNotification( |
| 292 | mShortcutManager, |
| 293 | mLauncherApps, |
| 294 | mMockPackageManager, |
| 295 | mMockINotificationManager, |
| 296 | mVisualStabilityManager, |
| 297 | TEST_PACKAGE_NAME, |
| 298 | mNotificationChannel, |
| 299 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 300 | mBubbleMetadata, |
| 301 | null, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 302 | null, |
| 303 | null, |
| 304 | true); |
| 305 | final TextView textView = mNotificationInfo.findViewById(R.id.parent_channel_name); |
| 306 | assertTrue(textView.getText().toString().contains(mNotificationChannel.getName())); |
| 307 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 308 | } |
Julia Reynolds | f2acd60 | 2020-01-21 16:01:25 -0500 | [diff] [blame] | 309 | */ |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 310 | @Test |
| 311 | public void testBindNotification_SetsTextGroupName() throws Exception { |
| 312 | NotificationChannelGroup group = new NotificationChannelGroup("id", "name"); |
| 313 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
| 314 | anyString(), anyString(), anyInt())).thenReturn(group); |
| 315 | mNotificationChannel.setGroup(group.getId()); |
| 316 | mConversationChannel.setGroup(group.getId()); |
| 317 | |
| 318 | mNotificationInfo.bindNotification( |
| 319 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 320 | mMockPackageManager, |
| 321 | mMockINotificationManager, |
| 322 | mVisualStabilityManager, |
| 323 | TEST_PACKAGE_NAME, |
| 324 | mNotificationChannel, |
| 325 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 326 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 327 | null, |
| 328 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 329 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 330 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 331 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 332 | true, |
| 333 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 334 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 335 | final TextView textView = mNotificationInfo.findViewById(R.id.group_name); |
| 336 | assertTrue(textView.getText().toString().contains(group.getName())); |
| 337 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 338 | assertEquals(VISIBLE, textView.getVisibility()); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | @Test |
| 342 | public void testBindNotification_GroupNameHiddenIfNoGroup() { |
| 343 | mNotificationInfo.bindNotification( |
| 344 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 345 | mMockPackageManager, |
| 346 | mMockINotificationManager, |
| 347 | mVisualStabilityManager, |
| 348 | TEST_PACKAGE_NAME, |
| 349 | mNotificationChannel, |
| 350 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 351 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 352 | null, |
| 353 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 354 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 355 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 356 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 357 | true, |
| 358 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 359 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 360 | final TextView textView = mNotificationInfo.findViewById(R.id.group_name); |
| 361 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 362 | assertEquals(GONE, textView.getVisibility()); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | @Test |
| 366 | public void testBindNotification_noDelegate() { |
| 367 | mNotificationInfo.bindNotification( |
| 368 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 369 | mMockPackageManager, |
| 370 | mMockINotificationManager, |
| 371 | mVisualStabilityManager, |
| 372 | TEST_PACKAGE_NAME, |
| 373 | mNotificationChannel, |
| 374 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 375 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 376 | null, |
| 377 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 378 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 379 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 380 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 381 | true, |
| 382 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 383 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 384 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 385 | assertEquals(GONE, nameView.getVisibility()); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Test |
| 389 | public void testBindNotification_delegate() throws Exception { |
| 390 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, "other", 0, null, TEST_UID, 0, |
| 391 | mSbn.getNotification(), UserHandle.CURRENT, null, 0); |
| 392 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
| 393 | applicationInfo.uid = 7; // non-zero |
| 394 | when(mMockPackageManager.getApplicationInfo(eq("other"), anyInt())).thenReturn( |
| 395 | applicationInfo); |
| 396 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Other"); |
| 397 | |
Julia Reynolds | 8582df5 | 2020-04-24 18:30:59 -0400 | [diff] [blame] | 398 | NotificationEntry entry = new NotificationEntryBuilder() |
| 399 | .setSbn(mSbn) |
| 400 | .setShortcutInfo(mShortcutInfo) |
| 401 | .build(); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 402 | mNotificationInfo.bindNotification( |
| 403 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 404 | mMockPackageManager, |
| 405 | mMockINotificationManager, |
| 406 | mVisualStabilityManager, |
| 407 | TEST_PACKAGE_NAME, |
| 408 | mNotificationChannel, |
| 409 | entry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 410 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 411 | null, |
| 412 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 413 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 414 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 415 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 416 | true, |
| 417 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 418 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 419 | final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name); |
| 420 | assertEquals(VISIBLE, nameView.getVisibility()); |
| 421 | assertTrue(nameView.getText().toString().contains("Proxied")); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | @Test |
| 425 | public void testBindNotification_SetsOnClickListenerForSettings() { |
| 426 | final CountDownLatch latch = new CountDownLatch(1); |
| 427 | mNotificationInfo.bindNotification( |
| 428 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 429 | mMockPackageManager, |
| 430 | mMockINotificationManager, |
| 431 | mVisualStabilityManager, |
| 432 | TEST_PACKAGE_NAME, |
| 433 | mNotificationChannel, |
| 434 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 435 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 436 | (View v, NotificationChannel c, int appUid) -> { |
| 437 | assertEquals(mConversationChannel, c); |
| 438 | latch.countDown(); |
| 439 | }, |
| 440 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 441 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 442 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 443 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 444 | true, |
| 445 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 446 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 447 | |
| 448 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
| 449 | settingsButton.performClick(); |
| 450 | // Verify that listener was triggered. |
| 451 | assertEquals(0, latch.getCount()); |
| 452 | } |
| 453 | |
| 454 | @Test |
| 455 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() { |
| 456 | mNotificationInfo.bindNotification( |
| 457 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 458 | mMockPackageManager, |
| 459 | mMockINotificationManager, |
| 460 | mVisualStabilityManager, |
| 461 | TEST_PACKAGE_NAME, |
| 462 | mNotificationChannel, |
| 463 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 464 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 465 | null, |
| 466 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 467 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 468 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 469 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 470 | true, |
| 471 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 472 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 473 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
| 474 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 475 | } |
| 476 | |
| 477 | @Test |
| 478 | public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned() { |
| 479 | final CountDownLatch latch = new CountDownLatch(1); |
| 480 | mNotificationInfo.bindNotification( |
| 481 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 482 | mMockPackageManager, |
| 483 | mMockINotificationManager, |
| 484 | mVisualStabilityManager, |
| 485 | TEST_PACKAGE_NAME, |
| 486 | mNotificationChannel, |
| 487 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 488 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 489 | (View v, NotificationChannel c, int appUid) -> { |
| 490 | assertEquals(mNotificationChannel, c); |
| 491 | latch.countDown(); |
| 492 | }, |
| 493 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 494 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 495 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 496 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 497 | false, |
| 498 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 499 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 500 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
| 501 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 502 | } |
| 503 | |
| 504 | @Test |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 505 | public void testBindNotification_silentSelected_isFave_isSilent() { |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 506 | mConversationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 507 | mConversationChannel.setImportantConversation(true); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 508 | mNotificationInfo.bindNotification( |
| 509 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 510 | mMockPackageManager, |
| 511 | mMockINotificationManager, |
| 512 | mVisualStabilityManager, |
| 513 | TEST_PACKAGE_NAME, |
| 514 | mNotificationChannel, |
| 515 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 516 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 517 | null, |
| 518 | null, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 519 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 520 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 521 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 522 | true, |
| 523 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 524 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 525 | View view = mNotificationInfo.findViewById(R.id.silence); |
| 526 | assertThat(view.isSelected()).isTrue(); |
| 527 | } |
| 528 | |
| 529 | @Test |
Julia Reynolds | 8d25709 | 2020-04-15 15:57:21 -0400 | [diff] [blame] | 530 | public void testBindNotification_defaultSelected_notFave_notSilent() throws Exception { |
| 531 | when(mMockINotificationManager.getBubblePreferenceForPackage(anyString(), anyInt())) |
| 532 | .thenReturn(BUBBLE_PREFERENCE_SELECTED); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 533 | mConversationChannel.setImportance(IMPORTANCE_HIGH); |
| 534 | mConversationChannel.setImportantConversation(false); |
| 535 | mConversationChannel.setAllowBubbles(true); |
| 536 | mNotificationInfo.bindNotification( |
| 537 | mShortcutManager, |
| 538 | mMockPackageManager, |
| 539 | mMockINotificationManager, |
| 540 | mVisualStabilityManager, |
| 541 | TEST_PACKAGE_NAME, |
| 542 | mNotificationChannel, |
| 543 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 544 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 545 | null, |
| 546 | null, |
| 547 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 548 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 549 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 550 | true, |
| 551 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 552 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 553 | View view = mNotificationInfo.findViewById(R.id.default_behavior); |
| 554 | assertThat(view.isSelected()).isTrue(); |
Julia Reynolds | 8d25709 | 2020-04-15 15:57:21 -0400 | [diff] [blame] | 555 | assertThat(((TextView) view.findViewById(R.id.default_summary)).getText()).isEqualTo( |
| 556 | mContext.getString(R.string.notification_channel_summary_default)); |
| 557 | } |
| 558 | |
| 559 | @Test |
| 560 | public void testBindNotification_default_allCanBubble() throws Exception { |
| 561 | when(mMockINotificationManager.getBubblePreferenceForPackage(anyString(), anyInt())) |
| 562 | .thenReturn(BUBBLE_PREFERENCE_ALL); |
| 563 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
| 564 | mConversationChannel.setImportance(IMPORTANCE_HIGH); |
| 565 | mConversationChannel.setImportantConversation(false); |
| 566 | mConversationChannel.setAllowBubbles(true); |
| 567 | mNotificationInfo.bindNotification( |
| 568 | mShortcutManager, |
| 569 | mMockPackageManager, |
| 570 | mMockINotificationManager, |
| 571 | mVisualStabilityManager, |
| 572 | TEST_PACKAGE_NAME, |
| 573 | mNotificationChannel, |
| 574 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 575 | mBubbleMetadata, |
Julia Reynolds | 8d25709 | 2020-04-15 15:57:21 -0400 | [diff] [blame] | 576 | null, |
| 577 | null, |
| 578 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 579 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 580 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 581 | true, |
| 582 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 583 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 8d25709 | 2020-04-15 15:57:21 -0400 | [diff] [blame] | 584 | View view = mNotificationInfo.findViewById(R.id.default_behavior); |
| 585 | assertThat(view.isSelected()).isTrue(); |
| 586 | assertThat(((TextView) view.findViewById(R.id.default_summary)).getText()).isEqualTo( |
| 587 | mContext.getString(R.string.notification_channel_summary_default_with_bubbles, |
| 588 | "App Name")); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | @Test |
| 592 | public void testFavorite() throws Exception { |
| 593 | mConversationChannel.setAllowBubbles(false); |
| 594 | mConversationChannel.setImportance(IMPORTANCE_LOW); |
| 595 | mConversationChannel.setImportantConversation(false); |
| 596 | |
| 597 | mNotificationInfo.bindNotification( |
| 598 | mShortcutManager, |
| 599 | mMockPackageManager, |
| 600 | mMockINotificationManager, |
| 601 | mVisualStabilityManager, |
| 602 | TEST_PACKAGE_NAME, |
| 603 | mNotificationChannel, |
| 604 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 605 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 606 | null, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 607 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 608 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 609 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 610 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 611 | true, |
| 612 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 613 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 614 | |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 615 | View fave = mNotificationInfo.findViewById(R.id.priority); |
| 616 | fave.performClick(); |
| 617 | mTestableLooper.processAllMessages(); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 618 | |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 619 | // silence subtext visible, others not |
| 620 | assertThat(mNotificationInfo.findViewById(R.id.priority_summary).getVisibility()) |
| 621 | .isEqualTo(VISIBLE); |
| 622 | assertThat(mNotificationInfo.findViewById(R.id.default_summary).getVisibility()) |
| 623 | .isEqualTo(GONE); |
| 624 | assertThat(mNotificationInfo.findViewById(R.id.silence_summary).getVisibility()) |
| 625 | .isEqualTo(GONE); |
| 626 | |
| 627 | // no changes until hit done |
Julia Reynolds | d5cc0ea | 2020-04-24 11:30:29 -0400 | [diff] [blame] | 628 | assertFalse(mNotificationInfo.shouldBeSaved()); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 629 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 630 | anyString(), anyInt(), any()); |
| 631 | assertFalse(mConversationChannel.isImportantConversation()); |
| 632 | assertFalse(mConversationChannel.canBubble()); |
| 633 | assertEquals(IMPORTANCE_LOW, mConversationChannel.getImportance()); |
| 634 | } |
| 635 | |
| 636 | @Test |
| 637 | public void testDefault() throws Exception { |
| 638 | mConversationChannel.setAllowBubbles(false); |
| 639 | mConversationChannel.setImportance(IMPORTANCE_LOW); |
| 640 | mConversationChannel.setImportantConversation(false); |
| 641 | mNotificationInfo.bindNotification( |
| 642 | mShortcutManager, |
| 643 | mMockPackageManager, |
| 644 | mMockINotificationManager, |
| 645 | mVisualStabilityManager, |
| 646 | TEST_PACKAGE_NAME, |
| 647 | mNotificationChannel, |
| 648 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 649 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 650 | null, |
| 651 | null, |
| 652 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 653 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 654 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 655 | true, |
| 656 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 657 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 658 | |
| 659 | mNotificationInfo.findViewById(R.id.default_behavior).performClick(); |
| 660 | mTestableLooper.processAllMessages(); |
| 661 | |
| 662 | // silence subtext visible, others not |
| 663 | assertThat(mNotificationInfo.findViewById(R.id.priority_summary).getVisibility()) |
| 664 | .isEqualTo(GONE); |
| 665 | assertThat(mNotificationInfo.findViewById(R.id.default_summary).getVisibility()) |
| 666 | .isEqualTo(VISIBLE); |
| 667 | assertThat(mNotificationInfo.findViewById(R.id.silence_summary).getVisibility()) |
| 668 | .isEqualTo(GONE); |
| 669 | |
| 670 | // no changes until hit done |
Julia Reynolds | d5cc0ea | 2020-04-24 11:30:29 -0400 | [diff] [blame] | 671 | assertFalse(mNotificationInfo.shouldBeSaved()); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 672 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 673 | anyString(), anyInt(), any()); |
| 674 | assertFalse(mConversationChannel.isImportantConversation()); |
| 675 | assertFalse(mConversationChannel.canBubble()); |
| 676 | assertEquals(IMPORTANCE_LOW, mConversationChannel.getImportance()); |
| 677 | } |
| 678 | |
| 679 | @Test |
| 680 | public void testSilence() throws Exception { |
| 681 | mConversationChannel.setImportance(IMPORTANCE_DEFAULT); |
| 682 | mConversationChannel.setImportantConversation(false); |
| 683 | |
| 684 | mNotificationInfo.bindNotification( |
| 685 | mShortcutManager, |
| 686 | mMockPackageManager, |
| 687 | mMockINotificationManager, |
| 688 | mVisualStabilityManager, |
| 689 | TEST_PACKAGE_NAME, |
| 690 | mNotificationChannel, |
| 691 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 692 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 693 | null, |
| 694 | null, |
| 695 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 696 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 697 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 698 | true, |
| 699 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 700 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 701 | |
| 702 | View silence = mNotificationInfo.findViewById(R.id.silence); |
| 703 | |
| 704 | silence.performClick(); |
| 705 | mTestableLooper.processAllMessages(); |
| 706 | |
| 707 | // silence subtext visible, others not |
| 708 | assertThat(mNotificationInfo.findViewById(R.id.priority_summary).getVisibility()) |
| 709 | .isEqualTo(GONE); |
| 710 | assertThat(mNotificationInfo.findViewById(R.id.default_summary).getVisibility()) |
| 711 | .isEqualTo(GONE); |
| 712 | assertThat(mNotificationInfo.findViewById(R.id.silence_summary).getVisibility()) |
| 713 | .isEqualTo(VISIBLE); |
| 714 | |
| 715 | // no changes until save |
Julia Reynolds | d5cc0ea | 2020-04-24 11:30:29 -0400 | [diff] [blame] | 716 | assertFalse(mNotificationInfo.shouldBeSaved()); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 717 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 718 | anyString(), anyInt(), any()); |
| 719 | assertEquals(IMPORTANCE_DEFAULT, mConversationChannel.getImportance()); |
| 720 | } |
| 721 | |
| 722 | @Test |
| 723 | public void testFavorite_andSave() throws Exception { |
| 724 | mConversationChannel.setAllowBubbles(false); |
| 725 | mConversationChannel.setImportance(IMPORTANCE_LOW); |
| 726 | mConversationChannel.setImportantConversation(false); |
| 727 | |
| 728 | mNotificationInfo.bindNotification( |
| 729 | mShortcutManager, |
| 730 | mMockPackageManager, |
| 731 | mMockINotificationManager, |
| 732 | mVisualStabilityManager, |
| 733 | TEST_PACKAGE_NAME, |
| 734 | mNotificationChannel, |
| 735 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 736 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 737 | null, |
| 738 | null, |
| 739 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 740 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 741 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 742 | true, |
| 743 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 744 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 745 | |
| 746 | View fave = mNotificationInfo.findViewById(R.id.priority); |
| 747 | fave.performClick(); |
| 748 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 749 | mTestableLooper.processAllMessages(); |
| 750 | |
| 751 | ArgumentCaptor<NotificationChannel> captor = |
| 752 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 753 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 754 | anyString(), anyInt(), captor.capture()); |
| 755 | assertTrue(captor.getValue().isImportantConversation()); |
| 756 | assertTrue(captor.getValue().canBubble()); |
| 757 | assertEquals(IMPORTANCE_DEFAULT, captor.getValue().getImportance()); |
| 758 | } |
| 759 | |
| 760 | @Test |
| 761 | public void testFavorite_andSave_doesNotLowerImportance() throws Exception { |
| 762 | mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); |
| 763 | mConversationChannel.setImportance(9); |
| 764 | |
| 765 | mNotificationInfo.bindNotification( |
| 766 | mShortcutManager, |
| 767 | mMockPackageManager, |
| 768 | mMockINotificationManager, |
| 769 | mVisualStabilityManager, |
| 770 | TEST_PACKAGE_NAME, |
| 771 | mNotificationChannel, |
| 772 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 773 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 774 | null, |
| 775 | null, |
| 776 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 777 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 778 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 779 | true, |
| 780 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 781 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 782 | |
| 783 | View fave = mNotificationInfo.findViewById(R.id.priority); |
| 784 | fave.performClick(); |
| 785 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 786 | mTestableLooper.processAllMessages(); |
| 787 | |
| 788 | ArgumentCaptor<NotificationChannel> captor = |
| 789 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 790 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 791 | anyString(), anyInt(), captor.capture()); |
| 792 | assertEquals(IMPORTANCE_HIGH, captor.getValue().getImportance()); |
| 793 | } |
| 794 | |
| 795 | @Test |
Julia Reynolds | e03aa8f | 2020-06-02 11:21:38 -0400 | [diff] [blame] | 796 | public void testFavorite_thenDefaultThenFavorite_andSave_nothingChanged() throws Exception { |
| 797 | mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); |
| 798 | mConversationChannel.setImportance(IMPORTANCE_HIGH); |
| 799 | mConversationChannel.setImportantConversation(true); |
| 800 | |
| 801 | mNotificationInfo.bindNotification( |
| 802 | mShortcutManager, |
| 803 | mMockPackageManager, |
| 804 | mMockINotificationManager, |
| 805 | mVisualStabilityManager, |
| 806 | TEST_PACKAGE_NAME, |
| 807 | mNotificationChannel, |
| 808 | mEntry, |
| 809 | mBubbleMetadata, |
| 810 | null, |
| 811 | null, |
| 812 | mIconFactory, |
| 813 | mContext, |
| 814 | mBuilderProvider, |
| 815 | true, |
| 816 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 817 | mTestHandler, null, mBubbleController); |
Julia Reynolds | e03aa8f | 2020-06-02 11:21:38 -0400 | [diff] [blame] | 818 | |
| 819 | View fave = mNotificationInfo.findViewById(R.id.priority); |
| 820 | fave.performClick(); |
| 821 | mNotificationInfo.findViewById(R.id.default_behavior).performClick(); |
| 822 | fave.performClick(); |
| 823 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 824 | mTestableLooper.processAllMessages(); |
| 825 | |
| 826 | ArgumentCaptor<NotificationChannel> captor = |
| 827 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 828 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 829 | anyString(), anyInt(), captor.capture()); |
| 830 | assertEquals(IMPORTANCE_HIGH, captor.getValue().getImportance()); |
| 831 | assertTrue(captor.getValue().isImportantConversation()); |
| 832 | } |
| 833 | |
| 834 | @Test |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 835 | public void testDefault_andSave() throws Exception { |
| 836 | mConversationChannel.setAllowBubbles(true); |
| 837 | mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); |
| 838 | mConversationChannel.setImportantConversation(true); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 839 | mNotificationInfo.bindNotification( |
| 840 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 841 | mMockPackageManager, |
| 842 | mMockINotificationManager, |
| 843 | mVisualStabilityManager, |
| 844 | TEST_PACKAGE_NAME, |
| 845 | mNotificationChannel, |
| 846 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 847 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 848 | null, |
| 849 | null, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 850 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 851 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 852 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 853 | true, |
| 854 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 855 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 856 | |
| 857 | mNotificationInfo.findViewById(R.id.default_behavior).performClick(); |
| 858 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 859 | mTestableLooper.processAllMessages(); |
| 860 | |
| 861 | ArgumentCaptor<NotificationChannel> captor = |
| 862 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 863 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 864 | anyString(), anyInt(), captor.capture()); |
| 865 | assertFalse(captor.getValue().isImportantConversation()); |
| 866 | assertFalse(captor.getValue().canBubble()); |
| 867 | assertEquals(IMPORTANCE_HIGH, captor.getValue().getImportance()); |
| 868 | } |
| 869 | |
| 870 | @Test |
| 871 | public void testDefault_andSave_doesNotChangeNonImportantBubbling() throws Exception { |
| 872 | mConversationChannel.setAllowBubbles(true); |
| 873 | mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); |
| 874 | mConversationChannel.setImportantConversation(false); |
| 875 | mNotificationInfo.bindNotification( |
| 876 | mShortcutManager, |
| 877 | mMockPackageManager, |
| 878 | mMockINotificationManager, |
| 879 | mVisualStabilityManager, |
| 880 | TEST_PACKAGE_NAME, |
| 881 | mNotificationChannel, |
| 882 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 883 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 884 | null, |
| 885 | null, |
| 886 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 887 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 888 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 889 | true, |
| 890 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 891 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 892 | |
| 893 | mNotificationInfo.findViewById(R.id.default_behavior).performClick(); |
| 894 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 895 | mTestableLooper.processAllMessages(); |
| 896 | |
| 897 | ArgumentCaptor<NotificationChannel> captor = |
| 898 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 899 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 900 | anyString(), anyInt(), captor.capture()); |
| 901 | assertFalse(captor.getValue().isImportantConversation()); |
| 902 | assertTrue(captor.getValue().canBubble()); |
| 903 | assertEquals(IMPORTANCE_HIGH, captor.getValue().getImportance()); |
| 904 | } |
| 905 | |
| 906 | @Test |
| 907 | public void testDefault_andSave_doesNotDemoteImportance() throws Exception { |
| 908 | mConversationChannel.setImportance(9); |
| 909 | mConversationChannel.setOriginalImportance(IMPORTANCE_HIGH); |
| 910 | |
| 911 | mNotificationInfo.bindNotification( |
| 912 | mShortcutManager, |
| 913 | mMockPackageManager, |
| 914 | mMockINotificationManager, |
| 915 | mVisualStabilityManager, |
| 916 | TEST_PACKAGE_NAME, |
| 917 | mNotificationChannel, |
| 918 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 919 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 920 | null, |
| 921 | null, |
| 922 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 923 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 924 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 925 | true, |
| 926 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 927 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 928 | |
| 929 | mNotificationInfo.findViewById(R.id.default_behavior).performClick(); |
| 930 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 931 | mTestableLooper.processAllMessages(); |
| 932 | |
| 933 | ArgumentCaptor<NotificationChannel> captor = |
| 934 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 935 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 936 | anyString(), anyInt(), captor.capture()); |
| 937 | assertEquals(IMPORTANCE_HIGH, captor.getValue().getImportance()); |
| 938 | } |
| 939 | |
| 940 | @Test |
| 941 | public void testSilence_andSave() throws Exception { |
| 942 | mConversationChannel.setImportance(IMPORTANCE_DEFAULT); |
| 943 | mConversationChannel.setImportantConversation(true); |
| 944 | mConversationChannel.setAllowBubbles(true); |
| 945 | |
| 946 | mNotificationInfo.bindNotification( |
| 947 | mShortcutManager, |
| 948 | mMockPackageManager, |
| 949 | mMockINotificationManager, |
| 950 | mVisualStabilityManager, |
| 951 | TEST_PACKAGE_NAME, |
| 952 | mNotificationChannel, |
| 953 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 954 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 955 | null, |
| 956 | null, |
| 957 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 958 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 959 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 960 | true, |
| 961 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 962 | mTestHandler, null, mBubbleController); |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 963 | |
| 964 | View silence = mNotificationInfo.findViewById(R.id.silence); |
| 965 | silence.performClick(); |
| 966 | mNotificationInfo.findViewById(R.id.done).performClick(); |
| 967 | mTestableLooper.processAllMessages(); |
| 968 | |
| 969 | ArgumentCaptor<NotificationChannel> captor = |
| 970 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 971 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 972 | anyString(), anyInt(), captor.capture()); |
| 973 | assertFalse(captor.getValue().isImportantConversation()); |
| 974 | assertFalse(captor.getValue().canBubble()); |
| 975 | assertEquals(IMPORTANCE_LOW, captor.getValue().getImportance()); |
| 976 | } |
| 977 | |
| 978 | @Test |
| 979 | public void testBindNotification_createsNewChannel() throws Exception { |
| 980 | mNotificationInfo.bindNotification( |
| 981 | mShortcutManager, |
| 982 | mMockPackageManager, |
| 983 | mMockINotificationManager, |
| 984 | mVisualStabilityManager, |
| 985 | TEST_PACKAGE_NAME, |
| 986 | mNotificationChannel, |
| 987 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 988 | mBubbleMetadata, |
Julia Reynolds | a856e49 | 2020-03-18 17:30:06 -0400 | [diff] [blame] | 989 | null, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 990 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 991 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 992 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 993 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 994 | true, |
| 995 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 996 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 997 | |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 998 | verify(mMockINotificationManager, times(1)).createConversationNotificationChannelForPackage( |
Julia Reynolds | 7c26752 | 2020-01-16 11:26:41 -0500 | [diff] [blame] | 999 | anyString(), anyInt(), anyString(), any(), eq(CONVERSATION_ID)); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | @Test |
| 1003 | public void testBindNotification_doesNotCreateNewChannelIfExists() throws Exception { |
| 1004 | mNotificationChannel.setConversationId("", CONVERSATION_ID); |
| 1005 | mNotificationInfo.bindNotification( |
| 1006 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 1007 | mMockPackageManager, |
| 1008 | mMockINotificationManager, |
| 1009 | mVisualStabilityManager, |
| 1010 | TEST_PACKAGE_NAME, |
| 1011 | mNotificationChannel, |
| 1012 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1013 | mBubbleMetadata, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 1014 | null, |
| 1015 | null, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 1016 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1017 | mContext, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1018 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 1019 | true, |
| 1020 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 1021 | mTestHandler, null, mBubbleController); |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 1022 | |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 1023 | verify(mMockINotificationManager, never()).createConversationNotificationChannelForPackage( |
Julia Reynolds | 7c26752 | 2020-01-16 11:26:41 -0500 | [diff] [blame] | 1024 | anyString(), anyInt(), anyString(), any(), eq(CONVERSATION_ID)); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 1025 | } |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1026 | |
| 1027 | @Test |
| 1028 | public void testSelectPriorityPresentsOnboarding_firstTime() { |
| 1029 | // GIVEN pref is false |
| 1030 | Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, false); |
| 1031 | |
| 1032 | // GIVEN the priority onboarding screen is present |
| 1033 | PriorityOnboardingDialogController.Builder b = |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1034 | mock(PriorityOnboardingDialogController.Builder.class, Answers.RETURNS_SELF); |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1035 | PriorityOnboardingDialogController controller = |
| 1036 | mock(PriorityOnboardingDialogController.class); |
| 1037 | when(b.build()).thenReturn(controller); |
| 1038 | |
| 1039 | // GIVEN the user is changing conversation settings |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1040 | mNotificationInfo.bindNotification( |
| 1041 | mShortcutManager, |
| 1042 | mMockPackageManager, |
| 1043 | mMockINotificationManager, |
| 1044 | mVisualStabilityManager, |
| 1045 | TEST_PACKAGE_NAME, |
| 1046 | mNotificationChannel, |
| 1047 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1048 | mBubbleMetadata, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1049 | null, |
| 1050 | null, |
| 1051 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1052 | mContext, |
| 1053 | () -> b, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 1054 | true, |
| 1055 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 1056 | mTestHandler, null, mBubbleController); |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1057 | |
| 1058 | // WHEN user clicks "priority" |
| 1059 | mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_FAVORITE); |
Julia Reynolds | e03aa8f | 2020-06-02 11:21:38 -0400 | [diff] [blame] | 1060 | verify(controller, never()).show(); |
| 1061 | |
| 1062 | // and then done |
| 1063 | mNotificationInfo.findViewById(R.id.done).performClick(); |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1064 | |
| 1065 | // THEN the user is presented with the priority onboarding screen |
| 1066 | verify(controller, atLeastOnce()).show(); |
| 1067 | } |
| 1068 | |
| 1069 | @Test |
| 1070 | public void testSelectPriorityDoesNotShowOnboarding_secondTime() { |
| 1071 | //WHEN pref is true |
| 1072 | Prefs.putBoolean(mContext, Prefs.Key.HAS_SEEN_PRIORITY_ONBOARDING, true); |
| 1073 | |
| 1074 | PriorityOnboardingDialogController.Builder b = |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1075 | mock(PriorityOnboardingDialogController.Builder.class, Answers.RETURNS_SELF); |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1076 | PriorityOnboardingDialogController controller = |
| 1077 | mock(PriorityOnboardingDialogController.class); |
| 1078 | when(b.build()).thenReturn(controller); |
| 1079 | |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1080 | mNotificationInfo.bindNotification( |
| 1081 | mShortcutManager, |
| 1082 | mMockPackageManager, |
| 1083 | mMockINotificationManager, |
| 1084 | mVisualStabilityManager, |
| 1085 | TEST_PACKAGE_NAME, |
| 1086 | mNotificationChannel, |
| 1087 | mEntry, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1088 | mBubbleMetadata, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1089 | null, |
| 1090 | null, |
| 1091 | mIconFactory, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 1092 | mContext, |
| 1093 | () -> b, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 1094 | true, |
| 1095 | mTestHandler, |
Lyn Han | b539797 | 2020-06-16 11:56:43 -0700 | [diff] [blame] | 1096 | mTestHandler, null, mBubbleController); |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 1097 | |
| 1098 | // WHEN user clicks "priority" |
| 1099 | mNotificationInfo.setSelectedAction(NotificationConversationInfo.ACTION_FAVORITE); |
| 1100 | |
| 1101 | // THEN the user is presented with the priority onboarding screen |
| 1102 | verify(controller, never()).show(); |
| 1103 | } |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 1104 | } |