1 /*
2  * Copyright (C) 2022 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.settings.display;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.doReturn;
22 import static org.mockito.Mockito.spy;
23 
24 import android.content.Context;
25 import android.view.Display;
26 
27 import androidx.test.core.app.ApplicationProvider;
28 import androidx.test.ext.junit.runners.AndroidJUnit4;
29 
30 import com.android.settings.core.BasePreferenceController;
31 
32 import org.junit.Before;
33 import org.junit.Ignore;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 
37 @RunWith(AndroidJUnit4.class)
38 public class ScreenResolutionControllerTest {
39     private ScreenResolutionController mController;
40     private int mHighWidth;
41     private int mFullWidth;
42 
43     @Before
setUp()44     public void setUp() {
45         Context context = spy(ApplicationProvider.getApplicationContext());
46         mController = spy(new ScreenResolutionController(context, "test"));
47 
48         mHighWidth = mController.getHighWidth();
49         mFullWidth = mController.getFullWidth();
50     }
51 
52     @Test
53     @Ignore("b/337417619")
getAvailabilityStatus_hasFhdAndQhdModes_returnAvailable()54     public void getAvailabilityStatus_hasFhdAndQhdModes_returnAvailable() {
55         Display.Mode modeA = new Display.Mode(0, mHighWidth, 0, 0);
56         Display.Mode modeB = new Display.Mode(0, mFullWidth, 0, 0);
57         Display.Mode[] modes = {modeA, modeB};
58         doReturn(modes).when(mController).getSupportedModes();
59 
60         assertThat(mController.getAvailabilityStatus())
61                 .isEqualTo(BasePreferenceController.AVAILABLE);
62     }
63 
64     @Test
getAvailabilityStatus_hasOneMode_returnUnsupported()65     public void getAvailabilityStatus_hasOneMode_returnUnsupported() {
66         doReturn(0).when(mController).getHighWidth();
67 
68         assertThat(mController.getAvailabilityStatus())
69                 .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
70     }
71 
72     @Test
updateState_HighResolution_shouldSetSummaryToHighResolution()73     public void updateState_HighResolution_shouldSetSummaryToHighResolution() {
74         int width = mHighWidth;
75         doReturn(width).when(mController).getDisplayWidth();
76 
77         assertThat(mController.getSummary().toString()).isEqualTo("High resolution");
78     }
79 
80     @Test
81     @Ignore("b/337417619")
updateState_FullResolution_shouldSetSummaryToFullResolution()82     public void updateState_FullResolution_shouldSetSummaryToFullResolution() {
83         int width = mFullWidth;
84         doReturn(width).when(mController).getDisplayWidth();
85 
86         assertThat(mController.getSummary().toString()).isEqualTo("Full resolution");
87     }
88 }
89