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