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