blob: e72e4601bbe8baaf878589b6488d3e52fd9e1d7c [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
38/**
39 * Tests for GlobalActionPerformer
40 */
41public class GlobalActionPerformerTest {
42 GlobalActionPerformer mGlobalActionPerformer;
43
44 @Mock Context mMockContext;
45 @Mock WindowManagerInternal mMockWindowManagerInternal;
46 @Mock StatusBarManager mMockStatusBarManager;
Phil Weaverd0429742018-01-16 15:32:30 -080047 @Mock ScreenshotHelper mMockScreenshotHelper;
Phil Weaver015847a2017-07-28 08:43:39 -070048
49 @Before
50 public void setup() {
51 MockitoAnnotations.initMocks(this);
52
53 when(mMockContext.getSystemService(android.app.Service.STATUS_BAR_SERVICE))
54 .thenReturn(mMockStatusBarManager);
55
56 mGlobalActionPerformer =
Phil Weaverd0429742018-01-16 15:32:30 -080057 new GlobalActionPerformer(mMockContext, mMockWindowManagerInternal,
58 () -> mMockScreenshotHelper);
Phil Weaver015847a2017-07-28 08:43:39 -070059 }
60
61 @Test
62 public void testNotifications_expandsNotificationPanel() {
63 mGlobalActionPerformer
64 .performGlobalAction(AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
65 verify(mMockStatusBarManager).expandNotificationsPanel();
66 }
67
68 @Test
69 public void testQuickSettings_requestsQuickSettingsPanel() {
70 mGlobalActionPerformer
71 .performGlobalAction(AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS);
72 verify(mMockStatusBarManager).expandSettingsPanel();
73 }
74
75 @Test
76 public void testPowerDialog_requestsFromWindowManager() {
77 mGlobalActionPerformer.performGlobalAction(AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
78 verify(mMockWindowManagerInternal).showGlobalActions();
79 }
Phil Weaverd0429742018-01-16 15:32:30 -080080
81 @Test
82 public void testScreenshot_requestsFromScreenshotHelper() {
83 mGlobalActionPerformer.performGlobalAction(
84 AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT);
85 verify(mMockScreenshotHelper).takeScreenshot(
86 eq(android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN), anyBoolean(),
87 anyBoolean(), any(Handler.class));
88 }
Phil Weaver015847a2017-07-28 08:43:39 -070089}