sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [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.policy; |
| 16 | |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 17 | import static junit.framework.TestCase.assertTrue; |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 18 | |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 19 | import static org.junit.Assert.assertFalse; |
| 20 | import static org.mockito.ArgumentMatchers.anyBoolean; |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 21 | import static org.mockito.ArgumentMatchers.anyInt; |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 22 | import static org.mockito.Mockito.atLeastOnce; |
| 23 | import static org.mockito.Mockito.mock; |
| 24 | import static org.mockito.Mockito.verify; |
| 25 | |
| 26 | import android.content.res.Configuration; |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 27 | import android.test.suitebuilder.annotation.SmallTest; |
| 28 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 29 | import androidx.test.runner.AndroidJUnit4; |
| 30 | |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 31 | import com.android.systemui.SysuiTestCase; |
| 32 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | eeff95b | 2018-12-21 12:54:37 -0500 | [diff] [blame] | 33 | import com.android.systemui.statusbar.policy.ConfigurationController; |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 34 | |
| 35 | import org.junit.Before; |
| 36 | import org.junit.Test; |
| 37 | import org.junit.runner.RunWith; |
| 38 | import org.mockito.MockitoAnnotations; |
| 39 | |
| 40 | @SmallTest |
| 41 | @RunWith(AndroidJUnit4.class) |
| 42 | public class RemoteInputQuickSettingsDisablerTest extends SysuiTestCase { |
| 43 | |
| 44 | private CommandQueue mCommandQueue; |
| 45 | private RemoteInputQuickSettingsDisabler mRemoteInputQuickSettingsDisabler; |
| 46 | |
| 47 | @Before |
| 48 | public void setUp() throws Exception { |
| 49 | MockitoAnnotations.initMocks(this); |
| 50 | |
| 51 | mCommandQueue = mock(CommandQueue.class); |
| 52 | mContext.putComponent(CommandQueue.class, mCommandQueue); |
| 53 | |
Jason Monk | eeff95b | 2018-12-21 12:54:37 -0500 | [diff] [blame] | 54 | mRemoteInputQuickSettingsDisabler = new RemoteInputQuickSettingsDisabler(mContext, |
| 55 | mock(ConfigurationController.class)); |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void shouldEnableQuickSetting_afterDeactiviate() { |
| 60 | mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.TRUE); |
| 61 | mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.FALSE); |
| 62 | assertFalse(mRemoteInputQuickSettingsDisabler.mRemoteInputActive); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 63 | verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean()); |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void shouldDisableQuickSetting_afteActiviate() { |
| 68 | mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.FALSE); |
| 69 | mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.TRUE); |
| 70 | assertTrue(mRemoteInputQuickSettingsDisabler.mRemoteInputActive); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 71 | verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean()); |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Test |
| 75 | public void testChangeToLandscape() { |
| 76 | Configuration c = new Configuration(mContext.getResources().getConfiguration()); |
| 77 | c.orientation = Configuration.ORIENTATION_PORTRAIT; |
| 78 | mRemoteInputQuickSettingsDisabler.onConfigChanged(c); |
| 79 | c.orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 80 | mRemoteInputQuickSettingsDisabler.onConfigChanged(c); |
| 81 | assertTrue(mRemoteInputQuickSettingsDisabler.misLandscape); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 82 | verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean()); |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testChangeToPortrait() { |
| 87 | Configuration c = new Configuration(mContext.getResources().getConfiguration()); |
| 88 | c.orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 89 | mRemoteInputQuickSettingsDisabler.onConfigChanged(c); |
| 90 | c.orientation = Configuration.ORIENTATION_PORTRAIT; |
| 91 | mRemoteInputQuickSettingsDisabler.onConfigChanged(c); |
| 92 | assertFalse(mRemoteInputQuickSettingsDisabler.misLandscape); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 93 | verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean()); |
sanryhuang | 6378786 | 2018-05-18 15:57:43 +0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | } |