blob: fe7bf2537085c9b0490486cfc19a825e2676ae51 [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;
64
65 @Before
66 public void setUp() throws Exception {
67 NotificationTestHelper testHelper = new NotificationTestHelper(getContext());
68 mFirst = testHelper.createRow();
Selim Cinek60ffea62018-03-22 13:16:44 -070069 mDependency.injectTestDependency(DarkIconDispatcher.class, mDarkIconDispatcher);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080070 mHeadsUpStatusBarView = new HeadsUpStatusBarView(mContext, mock(View.class),
71 mock(TextView.class));
72 mHeadsUpManager = mock(HeadsUpManagerPhone.class);
73 mHeadsUpAppearanceController = new HeadsUpAppearanceController(
74 mock(NotificationIconAreaController.class),
75 mHeadsUpManager,
76 mHeadsUpStatusBarView,
Selim Cinek60ffea62018-03-22 13:16:44 -070077 mStackScroller,
78 mPanelView,
Selim Cinekaa9db1f2018-02-27 17:35:47 -080079 new View(mContext));
80 mHeadsUpAppearanceController.setExpandedHeight(0.0f, 0.0f);
81 }
82
83 @Test
84 public void testShowinEntryUpdated() {
85 mFirst.setPinned(true);
86 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
87 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
88 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst);
89 Assert.assertEquals(mFirst.getEntry(), mHeadsUpStatusBarView.getShowingEntry());
90
91 mFirst.setPinned(false);
92 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
93 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst);
94 Assert.assertEquals(null, mHeadsUpStatusBarView.getShowingEntry());
95 }
96
97 @Test
98 public void testShownUpdated() {
99 mFirst.setPinned(true);
100 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
101 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
102 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst);
103 Assert.assertTrue(mHeadsUpAppearanceController.isShown());
104
105 mFirst.setPinned(false);
106 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
107 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst);
108 Assert.assertFalse(mHeadsUpAppearanceController.isShown());
109 }
110
111 @Test
112 public void testHeaderUpdated() {
113 mFirst.setPinned(true);
114 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(true);
115 when(mHeadsUpManager.getTopEntry()).thenReturn(mFirst.getEntry());
116 mHeadsUpAppearanceController.onHeadsUpPinned(mFirst);
117 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 0.0f, 0.0f);
118
119 mFirst.setPinned(false);
120 when(mHeadsUpManager.hasPinnedHeadsUp()).thenReturn(false);
121 mHeadsUpAppearanceController.onHeadsUpUnPinned(mFirst);
122 Assert.assertEquals(mFirst.getHeaderVisibleAmount(), 1.0f, 0.0f);
123 }
Selim Cinek60ffea62018-03-22 13:16:44 -0700124
125 @Test
felkachange6c03a02018-05-24 15:38:04 +0800126 public void testHeaderReadFromOldController() {
127 mHeadsUpAppearanceController.setExpandedHeight(1.0f, 1.0f);
128
129 HeadsUpAppearanceController newController = new HeadsUpAppearanceController(
130 mock(NotificationIconAreaController.class),
131 mHeadsUpManager,
132 mHeadsUpStatusBarView,
133 mStackScroller,
134 mPanelView,
135 new View(mContext));
136 newController.readFrom(mHeadsUpAppearanceController);
137
138 Assert.assertEquals(mHeadsUpAppearanceController.mExpandedHeight,
139 newController.mExpandedHeight, 0.0f);
140 Assert.assertEquals(mHeadsUpAppearanceController.mExpandFraction,
141 newController.mExpandFraction, 0.0f);
142 Assert.assertEquals(mHeadsUpAppearanceController.mIsExpanded,
143 newController.mIsExpanded);
144 }
145
146 @Test
Selim Cinek60ffea62018-03-22 13:16:44 -0700147 public void testDestroy() {
148 reset(mHeadsUpManager);
149 reset(mDarkIconDispatcher);
150 reset(mPanelView);
151 reset(mStackScroller);
152 mHeadsUpAppearanceController.destroy();
153 verify(mHeadsUpManager).removeListener(any());
154 verify(mDarkIconDispatcher).removeDarkReceiver((DarkIconDispatcher.DarkReceiver) any());
155 verify(mPanelView).removeVerticalTranslationListener(any());
156 verify(mPanelView).removeTrackingHeadsUpListener(any());
157 verify(mPanelView).setHeadsUpAppearanceController(any());
158 verify(mStackScroller).removeOnExpandedHeightListener(any());
159 verify(mStackScroller).removeOnLayoutChangeListener(any());
160 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800161}