blob: b45707ef6c10c23462caf0cb44ff163d665a41de [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;
Jason Monka716bac2018-12-05 15:48:21 -050026import android.testing.TestableLooper;
Jason Monk6dceace2018-05-15 20:24:07 -040027import android.testing.TestableLooper.RunWithLooper;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080028import android.view.View;
29import android.widget.TextView;
30
Brett Chabot84151d92019-02-27 15:37:59 -080031import androidx.test.filters.SmallTest;
32
Selim Cinekaa9db1f2018-02-27 17:35:47 -080033import com.android.systemui.SysuiTestCase;
Beverly1be62f42018-12-19 17:17:48 -050034import com.android.systemui.plugins.DarkIconDispatcher;
Selim Cinekc7e4cb52019-06-20 15:41:45 -070035import com.android.systemui.plugins.statusbar.StatusBarStateController;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080036import com.android.systemui.statusbar.HeadsUpStatusBarView;
37import com.android.systemui.statusbar.NotificationTestHelper;
Jason Monka716bac2018-12-05 15:48:21 -050038import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Rohan Shah20790b82018-07-02 17:21:04 -070039import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080040
41import org.junit.Assert;
42import org.junit.Before;
43import org.junit.Test;
44import org.junit.runner.RunWith;
45
Selim Cinekaa9db1f2018-02-27 17:35:47 -080046@SmallTest
Jason Monk6dceace2018-05-15 20:24:07 -040047@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050048@RunWithLooper
Selim Cinekaa9db1f2018-02-27 17:35:47 -080049public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
50
Selim Cinek60ffea62018-03-22 13:16:44 -070051 private final NotificationStackScrollLayout mStackScroller =
52 mock(NotificationStackScrollLayout.class);
53 private final NotificationPanelView mPanelView = mock(NotificationPanelView.class);
54 private final DarkIconDispatcher mDarkIconDispatcher = mock(DarkIconDispatcher.class);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080055 private HeadsUpAppearanceController mHeadsUpAppearanceController;
56 private ExpandableNotificationRow mFirst;
57 private HeadsUpStatusBarView mHeadsUpStatusBarView;
58 private HeadsUpManagerPhone mHeadsUpManager;
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090059 private View mOperatorNameView;
Selim Cinekc7e4cb52019-06-20 15:41:45 -070060 private StatusBarStateController mStatusbarStateController;
61 private KeyguardBypassController mBypassController;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080062
63 @Before
64 public void setUp() throws Exception {
Jason Monka716bac2018-12-05 15:48:21 -050065 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Selim Cinekaa9db1f2018-02-27 17:35:47 -080066 NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
67 mFirst = testHelper.createRow();
Selim Cinek60ffea62018-03-22 13:16:44 -070068 mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080069 mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
70 mock(TextView.class));
71 mHeadsUpManager = mock(HeadsUpManagerPhone.class);
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090072 mOperatorNameView = new View(mContext);
Selim Cinekc7e4cb52019-06-20 15:41:45 -070073 mStatusbarStateController = mock(StatusBarStateController.class);
74 mBypassController = mock(KeyguardBypassController.class);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080075 mHeadsUpAppearanceController = new HeadsUpAppearanceController(
76 mock(NotificationIconAreaController.class),
77 mHeadsUpManager,
Selim Cinekc7e4cb52019-06-20 15:41:45 -070078 mStatusbarStateController,
79 mBypassController,
Selim Cinekaa9db1f2018-02-27 17:35:47 -080080 mHeadsUpStatusBarView,
Selim Cinek60ffea62018-03-22 13:16:44 -070081 mStackScroller,
82 mPanelView,
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090083 new View(mContext),
Beverly40770652019-02-15 15:49:49 -050084 mOperatorNameView,
85 new View(mContext));
Selim Cinekc7e4cb52019-06-20 15:41:45 -070086 mHeadsUpAppearanceController.setAppearFraction(0.0f, 0.0f);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080087 }
88
89 @Test
90 public void testShowinEntryUpdated() {
91 mFirst.setPinned(true);
92 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
93 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -040094 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -080095 Assert.assertEquals(mFirst.getEntry(), mHeadsUpStatusBarView.getShowingEntry());
96
97 mFirst.setPinned(false);
98 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -040099 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800100 Assert.assertEquals(null, mHeadsUpStatusBarView.getShowingEntry());
101 }
102
103 @Test
104 public void testShownUpdated() {
105 mFirst.setPinned(true);
106 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
107 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -0400108 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800109 Assert.assertTrue(mHeadsUpAppearanceController.isShown());
110
111 mFirst.setPinned(false);
112 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400113 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800114 Assert.assertFalse(mHeadsUpAppearanceController.isShown());
115 }
116
117 @Test
118 public void testHeaderUpdated() {
119 mFirst.setPinned(true);
120 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
121 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -0400122 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800123 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 0.0f, 0.0f);
124
125 mFirst.setPinned(false);
126 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400127 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800128 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f);
129 }
Selim Cinek60ffea62018-03-22 13:16:44 -0700130
131 @Test
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900132 public void testOperatorNameViewUpdated() {
133 mHeadsUpAppearanceController.setAnimationsEnabled(false);
134
135 mFirst.setPinned(true);
136 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
137 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -0400138 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900139 Assert.assertEquals(View.INVISIBLE, mOperatorNameView.getVisibility());
140
141 mFirst.setPinned(false);
142 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400143 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900144 Assert.assertEquals(View.VISIBLE, mOperatorNameView.getVisibility());
145 }
146
147 @Test
felkachange6c03a02018-05-24 15:38:04 +0800148 public void testHeaderReadFromOldController() {
Selim Cinekc7e4cb52019-06-20 15:41:45 -0700149 mHeadsUpAppearanceController.setAppearFraction(1.0f, 1.0f);
felkachange6c03a02018-05-24 15:38:04 +0800150
151 HeadsUpAppearanceController newController = new HeadsUpAppearanceController(
152 mock(NotificationIconAreaController.class),
153 mHeadsUpManager,
Selim Cinekc7e4cb52019-06-20 15:41:45 -0700154 mStatusbarStateController,
155 mBypassController,
felkachange6c03a02018-05-24 15:38:04 +0800156 mHeadsUpStatusBarView,
157 mStackScroller,
158 mPanelView,
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900159 new View(mContext),
Beverly40770652019-02-15 15:49:49 -0500160 new View(mContext),
felkachange6c03a02018-05-24 15:38:04 +0800161 new View(mContext));
162 newController.readFrom(mHeadsUpAppearanceController);
163
164 Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight,
165 newController.mExpandedHeight, 0.0f);
Selim Cinekc7e4cb52019-06-20 15:41:45 -0700166 Assert.assertEquals(mHeadsUpAppearanceController.mAppearFraction,
167 newController.mAppearFraction, 0.0f);
felkachange6c03a02018-05-24 15:38:04 +0800168 Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded,
169 newController.mIsExpanded);
170 }
171
172 @Test
Selim Cinek60ffea62018-03-22 13:16:44 -0700173 public void testDestroy() {
174 reset(mHeadsUpManager);
175 reset(mDarkIconDispatcher);
176 reset(mPanelView);
177 reset(mStackScroller);
178 mHeadsUpAppearanceController.destroy();
179 verify(mHeadsUpManager).removeListener(any());
180 verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any());
181 verify(mPanelView).removeVerticalTranslationListener(any());
182 verify(mPanelView).removeTrackingHeadsUpListener(any());
183 verify(mPanelView).setHeadsUpAppearanceController(any());
Selim Cinekc7e4cb52019-06-20 15:41:45 -0700184 verify(mStackScroller).removeOnExpandedHeightChangedListener(any());
Selim Cinek60ffea62018-03-22 13:16:44 -0700185 verify(mStackScroller).removeOnLayoutChangeListener(any());
186 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800187}