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 17 package com.android.systemui.statusbar; 18 19 import static org.mockito.ArgumentMatchers.any; 20 import static org.mockito.Mockito.mock; 21 import static org.mockito.Mockito.spy; 22 import static org.mockito.Mockito.verify; 23 24 import android.support.test.filters.SmallTest; 25 import android.support.test.runner.AndroidJUnit4; 26 import android.view.View; 27 28 import com.android.systemui.SysuiTestCase; 29 import com.android.systemui.statusbar.notification.AboveShelfChangedListener; 30 import com.android.systemui.statusbar.stack.NotificationChildrenContainer; 31 32 import org.junit.Assert; 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 37 @SmallTest 38 @RunWith(AndroidJUnit4.class) 39 public class ExpandableNotificationRowTest extends SysuiTestCase { 40 41 private ExpandableNotificationRow mGroup; 42 private NotificationTestHelper mNotificationTestHelper; 43 44 @Before 45 public void setUp() throws Exception { 46 mNotificationTestHelper = new NotificationTestHelper(mContext); 47 mGroup = mNotificationTestHelper.createGroup(); 48 } 49 50 @Test 51 public void testGroupSummaryNotShowingIconWhenPublic() { 52 mGroup.setSensitive(true, true); 53 mGroup.setHideSensitive(true, false, 0, 0); 54 Assert.assertTrue(mGroup.isSummaryWithChildren()); 55 Assert.assertFalse(mGroup.isShowingIcon()); 56 } 57 58 @Test 59 public void testNotificationHeaderVisibleWhenAnimating() { 60 mGroup.setSensitive(true, true); 61 mGroup.setHideSensitive(true, false, 0, 0); 62 mGroup.setHideSensitive(false, true, 0, 0); 63 Assert.assertTrue(mGroup.getChildrenContainer().getVisibleHeader().getVisibility() 64 == View.VISIBLE); 65 } 66 67 @Test 68 public void testUserLockedResetEvenWhenNoChildren() { 69 mGroup.setUserLocked(true); 70 mGroup.removeAllChildren(); 71 mGroup.setUserLocked(false); 72 Assert.assertFalse("The childrencontainer should not be userlocked but is, the state " 73 + "seems out of sync.", mGroup.getChildrenContainer().isUserLocked()); 74 } 75 76 @Test 77 public void testReinflatedOnDensityChange() { 78 mGroup.setUserLocked(true); 79 mGroup.removeAllChildren(); 80 mGroup.setUserLocked(false); 81 NotificationChildrenContainer mockContainer = mock(NotificationChildrenContainer.class); 82 mGroup.setChildrenContainer(mockContainer); 83 mGroup.onDensityOrFontScaleChanged(); 84 verify(mockContainer).reInflateViews(any(), any()); 85 } 86 87 @Test 88 public void testIconColorShouldBeUpdatedWhenSensitive() throws Exception { 89 ExpandableNotificationRow row = spy(mNotificationTestHelper.createRow()); 90 row.setSensitive(true, true); 91 row.setHideSensitive(true, false, 0, 0); 92 verify(row).updateShelfIconColor(); 93 } 94 95 @Test 96 public void testIconColorShouldBeUpdatedWhenSettingDark() throws Exception { 97 ExpandableNotificationRow row = spy(mNotificationTestHelper.createRow()); 98 row.setDark(true, false, 0); 99 verify(row).updateShelfIconColor(); 100 } 101 102 @Test 103 public void testAboveShelfChangedListenerCalled() throws Exception { 104 ExpandableNotificationRow row = mNotificationTestHelper.createRow(); 105 AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); 106 row.setAboveShelfChangedListener(listener); 107 row.setHeadsUp(true); 108 verify(listener).onAboveShelfStateChanged(true); 109 } 110 111 @Test 112 public void testAboveShelfChangedListenerCalledPinned() throws Exception { 113 ExpandableNotificationRow row = mNotificationTestHelper.createRow(); 114 AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); 115 row.setAboveShelfChangedListener(listener); 116 row.setPinned(true); 117 verify(listener).onAboveShelfStateChanged(true); 118 } 119 120 @Test 121 public void testAboveShelfChangedListenerCalledHeadsUpGoingAway() throws Exception { 122 ExpandableNotificationRow row = mNotificationTestHelper.createRow(); 123 AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); 124 row.setAboveShelfChangedListener(listener); 125 row.setHeadsUpAnimatingAway(true); 126 verify(listener).onAboveShelfStateChanged(true); 127 } 128 @Test 129 public void testAboveShelfChangedListenerCalledWhenGoingBelow() throws Exception { 130 ExpandableNotificationRow row = mNotificationTestHelper.createRow(); 131 row.setHeadsUp(true); 132 AboveShelfChangedListener listener = mock(AboveShelfChangedListener.class); 133 row.setAboveShelfChangedListener(listener); 134 row.setAboveShelf(false); 135 verify(listener).onAboveShelfStateChanged(false); 136 } 137 138 @Test 139 public void testClickSound() throws Exception { 140 Assert.assertTrue("Should play sounds by default.", mGroup.isSoundEffectsEnabled()); 141 mGroup.setDark(true /* dark */, false /* fade */, 0 /* delay */); 142 mGroup.setSecureStateProvider(()-> false); 143 Assert.assertFalse("Shouldn't play sounds when dark and trusted.", 144 mGroup.isSoundEffectsEnabled()); 145 mGroup.setSecureStateProvider(()-> true); 146 Assert.assertTrue("Should always play sounds when not trusted.", 147 mGroup.isSoundEffectsEnabled()); 148 } 149 } 150