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