Merge "[RRS] show resolution option on Settings page."

This commit is contained in:
Amy Hsu
2023-02-04 15:10:13 +00:00
committed by Android (Google) Code Review
6 changed files with 142 additions and 89 deletions

View File

@@ -35,22 +35,23 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ScreenResolutionControllerTest {
private static final int FHD_WIDTH = 1080;
private static final int QHD_WIDTH = 1440;
private ScreenResolutionController mController;
private int mHighWidth;
private int mFullWidth;
@Before
public void setUp() {
Context context = spy(ApplicationProvider.getApplicationContext());
mController = spy(new ScreenResolutionController(context, "test"));
mHighWidth = mController.getHighWidth();
mFullWidth = mController.getFullWidth();
}
@Test
public void getAvailabilityStatus_hasFhdAndQhdModes_returnAvailable() {
Display.Mode modeA = new Display.Mode(0, FHD_WIDTH, 0, 0);
Display.Mode modeB = new Display.Mode(0, QHD_WIDTH, 0, 0);
Display.Mode modeA = new Display.Mode(0, mHighWidth, 0, 0);
Display.Mode modeB = new Display.Mode(0, mFullWidth, 0, 0);
Display.Mode[] modes = {modeA, modeB};
doReturn(modes).when(mController).getSupportedModes();
@@ -60,27 +61,25 @@ public class ScreenResolutionControllerTest {
@Test
public void getAvailabilityStatus_hasOneMode_returnUnsupported() {
Display.Mode modeA = new Display.Mode(0, FHD_WIDTH, 0, 0);
Display.Mode[] modes = {modeA};
doReturn(modes).when(mController).getSupportedModes();
doReturn(0).when(mController).getHighWidth();
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void updateState_screenResolutionFHD_shouldSetSummaryToFHD() {
int width = FHD_WIDTH;
public void updateState_HighResolution_shouldSetSummaryToHighResolution() {
int width = mHighWidth;
doReturn(width).when(mController).getDisplayWidth();
assertThat(mController.getSummary().toString()).isEqualTo("1080p FHD+");
assertThat(mController.getSummary().toString()).isEqualTo("High resolution");
}
@Test
public void updateState_screenResolutionQHD_shouldSetSummaryToQHD() {
int width = QHD_WIDTH;
public void updateState_FullResolution_shouldSetSummaryToFullResolution() {
int width = mFullWidth;
doReturn(width).when(mController).getDisplayWidth();
assertThat(mController.getSummary().toString()).isEqualTo("1440p QHD+");
assertThat(mController.getSummary().toString()).isEqualTo("Full resolution");
}
}

View File

@@ -37,59 +37,62 @@ public class ScreenResolutionFragmentTest {
private Context mContext;
private ScreenResolutionFragment mFragment;
private static final int FHD_WIDTH = 1080;
private static final int QHD_WIDTH = 1440;
private ScreenResolutionController mController;
private int mHighWidth;
private int mFullWidth;
@Before
@UiThreadTest
public void setup() {
mContext = spy(ApplicationProvider.getApplicationContext());
mFragment = spy(new ScreenResolutionFragment());
mController = spy(new ScreenResolutionController(mContext, "test"));
mHighWidth = mController.getHighWidth();
mFullWidth = mController.getFullWidth();
}
@Test
@UiThreadTest
public void getDefaultKey_FHD() {
Display.Mode mode = new Display.Mode(0, FHD_WIDTH, 0, 0);
public void getDefaultKey_highResolution() {
Display.Mode mode = new Display.Mode(0, mHighWidth, 0, 0);
doReturn(mode).when(mFragment).getDisplayMode();
doReturn(mContext).when(mFragment).getContext();
mFragment.onAttach(mContext);
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(FHD_WIDTH));
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(mHighWidth));
}
@Test
@UiThreadTest
public void getDefaultKey_QHD() {
Display.Mode mode = new Display.Mode(0, QHD_WIDTH, 0, 0);
public void getDefaultKey_fullResolution() {
Display.Mode mode = new Display.Mode(0, mFullWidth, 0, 0);
doReturn(mode).when(mFragment).getDisplayMode();
doReturn(mContext).when(mFragment).getContext();
mFragment.onAttach(mContext);
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(QHD_WIDTH));
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(mFullWidth));
}
@Test
@UiThreadTest
public void setDefaultKey_FHD() {
public void setDefaultKey_highResolution() {
doReturn(mContext).when(mFragment).getContext();
mFragment.onAttach(mContext);
mFragment.setDefaultKey(mFragment.getKeyForResolution(FHD_WIDTH));
mFragment.setDefaultKey(mFragment.getKeyForResolution(mHighWidth));
verify(mFragment).setDisplayMode(FHD_WIDTH);
verify(mFragment).setDisplayMode(mHighWidth);
}
@Test
@UiThreadTest
public void setDefaultKey_QHD() {
public void setDefaultKey_fullResolution() {
doReturn(mContext).when(mFragment).getContext();
mFragment.onAttach(mContext);
mFragment.setDefaultKey(mFragment.getKeyForResolution(QHD_WIDTH));
mFragment.setDefaultKey(mFragment.getKeyForResolution(mFullWidth));
verify(mFragment).setDisplayMode(QHD_WIDTH);
verify(mFragment).setDisplayMode(mFullWidth);
}
@Test