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