Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 18 | |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 19 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 20 | |
Ned Burns | 1a5e22f | 2019-02-14 15:11:52 -0500 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.notification.row.NotificationContentInflater.FLAG_CONTENT_VIEW_ALL; |
| 22 | import static com.android.systemui.statusbar.notification.row.NotificationContentInflater.FLAG_CONTENT_VIEW_HEADS_UP; |
| 23 | import static com.android.systemui.statusbar.notification.row.NotificationContentInflater.FLAG_CONTENT_VIEW_PUBLIC; |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 24 | |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 25 | import static org.junit.Assert.assertEquals; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 26 | import static org.junit.Assert.assertFalse; |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 27 | import static org.junit.Assert.assertNull; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 28 | import static org.junit.Assert.assertTrue; |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 29 | import static org.mockito.ArgumentMatchers.any; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 30 | import static org.mockito.ArgumentMatchers.anyInt; |
Rohan Shah | c6990a0 | 2018-03-23 17:24:17 -0700 | [diff] [blame] | 31 | import static org.mockito.ArgumentMatchers.eq; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 32 | import static org.mockito.Mockito.mock; |
Rohan Shah | c6990a0 | 2018-03-23 17:24:17 -0700 | [diff] [blame] | 33 | import static org.mockito.Mockito.reset; |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 34 | import static org.mockito.Mockito.spy; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 35 | import static org.mockito.Mockito.times; |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 36 | import static org.mockito.Mockito.verify; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 37 | import static org.mockito.Mockito.when; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 38 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 39 | import android.app.AppOpsManager; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 40 | import android.app.NotificationChannel; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 41 | import android.testing.AndroidTestingRunner; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 42 | import android.testing.TestableLooper; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 43 | import android.testing.TestableLooper.RunWithLooper; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 44 | import android.util.ArraySet; |
| 45 | import android.view.NotificationHeaderView; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 46 | import android.view.View; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 47 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 48 | import androidx.test.filters.SmallTest; |
| 49 | |
Jason Monk | c429f69 | 2017-06-27 13:13:49 -0400 | [diff] [blame] | 50 | import com.android.systemui.SysuiTestCase; |
Rohan Shah | c6990a0 | 2018-03-23 17:24:17 -0700 | [diff] [blame] | 51 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 52 | import com.android.systemui.statusbar.NotificationTestHelper; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 53 | import com.android.systemui.statusbar.notification.AboveShelfChangedListener; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 54 | import com.android.systemui.statusbar.notification.stack.NotificationChildrenContainer; |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 55 | |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 56 | import org.junit.Assert; |
| 57 | import org.junit.Before; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 58 | import org.junit.Rule; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 59 | import org.junit.Test; |
| 60 | import org.junit.runner.RunWith; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 61 | import org.mockito.Mock; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 62 | import org.mockito.junit.MockitoJUnit; |
| 63 | import org.mockito.junit.MockitoRule; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 64 | |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 65 | import java.util.List; |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 66 | |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 67 | @SmallTest |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 68 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 69 | @RunWithLooper |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 70 | public class ExpandableNotificationRowTest extends SysuiTestCase { |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 71 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 72 | private ExpandableNotificationRow mGroupRow; |
| 73 | |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 74 | private NotificationTestHelper mNotificationTestHelper; |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 75 | boolean mHeadsUpAnimatingAway = false; |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 76 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 77 | @Rule public MockitoRule mockito = MockitoJUnit.rule(); |
| 78 | @Mock private NotificationBlockingHelperManager mBlockingHelperManager; |
| 79 | |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 80 | @Before |
Selim Cinek | 2630dc7 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 81 | public void setUp() throws Exception { |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 82 | com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 83 | mNotificationTestHelper = new NotificationTestHelper(mContext); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 84 | mGroupRow = mNotificationTestHelper.createGroup(); |
| 85 | mGroupRow.setHeadsUpAnimatingAwayListener( |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 86 | animatingAway -> mHeadsUpAnimatingAway = animatingAway); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 87 | mDependency.injectTestDependency( |
| 88 | NotificationBlockingHelperManager.class, |
| 89 | mBlockingHelperManager); |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Test |
| 93 | public void testGroupSummaryNotShowingIconWhenPublic() { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 94 | mGroupRow.setSensitive(true, true); |
| 95 | mGroupRow.setHideSensitiveForIntrinsicHeight(true); |
| 96 | assertTrue(mGroupRow.isSummaryWithChildren()); |
| 97 | assertFalse(mGroupRow.isShowingIcon()); |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Selim Cinek | 1826d98 | 2017-03-06 20:47:37 -0800 | [diff] [blame] | 100 | @Test |
| 101 | public void testNotificationHeaderVisibleWhenAnimating() { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 102 | mGroupRow.setSensitive(true, true); |
| 103 | mGroupRow.setHideSensitive(true, false, 0, 0); |
| 104 | mGroupRow.setHideSensitive(false, true, 0, 0); |
| 105 | assertTrue(mGroupRow.getChildrenContainer().getVisibleHeader().getVisibility() |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 106 | == View.VISIBLE); |
Selim Cinek | 1826d98 | 2017-03-06 20:47:37 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 109 | @Test |
| 110 | public void testUserLockedResetEvenWhenNoChildren() { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 111 | mGroupRow.setUserLocked(true); |
| 112 | mGroupRow.removeAllChildren(); |
| 113 | mGroupRow.setUserLocked(false); |
| 114 | assertFalse("The childrencontainer should not be userlocked but is, the state " |
| 115 | + "seems out of sync.", mGroupRow.getChildrenContainer().isUserLocked()); |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Test |
| 119 | public void testReinflatedOnDensityChange() { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 120 | mGroupRow.setUserLocked(true); |
| 121 | mGroupRow.removeAllChildren(); |
| 122 | mGroupRow.setUserLocked(false); |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 123 | NotificationChildrenContainer mockContainer = mock(NotificationChildrenContainer.class); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 124 | mGroupRow.setChildrenContainer(mockContainer); |
| 125 | mGroupRow.onDensityOrFontScaleChanged(); |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 126 | verify(mockContainer).reInflateViews(any(), any()); |
| 127 | } |
| 128 | |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 129 | @Test |
| 130 | public void testIconColorShouldBeUpdatedWhenSensitive() throws Exception { |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 131 | ExpandableNotificationRow row = spy(mNotificationTestHelper.createRow( |
| 132 | FLAG_CONTENT_VIEW_ALL)); |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 133 | row.setSensitive(true, true); |
| 134 | row.setHideSensitive(true, false, 0, 0); |
| 135 | verify(row).updateShelfIconColor(); |
| 136 | } |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 137 | |
| 138 | @Test |
Selim Cinek | a7c6963 | 2017-06-07 15:51:29 -0700 | [diff] [blame] | 139 | public void testIconColorShouldBeUpdatedWhenSettingDark() throws Exception { |
| 140 | ExpandableNotificationRow row = spy(mNotificationTestHelper.createRow()); |
| 141 | row.setDark(true, false, 0); |
| 142 | verify(row).updateShelfIconColor(); |
| 143 | } |
Ian Pedowitz | a27856d | 2017-06-07 17:47:38 -0700 | [diff] [blame] | 144 | |
| 145 | @Test |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 146 | public void testFreeContentViewWhenSafe() throws Exception { |
| 147 | ExpandableNotificationRow row = mNotificationTestHelper.createRow(FLAG_CONTENT_VIEW_ALL); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 148 | |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 149 | row.freeContentViewWhenSafe(FLAG_CONTENT_VIEW_HEADS_UP); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 150 | |
| 151 | assertNull(row.getPrivateLayout().getHeadsUpChild()); |
| 152 | } |
| 153 | |
| 154 | @Test |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 155 | public void setNeedsRedactionSetsInflationFlag() throws Exception { |
| 156 | ExpandableNotificationRow row = mNotificationTestHelper.createRow(); |
| 157 | |
| 158 | row.setNeedsRedaction(true); |
| 159 | |
| 160 | assertTrue(row.getNotificationInflater().isInflationFlagSet(FLAG_CONTENT_VIEW_PUBLIC)); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void setNeedsRedactionFreesViewWhenFalse() throws Exception { |
| 165 | ExpandableNotificationRow row = mNotificationTestHelper.createRow(FLAG_CONTENT_VIEW_ALL); |
| 166 | row.setNeedsRedaction(true); |
| 167 | row.getPublicLayout().setVisibility(View.GONE); |
| 168 | |
| 169 | row.setNeedsRedaction(false); |
| 170 | |
| 171 | assertNull(row.getPublicLayout().getContractedChild()); |
| 172 | } |
| 173 | |
| 174 | @Test |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 175 | public void testAboveShelfChangedListenerCalled() throws Exception { |
| 176 | ExpandableNotificationRow row = mNotificationTestHelper.createRow(); |
| 177 | AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); |
| 178 | row.setAboveShelfChangedListener(listener); |
| 179 | row.setHeadsUp(true); |
| 180 | verify(listener).onAboveShelfStateChanged(true); |
| 181 | } |
| 182 | |
| 183 | @Test |
| 184 | public void testAboveShelfChangedListenerCalledPinned() throws Exception { |
| 185 | ExpandableNotificationRow row = mNotificationTestHelper.createRow(); |
| 186 | AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); |
| 187 | row.setAboveShelfChangedListener(listener); |
| 188 | row.setPinned(true); |
| 189 | verify(listener).onAboveShelfStateChanged(true); |
| 190 | } |
| 191 | |
| 192 | @Test |
| 193 | public void testAboveShelfChangedListenerCalledHeadsUpGoingAway() throws Exception { |
| 194 | ExpandableNotificationRow row = mNotificationTestHelper.createRow(); |
| 195 | AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); |
| 196 | row.setAboveShelfChangedListener(listener); |
| 197 | row.setHeadsUpAnimatingAway(true); |
| 198 | verify(listener).onAboveShelfStateChanged(true); |
| 199 | } |
| 200 | @Test |
| 201 | public void testAboveShelfChangedListenerCalledWhenGoingBelow() throws Exception { |
| 202 | ExpandableNotificationRow row = mNotificationTestHelper.createRow(); |
| 203 | row.setHeadsUp(true); |
| 204 | AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); |
| 205 | row.setAboveShelfChangedListener(listener); |
| 206 | row.setAboveShelf(false); |
| 207 | verify(listener).onAboveShelfStateChanged(false); |
| 208 | } |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 209 | |
| 210 | @Test |
| 211 | public void testClickSound() throws Exception { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 212 | assertTrue("Should play sounds by default.", mGroupRow.isSoundEffectsEnabled()); |
| 213 | mGroupRow.setDark(true /* dark */, false /* fade */, 0 /* delay */); |
| 214 | mGroupRow.setSecureStateProvider(()-> false); |
| 215 | assertFalse("Shouldn't play sounds when dark and trusted.", |
| 216 | mGroupRow.isSoundEffectsEnabled()); |
| 217 | mGroupRow.setSecureStateProvider(()-> true); |
| 218 | assertTrue("Should always play sounds when not trusted.", |
| 219 | mGroupRow.isSoundEffectsEnabled()); |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 220 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 221 | |
| 222 | @Test |
Rohan Shah | c6990a0 | 2018-03-23 17:24:17 -0700 | [diff] [blame] | 223 | public void testSetDismissed_longPressListenerRemoved() { |
| 224 | ExpandableNotificationRow.LongPressListener listener = |
| 225 | mock(ExpandableNotificationRow.LongPressListener.class); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 226 | mGroupRow.setLongPressListener(listener); |
| 227 | mGroupRow.doLongClickCallback(0,0); |
| 228 | verify(listener, times(1)).onLongPress(eq(mGroupRow), eq(0), eq(0), |
Rohan Shah | c6990a0 | 2018-03-23 17:24:17 -0700 | [diff] [blame] | 229 | any(NotificationMenuRowPlugin.MenuItem.class)); |
| 230 | reset(listener); |
| 231 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 232 | mGroupRow.setDismissed(true); |
| 233 | mGroupRow.doLongClickCallback(0,0); |
| 234 | verify(listener, times(0)).onLongPress(eq(mGroupRow), eq(0), eq(0), |
Rohan Shah | c6990a0 | 2018-03-23 17:24:17 -0700 | [diff] [blame] | 235 | any(NotificationMenuRowPlugin.MenuItem.class)); |
| 236 | } |
| 237 | |
| 238 | @Test |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 239 | public void testShowAppOps_noHeader() { |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 240 | // public notification is custom layout - no header |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 241 | mGroupRow.setSensitive(true, true); |
| 242 | mGroupRow.setAppOpsOnClickListener(null); |
| 243 | mGroupRow.showAppOpsIcons(null); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | @Test |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 247 | public void testShowAppOpsIcons_header() { |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 248 | NotificationHeaderView mockHeader = mock(NotificationHeaderView.class); |
| 249 | |
| 250 | NotificationContentView publicLayout = mock(NotificationContentView.class); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 251 | mGroupRow.setPublicLayout(publicLayout); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 252 | NotificationContentView privateLayout = mock(NotificationContentView.class); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 253 | mGroupRow.setPrivateLayout(privateLayout); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 254 | NotificationChildrenContainer mockContainer = mock(NotificationChildrenContainer.class); |
| 255 | when(mockContainer.getNotificationChildCount()).thenReturn(1); |
| 256 | when(mockContainer.getHeaderView()).thenReturn(mockHeader); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 257 | mGroupRow.setChildrenContainer(mockContainer); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 258 | |
| 259 | ArraySet<Integer> ops = new ArraySet<>(); |
| 260 | ops.add(AppOpsManager.OP_ANSWER_PHONE_CALLS); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 261 | mGroupRow.showAppOpsIcons(ops); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 262 | |
| 263 | verify(mockHeader, times(1)).showAppOpsIcons(ops); |
| 264 | verify(privateLayout, times(1)).showAppOpsIcons(ops); |
| 265 | verify(publicLayout, times(1)).showAppOpsIcons(ops); |
| 266 | |
| 267 | } |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 268 | |
| 269 | @Test |
| 270 | public void testAppOpsOnClick() { |
| 271 | ExpandableNotificationRow.OnAppOpsClickListener l = mock( |
| 272 | ExpandableNotificationRow.OnAppOpsClickListener.class); |
| 273 | View view = mock(View.class); |
| 274 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 275 | mGroupRow.setAppOpsOnClickListener(l); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 276 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 277 | mGroupRow.getAppOpsOnClickListener().onClick(view); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 278 | verify(l, times(1)).onClick(any(), anyInt(), anyInt(), any()); |
| 279 | } |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 280 | |
| 281 | @Test |
| 282 | public void testHeadsUpAnimatingAwayListener() { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 283 | mGroupRow.setHeadsUpAnimatingAway(true); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 284 | Assert.assertEquals(true, mHeadsUpAnimatingAway); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 285 | mGroupRow.setHeadsUpAnimatingAway(false); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 286 | Assert.assertEquals(false, mHeadsUpAnimatingAway); |
| 287 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 288 | |
| 289 | @Test |
| 290 | public void testPerformDismissWithBlockingHelper_falseWhenBlockingHelperIsntShown() { |
| 291 | when(mBlockingHelperManager.perhapsShowBlockingHelper( |
| 292 | eq(mGroupRow), any(NotificationMenuRowPlugin.class))).thenReturn(false); |
| 293 | |
| 294 | assertFalse( |
| 295 | mGroupRow.performDismissWithBlockingHelper(false /* fromAccessibility */)); |
| 296 | } |
| 297 | |
| 298 | @Test |
| 299 | public void testPerformDismissWithBlockingHelper_doesntPerformOnGroupSummary() { |
| 300 | ExpandableNotificationRow childRow = mGroupRow.getChildrenContainer().getViewAtPosition(0); |
| 301 | when(mBlockingHelperManager.perhapsShowBlockingHelper(eq(childRow), any(NotificationMenuRowPlugin.class))) |
| 302 | .thenReturn(true); |
| 303 | |
| 304 | assertTrue( |
| 305 | childRow.performDismissWithBlockingHelper(false /* fromAccessibility */)); |
| 306 | |
| 307 | verify(mBlockingHelperManager, times(1)) |
| 308 | .perhapsShowBlockingHelper(eq(childRow), any(NotificationMenuRowPlugin.class)); |
| 309 | verify(mBlockingHelperManager, times(0)) |
| 310 | .perhapsShowBlockingHelper(eq(mGroupRow), any(NotificationMenuRowPlugin.class)); |
| 311 | } |
| 312 | |
| 313 | @Test |
| 314 | public void testIsBlockingHelperShowing_isCorrectlyUpdated() { |
| 315 | mGroupRow.setBlockingHelperShowing(true); |
| 316 | assertTrue(mGroupRow.isBlockingHelperShowing()); |
| 317 | |
| 318 | mGroupRow.setBlockingHelperShowing(false); |
| 319 | assertFalse(mGroupRow.isBlockingHelperShowing()); |
| 320 | } |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 321 | |
| 322 | @Test |
| 323 | public void testGetNumUniqueChildren_defaultChannel() { |
| 324 | assertEquals(1, mGroupRow.getNumUniqueChannels()); |
| 325 | } |
| 326 | |
| 327 | @Test |
| 328 | public void testGetNumUniqueChildren_multiChannel() { |
| 329 | List<ExpandableNotificationRow> childRows = |
| 330 | mGroupRow.getChildrenContainer().getNotificationChildren(); |
| 331 | // Give each child a unique channel id/name. |
| 332 | int i = 0; |
| 333 | for (ExpandableNotificationRow childRow : childRows) { |
| 334 | childRow.getEntry().channel = |
| 335 | new NotificationChannel("id" + i, "dinnertime" + i, IMPORTANCE_DEFAULT); |
| 336 | i++; |
| 337 | } |
| 338 | |
| 339 | assertEquals(3, mGroupRow.getNumUniqueChannels()); |
| 340 | } |
shawnlin | 4fbeac4 | 2018-04-30 20:32:40 +0800 | [diff] [blame] | 341 | |
| 342 | @Test |
| 343 | public void testIconScrollXAfterTranslationAndReset() throws Exception { |
| 344 | mGroupRow.setTranslation(50); |
| 345 | assertEquals(50, -mGroupRow.getEntry().expandedIcon.getScrollX()); |
| 346 | |
| 347 | mGroupRow.resetTranslation(); |
| 348 | assertEquals(0, mGroupRow.getEntry().expandedIcon.getScrollX()); |
| 349 | } |
Aaron Heuckroth | 17ce40e | 2018-06-19 15:44:40 -0400 | [diff] [blame] | 350 | |
| 351 | @Test |
| 352 | public void testIsExpanded_userExpanded() { |
| 353 | mGroupRow.setExpandable(true); |
| 354 | Assert.assertFalse(mGroupRow.isExpanded()); |
| 355 | mGroupRow.setUserExpanded(true); |
| 356 | Assert.assertTrue(mGroupRow.isExpanded()); |
| 357 | } |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 358 | } |