• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Test;
34 import org.junit.runner.RunWith;
35 
36 @RunWith(AndroidJUnit4.class)
37 public class ScreenResolutionControllerTest {
38 
39     private static final int FHD_WIDTH = 1080;
40     private static final int QHD_WIDTH = 1440;
41 
42     private ScreenResolutionController mController;
43 
44     @Before
setUp()45     public void setUp() {
46         Context context = spy(ApplicationProvider.getApplicationContext());
47         mController = spy(new ScreenResolutionController(context, "test"));
48     }
49 
50     @Test
getAvailabilityStatus_hasFhdAndQhdModes_returnAvailable()51     public void getAvailabilityStatus_hasFhdAndQhdModes_returnAvailable() {
52         Display.Mode modeA = new Display.Mode(0, FHD_WIDTH, 0, 0);
53         Display.Mode modeB = new Display.Mode(0, QHD_WIDTH, 0, 0);
54         Display.Mode[] modes = {modeA, modeB};
55         doReturn(modes).when(mController).getSupportedModes();
56 
57         assertThat(mController.getAvailabilityStatus())
58                 .isEqualTo(BasePreferenceController.AVAILABLE);
59     }
60 
61     @Test
getAvailabilityStatus_hasOneMode_returnUnsupported()62     public void getAvailabilityStatus_hasOneMode_returnUnsupported() {
63         Display.Mode modeA = new Display.Mode(0, FHD_WIDTH, 0, 0);
64         Display.Mode[] modes = {modeA};
65         doReturn(modes).when(mController).getSupportedModes();
66 
67         assertThat(mController.getAvailabilityStatus())
68                 .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
69     }
70 
71     @Test
updateState_screenResolutionFHD_shouldSetSummaryToFHD()72     public void updateState_screenResolutionFHD_shouldSetSummaryToFHD() {
73         int width = FHD_WIDTH;
74         doReturn(width).when(mController).getDisplayWidth();
75 
76         assertThat(mController.getSummary().toString()).isEqualTo("1080p FHD+");
77     }
78 
79     @Test
updateState_screenResolutionQHD_shouldSetSummaryToQHD()80     public void updateState_screenResolutionQHD_shouldSetSummaryToQHD() {
81         int width = QHD_WIDTH;
82         doReturn(width).when(mController).getDisplayWidth();
83 
84         assertThat(mController.getSummary().toString()).isEqualTo("1440p QHD+");
85     }
86 }
87