Fix AutomaticBrightnessControllerTest
And at it to presubmit Test: atest AutomaticBrightnessControllerTest Bug: 180636644 Change-Id: I3447ab82d9e8a8fbba5b5bc5b161a18e9a8a3d1b
This commit is contained in:
@@ -30,11 +30,13 @@ import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
|
||||
import android.os.Handler;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -43,6 +45,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SmallTest
|
||||
@Presubmit
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AutomaticBrightnessControllerTest {
|
||||
private static final float BRIGHTNESS_MIN_FLOAT = 0.0f;
|
||||
@@ -55,9 +58,11 @@ public class AutomaticBrightnessControllerTest {
|
||||
private static final boolean RESET_AMBIENT_LUX_AFTER_WARMUP_CONFIG = false;
|
||||
private static final int DISPLAY_ID = 0;
|
||||
private static final int LAYER_STACK = 0;
|
||||
private static final int LIGHT_SENSOR_WARMUP_TIME = 0;
|
||||
|
||||
private Context mContext;
|
||||
private LogicalDisplay mLogicalDisplay;
|
||||
private AutomaticBrightnessController mController;
|
||||
|
||||
@Mock SensorManager mSensorManager;
|
||||
@Mock BrightnessMappingStrategy mBrightnessMappingStrategy;
|
||||
@@ -67,7 +72,6 @@ public class AutomaticBrightnessControllerTest {
|
||||
@Mock DisplayDevice mDisplayDevice;
|
||||
@Mock HighBrightnessModeController mHbmController;
|
||||
|
||||
private static final int LIGHT_SENSOR_WARMUP_TIME = 0;
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Share classloader to allow package private access.
|
||||
@@ -78,6 +82,15 @@ public class AutomaticBrightnessControllerTest {
|
||||
mLogicalDisplay = new LogicalDisplay(DISPLAY_ID, LAYER_STACK, mDisplayDevice);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (mController != null) {
|
||||
// Stop the update Brightness loop.
|
||||
mController.stop();
|
||||
mController = null;
|
||||
}
|
||||
}
|
||||
|
||||
private AutomaticBrightnessController setupController(Sensor lightSensor) {
|
||||
AutomaticBrightnessController controller = new AutomaticBrightnessController(
|
||||
new AutomaticBrightnessController.Injector() {
|
||||
@@ -94,7 +107,9 @@ public class AutomaticBrightnessControllerTest {
|
||||
mAmbientBrightnessThresholds, mScreenBrightnessThresholds, mLogicalDisplay,
|
||||
mContext, mHbmController
|
||||
);
|
||||
controller.setLoggingEnabled(true);
|
||||
|
||||
when(mHbmController.getCurrentBrightnessMax()).thenReturn(BRIGHTNESS_MAX_FLOAT);
|
||||
when(mHbmController.getCurrentBrightnessMin()).thenReturn(BRIGHTNESS_MIN_FLOAT);
|
||||
|
||||
// Configure the brightness controller and grab an instance of the sensor listener,
|
||||
// through which we can deliver fake (for test) sensor values.
|
||||
@@ -108,7 +123,7 @@ public class AutomaticBrightnessControllerTest {
|
||||
@Test
|
||||
public void testNoHysteresisAtMinBrightness() throws Exception {
|
||||
Sensor lightSensor = TestUtils.createSensor(Sensor.TYPE_LIGHT, "Light Sensor");
|
||||
AutomaticBrightnessController controller = setupController(lightSensor);
|
||||
mController = setupController(lightSensor);
|
||||
|
||||
ArgumentCaptor<SensorEventListener> listenerCaptor =
|
||||
ArgumentCaptor.forClass(SensorEventListener.class);
|
||||
@@ -135,7 +150,7 @@ public class AutomaticBrightnessControllerTest {
|
||||
|
||||
// Send new sensor value and verify
|
||||
listener.onSensorChanged(TestUtils.createSensorEvent(lightSensor, (int) lux1));
|
||||
assertEquals(normalizedBrightness1, controller.getAutomaticScreenBrightness(), 0.001f);
|
||||
assertEquals(normalizedBrightness1, mController.getAutomaticScreenBrightness(), 0.001f);
|
||||
|
||||
// Set up system to return 0.0f (minimum possible brightness) as a brightness value
|
||||
float lux2 = 10.0f;
|
||||
@@ -149,13 +164,13 @@ public class AutomaticBrightnessControllerTest {
|
||||
|
||||
// Send new sensor value and verify
|
||||
listener.onSensorChanged(TestUtils.createSensorEvent(lightSensor, (int) lux2));
|
||||
assertEquals(normalizedBrightness2, controller.getAutomaticScreenBrightness(), 0.001f);
|
||||
assertEquals(normalizedBrightness2, mController.getAutomaticScreenBrightness(), 0.001f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoHysteresisAtMaxBrightness() throws Exception {
|
||||
Sensor lightSensor = TestUtils.createSensor(Sensor.TYPE_LIGHT, "Light Sensor");
|
||||
AutomaticBrightnessController controller = setupController(lightSensor);
|
||||
mController = setupController(lightSensor);
|
||||
|
||||
ArgumentCaptor<SensorEventListener> listenerCaptor =
|
||||
ArgumentCaptor.forClass(SensorEventListener.class);
|
||||
@@ -181,7 +196,7 @@ public class AutomaticBrightnessControllerTest {
|
||||
|
||||
// Send new sensor value and verify
|
||||
listener.onSensorChanged(TestUtils.createSensorEvent(lightSensor, (int) lux1));
|
||||
assertEquals(normalizedBrightness1, controller.getAutomaticScreenBrightness(), 0.001f);
|
||||
assertEquals(normalizedBrightness1, mController.getAutomaticScreenBrightness(), 0.001f);
|
||||
|
||||
|
||||
// Set up system to return 1.0f as a brightness value (brightness_max)
|
||||
@@ -196,13 +211,13 @@ public class AutomaticBrightnessControllerTest {
|
||||
|
||||
// Send new sensor value and verify
|
||||
listener.onSensorChanged(TestUtils.createSensorEvent(lightSensor, (int) lux2));
|
||||
assertEquals(normalizedBrightness2, controller.getAutomaticScreenBrightness(), 0.001f);
|
||||
assertEquals(normalizedBrightness2, mController.getAutomaticScreenBrightness(), 0.001f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserAddUserDataPoint() throws Exception {
|
||||
Sensor lightSensor = TestUtils.createSensor(Sensor.TYPE_LIGHT, "Light Sensor");
|
||||
AutomaticBrightnessController controller = setupController(lightSensor);
|
||||
mController = setupController(lightSensor);
|
||||
|
||||
ArgumentCaptor<SensorEventListener> listenerCaptor =
|
||||
ArgumentCaptor.forClass(SensorEventListener.class);
|
||||
@@ -214,7 +229,7 @@ public class AutomaticBrightnessControllerTest {
|
||||
listener.onSensorChanged(TestUtils.createSensorEvent(lightSensor, 1000));
|
||||
|
||||
// User sets brightness to 100
|
||||
controller.configure(true /* enable */, null /* configuration */,
|
||||
mController.configure(true /* enable */, null /* configuration */,
|
||||
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
|
||||
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user