Merge "Move DisplayTransformManagerTest" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
37da9859f6
@@ -17,6 +17,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.frameworks.mockingservicestests">
|
||||
|
||||
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
|
||||
<uses-permission android:name="android.permission.HARDWARE_TEST"/>
|
||||
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
|
||||
|
||||
<application android:testOnly="true"
|
||||
|
||||
@@ -16,87 +16,119 @@
|
||||
|
||||
package com.android.server.display.color;
|
||||
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyString;
|
||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
|
||||
import static com.android.server.display.color.DisplayTransformManager.LEVEL_COLOR_MATRIX_NIGHT_DISPLAY;
|
||||
import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_DISPLAY_COLOR;
|
||||
import static com.android.server.display.color.DisplayTransformManager.PERSISTENT_PROPERTY_SATURATION;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.dx.mockito.inline.extended.ExtendedMockito;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoSession;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DisplayTransformManagerTest {
|
||||
|
||||
private MockitoSession mSession;
|
||||
private DisplayTransformManager mDtm;
|
||||
private float[] mNightDisplayMatrix;
|
||||
private HashMap<String, String> mSystemProperties;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mDtm = new DisplayTransformManager();
|
||||
mNightDisplayMatrix = mDtm.getColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY);
|
||||
|
||||
SystemProperties.set(PERSISTENT_PROPERTY_DISPLAY_COLOR, null);
|
||||
SystemProperties.set(PERSISTENT_PROPERTY_SATURATION, null);
|
||||
mSession = ExtendedMockito.mockitoSession()
|
||||
.initMocks(this)
|
||||
.strictness(Strictness.LENIENT)
|
||||
.spyStatic(SystemProperties.class)
|
||||
.startMocking();
|
||||
mSystemProperties = new HashMap<>();
|
||||
|
||||
doAnswer((Answer<Void>) invocationOnMock -> {
|
||||
mSystemProperties.put(invocationOnMock.getArgument(0),
|
||||
invocationOnMock.getArgument(1));
|
||||
return null;
|
||||
}
|
||||
).when(() -> SystemProperties.set(anyString(), any()));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
mSession.finishMocking();
|
||||
mSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setColorMode_natural() {
|
||||
mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_NATURAL, mNightDisplayMatrix);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
|
||||
.isEqualTo("0" /* managed */);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
|
||||
.isEqualTo("1.0" /* natural */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setColorMode_boosted() {
|
||||
mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_BOOSTED, mNightDisplayMatrix);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
|
||||
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
|
||||
.isEqualTo("0" /* managed */);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
|
||||
.isEqualTo("1.1" /* boosted */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setColorMode_saturated() {
|
||||
mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_SATURATED, mNightDisplayMatrix);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
|
||||
.isEqualTo("1" /* unmanaged */);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
|
||||
.isEqualTo("1.0" /* natural */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setColorMode_automatic() {
|
||||
mDtm.setColorMode(ColorDisplayManager.COLOR_MODE_AUTOMATIC, mNightDisplayMatrix);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
|
||||
.isEqualTo("2" /* enhanced */);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
|
||||
.isEqualTo("1.0" /* natural */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setColorMode_vendor() {
|
||||
mDtm.setColorMode(0x100, mNightDisplayMatrix);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
|
||||
.isEqualTo(Integer.toString(0x100) /* pass-through */);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
|
||||
.isEqualTo("1.0" /* default */);
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
|
||||
.isEqualTo("1.0" /* natural */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setColorMode_outOfBounds() {
|
||||
mDtm.setColorMode(0x50, mNightDisplayMatrix);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR, null))
|
||||
.isEqualTo("" /* default */);
|
||||
assertThat(SystemProperties.get(PERSISTENT_PROPERTY_SATURATION, null))
|
||||
.isEqualTo("" /* default */);
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_DISPLAY_COLOR))
|
||||
.isEqualTo(null);
|
||||
assertThat(mSystemProperties.get(PERSISTENT_PROPERTY_SATURATION))
|
||||
.isEqualTo(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user