blob: 51d94f08000add9e7bd4026a1b6b24b4dfd4e08a [file] [log] [blame]
Jason Monkb5b092012017-01-05 11:35:34 -05001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.statusbar;
16
Charles Chen24e7a9f2018-11-21 11:59:07 +080017import static android.view.Display.DEFAULT_DISPLAY;
18
Charles Chenf3d295c2018-11-30 18:15:21 +080019import static org.mockito.ArgumentMatchers.anyInt;
Jason Monkb5b092012017-01-05 11:35:34 -050020import static org.mockito.Matchers.eq;
21import static org.mockito.Mockito.mock;
22import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.verifyNoMoreInteractions;
24
25import android.content.ComponentName;
26import android.graphics.Rect;
27import android.os.Bundle;
Jason Monkfba8faf2017-05-23 10:42:59 -040028import android.support.test.filters.SmallTest;
Jason Monkb5b092012017-01-05 11:35:34 -050029
30import com.android.internal.statusbar.StatusBarIcon;
31import com.android.systemui.SysuiTestCase;
32import com.android.systemui.statusbar.CommandQueue.Callbacks;
33
34import org.junit.After;
35import org.junit.Before;
36import org.junit.Test;
37
Jason Monkfba8faf2017-05-23 10:42:59 -040038@SmallTest
Jason Monkb5b092012017-01-05 11:35:34 -050039public class CommandQueueTest extends SysuiTestCase {
40
41 private CommandQueue mCommandQueue;
42 private Callbacks mCallbacks;
43
44 @Before
45 public void setup() {
Charles Chenf3d295c2018-11-30 18:15:21 +080046 mCommandQueue = new CommandQueue(mContext);
Jason Monkb5b092012017-01-05 11:35:34 -050047 mCallbacks = mock(Callbacks.class);
Jason Monkd7c98552018-12-04 11:14:50 -050048 mCommandQueue.addCallback(mCallbacks);
Charles Chenf3d295c2018-11-30 18:15:21 +080049 verify(mCallbacks).disable(anyInt(), eq(0), eq(0), eq(false));
Jason Monkb5b092012017-01-05 11:35:34 -050050 }
51
52 @After
53 public void tearDown() {
54 verifyNoMoreInteractions(mCallbacks);
55 }
56
57 @Test
58 public void testIcon() {
59 String slot = "testSlot";
60 StatusBarIcon icon = mock(StatusBarIcon.class);
61 mCommandQueue.setIcon(slot, icon);
62 waitForIdleSync();
63 verify(mCallbacks).setIcon(eq(slot), eq(icon));
64
65 mCommandQueue.removeIcon(slot);
66 waitForIdleSync();
67 verify(mCallbacks).removeIcon(eq(slot));
68 }
69
Charles Chen24e7a9f2018-11-21 11:59:07 +080070 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -050071 @Test
72 public void testDisable() {
73 int state1 = 14;
74 int state2 = 42;
Charles Chen24e7a9f2018-11-21 11:59:07 +080075 mCommandQueue.disable(DEFAULT_DISPLAY, state1, state2);
Jason Monkb5b092012017-01-05 11:35:34 -050076 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +080077 verify(mCallbacks).disable(eq(DEFAULT_DISPLAY), eq(state1), eq(state2), eq(true));
Jason Monkb5b092012017-01-05 11:35:34 -050078 }
79
80 @Test
81 public void testExpandNotifications() {
82 mCommandQueue.animateExpandNotificationsPanel();
83 waitForIdleSync();
84 verify(mCallbacks).animateExpandNotificationsPanel();
85 }
86
87 @Test
88 public void testCollapsePanels() {
89 mCommandQueue.animateCollapsePanels();
90 waitForIdleSync();
Jason Monk297c04e2018-08-23 17:16:59 -040091 verify(mCallbacks).animateCollapsePanels(eq(0), eq(false));
Jason Monkb5b092012017-01-05 11:35:34 -050092 }
93
94 @Test
95 public void testExpandSettings() {
96 String panel = "some_panel";
97 mCommandQueue.animateExpandSettingsPanel(panel);
98 waitForIdleSync();
99 verify(mCallbacks).animateExpandSettingsPanel(eq(panel));
100 }
101
Charles Chen24e7a9f2018-11-21 11:59:07 +0800102 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500103 @Test
104 public void testSetSystemUiVisibility() {
105 Rect r = new Rect();
Charles Chen24e7a9f2018-11-21 11:59:07 +0800106 mCommandQueue.setSystemUiVisibility(DEFAULT_DISPLAY, 1, 2, 3, 4, null, r);
Jason Monkb5b092012017-01-05 11:35:34 -0500107 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800108 verify(mCallbacks).setSystemUiVisibility(eq(DEFAULT_DISPLAY), eq(1), eq(2), eq(3), eq(4),
109 eq(null), eq(r));
Jason Monkb5b092012017-01-05 11:35:34 -0500110 }
111
Charles Chen24e7a9f2018-11-21 11:59:07 +0800112 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500113 @Test
114 public void testTopAppWindowChanged() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800115 mCommandQueue.topAppWindowChanged(DEFAULT_DISPLAY, true);
Jason Monkb5b092012017-01-05 11:35:34 -0500116 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800117 verify(mCallbacks).topAppWindowChanged(eq(DEFAULT_DISPLAY), eq(true));
Jason Monkb5b092012017-01-05 11:35:34 -0500118 }
119
Charles Chen24e7a9f2018-11-21 11:59:07 +0800120 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500121 @Test
122 public void testShowImeButton() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800123 mCommandQueue.setImeWindowStatus(DEFAULT_DISPLAY, null, 1, 2, true);
Jason Monkb5b092012017-01-05 11:35:34 -0500124 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800125 verify(mCallbacks).setImeWindowStatus(
126 eq(DEFAULT_DISPLAY), eq(null), eq(1), eq(2), eq(true));
Jason Monkb5b092012017-01-05 11:35:34 -0500127 }
128
129 @Test
130 public void testShowRecentApps() {
Winson Chungdff7a732017-12-11 12:17:06 -0800131 mCommandQueue.showRecentApps(true);
Jason Monkb5b092012017-01-05 11:35:34 -0500132 waitForIdleSync();
Winson Chungdff7a732017-12-11 12:17:06 -0800133 verify(mCallbacks).showRecentApps(eq(true));
Jason Monkb5b092012017-01-05 11:35:34 -0500134 }
135
136 @Test
137 public void testHideRecentApps() {
138 mCommandQueue.hideRecentApps(true, false);
139 waitForIdleSync();
140 verify(mCallbacks).hideRecentApps(eq(true), eq(false));
141 }
142
143 @Test
144 public void testToggleRecentApps() {
145 mCommandQueue.toggleRecentApps();
146 waitForIdleSync();
147 verify(mCallbacks).toggleRecentApps();
148 }
149
150 @Test
151 public void testPreloadRecentApps() {
152 mCommandQueue.preloadRecentApps();
153 waitForIdleSync();
154 verify(mCallbacks).preloadRecentApps();
155 }
156
157 @Test
158 public void testCancelPreloadRecentApps() {
159 mCommandQueue.cancelPreloadRecentApps();
160 waitForIdleSync();
161 verify(mCallbacks).cancelPreloadRecentApps();
162 }
163
164 @Test
165 public void testDismissKeyboardShortcuts() {
166 mCommandQueue.dismissKeyboardShortcutsMenu();
167 waitForIdleSync();
168 verify(mCallbacks).dismissKeyboardShortcutsMenu();
169 }
170
171 @Test
172 public void testToggleKeyboardShortcuts() {
173 mCommandQueue.toggleKeyboardShortcutsMenu(1);
174 waitForIdleSync();
175 verify(mCallbacks).toggleKeyboardShortcutsMenu(eq(1));
176 }
177
Charles Chen24e7a9f2018-11-21 11:59:07 +0800178 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500179 @Test
180 public void testSetWindowState() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800181 mCommandQueue.setWindowState(DEFAULT_DISPLAY, 1, 2);
Jason Monkb5b092012017-01-05 11:35:34 -0500182 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800183 verify(mCallbacks).setWindowState(eq(DEFAULT_DISPLAY), eq(1), eq(2));
Jason Monkb5b092012017-01-05 11:35:34 -0500184 }
185
186 @Test
Jason Monkb5b092012017-01-05 11:35:34 -0500187 public void testScreenPinRequest() {
188 mCommandQueue.showScreenPinningRequest(1);
189 waitForIdleSync();
190 verify(mCallbacks).showScreenPinningRequest(eq(1));
191 }
192
Charles Chen24e7a9f2018-11-21 11:59:07 +0800193 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500194 @Test
195 public void testAppTransitionPending() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800196 mCommandQueue.appTransitionPending(DEFAULT_DISPLAY);
Jason Monkb5b092012017-01-05 11:35:34 -0500197 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800198 verify(mCallbacks).appTransitionPending(eq(DEFAULT_DISPLAY), eq(false));
Jason Monkb5b092012017-01-05 11:35:34 -0500199 }
200
Charles Chen24e7a9f2018-11-21 11:59:07 +0800201 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500202 @Test
203 public void testAppTransitionCancelled() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800204 mCommandQueue.appTransitionCancelled(DEFAULT_DISPLAY);
Jason Monkb5b092012017-01-05 11:35:34 -0500205 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800206 verify(mCallbacks).appTransitionCancelled(eq(DEFAULT_DISPLAY));
Jason Monkb5b092012017-01-05 11:35:34 -0500207 }
208
Charles Chen24e7a9f2018-11-21 11:59:07 +0800209 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500210 @Test
211 public void testAppTransitionStarting() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800212 mCommandQueue.appTransitionStarting(DEFAULT_DISPLAY, 1, 2);
Jason Monkb5b092012017-01-05 11:35:34 -0500213 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800214 verify(mCallbacks).appTransitionStarting(
215 eq(DEFAULT_DISPLAY), eq(1L), eq(2L), eq(false));
Jason Monkb5b092012017-01-05 11:35:34 -0500216 }
217
Charles Chen24e7a9f2018-11-21 11:59:07 +0800218 // TODO(b/117478341): add test case for multi-display
Jason Monkb5b092012017-01-05 11:35:34 -0500219 @Test
220 public void testAppTransitionFinished() {
Charles Chen24e7a9f2018-11-21 11:59:07 +0800221 mCommandQueue.appTransitionFinished(DEFAULT_DISPLAY);
Jason Monkb5b092012017-01-05 11:35:34 -0500222 waitForIdleSync();
Charles Chenf3d295c2018-11-30 18:15:21 +0800223 verify(mCallbacks).appTransitionFinished(eq(DEFAULT_DISPLAY));
Jason Monkb5b092012017-01-05 11:35:34 -0500224 }
225
226 @Test
227 public void testAssistDisclosure() {
228 mCommandQueue.showAssistDisclosure();
229 waitForIdleSync();
230 verify(mCallbacks).showAssistDisclosure();
231 }
232
233 @Test
234 public void testStartAssist() {
235 Bundle b = new Bundle();
236 mCommandQueue.startAssist(b);
237 waitForIdleSync();
238 verify(mCallbacks).startAssist(eq(b));
239 }
240
241 @Test
242 public void testCameraLaunchGesture() {
243 mCommandQueue.onCameraLaunchGestureDetected(1);
244 waitForIdleSync();
245 verify(mCallbacks).onCameraLaunchGestureDetected(eq(1));
246 }
247
248 @Test
Winson Chungac52f282017-03-30 14:44:52 -0700249 public void testShowPipMenu() {
250 mCommandQueue.showPictureInPictureMenu();
Jason Monkb5b092012017-01-05 11:35:34 -0500251 waitForIdleSync();
Winson Chungac52f282017-03-30 14:44:52 -0700252 verify(mCallbacks).showPictureInPictureMenu();
Jason Monkb5b092012017-01-05 11:35:34 -0500253 }
254
255 @Test
256 public void testAddQsTile() {
257 ComponentName c = new ComponentName("testpkg", "testcls");
258 mCommandQueue.addQsTile(c);
259 waitForIdleSync();
260 verify(mCallbacks).addQsTile(eq(c));
261 }
262
263 @Test
264 public void testRemoveQsTile() {
265 ComponentName c = new ComponentName("testpkg", "testcls");
266 mCommandQueue.remQsTile(c);
267 waitForIdleSync();
268 verify(mCallbacks).remQsTile(eq(c));
269 }
270
271 @Test
272 public void testClickQsTile() {
273 ComponentName c = new ComponentName("testpkg", "testcls");
274 mCommandQueue.clickQsTile(c);
275 waitForIdleSync();
276 verify(mCallbacks).clickTile(eq(c));
277 }
278
279 @Test
280 public void testToggleAppSplitScreen() {
281 mCommandQueue.toggleSplitScreen();
282 waitForIdleSync();
283 verify(mCallbacks).toggleSplitScreen();
284 }
285
286 @Test
Philip Quinnc3a503d2017-07-18 23:23:41 -0700287 public void testHandleSysKey() {
288 mCommandQueue.handleSystemKey(1);
Jason Monkb5b092012017-01-05 11:35:34 -0500289 waitForIdleSync();
Philip Quinnc3a503d2017-07-18 23:23:41 -0700290 verify(mCallbacks).handleSystemKey(eq(1));
Jason Monkb5b092012017-01-05 11:35:34 -0500291 }
292}