blob: c73be6f100cdda288762c35d6799fc02096d18d6 [file] [log] [blame]
Phil Weaver015847a2017-07-28 08:43:39 -07001/*
2 ** Copyright 2017, 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.server.accessibility;
18
Phil Weaverd0429742018-01-16 15:32:30 -080019import static org.mockito.ArgumentMatchers.any;
20import static org.mockito.ArgumentMatchers.anyBoolean;
21import static org.mockito.ArgumentMatchers.eq;
Phil Weaver015847a2017-07-28 08:43:39 -070022import static org.mockito.Mockito.verify;
23import static org.mockito.Mockito.when;
24
25import android.accessibilityservice.AccessibilityService;
26import android.app.StatusBarManager;
27import android.content.Context;
Phil Weaverd0429742018-01-16 15:32:30 -080028import android.os.Handler;
Adrian Roose99bc052017-11-20 17:55:31 +010029
Phil Weaverd0429742018-01-16 15:32:30 -080030import com.android.internal.util.ScreenshotHelper;
Adrian Roose99bc052017-11-20 17:55:31 +010031import com.android.server.wm.WindowManagerInternal;
Phil Weaver015847a2017-07-28 08:43:39 -070032
33import org.junit.Before;
34import org.junit.Test;
35import org.mockito.Mock;
36import org.mockito.MockitoAnnotations;
37
James O'Learyfa5bb7a2019-09-05 13:43:29 -040038import java.util.function.Consumer;
39
Phil Weaver015847a2017-07-28 08:43:39 -070040/**
41 * Tests for GlobalActionPerformer
42 */
43public class GlobalActionPerformerTest {
44 GlobalActionPerformer mGlobalActionPerformer;
45
46 @Mock Context mMockContext;
47 @Mock WindowManagerInternal mMockWindowManagerInternal;
48 @Mock StatusBarManager mMockStatusBarManager;
Phil Weaverd0429742018-01-16 15:32:30 -080049 @Mock ScreenshotHelper mMockScreenshotHelper;
Phil Weaver015847a2017-07-28 08:43:39 -070050
51 @Before
52 public void setup() {
53 MockitoAnnotations.initMocks(this);
54
55 when(mMockContext.getSystemService(android.app.Service.STATUS_BAR_SERVICE))
56 .thenReturn(mMockStatusBarManager);
57
58 mGlobalActionPerformer =
Phil Weaverd0429742018-01-16 15:32:30 -080059 new GlobalActionPerformer(mMockContext, mMockWindowManagerInternal,
60 () -> mMockScreenshotHelper);
Phil Weaver015847a2017-07-28 08:43:39 -070061 }
62
63 @Test
64 public void testNotifications_expandsNotificationPanel() {
65 mGlobalActionPerformer
66 .performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
67 verify(mMockStatusBarManager).expandNotificationsPanel();
68 }
69
70 @Test
71 public void testQuickSettings_requestsQuickSettingsPanel() {
72 mGlobalActionPerformer
73 .performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS);
74 verify(mMockStatusBarManager).expandSettingsPanel();
75 }
76
77 @Test
78 public void testPowerDialog_requestsFromWindowManager() {
79 mGlobalActionPerformer.performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
80 verify(mMockWindowManagerInternal).showGlobalActions();
81 }
Phil Weaverd0429742018-01-16 15:32:30 -080082
83 @Test
84 public void testScreenshot_requestsFromScreenshotHelper() {
85 mGlobalActionPerformer.performGlobalAction(
86 AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT);
87 verify(mMockScreenshotHelper).takeScreenshot(
88 eq(android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN), anyBoolean(),
James O'Learyfa5bb7a2019-09-05 13:43:29 -040089 anyBoolean(), any(Handler.class), any());
Phil Weaverd0429742018-01-16 15:32:30 -080090 }
Phil Weaver015847a2017-07-28 08:43:39 -070091}