Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 1 | /* |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 3 | * |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 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 |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 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 |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
Selim Cinek | a7679b6 | 2017-05-10 16:33:25 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 18 | |
Gus Prevas | 5b9098dc | 2018-12-21 17:07:15 -0500 | [diff] [blame] | 19 | import static junit.framework.Assert.assertEquals; |
| 20 | |
| 21 | import static org.mockito.Matchers.anyObject; |
| 22 | import static org.mockito.Mockito.mock; |
| 23 | import static org.mockito.Mockito.verify; |
| 24 | import static org.mockito.Mockito.when; |
| 25 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 26 | import android.service.notification.StatusBarNotification; |
| 27 | import android.support.test.runner.AndroidJUnit4; |
| 28 | import android.test.suitebuilder.annotation.SmallTest; |
| 29 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 30 | import com.android.systemui.SysuiTestCase; |
Gus Prevas | 5b9098dc | 2018-12-21 17:07:15 -0500 | [diff] [blame] | 31 | import com.android.systemui.statusbar.NotificationPresenter; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 32 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 33 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 34 | |
| 35 | import org.junit.Before; |
| 36 | import org.junit.Test; |
| 37 | import org.junit.runner.RunWith; |
| 38 | |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 39 | @SmallTest |
| 40 | @RunWith(AndroidJUnit4.class) |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 41 | public class VisualStabilityManagerTest extends SysuiTestCase { |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 42 | |
Gus Prevas | 5b9098dc | 2018-12-21 17:07:15 -0500 | [diff] [blame] | 43 | private VisualStabilityManager mVisualStabilityManager = new VisualStabilityManager( |
| 44 | mock(NotificationEntryManager.class)); |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 45 | private VisualStabilityManager.Callback mCallback = mock(VisualStabilityManager.Callback.class); |
| 46 | private VisibilityLocationProvider mLocationProvider = mock(VisibilityLocationProvider.class); |
| 47 | private ExpandableNotificationRow mRow = mock(ExpandableNotificationRow.class); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 48 | private NotificationEntry mEntry; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 49 | |
| 50 | @Before |
| 51 | public void setUp() { |
Gus Prevas | 5b9098dc | 2018-12-21 17:07:15 -0500 | [diff] [blame] | 52 | mVisualStabilityManager.setUpWithPresenter(mock(NotificationPresenter.class)); |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 53 | mVisualStabilityManager.setVisibilityLocationProvider(mLocationProvider); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 54 | mEntry = new NotificationEntry(mock(StatusBarNotification.class)); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 55 | mEntry.setRow(mRow); |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void testPanelExpansion() { |
| 60 | mVisualStabilityManager.setPanelExpanded(true); |
| 61 | mVisualStabilityManager.setScreenOn(true); |
| 62 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), false); |
| 63 | mVisualStabilityManager.setPanelExpanded(false); |
| 64 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), true); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testScreenOn() { |
| 69 | mVisualStabilityManager.setPanelExpanded(true); |
| 70 | mVisualStabilityManager.setScreenOn(true); |
| 71 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), false); |
| 72 | mVisualStabilityManager.setScreenOn(false); |
| 73 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), true); |
| 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void testReorderingAllowedChangesScreenOn() { |
| 78 | mVisualStabilityManager.setPanelExpanded(true); |
| 79 | mVisualStabilityManager.setScreenOn(true); |
| 80 | assertEquals(mVisualStabilityManager.isReorderingAllowed(), false); |
| 81 | mVisualStabilityManager.setScreenOn(false); |
| 82 | assertEquals(mVisualStabilityManager.isReorderingAllowed(), true); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testReorderingAllowedChangesPanel() { |
| 87 | mVisualStabilityManager.setPanelExpanded(true); |
| 88 | mVisualStabilityManager.setScreenOn(true); |
| 89 | assertEquals(mVisualStabilityManager.isReorderingAllowed(), false); |
| 90 | mVisualStabilityManager.setPanelExpanded(false); |
| 91 | assertEquals(mVisualStabilityManager.isReorderingAllowed(), true); |
| 92 | } |
| 93 | |
| 94 | @Test |
| 95 | public void testCallBackCalledScreenOn() { |
| 96 | mVisualStabilityManager.setPanelExpanded(true); |
| 97 | mVisualStabilityManager.setScreenOn(true); |
| 98 | mVisualStabilityManager.addReorderingAllowedCallback(mCallback); |
| 99 | mVisualStabilityManager.setScreenOn(false); |
| 100 | verify(mCallback).onReorderingAllowed(); |
| 101 | } |
| 102 | |
| 103 | @Test |
| 104 | public void testCallBackCalledPanelExpanded() { |
| 105 | mVisualStabilityManager.setPanelExpanded(true); |
| 106 | mVisualStabilityManager.setScreenOn(true); |
| 107 | mVisualStabilityManager.addReorderingAllowedCallback(mCallback); |
| 108 | mVisualStabilityManager.setPanelExpanded(false); |
| 109 | verify(mCallback).onReorderingAllowed(); |
| 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void testCallBackExactlyOnce() { |
| 114 | mVisualStabilityManager.setPanelExpanded(true); |
| 115 | mVisualStabilityManager.setScreenOn(true); |
| 116 | mVisualStabilityManager.addReorderingAllowedCallback(mCallback); |
| 117 | mVisualStabilityManager.setScreenOn(false); |
| 118 | mVisualStabilityManager.setScreenOn(true); |
| 119 | mVisualStabilityManager.setScreenOn(false); |
| 120 | verify(mCallback).onReorderingAllowed(); |
| 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void testAddedCanReorder() { |
| 125 | mVisualStabilityManager.setPanelExpanded(true); |
| 126 | mVisualStabilityManager.setScreenOn(true); |
| 127 | mVisualStabilityManager.notifyViewAddition(mRow); |
| 128 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), true); |
| 129 | } |
| 130 | |
| 131 | @Test |
| 132 | public void testReorderingVisibleHeadsUpNotAllowed() { |
| 133 | mVisualStabilityManager.setPanelExpanded(true); |
| 134 | mVisualStabilityManager.setScreenOn(true); |
| 135 | when(mLocationProvider.isInVisibleLocation(anyObject())).thenReturn(true); |
| 136 | mVisualStabilityManager.onHeadsUpStateChanged(mEntry, true); |
| 137 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), false); |
| 138 | } |
| 139 | |
| 140 | @Test |
| 141 | public void testReorderingVisibleHeadsUpAllowed() { |
| 142 | mVisualStabilityManager.setPanelExpanded(true); |
| 143 | mVisualStabilityManager.setScreenOn(true); |
| 144 | when(mLocationProvider.isInVisibleLocation(anyObject())).thenReturn(false); |
| 145 | mVisualStabilityManager.onHeadsUpStateChanged(mEntry, true); |
| 146 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), true); |
| 147 | } |
| 148 | |
| 149 | @Test |
| 150 | public void testReorderingVisibleHeadsUpAllowedOnce() { |
| 151 | mVisualStabilityManager.setPanelExpanded(true); |
| 152 | mVisualStabilityManager.setScreenOn(true); |
| 153 | when(mLocationProvider.isInVisibleLocation(anyObject())).thenReturn(false); |
| 154 | mVisualStabilityManager.onHeadsUpStateChanged(mEntry, true); |
| 155 | mVisualStabilityManager.onReorderingFinished(); |
| 156 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), false); |
| 157 | } |
Adrian Roos | 4b820e4 | 2017-01-13 17:40:43 -0800 | [diff] [blame] | 158 | |
| 159 | @Test |
| 160 | public void testPulsing() { |
| 161 | mVisualStabilityManager.setPulsing(true); |
| 162 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), false); |
| 163 | mVisualStabilityManager.setPulsing(false); |
| 164 | assertEquals(mVisualStabilityManager.canReorderNotification(mRow), true); |
| 165 | } |
| 166 | |
| 167 | @Test |
| 168 | public void testReorderingAllowedChanges_Pulsing() { |
| 169 | mVisualStabilityManager.setPulsing(true); |
| 170 | assertEquals(mVisualStabilityManager.isReorderingAllowed(), false); |
| 171 | mVisualStabilityManager.setPulsing(false); |
| 172 | assertEquals(mVisualStabilityManager.isReorderingAllowed(), true); |
| 173 | } |
| 174 | |
| 175 | @Test |
| 176 | public void testCallBackCalled_Pulsing() { |
| 177 | mVisualStabilityManager.setPulsing(true); |
| 178 | mVisualStabilityManager.addReorderingAllowedCallback(mCallback); |
| 179 | mVisualStabilityManager.setPulsing(false); |
| 180 | verify(mCallback).onReorderingAllowed(); |
| 181 | } |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 182 | } |