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