Phil Weaver | 015847a | 2017-07-28 08:43:39 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.accessibility; |
| 18 | |
Phil Weaver | d042974 | 2018-01-16 15:32:30 -0800 | [diff] [blame] | 19 | import static org.mockito.ArgumentMatchers.any; |
| 20 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 21 | import static org.mockito.ArgumentMatchers.eq; |
Phil Weaver | 015847a | 2017-07-28 08:43:39 -0700 | [diff] [blame] | 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
| 25 | import android.accessibilityservice.AccessibilityService; |
| 26 | import android.app.StatusBarManager; |
| 27 | import android.content.Context; |
Phil Weaver | d042974 | 2018-01-16 15:32:30 -0800 | [diff] [blame] | 28 | import android.os.Handler; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 29 | |
Phil Weaver | d042974 | 2018-01-16 15:32:30 -0800 | [diff] [blame] | 30 | import com.android.internal.util.ScreenshotHelper; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 31 | import com.android.server.wm.WindowManagerInternal; |
Phil Weaver | 015847a | 2017-07-28 08:43:39 -0700 | [diff] [blame] | 32 | |
| 33 | import org.junit.Before; |
| 34 | import org.junit.Test; |
| 35 | import org.mockito.Mock; |
| 36 | import org.mockito.MockitoAnnotations; |
| 37 | |
James O'Leary | fa5bb7a | 2019-09-05 13:43:29 -0400 | [diff] [blame] | 38 | import java.util.function.Consumer; |
| 39 | |
Phil Weaver | 015847a | 2017-07-28 08:43:39 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Tests for GlobalActionPerformer |
| 42 | */ |
| 43 | public class GlobalActionPerformerTest { |
| 44 | GlobalActionPerformer mGlobalActionPerformer; |
| 45 | |
| 46 | @Mock Context mMockContext; |
| 47 | @Mock WindowManagerInternal mMockWindowManagerInternal; |
| 48 | @Mock StatusBarManager mMockStatusBarManager; |
Phil Weaver | d042974 | 2018-01-16 15:32:30 -0800 | [diff] [blame] | 49 | @Mock ScreenshotHelper mMockScreenshotHelper; |
Phil Weaver | 015847a | 2017-07-28 08:43:39 -0700 | [diff] [blame] | 50 | |
| 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 Weaver | d042974 | 2018-01-16 15:32:30 -0800 | [diff] [blame] | 59 | new GlobalActionPerformer(mMockContext, mMockWindowManagerInternal, |
| 60 | () -> mMockScreenshotHelper); |
Phil Weaver | 015847a | 2017-07-28 08:43:39 -0700 | [diff] [blame] | 61 | } |
| 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 Weaver | d042974 | 2018-01-16 15:32:30 -0800 | [diff] [blame] | 82 | |
| 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'Leary | fa5bb7a | 2019-09-05 13:43:29 -0400 | [diff] [blame] | 89 | anyBoolean(), any(Handler.class), any()); |
Phil Weaver | d042974 | 2018-01-16 15:32:30 -0800 | [diff] [blame] | 90 | } |
Phil Weaver | 015847a | 2017-07-28 08:43:39 -0700 | [diff] [blame] | 91 | } |