Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 19 | import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 20 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
| 22 | import static android.app.NotificationManager.IMPORTANCE_NONE; |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 23 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 24 | import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 25 | import static android.view.View.GONE; |
| 26 | import static android.view.View.VISIBLE; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 27 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 28 | import static junit.framework.Assert.assertEquals; |
| 29 | import static junit.framework.Assert.assertFalse; |
| 30 | import static junit.framework.Assert.assertTrue; |
Julia Reynolds | 5a31193 | 2017-03-01 16:33:44 -0500 | [diff] [blame] | 31 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 32 | import static org.mockito.Mockito.any; |
| 33 | import static org.mockito.Mockito.anyBoolean; |
| 34 | import static org.mockito.Mockito.anyInt; |
| 35 | import static org.mockito.Mockito.anyString; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 36 | import static org.mockito.Mockito.doCallRealMethod; |
| 37 | import static org.mockito.Mockito.doNothing; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 38 | import static org.mockito.Mockito.eq; |
| 39 | import static org.mockito.Mockito.mock; |
| 40 | import static org.mockito.Mockito.never; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 41 | import static org.mockito.Mockito.spy; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 42 | import static org.mockito.Mockito.times; |
| 43 | import static org.mockito.Mockito.verify; |
| 44 | import static org.mockito.Mockito.when; |
| 45 | |
| 46 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 47 | import android.app.Notification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 48 | import android.app.NotificationChannel; |
| 49 | import android.app.NotificationChannelGroup; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 50 | import android.content.Intent; |
| 51 | import android.content.pm.ActivityInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 52 | import android.content.pm.ApplicationInfo; |
| 53 | import android.content.pm.PackageInfo; |
| 54 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 55 | import android.content.pm.ResolveInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 56 | import android.graphics.drawable.Drawable; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 57 | import android.os.IBinder; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 58 | import android.os.UserHandle; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 59 | import android.service.notification.StatusBarNotification; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 60 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 61 | import android.testing.AndroidTestingRunner; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 62 | import android.testing.PollingCheck; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 63 | import android.testing.TestableLooper; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 64 | import android.testing.UiThreadTest; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 65 | import android.view.LayoutInflater; |
| 66 | import android.view.View; |
| 67 | import android.widget.ImageView; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 68 | import android.widget.TextView; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 69 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 70 | import com.android.internal.logging.MetricsLogger; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 71 | import com.android.systemui.Dependency; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 72 | import com.android.systemui.R; |
| 73 | import com.android.systemui.SysuiTestCase; |
Jason Monk | ba36432 | 2017-03-06 11:19:20 -0500 | [diff] [blame] | 74 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 75 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 76 | import org.junit.Rule; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 77 | import org.junit.Test; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 78 | import org.junit.runner.RunWith; |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 79 | import org.mockito.ArgumentCaptor; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 80 | import org.mockito.Mock; |
| 81 | import org.mockito.junit.MockitoJUnit; |
| 82 | import org.mockito.junit.MockitoRule; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 83 | |
| 84 | import java.util.ArrayList; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 85 | import java.util.List; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 86 | import java.util.concurrent.CountDownLatch; |
| 87 | |
| 88 | @SmallTest |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 89 | @RunWith(AndroidTestingRunner.class) |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 90 | @TestableLooper.RunWithLooper |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 91 | public class NotificationInfoTest extends SysuiTestCase { |
| 92 | private static final String TEST_PACKAGE_NAME = "test_package"; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 93 | private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 94 | private static final int TEST_UID = 1; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 95 | private static final int MULTIPLE_CHANNEL_COUNT = 2; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 96 | private static final String TEST_CHANNEL = "test_channel"; |
| 97 | private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME"; |
| 98 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 99 | private TestableLooper mTestableLooper; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 100 | private NotificationInfo mNotificationInfo; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 101 | private NotificationChannel mNotificationChannel; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 102 | private NotificationChannel mDefaultNotificationChannel; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 103 | private StatusBarNotification mSbn; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 104 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 105 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 106 | @Mock private MetricsLogger mMetricsLogger; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 107 | @Mock private INotificationManager mMockINotificationManager; |
| 108 | @Mock private PackageManager mMockPackageManager; |
| 109 | @Mock private NotificationBlockingHelperManager mBlockingHelperManager; |
| 110 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 111 | @Before |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 112 | public void setUp() throws Exception { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 113 | mDependency.injectTestDependency( |
| 114 | NotificationBlockingHelperManager.class, |
| 115 | mBlockingHelperManager); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 116 | mTestableLooper = TestableLooper.get(this); |
| 117 | mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper()); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 118 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 119 | // Inflate the layout |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 120 | final LayoutInflater layoutInflater = LayoutInflater.from(mContext); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 121 | mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info, |
| 122 | null); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 123 | mNotificationInfo.setGutsParent(mock(NotificationGuts.class)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 124 | |
| 125 | // PackageManager must return a packageInfo and applicationInfo. |
| 126 | final PackageInfo packageInfo = new PackageInfo(); |
| 127 | packageInfo.packageName = TEST_PACKAGE_NAME; |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 128 | when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt())) |
| 129 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 130 | final ApplicationInfo applicationInfo = new ApplicationInfo(); |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 131 | applicationInfo.uid = TEST_UID; // non-zero |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 132 | when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn( |
| 133 | applicationInfo); |
Julia Reynolds | f732159 | 2017-05-24 16:09:19 -0400 | [diff] [blame] | 134 | final PackageInfo systemPackageInfo = new PackageInfo(); |
| 135 | systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME; |
| 136 | when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt())) |
| 137 | .thenReturn(systemPackageInfo); |
| 138 | when(mMockPackageManager.getPackageInfo(eq("android"), anyInt())) |
| 139 | .thenReturn(packageInfo); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 140 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 141 | // Package has one channel by default. |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 142 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 143 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 144 | |
| 145 | // Some test channels. |
| 146 | mNotificationChannel = new NotificationChannel( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 147 | TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 148 | mDefaultNotificationChannel = new NotificationChannel( |
| 149 | NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 150 | IMPORTANCE_LOW); |
Julia Reynolds | 33bef2c | 2017-09-05 11:07:18 -0400 | [diff] [blame] | 151 | 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] | 152 | new Notification(), UserHandle.CURRENT, null, 0); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 153 | } |
| 154 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 155 | // TODO: if tests are taking too long replace this with something that makes the animation |
| 156 | // finish instantly. |
| 157 | private void waitForUndoButton() { |
| 158 | PollingCheck.waitFor(1000, |
| 159 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 160 | } |
Gus Prevas | f4f0b06 | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 161 | private void ensureNoUndoButton() { |
| 162 | PollingCheck.waitFor(1000, |
| 163 | () -> GONE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility() |
| 164 | && !mNotificationInfo.isAnimating()); |
| 165 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 166 | private void waitForStopButton() { |
| 167 | PollingCheck.waitFor(1000, |
| 168 | () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 171 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 172 | public void testBindNotification_SetsTextApplicationName() throws Exception { |
| 173 | when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name"); |
| 174 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 175 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 176 | final TextView textView = mNotificationInfo.findViewById(R.id.pkgname); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 177 | assertTrue(textView.getText().toString().contains("App Name")); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 178 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 182 | public void testBindNotification_SetsPackageIcon() throws Exception { |
| 183 | final Drawable iconDrawable = mock(Drawable.class); |
| 184 | when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class))) |
| 185 | .thenReturn(iconDrawable); |
| 186 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 187 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 188 | final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 189 | assertEquals(iconDrawable, iconView.getDrawable()); |
| 190 | } |
| 191 | |
| 192 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 193 | public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception { |
| 194 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 195 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 196 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
| 197 | assertEquals(GONE, groupNameView.getVisibility()); |
| 198 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
| 199 | assertEquals(GONE, groupDividerView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 203 | public void testBindNotification_SetsGroupNameIfNonNull() throws Exception { |
| 204 | mNotificationChannel.setGroup("test_group_id"); |
| 205 | final NotificationChannelGroup notificationChannelGroup = |
| 206 | new NotificationChannelGroup("test_group_id", "Test Group Name"); |
| 207 | when(mMockINotificationManager.getNotificationChannelGroupForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 208 | eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID))) |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 209 | .thenReturn(notificationChannelGroup); |
| 210 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 211 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 212 | final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 213 | assertEquals(View.VISIBLE, groupNameView.getVisibility()); |
| 214 | assertEquals("Test Group Name", groupNameView.getText()); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 215 | final TextView groupDividerView = mNotificationInfo.findViewById(R.id.pkg_group_divider); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 216 | assertEquals(View.VISIBLE, groupDividerView.getVisibility()); |
| 217 | } |
| 218 | |
| 219 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 220 | public void testBindNotification_SetsTextChannelName() throws Exception { |
| 221 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 222 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 223 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 224 | assertEquals(TEST_CHANNEL_NAME, textView.getText()); |
| 225 | } |
| 226 | |
| 227 | @Test |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 228 | public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception { |
| 229 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 230 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 231 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 232 | assertEquals(GONE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Test |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 236 | public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist() |
| 237 | throws Exception { |
| 238 | // Package has one channel by default. |
| 239 | when(mMockINotificationManager.getNumNotificationChannelsForPackage( |
| 240 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10); |
| 241 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 242 | TEST_PACKAGE_NAME, mDefaultNotificationChannel, 1, mSbn, null, null, null, false); |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 243 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 244 | assertEquals(VISIBLE, textView.getVisibility()); |
| 245 | } |
| 246 | |
| 247 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 248 | public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception { |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 249 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 250 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 251 | final TextView textView = mNotificationInfo.findViewById(R.id.channel_name); |
| 252 | assertEquals(VISIBLE, textView.getVisibility()); |
Geoffrey Pitsch | 1fbf66e | 2017-05-09 11:32:27 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 256 | public void testBindNotification_BlockButton() throws Exception { |
| 257 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 258 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 259 | final View block = mNotificationInfo.findViewById(R.id.block); |
| 260 | final View minimize = mNotificationInfo.findViewById(R.id.minimize); |
| 261 | assertEquals(VISIBLE, block.getVisibility()); |
| 262 | assertEquals(GONE, minimize.getVisibility()); |
| 263 | } |
| 264 | |
| 265 | @Test |
| 266 | public void testBindNotification_MinButton() throws Exception { |
| 267 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 268 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 269 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 270 | final View block = mNotificationInfo.findViewById(R.id.block); |
| 271 | final View minimize = mNotificationInfo.findViewById(R.id.minimize); |
| 272 | assertEquals(GONE, block.getVisibility()); |
| 273 | assertEquals(VISIBLE, minimize.getVisibility()); |
| 274 | } |
| 275 | |
| 276 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 277 | public void testBindNotification_SetsOnClickListenerForSettings() throws Exception { |
| 278 | final CountDownLatch latch = new CountDownLatch(1); |
| 279 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 280 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 281 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 282 | assertEquals(mNotificationChannel, c); |
| 283 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 284 | }, null, false); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 285 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 286 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 287 | settingsButton.performClick(); |
| 288 | // Verify that listener was triggered. |
| 289 | assertEquals(0, latch.getCount()); |
| 290 | } |
| 291 | |
| 292 | @Test |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 293 | public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception { |
| 294 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 295 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 296 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 297 | assertTrue(settingsButton.getVisibility() != View.VISIBLE); |
| 298 | } |
| 299 | |
| 300 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 301 | public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception { |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 302 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 303 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 304 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 305 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, |
| 306 | (View v, NotificationChannel c, int appUid) -> { |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 307 | }, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 308 | final View settingsButton = mNotificationInfo.findViewById(R.id.info); |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 309 | assertEquals(View.VISIBLE, settingsButton.getVisibility()); |
| 310 | } |
| 311 | |
| 312 | @Test |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 313 | public void testLogBlockingHelperCounter_doesntLogForNormalGutsView() throws Exception { |
| 314 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 315 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
| 316 | mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent"); |
| 317 | verify(mMetricsLogger, times(0)).count(anyString(), anyInt()); |
| 318 | } |
| 319 | |
| 320 | @Test |
| 321 | public void testLogBlockingHelperCounter_logsForBlockingHelper() throws Exception { |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 322 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 323 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, true, |
| 324 | true); |
| 325 | mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent"); |
Rohan Shah | c6b0d54 | 2018-05-10 13:00:54 -0700 | [diff] [blame] | 326 | verify(mMetricsLogger, times(1)).count(anyString(), anyInt()); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 330 | public void testOnClickListenerPassesNullChannelForBundle() throws Exception { |
| 331 | final CountDownLatch latch = new CountDownLatch(1); |
| 332 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 333 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 334 | (View v, NotificationChannel c, int appUid) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 335 | assertEquals(null, c); |
| 336 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 337 | }, null, true); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 338 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 339 | mNotificationInfo.findViewById(R.id.info).performClick(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 340 | // Verify that listener was triggered. |
| 341 | assertEquals(0, latch.getCount()); |
| 342 | } |
| 343 | |
| 344 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 345 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 346 | public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels() |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 347 | throws Exception { |
| 348 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 349 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null, |
| 350 | null, true); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 351 | final TextView channelNameView = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 352 | mNotificationInfo.findViewById(R.id.channel_name); |
| 353 | assertEquals(GONE, channelNameView.getVisibility()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | @Test |
| 357 | @UiThreadTest |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 358 | public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 359 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 360 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, mSbn, null, null, |
| 361 | null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 362 | final TextView blockView = mNotificationInfo.findViewById(R.id.block); |
| 363 | assertEquals(GONE, blockView.getVisibility()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | @Test |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 367 | public void testbindNotification_BlockingHelper() throws Exception { |
| 368 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 369 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false, false, |
| 370 | true); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 371 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 372 | assertEquals(View.VISIBLE, view.getVisibility()); |
| 373 | assertEquals(mContext.getString(R.string.inline_blocking_helper), view.getText()); |
| 374 | } |
| 375 | |
| 376 | @Test |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 377 | public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception { |
| 378 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 379 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 380 | final TextView view = mNotificationInfo.findViewById(R.id.block_prompt); |
| 381 | assertEquals(View.VISIBLE, view.getVisibility()); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 382 | assertEquals(mContext.getString(R.string.notification_unblockable_desc), |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 383 | view.getText()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 387 | public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception { |
| 388 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 389 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 390 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 391 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 392 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 396 | public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 397 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 398 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 399 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 400 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 401 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 402 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 403 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 404 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 408 | public void testDoesNotUpdateNotificationChannelAfterImportanceChangedMin() |
| 409 | throws Exception { |
| 410 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 411 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 412 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 413 | |
| 414 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 415 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 416 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 417 | anyString(), eq(TEST_UID), any()); |
| 418 | } |
| 419 | |
| 420 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 421 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged() |
| 422 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 423 | int originalImportance = mNotificationChannel.getImportance(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 424 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 425 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 426 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 427 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 428 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 429 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 430 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 431 | assertEquals(originalImportance, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | @Test |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 435 | public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified() |
| 436 | throws Exception { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 437 | mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 438 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 439 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 440 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 441 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 442 | |
| 443 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 444 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 445 | anyString(), eq(TEST_UID), any()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 446 | assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | @Test |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 450 | public void testHandleCloseControls_setsNotificationsDisabledForMultipleChannelNotifications() |
| 451 | throws Exception { |
| 452 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 453 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 454 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 455 | 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */, |
| 456 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
| 457 | false /* isNonblockable */); |
| 458 | |
| 459 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 460 | waitForUndoButton(); |
| 461 | mNotificationInfo.handleCloseControls(true, false); |
| 462 | |
| 463 | mTestableLooper.processAllMessages(); |
| 464 | verify(mMockINotificationManager, times(1)) |
| 465 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 466 | anyString(), eq(TEST_UID), eq(false)); |
| 467 | } |
| 468 | |
| 469 | |
| 470 | @Test |
| 471 | public void testHandleCloseControls_keepsNotificationsEnabledForMultipleChannelNotifications() |
| 472 | throws Exception { |
| 473 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 474 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 475 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 476 | 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */, |
| 477 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
| 478 | false /* isNonblockable */); |
| 479 | |
| 480 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 481 | waitForUndoButton(); |
| 482 | mNotificationInfo.handleCloseControls(true, false); |
| 483 | |
| 484 | mTestableLooper.processAllMessages(); |
| 485 | verify(mMockINotificationManager, times(1)) |
| 486 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 487 | anyString(), eq(TEST_UID), eq(false)); |
| 488 | } |
| 489 | |
| 490 | @Test |
| 491 | public void testCloseControls_blockingHelperSavesImportanceForMultipleChannelNotifications() |
| 492 | throws Exception { |
| 493 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 494 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 495 | 10 /* numUniqueChannelsInRow */, mSbn, null /* checkSaveListener */, |
| 496 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
| 497 | false /* isNonblockable */, true /* isForBlockingHelper */, |
| 498 | true /* isUserSentimentNegative */); |
| 499 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 500 | NotificationGuts guts = spy(new NotificationGuts(mContext, null)); |
| 501 | when(guts.getWindowToken()).thenReturn(mock(IBinder.class)); |
| 502 | doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean()); |
| 503 | doNothing().when(guts).setExposed(anyBoolean(), anyBoolean()); |
| 504 | guts.setGutsContent(mNotificationInfo); |
| 505 | mNotificationInfo.setGutsParent(guts); |
| 506 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 507 | mNotificationInfo.findViewById(R.id.keep).performClick(); |
| 508 | |
| 509 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 510 | mTestableLooper.processAllMessages(); |
| 511 | verify(mMockINotificationManager, times(1)) |
| 512 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 513 | anyString(), eq(TEST_UID), eq(true)); |
| 514 | } |
| 515 | |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 516 | @Test |
| 517 | public void testCloseControls_nonNullCheckSaveListenerDoesntDelayKeepShowing() |
| 518 | throws Exception { |
| 519 | NotificationInfo.CheckSaveListener listener = |
| 520 | mock(NotificationInfo.CheckSaveListener.class); |
| 521 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 522 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 523 | 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */, |
| 524 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
| 525 | false /* isNonblockable */, true /* isForBlockingHelper */, |
| 526 | true /* isUserSentimentNegative */); |
| 527 | |
| 528 | NotificationGuts guts = spy(new NotificationGuts(mContext, null)); |
| 529 | when(guts.getWindowToken()).thenReturn(mock(IBinder.class)); |
| 530 | doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean()); |
| 531 | doNothing().when(guts).setExposed(anyBoolean(), anyBoolean()); |
| 532 | guts.setGutsContent(mNotificationInfo); |
| 533 | mNotificationInfo.setGutsParent(guts); |
| 534 | |
| 535 | mNotificationInfo.findViewById(R.id.keep).performClick(); |
| 536 | |
| 537 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 538 | mTestableLooper.processAllMessages(); |
| 539 | verify(mMockINotificationManager, times(1)) |
| 540 | .setNotificationsEnabledWithImportanceLockForPackage( |
| 541 | anyString(), eq(TEST_UID), eq(true)); |
| 542 | } |
| 543 | |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 544 | @Test |
| 545 | public void testCloseControls_nonNullCheckSaveListenerDoesntDelayDismiss() |
| 546 | throws Exception { |
| 547 | NotificationInfo.CheckSaveListener listener = |
| 548 | mock(NotificationInfo.CheckSaveListener.class); |
| 549 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 550 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 551 | 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */, |
| 552 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
| 553 | false /* isNonblockable */, true /* isForBlockingHelper */, |
| 554 | true /* isUserSentimentNegative */); |
| 555 | |
| 556 | mNotificationInfo.handleCloseControls(true /* save */, false /* force */); |
| 557 | |
| 558 | mTestableLooper.processAllMessages(); |
| 559 | verify(listener, times(0)).checkSave(any(Runnable.class), eq(mSbn)); |
| 560 | } |
| 561 | |
| 562 | @Test |
| 563 | public void testCloseControls_checkSaveListenerDelaysStopNotifications() |
| 564 | throws Exception { |
| 565 | NotificationInfo.CheckSaveListener listener = |
| 566 | mock(NotificationInfo.CheckSaveListener.class); |
| 567 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 568 | TEST_PACKAGE_NAME, mNotificationChannel /* notificationChannel */, |
| 569 | 10 /* numUniqueChannelsInRow */, mSbn, listener /* checkSaveListener */, |
| 570 | null /* onSettingsClick */, null /* onAppSettingsClick */ , |
| 571 | false /* isNonblockable */, true /* isForBlockingHelper */, |
| 572 | true /* isUserSentimentNegative */); |
| 573 | |
| 574 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Rohan Shah | 593e8f1 | 2018-05-22 10:06:23 -0700 | [diff] [blame] | 575 | mTestableLooper.processAllMessages(); |
| 576 | verify(listener).checkSave(any(Runnable.class), eq(mSbn)); |
| 577 | } |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 578 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 579 | @Test |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 580 | public void testCloseControls_blockingHelperDismissedIfShown() throws Exception { |
| 581 | mNotificationInfo.bindNotification( |
| 582 | mMockPackageManager, |
| 583 | mMockINotificationManager, |
| 584 | TEST_PACKAGE_NAME, |
| 585 | mNotificationChannel, |
| 586 | 1 /* numChannels */, |
| 587 | mSbn, |
| 588 | null /* checkSaveListener */, |
| 589 | null /* onSettingsClick */, |
| 590 | null /* onAppSettingsClick */, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 591 | false /* isNonblockable */, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 592 | true /* isForBlockingHelper */, |
| 593 | false /* isUserSentimentNegative */); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 594 | NotificationGuts guts = mock(NotificationGuts.class); |
| 595 | doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean()); |
| 596 | mNotificationInfo.setGutsParent(guts); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 597 | |
| 598 | mNotificationInfo.closeControls(mNotificationInfo); |
| 599 | |
| 600 | verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); |
| 601 | } |
| 602 | |
| 603 | @Test |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 604 | public void testNonBlockableAppDoesNotBecomeBlocked() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 605 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 606 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 607 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 608 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 609 | waitForUndoButton(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 610 | |
| 611 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 612 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 613 | anyString(), eq(TEST_UID), any()); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 617 | public void testBlockChangedCallsUpdateNotificationChannel() throws Exception { |
| 618 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 619 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 620 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 621 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 622 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 623 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 624 | mNotificationInfo.handleCloseControls(true, false); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 625 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 626 | mTestableLooper.processAllMessages(); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 627 | ArgumentCaptor<NotificationChannel> updated = |
| 628 | ArgumentCaptor.forClass(NotificationChannel.class); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 629 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 630 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 631 | assertTrue((updated.getValue().getUserLockedFields() |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 632 | & USER_LOCKED_IMPORTANCE) != 0); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 633 | assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance()); |
| 634 | } |
| 635 | |
| 636 | @Test |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 637 | public void testBlockChangedCallsUpdateNotificationChannel_blockingHelper() throws Exception { |
| 638 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 639 | mNotificationInfo.bindNotification( |
| 640 | mMockPackageManager, |
| 641 | mMockINotificationManager, |
| 642 | TEST_PACKAGE_NAME, |
| 643 | mNotificationChannel, |
| 644 | 1 /* numChannels */, |
| 645 | mSbn, |
| 646 | null /* checkSaveListener */, |
| 647 | null /* onSettingsClick */, |
| 648 | null /* onAppSettingsClick */, |
| 649 | false /* isNonblockable */, |
| 650 | true /* isForBlockingHelper */, |
| 651 | true /* isUserSentimentNegative */); |
| 652 | |
| 653 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 654 | waitForUndoButton(); |
| 655 | mNotificationInfo.handleCloseControls(true, false); |
| 656 | |
| 657 | mTestableLooper.processAllMessages(); |
| 658 | ArgumentCaptor<NotificationChannel> updated = |
| 659 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 660 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 661 | anyString(), eq(TEST_UID), updated.capture()); |
| 662 | assertTrue((updated.getValue().getUserLockedFields() |
| 663 | & USER_LOCKED_IMPORTANCE) != 0); |
| 664 | assertEquals(IMPORTANCE_NONE, updated.getValue().getImportance()); |
| 665 | } |
| 666 | |
| 667 | |
| 668 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 669 | public void testNonBlockableAppDoesNotBecomeMin() throws Exception { |
| 670 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 671 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 672 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 673 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 674 | waitForUndoButton(); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 675 | |
| 676 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 677 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 678 | anyString(), eq(TEST_UID), any()); |
| 679 | } |
| 680 | |
| 681 | @Test |
| 682 | public void testMinChangedCallsUpdateNotificationChannel() throws Exception { |
| 683 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 684 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 685 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 686 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 687 | |
| 688 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 689 | waitForUndoButton(); |
| 690 | mNotificationInfo.handleCloseControls(true, false); |
| 691 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 692 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 693 | ArgumentCaptor<NotificationChannel> updated = |
| 694 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 695 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 696 | anyString(), eq(TEST_UID), updated.capture()); |
| 697 | assertTrue((updated.getValue().getUserLockedFields() |
| 698 | & USER_LOCKED_IMPORTANCE) != 0); |
| 699 | assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance()); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | @Test |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 703 | public void testKeepUpdatesNotificationChannel() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 704 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 705 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 706 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 707 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 708 | mNotificationInfo.handleCloseControls(true, false); |
| 709 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 710 | mTestableLooper.processAllMessages(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 711 | ArgumentCaptor<NotificationChannel> updated = |
| 712 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 713 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 714 | anyString(), eq(TEST_UID), updated.capture()); |
| 715 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 716 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 717 | } |
| 718 | |
| 719 | @Test |
| 720 | public void testBlockUndoDoesNotBlockNotificationChannel() throws Exception { |
| 721 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 722 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 723 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 724 | |
| 725 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 726 | waitForUndoButton(); |
| 727 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 728 | waitForStopButton(); |
| 729 | mNotificationInfo.handleCloseControls(true, false); |
| 730 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 731 | mTestableLooper.processAllMessages(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 732 | ArgumentCaptor<NotificationChannel> updated = |
| 733 | ArgumentCaptor.forClass(NotificationChannel.class); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 734 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 735 | anyString(), eq(TEST_UID), updated.capture()); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 736 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 737 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 738 | } |
| 739 | |
| 740 | @Test |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 741 | public void testMinUndoDoesNotMinNotificationChannel() throws Exception { |
| 742 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 743 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 744 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, false); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 745 | |
| 746 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 747 | waitForUndoButton(); |
| 748 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 749 | waitForStopButton(); |
| 750 | mNotificationInfo.handleCloseControls(true, false); |
| 751 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 752 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 753 | ArgumentCaptor<NotificationChannel> updated = |
| 754 | ArgumentCaptor.forClass(NotificationChannel.class); |
| 755 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
| 756 | anyString(), eq(TEST_UID), updated.capture()); |
| 757 | assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE)); |
| 758 | assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance()); |
| 759 | } |
| 760 | |
| 761 | @Test |
| 762 | public void testCloseControlsDoesNotUpdateiMinIfSaveIsFalse() throws Exception { |
| 763 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 764 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 765 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 766 | |
| 767 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 768 | waitForUndoButton(); |
| 769 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 770 | |
| 771 | mTestableLooper.processAllMessages(); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 772 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 773 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 774 | } |
| 775 | |
| 776 | @Test |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 777 | public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception { |
| 778 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 779 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 780 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 781 | |
| 782 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 783 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 784 | mNotificationInfo.handleCloseControls(false, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 785 | |
| 786 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 787 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 788 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 789 | } |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 790 | |
| 791 | @Test |
Gus Prevas | f4f0b06 | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 792 | public void testBlockDoesNothingIfCheckSaveListenerIsNoOp() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 793 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 794 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 795 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 796 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 797 | }, null, null, true); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 798 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 799 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Gus Prevas | f4f0b06 | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 800 | mTestableLooper.processAllMessages(); |
| 801 | ensureNoUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 802 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 803 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 804 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 805 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | @Test |
| 809 | public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 810 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 811 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 812 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 813 | (Runnable saveImportance, StatusBarNotification sbn) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 814 | saveImportance.run(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 815 | }, null, null, false); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 816 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 817 | mNotificationInfo.findViewById(R.id.block).performClick(); |
Gus Prevas | f4f0b06 | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 818 | mTestableLooper.processAllMessages(); |
| 819 | verify(mMockINotificationManager, never()).updateNotificationChannelForPackage( |
| 820 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
| 821 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 822 | waitForUndoButton(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 823 | mNotificationInfo.handleCloseControls(true, false); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 824 | |
| 825 | mTestableLooper.processAllMessages(); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 826 | verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 827 | eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel)); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 828 | } |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 829 | |
| 830 | @Test |
| 831 | public void testDisplaySettingsLink() throws Exception { |
| 832 | final CountDownLatch latch = new CountDownLatch(1); |
| 833 | final String settingsText = "work chats"; |
| 834 | final ResolveInfo ri = new ResolveInfo(); |
| 835 | ri.activityInfo = new ActivityInfo(); |
| 836 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 837 | ri.activityInfo.name = "something"; |
| 838 | List<ResolveInfo> ris = new ArrayList<>(); |
| 839 | ris.add(ri); |
| 840 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 841 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 842 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 843 | .setSettingsText(settingsText).build(); |
| 844 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 845 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 846 | |
| 847 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 848 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 849 | (View v, Intent intent) -> { |
| 850 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 851 | }, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 852 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 853 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 854 | settingsLink.performClick(); |
| 855 | assertEquals(0, latch.getCount()); |
| 856 | } |
| 857 | |
| 858 | @Test |
| 859 | public void testDisplaySettingsLink_multipleChannels() throws Exception { |
| 860 | final CountDownLatch latch = new CountDownLatch(1); |
| 861 | final String settingsText = "work chats"; |
| 862 | final ResolveInfo ri = new ResolveInfo(); |
| 863 | ri.activityInfo = new ActivityInfo(); |
| 864 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 865 | ri.activityInfo.name = "something"; |
| 866 | List<ResolveInfo> ris = new ArrayList<>(); |
| 867 | ris.add(ri); |
| 868 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 869 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 870 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 871 | .setSettingsText(settingsText).build(); |
| 872 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 873 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 874 | |
| 875 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 876 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 877 | (View v, Intent intent) -> { |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 878 | latch.countDown(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 879 | }, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 880 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 881 | assertEquals(View.VISIBLE, settingsLink.getVisibility()); |
| 882 | settingsLink.performClick(); |
| 883 | assertEquals(0, latch.getCount()); |
| 884 | } |
| 885 | |
| 886 | @Test |
| 887 | public void testNoSettingsLink_noHandlingActivity() throws Exception { |
| 888 | final String settingsText = "work chats"; |
| 889 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(null); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 890 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 891 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 892 | .setSettingsText(settingsText).build(); |
| 893 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 894 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 895 | |
| 896 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 897 | TEST_PACKAGE_NAME, mNotificationChannel, MULTIPLE_CHANNEL_COUNT, sbn, null, null, |
| 898 | null, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 899 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 900 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | @Test |
| 904 | public void testNoSettingsLink_noLinkText() throws Exception { |
| 905 | final ResolveInfo ri = new ResolveInfo(); |
| 906 | ri.activityInfo = new ActivityInfo(); |
| 907 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 908 | ri.activityInfo.name = "something"; |
| 909 | List<ResolveInfo> ris = new ArrayList<>(); |
| 910 | ris.add(ri); |
| 911 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 912 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 913 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()).build(); |
| 914 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 915 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 916 | |
| 917 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 918 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 919 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 920 | assertEquals(GONE, settingsLink.getVisibility()); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 921 | } |
| 922 | |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 923 | @Test |
| 924 | public void testBindHeader_noSettingsLinkWhenIsForBlockingHelper() throws Exception { |
| 925 | final String settingsText = "work chats"; |
| 926 | final ResolveInfo ri = new ResolveInfo(); |
| 927 | ri.activityInfo = new ActivityInfo(); |
| 928 | ri.activityInfo.packageName = TEST_PACKAGE_NAME; |
| 929 | ri.activityInfo.name = "something"; |
| 930 | List<ResolveInfo> ris = new ArrayList<>(); |
| 931 | ris.add(ri); |
| 932 | when(mMockPackageManager.queryIntentActivities(any(), anyInt())).thenReturn(ris); |
| 933 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 934 | Notification n = new Notification.Builder(mContext, mNotificationChannel.getId()) |
| 935 | .setSettingsText(settingsText).build(); |
| 936 | StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, |
| 937 | 0, null, 0, 0, n, UserHandle.CURRENT, null, 0); |
| 938 | |
| 939 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
| 940 | TEST_PACKAGE_NAME, mNotificationChannel, 1, sbn, null, null, null, false, true, |
| 941 | true); |
| 942 | final TextView settingsLink = mNotificationInfo.findViewById(R.id.app_settings); |
| 943 | assertEquals(GONE, settingsLink.getVisibility()); |
| 944 | } |
| 945 | |
Geoffrey Pitsch | 8c8dbde | 2017-04-20 11:44:33 -0400 | [diff] [blame] | 946 | |
| 947 | @Test |
| 948 | public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception { |
| 949 | assertFalse(mNotificationInfo.willBeRemoved()); |
| 950 | } |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 951 | |
| 952 | @Test |
| 953 | public void testUndoText_min() throws Exception { |
| 954 | mSbn.getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; |
| 955 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 956 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 957 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 958 | |
| 959 | mNotificationInfo.findViewById(R.id.minimize).performClick(); |
| 960 | waitForUndoButton(); |
| 961 | TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text); |
| 962 | assertTrue(confirmationText.getText().toString().contains("minimized")); |
| 963 | } |
| 964 | |
| 965 | @Test |
| 966 | public void testUndoText_block() throws Exception { |
| 967 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 968 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 969 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 970 | |
| 971 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 972 | waitForUndoButton(); |
| 973 | TextView confirmationText = mNotificationInfo.findViewById(R.id.confirmation_text); |
| 974 | assertTrue(confirmationText.getText().toString().contains("won't see")); |
| 975 | } |
| 976 | |
| 977 | @Test |
| 978 | public void testNoHeaderOnConfirmation() throws Exception { |
| 979 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 980 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 981 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 982 | |
| 983 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 984 | waitForUndoButton(); |
| 985 | assertEquals(GONE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 986 | } |
| 987 | |
| 988 | @Test |
| 989 | public void testHeaderOnUndo() throws Exception { |
| 990 | mNotificationChannel.setImportance(IMPORTANCE_LOW); |
| 991 | mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 992 | TEST_PACKAGE_NAME, mNotificationChannel, 1, mSbn, null, null, null, true); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 993 | |
| 994 | mNotificationInfo.findViewById(R.id.block).performClick(); |
| 995 | waitForUndoButton(); |
| 996 | mNotificationInfo.findViewById(R.id.undo).performClick(); |
| 997 | waitForStopButton(); |
| 998 | assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility()); |
| 999 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 1000 | } |