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