Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.mockito.ArgumentMatchers.any; |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 22 | import static org.mockito.ArgumentMatchers.anyInt; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 23 | import static org.mockito.Mockito.reset; |
| 24 | import static org.mockito.Mockito.verify; |
| 25 | import static org.mockito.Mockito.when; |
| 26 | |
| 27 | import android.app.IActivityManager; |
| 28 | import android.support.test.filters.SmallTest; |
| 29 | import android.testing.AndroidTestingRunner; |
| 30 | import android.testing.TestableLooper.RunWithLooper; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 31 | import android.view.ViewGroup; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 32 | import android.view.WindowManager; |
| 33 | |
| 34 | import com.android.systemui.SysuiTestCase; |
| 35 | |
| 36 | import org.junit.Before; |
| 37 | import org.junit.Test; |
| 38 | import org.junit.runner.RunWith; |
| 39 | import org.mockito.ArgumentCaptor; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 40 | import org.mockito.Mock; |
| 41 | import org.mockito.MockitoAnnotations; |
| 42 | |
| 43 | @RunWith(AndroidTestingRunner.class) |
| 44 | @RunWithLooper |
| 45 | @SmallTest |
| 46 | public class StatusBarWindowControllerTest extends SysuiTestCase { |
| 47 | |
| 48 | @Mock |
| 49 | private WindowManager mWindowManager; |
| 50 | @Mock |
| 51 | private DozeParameters mDozeParameters; |
| 52 | @Mock |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 53 | private ViewGroup mStatusBarView; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 54 | @Mock |
| 55 | private IActivityManager mActivityManager; |
| 56 | |
| 57 | private StatusBarWindowController mStatusBarWindowController; |
| 58 | |
| 59 | @Before |
| 60 | public void setUp() { |
| 61 | MockitoAnnotations.initMocks(this); |
| 62 | when(mDozeParameters.getAlwaysOn()).thenReturn(true); |
| 63 | |
| 64 | mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager, |
| 65 | mActivityManager, mDozeParameters); |
| 66 | mStatusBarWindowController.add(mStatusBarView, 100 /* height */); |
| 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void testSetDozing_hidesSystemOverlays() { |
| 71 | mStatusBarWindowController.setDozing(true); |
| 72 | ArgumentCaptor<WindowManager.LayoutParams> captor = |
| 73 | ArgumentCaptor.forClass(WindowManager.LayoutParams.class); |
| 74 | verify(mWindowManager).updateViewLayout(any(), captor.capture()); |
| 75 | int flag = captor.getValue().privateFlags |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 76 | & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 77 | assertThat(flag).isNotEqualTo(0); |
| 78 | |
| 79 | reset(mWindowManager); |
| 80 | mStatusBarWindowController.setDozing(false); |
| 81 | verify(mWindowManager).updateViewLayout(any(), captor.capture()); |
| 82 | flag = captor.getValue().privateFlags |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 83 | & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 84 | assertThat(flag).isEqualTo(0); |
| 85 | } |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 86 | |
| 87 | @Test |
| 88 | public void testOnThemeChanged_doesntCrash() { |
| 89 | mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager, |
| 90 | mActivityManager, mDozeParameters); |
| 91 | mStatusBarWindowController.onThemeChanged(); |
| 92 | } |
| 93 | |
| 94 | @Test |
| 95 | public void testAdd_updatesVisibilityFlags() { |
| 96 | verify(mStatusBarView).setSystemUiVisibility(anyInt()); |
| 97 | } |
Lucas Dupin | 42ebe54 | 2019-01-22 09:45:09 -0800 | [diff] [blame] | 98 | |
| 99 | @Test |
| 100 | public void testSetForcePluginOpen_beforeStatusBarInitialization() { |
| 101 | mStatusBarWindowController = new StatusBarWindowController(mContext, mWindowManager, |
| 102 | mActivityManager, mDozeParameters); |
| 103 | mStatusBarWindowController.setForcePluginOpen(true); |
| 104 | } |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 105 | } |