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; |
| 26 | import android.testing.TestableLooper.RunWithLooper; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 27 | import android.view.View; |
| 28 | import android.widget.TextView; |
| 29 | |
Brett Chabot | 8091d9e | 2019-02-26 14:52:33 -0800 | [diff] [blame] | 30 | import androidx.test.filters.SmallTest; |
| 31 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 32 | import com.android.systemui.SysuiTestCase; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 33 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
| 34 | import com.android.systemui.statusbar.HeadsUpStatusBarView; |
| 35 | import com.android.systemui.statusbar.NotificationTestHelper; |
| 36 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
| 37 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
| 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) |
| 46 | @RunWithLooper(setAsMainLooper = true) |
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 | f1e0f7a | 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 { |
| 61 | NotificationTestHelper testHelper = new NotificationTestHelper(getContext()); |
| 62 | mFirst = testHelper.createRow(); |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 63 | mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 64 | mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class), |
| 65 | mock(TextView.class)); |
| 66 | mHeadsUpManager = mock(HeadsUpManagerPhone.class); |
Tetsutoki Shiozawa | f1e0f7a | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 67 | mOperatorNameView = new View(mContext); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 68 | mHeadsUpAppearanceController = new HeadsUpAppearanceController( |
| 69 | mock(NotificationIconAreaController.class), |
| 70 | mHeadsUpManager, |
| 71 | mHeadsUpStatusBarView, |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 72 | mStackScroller, |
| 73 | mPanelView, |
Tetsutoki Shiozawa | f1e0f7a | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 74 | new View(mContext), |
| 75 | mOperatorNameView); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 76 | mHeadsUpAppearanceController.setExpandedHeight(0.0f, 0.0f); |
| 77 | } |
| 78 | |
| 79 | @Test |
| 80 | public void testShowinEntryUpdated() { |
| 81 | mFirst.setPinned(true); |
| 82 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 83 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
| 84 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst); |
| 85 | Assert.assertEquals(mFirst.getEntry(), mHeadsUpStatusBarView.getShowingEntry()); |
| 86 | |
| 87 | mFirst.setPinned(false); |
| 88 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 89 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst); |
| 90 | Assert.assertEquals(null, mHeadsUpStatusBarView.getShowingEntry()); |
| 91 | } |
| 92 | |
| 93 | @Test |
| 94 | public void testShownUpdated() { |
| 95 | mFirst.setPinned(true); |
| 96 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 97 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
| 98 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst); |
| 99 | Assert.assertTrue(mHeadsUpAppearanceController.isShown()); |
| 100 | |
| 101 | mFirst.setPinned(false); |
| 102 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 103 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst); |
| 104 | Assert.assertFalse(mHeadsUpAppearanceController.isShown()); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void testHeaderUpdated() { |
| 109 | mFirst.setPinned(true); |
| 110 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 111 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
| 112 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst); |
| 113 | Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 0.0f, 0.0f); |
| 114 | |
| 115 | mFirst.setPinned(false); |
| 116 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 117 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst); |
| 118 | Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f); |
| 119 | } |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 120 | |
| 121 | @Test |
Tetsutoki Shiozawa | f1e0f7a | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 122 | public void testOperatorNameViewUpdated() { |
| 123 | mHeadsUpAppearanceController.setAnimationsEnabled(false); |
| 124 | |
| 125 | mFirst.setPinned(true); |
| 126 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true); |
| 127 | when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry()); |
| 128 | mHeadsUpAppearanceController.onHeadsUpPinned(mFirst); |
| 129 | Assert.assertEquals(View.INVISIBLE, mOperatorNameView.getVisibility()); |
| 130 | |
| 131 | mFirst.setPinned(false); |
| 132 | when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false); |
| 133 | mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst); |
| 134 | Assert.assertEquals(View.VISIBLE, mOperatorNameView.getVisibility()); |
| 135 | } |
| 136 | |
| 137 | @Test |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 138 | public void testDestroy() { |
| 139 | reset(mHeadsUpManager); |
| 140 | reset(mDarkIconDispatcher); |
| 141 | reset(mPanelView); |
| 142 | reset(mStackScroller); |
| 143 | mHeadsUpAppearanceController.destroy(); |
| 144 | verify(mHeadsUpManager).removeListener(any()); |
| 145 | verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any()); |
| 146 | verify(mPanelView).removeVerticalTranslationListener(any()); |
| 147 | verify(mPanelView).removeTrackingHeadsUpListener(any()); |
| 148 | verify(mPanelView).setHeadsUpAppearanceController(any()); |
| 149 | verify(mStackScroller).removeOnExpandedHeightListener(any()); |
| 150 | verify(mStackScroller).removeOnLayoutChangeListener(any()); |
| 151 | } |
felkachang | 3b2ab9b | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 152 | |
| 153 | @Test |
| 154 | public void testHeaderReadFromOldController() { |
| 155 | mHeadsUpAppearanceController.setExpandedHeight(1.0f, 1.0f); |
| 156 | |
| 157 | HeadsUpAppearanceController newController = new HeadsUpAppearanceController( |
| 158 | mock(NotificationIconAreaController.class), |
| 159 | mHeadsUpManager, |
| 160 | mHeadsUpStatusBarView, |
| 161 | mStackScroller, |
| 162 | mPanelView, |
Xin Li | 0e71b4f | 2019-02-13 22:36:25 -0800 | [diff] [blame] | 163 | new View(mContext), |
felkachang | 3b2ab9b | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 164 | new View(mContext)); |
| 165 | newController.readFrom(mHeadsUpAppearanceController); |
| 166 | |
| 167 | Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight, |
| 168 | newController.mExpandedHeight, 0.0f); |
| 169 | Assert.assertEquals(mHeadsUpAppearanceController.mExpandFraction, |
| 170 | newController.mExpandFraction, 0.0f); |
| 171 | Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded, |
| 172 | newController.mIsExpanded); |
| 173 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 174 | } |