blob: 96ec7ece038b5c3f8a02f99f19a8120b89259237 [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;
20import static org.mockito.ArgumentMatchers.anyObject;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080021import static org.mockito.Mockito.atLeast;
22import static org.mockito.Mockito.mock;
Selim Cinek60ffea62018-03-22 13:16:44 -070023import static org.mockito.Mockito.reset;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080024import static org.mockito.Mockito.verify;
25import static org.mockito.Mockito.when;
26
27import android.support.test.filters.SmallTest;
28import android.support.test.runner.AndroidJUnit4;
Jason Monk6dceace2018-05-15 20:24:07 -040029import android.testing.AndroidTestingRunner;
30import android.testing.TestableLooper.RunWithLooper;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080031import android.view.View;
32import android.widget.TextView;
33
Selim Cinek60ffea62018-03-22 13:16:44 -070034import com.android.systemui.Dependency;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080035import com.android.systemui.SysuiTestCase;
36import com.android.systemui.TestableDependency;
37import com.android.systemui.statusbar.CommandQueue;
38import com.android.systemui.statusbar.ExpandableNotificationRow;
39import com.android.systemui.statusbar.HeadsUpStatusBarView;
40import com.android.systemui.statusbar.NotificationTestHelper;
41import com.android.systemui.statusbar.policy.DarkIconDispatcher;
42import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
43
44import org.junit.Assert;
45import org.junit.Before;
46import org.junit.Test;
47import org.junit.runner.RunWith;
48
49import java.util.HashSet;
50
51@SmallTest
Jason Monk6dceace2018-05-15 20:24:07 -040052@RunWith(AndroidTestingRunner.class)
53@RunWithLooper(setAsMainLooper = true)
Selim Cinekaa9db1f2018-02-27 17:35:47 -080054public class HeadsUpAppearanceControllerTest extends SysuiTestCase {
55
Selim Cinek60ffea62018-03-22 13:16:44 -070056 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 Cinekaa9db1f2018-02-27 17:35:47 -080060 private HeadsUpAppearanceController mHeadsUpAppearanceController;
61 private ExpandableNotificationRow mFirst;
62 private HeadsUpStatusBarView mHeadsUpStatusBarView;
63 private HeadsUpManagerPhone mHeadsUpManager;
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +090064 private View mOperatorNameView;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080065
66 @Before
67 public void setUp() throws Exception {
68 NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
69 mFirst = testHelper.createRow();
Selim Cinek60ffea62018-03-22 13:16:44 -070070 mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080071 mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
72 mock(TextView.class));
73 mHeadsUpManager = mock(HeadsUpManagerPhone.class);
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +090074 mOperatorNameView = new View(mContext);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080075 mHeadsUpAppearanceController = new HeadsUpAppearanceController(
76 mock(NotificationIconAreaController.class),
77 mHeadsUpManager,
78 mHeadsUpStatusBarView,
Selim Cinek60ffea62018-03-22 13:16:44 -070079 mStackScroller,
80 mPanelView,
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +090081 new View(mContext),
82 mOperatorNameView);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080083 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 Cinek60ffea62018-03-22 13:16:44 -0700127
128 @Test
Tetsutoki Shiozawaf1e0f7a2018-09-05 13:17:01 +0900129 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
felkachang08579552018-05-24 15:38:04 +0800145 public void testHeaderReadFromOldController() {
146 mHeadsUpAppearanceController.setExpandedHeight(1.0f, 1.0f);
147
148 HeadsUpAppearanceController newController = new HeadsUpAppearanceController(
149 mock(NotificationIconAreaController.class),
150 mHeadsUpManager,
151 mHeadsUpStatusBarView,
152 mStackScroller,
153 mPanelView,
Felka Chang09c9c772018-11-15 14:34:36 +0800154 new View(mContext),
felkachang08579552018-05-24 15:38:04 +0800155 new View(mContext));
156 newController.readFrom(mHeadsUpAppearanceController);
157
158 Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight,
159 newController.mExpandedHeight, 0.0f);
160 Assert.assertEquals(mHeadsUpAppearanceController.mExpandFraction,
161 newController.mExpandFraction, 0.0f);
162 Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded,
163 newController.mIsExpanded);
164 }
165
166 @Test
Selim Cinek60ffea62018-03-22 13:16:44 -0700167 public void testDestroy() {
168 reset(mHeadsUpManager);
169 reset(mDarkIconDispatcher);
170 reset(mPanelView);
171 reset(mStackScroller);
172 mHeadsUpAppearanceController.destroy();
173 verify(mHeadsUpManager).removeListener(any());
174 verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any());
175 verify(mPanelView).removeVerticalTranslationListener(any());
176 verify(mPanelView).removeTrackingHeadsUpListener(any());
177 verify(mPanelView).setHeadsUpAppearanceController(any());
178 verify(mStackScroller).removeOnExpandedHeightListener(any());
179 verify(mStackScroller).removeOnLayoutChangeListener(any());
180 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800181}