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 |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 14 | * limitations under the License. |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 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 | 1bd84d3 | 2020-03-13 17:28:18 -0700 | [diff] [blame] | 23 | import static org.mockito.ArgumentMatchers.eq; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 24 | import static org.mockito.Mockito.reset; |
| 25 | import static org.mockito.Mockito.verify; |
| 26 | import static org.mockito.Mockito.when; |
| 27 | |
| 28 | import android.app.IActivityManager; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 29 | import android.testing.AndroidTestingRunner; |
| 30 | import android.testing.TestableLooper.RunWithLooper; |
Lucas Dupin | 1bd84d3 | 2020-03-13 17:28:18 -0700 | [diff] [blame] | 31 | import android.view.View; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 32 | import android.view.WindowManager; |
| 33 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 34 | import androidx.test.filters.SmallTest; |
| 35 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 36 | import com.android.internal.colorextraction.ColorExtractor; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 37 | import com.android.systemui.SysuiTestCase; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 38 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 39 | import com.android.systemui.dump.DumpManager; |
Lucas Dupin | e25c487 | 2019-07-29 13:51:35 -0700 | [diff] [blame] | 40 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
| 41 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 42 | |
| 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | import org.mockito.ArgumentCaptor; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 47 | import org.mockito.Mock; |
| 48 | import org.mockito.MockitoAnnotations; |
| 49 | |
| 50 | @RunWith(AndroidTestingRunner.class) |
| 51 | @RunWithLooper |
| 52 | @SmallTest |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 53 | public class NotificationShadeWindowControllerTest extends SysuiTestCase { |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 54 | |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 55 | @Mock private WindowManager mWindowManager; |
| 56 | @Mock private DozeParameters mDozeParameters; |
wilsonshih | f587b63 | 2020-02-12 13:16:12 +0800 | [diff] [blame] | 57 | @Mock private NotificationShadeWindowView mNotificationShadeWindowView; |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 58 | @Mock private IActivityManager mActivityManager; |
| 59 | @Mock private SysuiStatusBarStateController mStatusBarStateController; |
| 60 | @Mock private ConfigurationController mConfigurationController; |
| 61 | @Mock private KeyguardBypassController mKeyguardBypassController; |
| 62 | @Mock private SysuiColorExtractor mColorExtractor; |
| 63 | @Mock ColorExtractor.GradientColors mGradientColors; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 64 | @Mock private DumpManager mDumpManager; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 65 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 66 | private NotificationShadeWindowController mNotificationShadeWindowController; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 67 | |
| 68 | @Before |
| 69 | public void setUp() { |
| 70 | MockitoAnnotations.initMocks(this); |
| 71 | when(mDozeParameters.getAlwaysOn()).thenReturn(true); |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 72 | when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 73 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 74 | mNotificationShadeWindowController = new NotificationShadeWindowController(mContext, |
| 75 | mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController, |
Lucas Dupin | d73410a | 2020-02-18 12:54:41 -0800 | [diff] [blame] | 76 | mConfigurationController, mKeyguardBypassController, mColorExtractor, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 77 | mDumpManager); |
wilsonshih | f587b63 | 2020-02-12 13:16:12 +0800 | [diff] [blame] | 78 | mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView); |
Heemin Seog | afb3dbc | 2019-11-04 16:05:19 -0800 | [diff] [blame] | 79 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 80 | mNotificationShadeWindowController.attach(); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testSetDozing_hidesSystemOverlays() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 85 | mNotificationShadeWindowController.setDozing(true); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 86 | ArgumentCaptor<WindowManager.LayoutParams> captor = |
| 87 | ArgumentCaptor.forClass(WindowManager.LayoutParams.class); |
| 88 | verify(mWindowManager).updateViewLayout(any(), captor.capture()); |
| 89 | int flag = captor.getValue().privateFlags |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 90 | & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 91 | assertThat(flag).isNotEqualTo(0); |
| 92 | |
| 93 | reset(mWindowManager); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 94 | mNotificationShadeWindowController.setDozing(false); |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 95 | verify(mWindowManager).updateViewLayout(any(), captor.capture()); |
| 96 | flag = captor.getValue().privateFlags |
Philip P. Moltmann | 66ce238 | 2018-10-09 13:46:11 -0700 | [diff] [blame] | 97 | & WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 98 | assertThat(flag).isEqualTo(0); |
| 99 | } |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 100 | |
| 101 | @Test |
| 102 | public void testOnThemeChanged_doesntCrash() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 103 | mNotificationShadeWindowController.onThemeChanged(); |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Test |
| 107 | public void testAdd_updatesVisibilityFlags() { |
wilsonshih | f587b63 | 2020-02-12 13:16:12 +0800 | [diff] [blame] | 108 | verify(mNotificationShadeWindowView).setSystemUiVisibility(anyInt()); |
Lucas Dupin | fdbfc54 | 2018-09-17 15:56:09 -0700 | [diff] [blame] | 109 | } |
Lucas Dupin | 42ebe54 | 2019-01-22 09:45:09 -0800 | [diff] [blame] | 110 | |
| 111 | @Test |
| 112 | public void testSetForcePluginOpen_beforeStatusBarInitialization() { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 113 | mNotificationShadeWindowController.setForcePluginOpen(true); |
Lucas Dupin | 42ebe54 | 2019-01-22 09:45:09 -0800 | [diff] [blame] | 114 | } |
Lucas Dupin | 1bd84d3 | 2020-03-13 17:28:18 -0700 | [diff] [blame] | 115 | |
| 116 | @Test |
| 117 | public void setBackgroundBlurRadius_expandedWithBlurs() { |
| 118 | mNotificationShadeWindowController.setBackgroundBlurRadius(10); |
| 119 | verify(mNotificationShadeWindowView).setVisibility(eq(View.VISIBLE)); |
| 120 | |
| 121 | mNotificationShadeWindowController.setBackgroundBlurRadius(0); |
| 122 | verify(mNotificationShadeWindowView).setVisibility(eq(View.INVISIBLE)); |
| 123 | } |
Lucas Dupin | a3e3627 | 2018-08-21 13:22:33 -0700 | [diff] [blame] | 124 | } |