blob: f1bf31d7a58ad3470f303eb5b0780c37a1c765ac [file] [log] [blame]
Jason Monkd4afe152017-05-01 15:37:43 -04001/*
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;
16
Adrian Roos5b518852018-01-23 17:23:38 +010017import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY;
18
Jason Monkd4afe152017-05-01 15:37:43 -040019import static com.android.systemui.tuner.TunablePadding.FLAG_END;
20import static com.android.systemui.tuner.TunablePadding.FLAG_START;
21
Adrian Roos5b518852018-01-23 17:23:38 +010022import static org.hamcrest.Matchers.is;
23import static org.junit.Assert.assertThat;
Jason Monkd4afe152017-05-01 15:37:43 -040024import static org.mockito.ArgumentMatchers.any;
25import static org.mockito.ArgumentMatchers.anyInt;
26import static org.mockito.ArgumentMatchers.anyString;
27import static org.mockito.ArgumentMatchers.eq;
Jason Monkd4afe152017-05-01 15:37:43 -040028import static org.mockito.Mockito.mock;
29import static org.mockito.Mockito.never;
30import static org.mockito.Mockito.spy;
31import static org.mockito.Mockito.times;
32import static org.mockito.Mockito.verify;
33import static org.mockito.Mockito.when;
34
35import android.app.Fragment;
Adrian Roos5b518852018-01-23 17:23:38 +010036import android.content.res.Configuration;
Jason Monkfba8faf2017-05-23 10:42:59 -040037import android.support.test.filters.SmallTest;
Jason Monkd4afe152017-05-01 15:37:43 -040038import android.testing.AndroidTestingRunner;
Beverlye91f0d02018-05-15 14:40:47 -040039import android.testing.TestableLooper.RunWithLooper;
Jason Monkd4afe152017-05-01 15:37:43 -040040import android.view.Display;
41import android.view.View;
42import android.view.WindowManager;
43
44import com.android.systemui.R.dimen;
Adrian Roos5b518852018-01-23 17:23:38 +010045import com.android.systemui.ScreenDecorations.TunablePaddingTagListener;
Jason Monkd4afe152017-05-01 15:37:43 -040046import com.android.systemui.fragments.FragmentHostManager;
47import com.android.systemui.fragments.FragmentService;
48import com.android.systemui.statusbar.phone.StatusBar;
49import com.android.systemui.statusbar.phone.StatusBarWindowView;
50import com.android.systemui.tuner.TunablePadding;
51import com.android.systemui.tuner.TunablePadding.TunablePaddingService;
52import com.android.systemui.tuner.TunerService;
53
54import org.junit.Before;
55import org.junit.Test;
56import org.junit.runner.RunWith;
57
Beverlye91f0d02018-05-15 14:40:47 -040058@RunWithLooper
Jason Monkd4afe152017-05-01 15:37:43 -040059@RunWith(AndroidTestingRunner.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040060@SmallTest
Adrian Roos5b518852018-01-23 17:23:38 +010061public class ScreenDecorationsTest extends SysuiTestCase {
Jason Monkd4afe152017-05-01 15:37:43 -040062
Adrian Roos5b518852018-01-23 17:23:38 +010063 private ScreenDecorations mScreenDecorations;
Jason Monkd4afe152017-05-01 15:37:43 -040064 private StatusBar mStatusBar;
65 private WindowManager mWindowManager;
66 private FragmentService mFragmentService;
67 private FragmentHostManager mFragmentHostManager;
68 private TunerService mTunerService;
69 private StatusBarWindowView mView;
70 private TunablePaddingService mTunablePaddingService;
71
72 @Before
73 public void setup() {
74 mStatusBar = mock(StatusBar.class);
75 mWindowManager = mock(WindowManager.class);
76 mView = spy(new StatusBarWindowView(mContext, null));
77 when(mStatusBar.getStatusBarWindow()).thenReturn(mView);
Jason Monkc429f692017-06-27 13:13:49 -040078 when(mStatusBar.getNavigationBarWindow()).thenReturn(mView);
Jason Monkd4afe152017-05-01 15:37:43 -040079 mContext.putComponent(StatusBar.class, mStatusBar);
80
81 Display display = mContext.getSystemService(WindowManager.class).getDefaultDisplay();
82 when(mWindowManager.getDefaultDisplay()).thenReturn(display);
83 mContext.addMockSystemService(WindowManager.class, mWindowManager);
84
85 mFragmentService = mDependency.injectMockDependency(FragmentService.class);
86 mFragmentHostManager = mock(FragmentHostManager.class);
87 when(mFragmentService.getFragmentHostManager(any())).thenReturn(mFragmentHostManager);
88
89 mTunerService = mDependency.injectMockDependency(TunerService.class);
90
Adrian Roos5b518852018-01-23 17:23:38 +010091 mScreenDecorations = new ScreenDecorations();
92 mScreenDecorations.mContext = mContext;
93 mScreenDecorations.mComponents = mContext.getComponents();
Jason Monkd4afe152017-05-01 15:37:43 -040094
95 mTunablePaddingService = mDependency.injectMockDependency(TunablePaddingService.class);
96 }
97
98 @Test
Adrian Roos5b518852018-01-23 17:23:38 +010099 public void testNoRounding_NoCutout() {
100 mContext.getOrCreateTestableResources().addOverride(
101 com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
Jason Monkd4afe152017-05-01 15:37:43 -0400102 mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius, 0);
Beverlye91f0d02018-05-15 14:40:47 -0400103 mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius_top, 0);
104 mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius_bottom, 0);
Jason Monkc429f692017-06-27 13:13:49 -0400105 mContext.getOrCreateTestableResources()
106 .addOverride(dimen.rounded_corner_content_padding, 0);
Jason Monkd4afe152017-05-01 15:37:43 -0400107
Adrian Roos5b518852018-01-23 17:23:38 +0100108 mScreenDecorations.start();
Jason Monkd4afe152017-05-01 15:37:43 -0400109 // No views added.
110 verify(mWindowManager, never()).addView(any(), any());
111 // No Fragments watched.
112 verify(mFragmentHostManager, never()).addTagListener(any(), any());
113 // No Tuners tuned.
114 verify(mTunerService, never()).addTunable(any(), any());
115 }
116
117 @Test
118 public void testRounding() {
Adrian Roos5b518852018-01-23 17:23:38 +0100119 mContext.getOrCreateTestableResources().addOverride(
120 com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
Jason Monkd4afe152017-05-01 15:37:43 -0400121 mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius, 20);
Jason Monkc429f692017-06-27 13:13:49 -0400122 mContext.getOrCreateTestableResources()
123 .addOverride(dimen.rounded_corner_content_padding, 20);
Jason Monkd4afe152017-05-01 15:37:43 -0400124
Adrian Roos5b518852018-01-23 17:23:38 +0100125 mScreenDecorations.start();
Jason Monkd4afe152017-05-01 15:37:43 -0400126 // Add 2 windows for rounded corners (top and bottom).
127 verify(mWindowManager, times(2)).addView(any(), any());
128
Jason Monk089981b2017-06-30 09:10:01 -0400129 // Add 2 tag listeners for each of the fragments that are needed.
130 verify(mFragmentHostManager, times(2)).addTagListener(any(), any());
Jason Monkd4afe152017-05-01 15:37:43 -0400131 // One tunable.
132 verify(mTunerService, times(1)).addTunable(any(), any());
133 // One TunablePadding.
134 verify(mTunablePaddingService, times(1)).add(any(), anyString(), anyInt(), anyInt());
135 }
136
137 @Test
Adrian Roos5b518852018-01-23 17:23:38 +0100138 public void testCutout() {
139 mContext.getOrCreateTestableResources().addOverride(
140 com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, true);
141 mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius, 0);
142 mContext.getOrCreateTestableResources()
143 .addOverride(dimen.rounded_corner_content_padding, 0);
144
145 mScreenDecorations.start();
146 // Add 2 windows for rounded corners (top and bottom).
147 verify(mWindowManager, times(2)).addView(any(), any());
148 }
149
150 @Test
151 public void testDelayedCutout() {
152 mContext.getOrCreateTestableResources().addOverride(
153 com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
154 mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius, 0);
155 mContext.getOrCreateTestableResources()
156 .addOverride(dimen.rounded_corner_content_padding, 0);
157
158 mScreenDecorations.start();
159
160 mContext.getOrCreateTestableResources().addOverride(
161 com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, true);
162 mScreenDecorations.onConfigurationChanged(new Configuration());
163
164 // Add 2 windows for rounded corners (top and bottom).
165 verify(mWindowManager, times(2)).addView(any(), any());
166 }
167
168 @Test
169 public void hasRoundedCornerOverlayFlagSet() {
170 assertThat(mScreenDecorations.getWindowLayoutParams().privateFlags
171 & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY,
172 is(PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY));
173 }
174
175 @Test
Jason Monkd4afe152017-05-01 15:37:43 -0400176 public void testPaddingTagListener() {
177 TunablePaddingTagListener tagListener = new TunablePaddingTagListener(14, 5);
178 View v = mock(View.class);
179 View child = mock(View.class);
180 Fragment f = mock(Fragment.class);
181 TunablePadding padding = mock(TunablePadding.class);
182
183 when(mTunablePaddingService.add(any(), anyString(), anyInt(), anyInt()))
184 .thenReturn(padding);
185 when(f.getView()).thenReturn(v);
186 when(v.findViewById(5)).thenReturn(child);
187
188 // Trigger callback and verify we get a TunablePadding created.
189 tagListener.onFragmentViewCreated(null, f);
Adrian Roos5b518852018-01-23 17:23:38 +0100190 verify(mTunablePaddingService).add(eq(child), eq(ScreenDecorations.PADDING), eq(14),
Jason Monkd4afe152017-05-01 15:37:43 -0400191 eq(FLAG_START | FLAG_END));
192
193 // Call again and verify destroy is called.
194 tagListener.onFragmentViewCreated(null, f);
195 verify(padding).destroy();
196 }
197
Geoffrey Pitsch0053e992017-05-22 15:32:29 -0400198}