blob: b7740e3b5367ccc0df1260fecf6641446b1fe9ce [file] [log] [blame]
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001/*
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
17package com.android.systemui.statusbar.phone;
18
Selim Cinek60ffea62018-03-22 13:16:44 -070019import static org.mockito.ArgumentMatchers.any;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080020import static org.mockito.Mockito.mock;
Selim Cinek60ffea62018-03-22 13:16:44 -070021import static org.mockito.Mockito.reset;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080022import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
24
Jason Monk6dceace2018-05-15 20:24:07 -040025import android.testing.AndroidTestingRunner;
26import android.testing.TestableLooper.RunWithLooper;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080027import android.view.View;
28import android.widget.TextView;
29
Brett Chabot8091d9e2019-02-26 14:52:33 -080030import androidx.test.filters.SmallTest;
31
Selim Cinekaa9db1f2018-02-27 17:35:47 -080032import com.android.systemui.SysuiTestCase;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080033import com.android.systemui.statusbar.ExpandableNotificationRow;
34import com.android.systemui.statusbar.HeadsUpStatusBarView;
35import com.android.systemui.statusbar.NotificationTestHelper;
36import com.android.systemui.statusbar.policy.DarkIconDispatcher;
37import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
38
39import org.junit.Assert;
40import org.junit.Before;
41import org.junit.Test;
42import org.junit.runner.RunWith;
43
Selim Cinekaa9db1f2018-02-27 17:35:47 -080044@SmallTest
Jason Monk6dceace2018-05-15 20:24:07 -040045@RunWith(AndroidTestingRunner.class)
46@RunWithLooper(setAsMainLooper = true)
Selim Cinekaa9db1f2018-02-27 17:35:47 -080047public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
48
Selim Cinek60ffea62018-03-22 13:16:44 -070049 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 Cinekaa9db1f2018-02-27 17:35:47 -080053 private HeadsUpAppearanceController mHeadsUpAppearanceController;
54 private ExpandableNotificationRow mFirst;
55 private HeadsUpStatusBarView mHeadsUpStatusBarView;
56 private HeadsUpManagerPhone mHeadsUpManager;
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +090057 private View mOperatorNameView;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080058
59 @Before
60 public void setUp() throws Exception {
61 NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
62 mFirst = testHelper.createRow();
Selim Cinek60ffea62018-03-22 13:16:44 -070063 mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080064 mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
65 mock(TextView.class));
66 mHeadsUpManager = mock(HeadsUpManagerPhone.class);
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +090067 mOperatorNameView = new View(mContext);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080068 mHeadsUpAppearanceController = new HeadsUpAppearanceController(
69 mock(NotificationIconAreaController.class),
70 mHeadsUpManager,
71 mHeadsUpStatusBarView,
Selim Cinek60ffea62018-03-22 13:16:44 -070072 mStackScroller,
73 mPanelView,
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +090074 new View(mContext),
75 mOperatorNameView);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080076 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 Cinek60ffea62018-03-22 13:16:44 -0700120
121 @Test
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +0900122 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
felkachang08579552018-05-24 15:38:04 +0800138 public void testHeaderReadFromOldController() {
139 mHeadsUpAppearanceController.setExpandedHeight(1.0f, 1.0f);
140
141 HeadsUpAppearanceController newController = new HeadsUpAppearanceController(
142 mock(NotificationIconAreaController.class),
143 mHeadsUpManager,
144 mHeadsUpStatusBarView,
145 mStackScroller,
146 mPanelView,
Felka Chang09c9c772018-11-15 14:34:36 +0800147 new View(mContext),
felkachang08579552018-05-24 15:38:04 +0800148 new View(mContext));
149 newController.readFrom(mHeadsUpAppearanceController);
150
151 Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight,
152 newController.mExpandedHeight, 0.0f);
153 Assert.assertEquals(mHeadsUpAppearanceController.mExpandFraction,
154 newController.mExpandFraction, 0.0f);
155 Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded,
156 newController.mIsExpanded);
157 }
158
159 @Test
Selim Cinek60ffea62018-03-22 13:16:44 -0700160 public void testDestroy() {
161 reset(mHeadsUpManager);
162 reset(mDarkIconDispatcher);
163 reset(mPanelView);
164 reset(mStackScroller);
165 mHeadsUpAppearanceController.destroy();
166 verify(mHeadsUpManager).removeListener(any());
167 verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any());
168 verify(mPanelView).removeVerticalTranslationListener(any());
169 verify(mPanelView).removeTrackingHeadsUpListener(any());
170 verify(mPanelView).setHeadsUpAppearanceController(any());
171 verify(mStackScroller).removeOnExpandedHeightListener(any());
172 verify(mStackScroller).removeOnLayoutChangeListener(any());
173 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800174}