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