blob: 44df237d70c8f7fc4f07be6f9ade39504177bcbb [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 Cinekaa9db1f2018-02-27 17:35:47 -080035import com.android.systemui.statusbar.HeadsUpStatusBarView;
36import com.android.systemui.statusbar.NotificationTestHelper;
Jason Monka716bac2018-12-05 15:48:21 -050037import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Rohan Shah20790b82018-07-02 17:21:04 -070038import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080039
40import org.junit.Assert;
41import org.junit.Before;
42import org.junit.Test;
43import org.junit.runner.RunWith;
44
Selim Cinekaa9db1f2018-02-27 17:35:47 -080045@SmallTest
Jason Monk6dceace2018-05-15 20:24:07 -040046@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050047@RunWithLooper
Selim Cinekaa9db1f2018-02-27 17:35:47 -080048public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
49
Selim Cinek60ffea62018-03-22 13:16:44 -070050 private final NotificationStackScrollLayout mStackScroller =
51 mock(NotificationStackScrollLayout.class);
52 private final NotificationPanelView mPanelView = mock(NotificationPanelView.class);
53 private final DarkIconDispatcher mDarkIconDispatcher = mock(DarkIconDispatcher.class);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080054 private HeadsUpAppearanceController mHeadsUpAppearanceController;
55 private ExpandableNotificationRow mFirst;
56 private HeadsUpStatusBarView mHeadsUpStatusBarView;
57 private HeadsUpManagerPhone mHeadsUpManager;
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090058 private View mOperatorNameView;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080059
60 @Before
61 public void setUp() throws Exception {
Jason Monka716bac2018-12-05 15:48:21 -050062 com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper();
Selim Cinekaa9db1f2018-02-27 17:35:47 -080063 NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
64 mFirst = testHelper.createRow();
Selim Cinek60ffea62018-03-22 13:16:44 -070065 mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080066 mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
67 mock(TextView.class));
68 mHeadsUpManager = mock(HeadsUpManagerPhone.class);
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090069 mOperatorNameView = new View(mContext);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080070 mHeadsUpAppearanceController = new HeadsUpAppearanceController(
71 mock(NotificationIconAreaController.class),
72 mHeadsUpManager,
73 mHeadsUpStatusBarView,
Selim Cinek60ffea62018-03-22 13:16:44 -070074 mStackScroller,
75 mPanelView,
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +090076 new View(mContext),
77 mOperatorNameView);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080078 mHeadsUpAppearanceController.setExpandedHeight(0.0f, 0.0f);
79 }
80
81 @Test
82 public void testShowinEntryUpdated() {
83 mFirst.setPinned(true);
84 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
85 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -040086 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -080087 Assert.assertEquals(mFirst.getEntry(), mHeadsUpStatusBarView.getShowingEntry());
88
89 mFirst.setPinned(false);
90 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -040091 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -080092 Assert.assertEquals(null, mHeadsUpStatusBarView.getShowingEntry());
93 }
94
95 @Test
96 public void testShownUpdated() {
97 mFirst.setPinned(true);
98 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
99 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -0400100 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800101 Assert.assertTrue(mHeadsUpAppearanceController.isShown());
102
103 mFirst.setPinned(false);
104 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400105 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800106 Assert.assertFalse(mHeadsUpAppearanceController.isShown());
107 }
108
109 @Test
110 public void testHeaderUpdated() {
111 mFirst.setPinned(true);
112 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
113 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -0400114 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800115 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 0.0f, 0.0f);
116
117 mFirst.setPinned(false);
118 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400119 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800120 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f);
121 }
Selim Cinek60ffea62018-03-22 13:16:44 -0700122
123 @Test
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900124 public void testOperatorNameViewUpdated() {
125 mHeadsUpAppearanceController.setAnimationsEnabled(false);
126
127 mFirst.setPinned(true);
128 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
129 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
Evan Laird94492852018-10-25 13:43:01 -0400130 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst.getEntry());
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900131 Assert.assertEquals(View.INVISIBLE, mOperatorNameView.getVisibility());
132
133 mFirst.setPinned(false);
134 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
Evan Laird94492852018-10-25 13:43:01 -0400135 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst.getEntry());
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900136 Assert.assertEquals(View.VISIBLE, mOperatorNameView.getVisibility());
137 }
138
139 @Test
felkachange6c03a02018-05-24 15:38:04 +0800140 public void testHeaderReadFromOldController() {
141 mHeadsUpAppearanceController.setExpandedHeight(1.0f, 1.0f);
142
143 HeadsUpAppearanceController newController = new HeadsUpAppearanceController(
144 mock(NotificationIconAreaController.class),
145 mHeadsUpManager,
146 mHeadsUpStatusBarView,
147 mStackScroller,
148 mPanelView,
Tetsutoki Shiozawace9645b2018-09-05 13:17:01 +0900149 new View(mContext),
felkachange6c03a02018-05-24 15:38:04 +0800150 new View(mContext));
151 newController.readFrom(mHeadsUpAppearanceController);
152
153 Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight,
154 newController.mExpandedHeight, 0.0f);
155 Assert.assertEquals(mHeadsUpAppearanceController.mExpandFraction,
156 newController.mExpandFraction, 0.0f);
157 Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded,
158 newController.mIsExpanded);
159 }
160
161 @Test
Selim Cinek60ffea62018-03-22 13:16:44 -0700162 public void testDestroy() {
163 reset(mHeadsUpManager);
164 reset(mDarkIconDispatcher);
165 reset(mPanelView);
166 reset(mStackScroller);
167 mHeadsUpAppearanceController.destroy();
168 verify(mHeadsUpManager).removeListener(any());
169 verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any());
170 verify(mPanelView).removeVerticalTranslationListener(any());
171 verify(mPanelView).removeTrackingHeadsUpListener(any());
172 verify(mPanelView).setHeadsUpAppearanceController(any());
173 verify(mStackScroller).removeOnExpandedHeightListener(any());
174 verify(mStackScroller).removeOnLayoutChangeListener(any());
175 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800176}