blob: fea41a441065bbfd883fc7347f20a9b78c28f003 [file] [log] [blame]
Lucas Dupina3e36272018-08-21 13:22:33 -07001/*
2 * Copyright (C) 2018 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.systemui.statusbar.phone;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import static org.mockito.ArgumentMatchers.any;
Lucas Dupinfdbfc542018-09-17 15:56:09 -070022import static org.mockito.ArgumentMatchers.anyInt;
Lucas Dupina3e36272018-08-21 13:22:33 -070023import static org.mockito.Mockito.reset;
24import static org.mockito.Mockito.verify;
25import static org.mockito.Mockito.when;
26
27import android.app.IActivityManager;
Lucas Dupina3e36272018-08-21 13:22:33 -070028import android.testing.AndroidTestingRunner;
29import android.testing.TestableLooper.RunWithLooper;
Mady Mellord1c78b262018-11-06 18:04:40 -080030import android.view.ViewGroup;
Lucas Dupina3e36272018-08-21 13:22:33 -070031import android.view.WindowManager;
32
Brett Chabot84151d92019-02-27 15:37:59 -080033import androidx.test.filters.SmallTest;
34
Lucas Dupina3e36272018-08-21 13:22:33 -070035import com.android.systemui.SysuiTestCase;
36
37import org.junit.Before;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40import org.mockito.ArgumentCaptor;
Lucas Dupina3e36272018-08-21 13:22:33 -070041import org.mockito.Mock;
42import org.mockito.MockitoAnnotations;
43
44@RunWith(AndroidTestingRunner.class)
45@RunWithLooper
46@SmallTest
47public class StatusBarWindowControllerTest extends SysuiTestCase {
48
49 @Mock
50 private WindowManager mWindowManager;
51 @Mock
52 private DozeParameters mDozeParameters;
53 @Mock
Mady Mellord1c78b262018-11-06 18:04:40 -080054 private ViewGroup mStatusBarView;
Lucas Dupina3e36272018-08-21 13:22:33 -070055 @Mock
56 private IActivityManager mActivityManager;
57
58 private StatusBarWindowController mStatusBarWindowController;
59
60 @Before
61 public void setUp() {
62 MockitoAnnotations.initMocks(this);
63 when(mDozeParameters.getAlwaysOn()).thenReturn(true);
64
65 mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager,
66 mActivityManager, mDozeParameters);
67 mStatusBarWindowController.add(mStatusBarView, 100 /* height */);
68 }
69
70 @Test
71 public void testSetDozing_hidesSystemOverlays() {
72 mStatusBarWindowController.setDozing(true);
73 ArgumentCaptor<WindowManager.LayoutParams> captor =
74 ArgumentCaptor.forClass(WindowManager.LayoutParams.class);
75 verify(mWindowManager).updateViewLayout(any(), captor.capture());
76 int flag = captor.getValue().privateFlags
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070077 & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -070078 assertThat(flag).isNotEqualTo(0);
79
80 reset(mWindowManager);
81 mStatusBarWindowController.setDozing(false);
82 verify(mWindowManager).updateViewLayout(any(), captor.capture());
83 flag = captor.getValue().privateFlags
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070084 & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Lucas Dupina3e36272018-08-21 13:22:33 -070085 assertThat(flag).isEqualTo(0);
86 }
Lucas Dupinfdbfc542018-09-17 15:56:09 -070087
88 @Test
89 public void testOnThemeChanged_doesntCrash() {
90 mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager,
91 mActivityManager, mDozeParameters);
92 mStatusBarWindowController.onThemeChanged();
93 }
94
95 @Test
96 public void testAdd_updatesVisibilityFlags() {
97 verify(mStatusBarView).setSystemUiVisibility(anyInt());
98 }
Lucas Dupin42ebe542019-01-22 09:45:09 -080099
100 @Test
101 public void testSetForcePluginOpen_beforeStatusBarInitialization() {
102 mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager,
103 mActivityManager, mDozeParameters);
104 mStatusBarWindowController.setForcePluginOpen(true);
105 }
Lucas Dupina3e36272018-08-21 13:22:33 -0700106}