Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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.phone; |
| 18 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.any; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 20 | import static org.mockito.Mockito.mock; |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 21 | import static org.mockito.Mockito.reset; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 25 | import android.testing.AndroidTestingRunner; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 26 | import android.testing.TestableLooper; |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 27 | import android.testing.TestableLooper.RunWithLooper; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.widget.TextView; |
| 30 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 31 | import androidx.test.filters.SmallTest; |
| 32 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 33 | import com.android.systemui.SysuiTestCase; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 34 | import com.android.systemui.plugins.DarkIconDispatcher; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 35 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 36 | import com.android.systemui.statusbar.HeadsUpStatusBarView; |
| 37 | import com.android.systemui.statusbar.NotificationTestHelper; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 38 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 39 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 40 | |
| 41 | import org.junit.Assert; |
| 42 | import org.junit.Before; |
| 43 | import org.junit.Test; |
| 44 | import org.junit.runner.RunWith; |
| 45 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 46 | @SmallTest |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 47 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 48 | @RunWithLooper |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 49 | public class HeadsUpAppearanceControllerTest extends SysuiTestCase { |
| 50 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 51 | private final NotificationStackScrollLayout mStackScroller = |
| 52 | mock(NotificationStackScrollLayout.class); |
| 53 | private final NotificationPanelView mPanelView = mock(NotificationPanelView.class); |
| 54 | private final DarkIconDispatcher mDarkIconDispatcher = mock(DarkIconDispatcher.class); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 55 | private HeadsUpAppearanceController mHeadsUpAppearanceController; |
| 56 | private ExpandableNotificationRow mFirst; |
| 57 | private HeadsUpStatusBarView mHeadsUpStatusBarView; |
| 58 | private HeadsUpManagerPhone mHeadsUpManager; |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 59 | private View mOperatorNameView; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 60 | private StatusBarStateController mStatusbarStateController; |
| 61 | private KeyguardBypassController mBypassController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 62 | |
| 63 | @Before |
| 64 | public void setUp() throws Exception { |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 65 | com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 66 | NotificationTestHelper testHelper = new NotificationTestHelper(getContext()); |
| 67 | mFirst = testHelper.createRow(); |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 68 | mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 69 | mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class), |
| 70 | mock(TextView.class)); |
| 71 | mHeadsUpManager = mock(HeadsUpManagerPhone.class); |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 72 | mOperatorNameView = new View(mContext); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 73 | mStatusbarStateController = mock(StatusBarStateController.class); |
| 74 | mBypassController = mock(KeyguardBypassController.class); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 75 | mHeadsUpAppearanceController = new HeadsUpAppearanceController( |
| 76 | mock(NotificationIconAreaController.class), |
| 77 | mHeadsUpManager, |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 78 | mStatusbarStateController, |
| 79 | mBypassController, |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 80 | mHeadsUpStatusBarView, |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 81 | mStackScroller, |
| 82 | mPanelView, |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 83 | new View(mContext), |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 84 | mOperatorNameView, |
| 85 | new View(mContext)); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 86 | mHeadsUpAppearanceController.setAppearFraction(0.0f, 0.0f); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testShowinEntryUpdated() { |
| 91 | mFirst.setPinned(true); |
| 92 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 93 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 94 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry()); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 95 | Assert.assertEquals(mFirst.getEntry(), mHeadsUpStatusBarView.getShowingEntry()); |
| 96 | |
| 97 | mFirst.setPinned(false); |
| 98 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 99 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry()); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 100 | Assert.assertEquals(null, mHeadsUpStatusBarView.getShowingEntry()); |
| 101 | } |
| 102 | |
| 103 | @Test |
| 104 | public void testShownUpdated() { |
| 105 | mFirst.setPinned(true); |
| 106 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 107 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 108 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry()); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 109 | Assert.assertTrue(mHeadsUpAppearanceController.isShown()); |
| 110 | |
| 111 | mFirst.setPinned(false); |
| 112 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 113 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry()); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 114 | Assert.assertFalse(mHeadsUpAppearanceController.isShown()); |
| 115 | } |
| 116 | |
| 117 | @Test |
| 118 | public void testHeaderUpdated() { |
| 119 | mFirst.setPinned(true); |
| 120 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 121 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 122 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry()); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 123 | Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 0.0f, 0.0f); |
| 124 | |
| 125 | mFirst.setPinned(false); |
| 126 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 127 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry()); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 128 | Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f); |
| 129 | } |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 130 | |
| 131 | @Test |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 132 | public void testOperatorNameViewUpdated() { |
| 133 | mHeadsUpAppearanceController.setAnimationsEnabled(false); |
| 134 | |
| 135 | mFirst.setPinned(true); |
| 136 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 137 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 138 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry()); |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 139 | Assert.assertEquals(View.INVISIBLE, mOperatorNameView.getVisibility()); |
| 140 | |
| 141 | mFirst.setPinned(false); |
| 142 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 143 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry()); |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 144 | Assert.assertEquals(View.VISIBLE, mOperatorNameView.getVisibility()); |
| 145 | } |
| 146 | |
| 147 | @Test |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 148 | public void testHeaderReadFromOldController() { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 149 | mHeadsUpAppearanceController.setAppearFraction(1.0f, 1.0f); |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 150 | |
| 151 | HeadsUpAppearanceController newController = new HeadsUpAppearanceController( |
| 152 | mock(NotificationIconAreaController.class), |
| 153 | mHeadsUpManager, |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 154 | mStatusbarStateController, |
| 155 | mBypassController, |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 156 | mHeadsUpStatusBarView, |
| 157 | mStackScroller, |
| 158 | mPanelView, |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 159 | new View(mContext), |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 160 | new View(mContext), |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 161 | new View(mContext)); |
| 162 | newController.readFrom(mHeadsUpAppearanceController); |
| 163 | |
| 164 | Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight, |
| 165 | newController.mExpandedHeight, 0.0f); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 166 | Assert.assertEquals(mHeadsUpAppearanceController.mAppearFraction, |
| 167 | newController.mAppearFraction, 0.0f); |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 168 | Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded, |
| 169 | newController.mIsExpanded); |
| 170 | } |
| 171 | |
| 172 | @Test |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 173 | public void testDestroy() { |
| 174 | reset(mHeadsUpManager); |
| 175 | reset(mDarkIconDispatcher); |
| 176 | reset(mPanelView); |
| 177 | reset(mStackScroller); |
| 178 | mHeadsUpAppearanceController.destroy(); |
| 179 | verify(mHeadsUpManager).removeListener(any()); |
| 180 | verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any()); |
| 181 | verify(mPanelView).removeVerticalTranslationListener(any()); |
| 182 | verify(mPanelView).removeTrackingHeadsUpListener(any()); |
| 183 | verify(mPanelView).setHeadsUpAppearanceController(any()); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 184 | verify(mStackScroller).removeOnExpandedHeightChangedListener(any()); |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 185 | verify(mStackScroller).removeOnLayoutChangeListener(any()); |
| 186 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 187 | } |