1 /*
2  * Copyright (C) 2020 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.wm;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.ArgumentMatchers.anyInt;
22 import static org.mockito.Mockito.when;
23 
24 import android.car.settings.CarSettings;
25 import android.os.Handler;
26 import android.provider.Settings;
27 import android.testing.AndroidTestingRunner;
28 import android.testing.TestableLooper;
29 import android.view.IWindowManager;
30 
31 import androidx.test.filters.SmallTest;
32 
33 import com.android.systemui.SysuiTestCase;
34 import com.android.wm.shell.common.DisplayController;
35 import com.android.wm.shell.common.DisplayInsetsController;
36 import com.android.wm.shell.common.DisplayLayout;
37 
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
43 
44 @RunWith(AndroidTestingRunner.class)
45 @TestableLooper.RunWithLooper
46 @SmallTest
47 public class DisplaySystemBarsControllerTest extends SysuiTestCase {
48 
49     private DisplaySystemBarsController mController;
50 
51     private static final int DISPLAY_ID = 1;
52 
53     @Mock
54     private IWindowManager mIWindowManager;
55     @Mock
56     private DisplayController mDisplayController;
57     @Mock
58     private DisplayLayout mDisplayLayout;
59     @Mock
60     private DisplayInsetsController mDisplayInsetsController;
61     @Mock
62     private Handler mHandler;
63 
64     @Before
setUp()65     public void setUp() {
66         MockitoAnnotations.initMocks(this);
67         when(mDisplayLayout.rotation()).thenReturn(0);
68         when(mDisplayController.getDisplayLayout(anyInt())).thenReturn(mDisplayLayout);
69 
70         mController = new DisplaySystemBarsController(
71                 mContext,
72                 mIWindowManager,
73                 mDisplayController,
74                 mDisplayInsetsController,
75                 mHandler
76         );
77     }
78 
79     @Test
onDisplayAdded_loadsBarControlPolicyFilters()80     public void onDisplayAdded_loadsBarControlPolicyFilters() {
81         String text = "sample text";
82         Settings.Global.putString(
83                 mContext.getContentResolver(),
84                 CarSettings.Global.SYSTEM_BAR_VISIBILITY_OVERRIDE,
85                 text
86         );
87 
88         mController.onDisplayAdded(DISPLAY_ID);
89 
90         assertThat(BarControlPolicy.sSettingValue).isEqualTo(text);
91     }
92 }
93