blob: 8b8e3f195d40358738f95e3b6ea897177810d9fa [file] [log] [blame]
sanryhuang63787862018-05-18 15:57:43 +08001/*
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
15package com.android.systemui.statusbar.policy;
16
sanryhuang63787862018-05-18 15:57:43 +080017import static junit.framework.TestCase.assertTrue;
Charles Chenf3d295c2018-11-30 18:15:21 +080018
sanryhuang63787862018-05-18 15:57:43 +080019import static org.junit.Assert.assertFalse;
20import static org.mockito.ArgumentMatchers.anyBoolean;
Charles Chenf3d295c2018-11-30 18:15:21 +080021import static org.mockito.ArgumentMatchers.anyInt;
sanryhuang63787862018-05-18 15:57:43 +080022import static org.mockito.Mockito.atLeastOnce;
23import static org.mockito.Mockito.mock;
24import static org.mockito.Mockito.verify;
25
26import android.content.res.Configuration;
27import android.support.test.runner.AndroidJUnit4;
28import android.test.suitebuilder.annotation.SmallTest;
29
30import com.android.systemui.SysuiTestCase;
31import com.android.systemui.statusbar.CommandQueue;
Jason Monkeeff95b2018-12-21 12:54:37 -050032import com.android.systemui.statusbar.policy.ConfigurationController;
sanryhuang63787862018-05-18 15:57:43 +080033
34import org.junit.Before;
35import org.junit.Test;
36import org.junit.runner.RunWith;
37import org.mockito.MockitoAnnotations;
38
39@SmallTest
40@RunWith(AndroidJUnit4.class)
41public 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 Monkeeff95b2018-12-21 12:54:37 -050053 mRemoteInputQuickSettingsDisabler = new RemoteInputQuickSettingsDisabler(mContext,
54 mock(ConfigurationController.class));
sanryhuang63787862018-05-18 15:57:43 +080055 }
56
57 @Test
58 public void shouldEnableQuickSetting_afterDeactiviate() {
59 mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.TRUE);
60 mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.FALSE);
61 assertFalse(mRemoteInputQuickSettingsDisabler.mRemoteInputActive);
Charles Chenf3d295c2018-11-30 18:15:21 +080062 verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean());
sanryhuang63787862018-05-18 15:57:43 +080063 }
64
65 @Test
66 public void shouldDisableQuickSetting_afteActiviate() {
67 mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.FALSE);
68 mRemoteInputQuickSettingsDisabler.setRemoteInputActive(Boolean.TRUE);
69 assertTrue(mRemoteInputQuickSettingsDisabler.mRemoteInputActive);
Charles Chenf3d295c2018-11-30 18:15:21 +080070 verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean());
sanryhuang63787862018-05-18 15:57:43 +080071 }
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 Chenf3d295c2018-11-30 18:15:21 +080081 verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean());
sanryhuang63787862018-05-18 15:57:43 +080082 }
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 Chenf3d295c2018-11-30 18:15:21 +080092 verify(mCommandQueue, atLeastOnce()).recomputeDisableFlags(anyInt(), anyBoolean());
sanryhuang63787862018-05-18 15:57:43 +080093 }
94
95}