1/*
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
17import static org.mockito.Matchers.eq;
18import static org.mockito.Mockito.mock;
19import static org.mockito.Mockito.verify;
20import static org.mockito.Mockito.verifyNoMoreInteractions;
21
22import android.content.ComponentName;
23import android.graphics.Rect;
24import android.os.Bundle;
25import android.support.test.filters.SmallTest;
26
27import com.android.internal.statusbar.StatusBarIcon;
28import com.android.systemui.SysuiTestCase;
29import com.android.systemui.statusbar.CommandQueue.Callbacks;
30
31import org.junit.After;
32import org.junit.Before;
33import org.junit.Test;
34
35@SmallTest
36public class CommandQueueTest extends SysuiTestCase {
37
38    private CommandQueue mCommandQueue;
39    private Callbacks mCallbacks;
40
41    @Before
42    public void setup() {
43        mCommandQueue = new CommandQueue();
44        mCallbacks = mock(Callbacks.class);
45        mCommandQueue.addCallbacks(mCallbacks);
46        verify(mCallbacks).disable(eq(0), eq(0), eq(false));
47    }
48
49    @After
50    public void tearDown() {
51        verifyNoMoreInteractions(mCallbacks);
52    }
53
54    @Test
55    public void testIcon() {
56        String slot = "testSlot";
57        StatusBarIcon icon = mock(StatusBarIcon.class);
58        mCommandQueue.setIcon(slot, icon);
59        waitForIdleSync();
60        verify(mCallbacks).setIcon(eq(slot), eq(icon));
61
62        mCommandQueue.removeIcon(slot);
63        waitForIdleSync();
64        verify(mCallbacks).removeIcon(eq(slot));
65    }
66
67    @Test
68    public void testDisable() {
69        int state1 = 14;
70        int state2 = 42;
71        mCommandQueue.disable(state1, state2);
72        waitForIdleSync();
73        verify(mCallbacks).disable(eq(state1), eq(state2), eq(true));
74    }
75
76    @Test
77    public void testExpandNotifications() {
78        mCommandQueue.animateExpandNotificationsPanel();
79        waitForIdleSync();
80        verify(mCallbacks).animateExpandNotificationsPanel();
81    }
82
83    @Test
84    public void testCollapsePanels() {
85        mCommandQueue.animateCollapsePanels();
86        waitForIdleSync();
87        verify(mCallbacks).animateCollapsePanels(eq(0));
88    }
89
90    @Test
91    public void testExpandSettings() {
92        String panel = "some_panel";
93        mCommandQueue.animateExpandSettingsPanel(panel);
94        waitForIdleSync();
95        verify(mCallbacks).animateExpandSettingsPanel(eq(panel));
96    }
97
98    @Test
99    public void testSetSystemUiVisibility() {
100        Rect r = new Rect();
101        mCommandQueue.setSystemUiVisibility(1, 2, 3, 4, null, r);
102        waitForIdleSync();
103        verify(mCallbacks).setSystemUiVisibility(eq(1), eq(2), eq(3), eq(4), eq(null), eq(r));
104    }
105
106    @Test
107    public void testTopAppWindowChanged() {
108        mCommandQueue.topAppWindowChanged(true);
109        waitForIdleSync();
110        verify(mCallbacks).topAppWindowChanged(eq(true));
111    }
112
113    @Test
114    public void testShowImeButton() {
115        mCommandQueue.setImeWindowStatus(null, 1, 2, true);
116        waitForIdleSync();
117        verify(mCallbacks).setImeWindowStatus(eq(null), eq(1), eq(2), eq(true));
118    }
119
120    @Test
121    public void testShowRecentApps() {
122        mCommandQueue.showRecentApps(true);
123        waitForIdleSync();
124        verify(mCallbacks).showRecentApps(eq(true));
125    }
126
127    @Test
128    public void testHideRecentApps() {
129        mCommandQueue.hideRecentApps(true, false);
130        waitForIdleSync();
131        verify(mCallbacks).hideRecentApps(eq(true), eq(false));
132    }
133
134    @Test
135    public void testToggleRecentApps() {
136        mCommandQueue.toggleRecentApps();
137        waitForIdleSync();
138        verify(mCallbacks).toggleRecentApps();
139    }
140
141    @Test
142    public void testPreloadRecentApps() {
143        mCommandQueue.preloadRecentApps();
144        waitForIdleSync();
145        verify(mCallbacks).preloadRecentApps();
146    }
147
148    @Test
149    public void testCancelPreloadRecentApps() {
150        mCommandQueue.cancelPreloadRecentApps();
151        waitForIdleSync();
152        verify(mCallbacks).cancelPreloadRecentApps();
153    }
154
155    @Test
156    public void testDismissKeyboardShortcuts() {
157        mCommandQueue.dismissKeyboardShortcutsMenu();
158        waitForIdleSync();
159        verify(mCallbacks).dismissKeyboardShortcutsMenu();
160    }
161
162    @Test
163    public void testToggleKeyboardShortcuts() {
164        mCommandQueue.toggleKeyboardShortcutsMenu(1);
165        waitForIdleSync();
166        verify(mCallbacks).toggleKeyboardShortcutsMenu(eq(1));
167    }
168
169    @Test
170    public void testSetWindowState() {
171        mCommandQueue.setWindowState(1, 2);
172        waitForIdleSync();
173        verify(mCallbacks).setWindowState(eq(1), eq(2));
174    }
175
176    @Test
177    public void testScreenPinRequest() {
178        mCommandQueue.showScreenPinningRequest(1);
179        waitForIdleSync();
180        verify(mCallbacks).showScreenPinningRequest(eq(1));
181    }
182
183    @Test
184    public void testAppTransitionPending() {
185        mCommandQueue.appTransitionPending();
186        waitForIdleSync();
187        verify(mCallbacks).appTransitionPending(eq(false));
188    }
189
190    @Test
191    public void testAppTransitionCancelled() {
192        mCommandQueue.appTransitionCancelled();
193        waitForIdleSync();
194        verify(mCallbacks).appTransitionCancelled();
195    }
196
197    @Test
198    public void testAppTransitionStarting() {
199        mCommandQueue.appTransitionStarting(1, 2);
200        waitForIdleSync();
201        verify(mCallbacks).appTransitionStarting(eq(1L), eq(2L), eq(false));
202    }
203
204    @Test
205    public void testAppTransitionFinished() {
206        mCommandQueue.appTransitionFinished();
207        waitForIdleSync();
208        verify(mCallbacks).appTransitionFinished();
209    }
210
211    @Test
212    public void testAssistDisclosure() {
213        mCommandQueue.showAssistDisclosure();
214        waitForIdleSync();
215        verify(mCallbacks).showAssistDisclosure();
216    }
217
218    @Test
219    public void testStartAssist() {
220        Bundle b = new Bundle();
221        mCommandQueue.startAssist(b);
222        waitForIdleSync();
223        verify(mCallbacks).startAssist(eq(b));
224    }
225
226    @Test
227    public void testCameraLaunchGesture() {
228        mCommandQueue.onCameraLaunchGestureDetected(1);
229        waitForIdleSync();
230        verify(mCallbacks).onCameraLaunchGestureDetected(eq(1));
231    }
232
233    @Test
234    public void testShowPipMenu() {
235        mCommandQueue.showPictureInPictureMenu();
236        waitForIdleSync();
237        verify(mCallbacks).showPictureInPictureMenu();
238    }
239
240    @Test
241    public void testAddQsTile() {
242        ComponentName c = new ComponentName("testpkg", "testcls");
243        mCommandQueue.addQsTile(c);
244        waitForIdleSync();
245        verify(mCallbacks).addQsTile(eq(c));
246    }
247
248    @Test
249    public void testRemoveQsTile() {
250        ComponentName c = new ComponentName("testpkg", "testcls");
251        mCommandQueue.remQsTile(c);
252        waitForIdleSync();
253        verify(mCallbacks).remQsTile(eq(c));
254    }
255
256    @Test
257    public void testClickQsTile() {
258        ComponentName c = new ComponentName("testpkg", "testcls");
259        mCommandQueue.clickQsTile(c);
260        waitForIdleSync();
261        verify(mCallbacks).clickTile(eq(c));
262    }
263
264    @Test
265    public void testToggleAppSplitScreen() {
266        mCommandQueue.toggleSplitScreen();
267        waitForIdleSync();
268        verify(mCallbacks).toggleSplitScreen();
269    }
270
271    @Test
272    public void testHandleSysKey() {
273        mCommandQueue.handleSystemKey(1);
274        waitForIdleSync();
275        verify(mCallbacks).handleSystemKey(eq(1));
276    }
277}
278