blob: 38d9ae7cfab462fd06e67b028f4a64228edd8a9b [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
25import android.support.test.filters.SmallTest;
Jason Monk6dceace2018-05-15 20:24:07 -040026import android.testing.AndroidTestingRunner;
Jason Monka716bac2018-12-05 15:48:21 -050027import android.testing.TestableLooper;
Jason Monk6dceace2018-05-15 20:24:07 -040028import android.testing.TestableLooper.RunWithLooper;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080029import android.view.View;
30import android.widget.TextView;
31
32import com.android.systemui.SysuiTestCase;
Beverly1be62f42018-12-19 17:17:48 -050033import com.android.systemui.plugins.DarkIconDispatcher;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080034import com.android.systemui.statusbar.HeadsUpStatusBarView;
35import com.android.systemui.statusbar.NotificationTestHelper;
Jason Monka716bac2018-12-05 15:48:21 -050036import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Rohan Shah20790b82018-07-02 17:21:04 -070037import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080038
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)
Jason Monka716bac2018-12-05 15:48:21 -050046@RunWithLooper
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 Shiozawace9645b2018-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 {
Jason Monka716bac2018-12-05 15:48:21 -050061 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Selim Cinekaa9db1f2018-02-27 17:35:47 -080062 NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
63 mFirst = testHelper.createRow();
Selim Cinek60ffea62018-03-22 13:16:44 -070064 mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080065 mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
66 mock(TextView.class));
67 mHeadsUpManager = mock(HeadsUpManagerPhone.class);
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090068 mOperatorNameView = new View(mContext);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080069 mHeadsUpAppearanceController = new HeadsUpAppearanceController(
70 mock(NotificationIconAreaController.class),
71 mHeadsUpManager,
72 mHeadsUpStatusBarView,
Selim Cinek60ffea62018-03-22 13:16:44 -070073 mStackScroller,
74 mPanelView,
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090075 new View(mContext),
76 mOperatorNameView);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080077 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 Laird94492852018-10-25 13:43:01 -040085 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -080086 Assert.assertEquals(mFirst.getEntry(), mHeadsUpStatusBarView.getShowingEntry());
87
88 mFirst.setPinned(false);
89 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -040090 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -080091 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 Laird94492852018-10-25 13:43:01 -040099 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800100 Assert.assertTrue(mHeadsUpAppearanceController.isShown());
101
102 mFirst.setPinned(false);
103 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400104 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800105 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 Laird94492852018-10-25 13:43:01 -0400113 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800114 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 0.0f, 0.0f);
115
116 mFirst.setPinned(false);
117 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400118 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800119 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f);
120 }
Selim Cinek60ffea62018-03-22 13:16:44 -0700121
122 @Test
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900123 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 Laird94492852018-10-25 13:43:01 -0400129 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900130 Assert.assertEquals(View.INVISIBLE, mOperatorNameView.getVisibility());
131
132 mFirst.setPinned(false);
133 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400134 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900135 Assert.assertEquals(View.VISIBLE, mOperatorNameView.getVisibility());
136 }
137
138 @Test
felkachange6c03a02018-05-24 15:38:04 +0800139 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 Shiozawace9645b2018-09-05 13:17:01 +0900148 new View(mContext),
felkachange6c03a02018-05-24 15:38:04 +0800149 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 Cinek60ffea62018-03-22 13:16:44 -0700161 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 Cinekaa9db1f2018-02-27 17:35:47 -0800175}