Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 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 | |
| 15 | package com.android.systemui.statusbar; |
| 16 | |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 17 | import static android.view.Display.DEFAULT_DISPLAY; |
| 18 | |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.anyInt; |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 20 | import static org.mockito.Matchers.eq; |
| 21 | import static org.mockito.Mockito.mock; |
| 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
| 24 | |
| 25 | import android.content.ComponentName; |
| 26 | import android.graphics.Rect; |
| 27 | import android.os.Bundle; |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 28 | import android.support.test.filters.SmallTest; |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 29 | |
| 30 | import com.android.internal.statusbar.StatusBarIcon; |
| 31 | import com.android.systemui.SysuiTestCase; |
| 32 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
| 33 | |
| 34 | import org.junit.After; |
| 35 | import org.junit.Before; |
| 36 | import org.junit.Test; |
| 37 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 38 | @SmallTest |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 39 | public class CommandQueueTest extends SysuiTestCase { |
| 40 | |
| 41 | private CommandQueue mCommandQueue; |
| 42 | private Callbacks mCallbacks; |
| 43 | |
| 44 | @Before |
| 45 | public void setup() { |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 46 | mCommandQueue = new CommandQueue(mContext); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 47 | mCallbacks = mock(Callbacks.class); |
Jason Monk | d7c9855 | 2018-12-04 11:14:50 -0500 | [diff] [blame] | 48 | mCommandQueue.addCallback(mCallbacks); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 49 | verify(mCallbacks).disable(anyInt(), eq(0), eq(0), eq(false)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 50 | } |
| 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 Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 70 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 71 | @Test |
| 72 | public void testDisable() { |
| 73 | int state1 = 14; |
| 74 | int state2 = 42; |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 75 | mCommandQueue.disable(DEFAULT_DISPLAY, state1, state2); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 76 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 77 | verify(mCallbacks).disable(eq(DEFAULT_DISPLAY), eq(state1), eq(state2), eq(true)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 78 | } |
| 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 Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 91 | verify(mCallbacks).animateCollapsePanels(eq(0), eq(false)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 92 | } |
| 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 Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 102 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 103 | @Test |
| 104 | public void testSetSystemUiVisibility() { |
| 105 | Rect r = new Rect(); |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 106 | mCommandQueue.setSystemUiVisibility(DEFAULT_DISPLAY, 1, 2, 3, 4, null, r); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 107 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 108 | verify(mCallbacks).setSystemUiVisibility(eq(DEFAULT_DISPLAY), eq(1), eq(2), eq(3), eq(4), |
| 109 | eq(null), eq(r)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 110 | } |
| 111 | |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 112 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 113 | @Test |
| 114 | public void testTopAppWindowChanged() { |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 115 | mCommandQueue.topAppWindowChanged(DEFAULT_DISPLAY, true); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 116 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 117 | verify(mCallbacks).topAppWindowChanged(eq(DEFAULT_DISPLAY), eq(true)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 118 | } |
| 119 | |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 120 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 121 | @Test |
| 122 | public void testShowImeButton() { |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 123 | mCommandQueue.setImeWindowStatus(DEFAULT_DISPLAY, null, 1, 2, true); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 124 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 125 | verify(mCallbacks).setImeWindowStatus( |
| 126 | eq(DEFAULT_DISPLAY), eq(null), eq(1), eq(2), eq(true)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Test |
| 130 | public void testShowRecentApps() { |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 131 | mCommandQueue.showRecentApps(true); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 132 | waitForIdleSync(); |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 133 | verify(mCallbacks).showRecentApps(eq(true)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 134 | } |
| 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 Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 178 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 179 | @Test |
| 180 | public void testSetWindowState() { |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 181 | mCommandQueue.setWindowState(DEFAULT_DISPLAY, 1, 2); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 182 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 183 | verify(mCallbacks).setWindowState(eq(DEFAULT_DISPLAY), eq(1), eq(2)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | @Test |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 187 | public void testScreenPinRequest() { |
| 188 | mCommandQueue.showScreenPinningRequest(1); |
| 189 | waitForIdleSync(); |
| 190 | verify(mCallbacks).showScreenPinningRequest(eq(1)); |
| 191 | } |
| 192 | |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 193 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 194 | @Test |
| 195 | public void testAppTransitionPending() { |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 196 | mCommandQueue.appTransitionPending(DEFAULT_DISPLAY); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 197 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 198 | verify(mCallbacks).appTransitionPending(eq(DEFAULT_DISPLAY), eq(false)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 199 | } |
| 200 | |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 201 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 202 | @Test |
| 203 | public void testAppTransitionCancelled() { |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 204 | mCommandQueue.appTransitionCancelled(DEFAULT_DISPLAY); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 205 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 206 | verify(mCallbacks).appTransitionCancelled(eq(DEFAULT_DISPLAY)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 207 | } |
| 208 | |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 209 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 210 | @Test |
| 211 | public void testAppTransitionStarting() { |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 212 | mCommandQueue.appTransitionStarting(DEFAULT_DISPLAY, 1, 2); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 213 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 214 | verify(mCallbacks).appTransitionStarting( |
| 215 | eq(DEFAULT_DISPLAY), eq(1L), eq(2L), eq(false)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 216 | } |
| 217 | |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 218 | // TODO(b/117478341): add test case for multi-display |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 219 | @Test |
| 220 | public void testAppTransitionFinished() { |
Charles Chen | 24e7a9f | 2018-11-21 11:59:07 +0800 | [diff] [blame] | 221 | mCommandQueue.appTransitionFinished(DEFAULT_DISPLAY); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 222 | waitForIdleSync(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 223 | verify(mCallbacks).appTransitionFinished(eq(DEFAULT_DISPLAY)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 224 | } |
| 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 Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 249 | public void testShowPipMenu() { |
| 250 | mCommandQueue.showPictureInPictureMenu(); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 251 | waitForIdleSync(); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 252 | verify(mCallbacks).showPictureInPictureMenu(); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 253 | } |
| 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 Quinn | c3a503d | 2017-07-18 23:23:41 -0700 | [diff] [blame] | 287 | public void testHandleSysKey() { |
| 288 | mCommandQueue.handleSystemKey(1); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 289 | waitForIdleSync(); |
Philip Quinn | c3a503d | 2017-07-18 23:23:41 -0700 | [diff] [blame] | 290 | verify(mCallbacks).handleSystemKey(eq(1)); |
Jason Monk | b5b09201 | 2017-01-05 11:35:34 -0500 | [diff] [blame] | 291 | } |
| 292 | } |