Fix TaskViewSimulatorTest to be independent of device it runs on
- Fix TaskViewSimulatorTest to properly set up densityDpi, so the test result is consistent regardless of the device it runs on. Also used SandboxContedxt's putObject() to avoid using reflection
Bug: 283246928
Test: TaskViewSimulatorTest
Flag: None
Change-Id: I926459fa97dd09a266cd017e4a0fb8e658a3509c
diff --git a/quickstep/tests/src/com/android/quickstep/util/TaskViewSimulatorTest.java b/quickstep/tests/src/com/android/quickstep/util/TaskViewSimulatorTest.java
index a54dc2d..b365173 100644
--- a/quickstep/tests/src/com/android/quickstep/util/TaskViewSimulatorTest.java
+++ b/quickstep/tests/src/com/android/quickstep/util/TaskViewSimulatorTest.java
@@ -18,11 +18,15 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import android.content.Context;
+import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.ArrayMap;
+import android.util.DisplayMetrics;
import android.view.RemoteAnimationTarget;
import android.view.Surface;
@@ -35,7 +39,6 @@
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.LauncherModelHelper;
import com.android.launcher3.util.NavigationMode;
-import com.android.launcher3.util.ReflectionHelpers;
import com.android.launcher3.util.RotationUtils;
import com.android.launcher3.util.WindowBounds;
import com.android.launcher3.util.window.CachedDisplayInfo;
@@ -61,6 +64,7 @@
public void taskProperlyScaled_portrait_noRotation_sameInsets1() {
new TaskMatrixVerifier()
.withLauncherSize(1200, 2450)
+ .withDensityDpi(420)
.withInsets(new Rect(0, 80, 0, 120))
.verifyNoTransforms();
}
@@ -69,6 +73,7 @@
public void taskProperlyScaled_portrait_noRotation_sameInsets2() {
new TaskMatrixVerifier()
.withLauncherSize(1200, 2450)
+ .withDensityDpi(420)
.withInsets(new Rect(55, 80, 55, 120))
.verifyNoTransforms();
}
@@ -77,6 +82,7 @@
public void taskProperlyScaled_landscape_noRotation_sameInsets1() {
new TaskMatrixVerifier()
.withLauncherSize(2450, 1250)
+ .withDensityDpi(420)
.withInsets(new Rect(0, 80, 0, 40))
.verifyNoTransforms();
}
@@ -85,6 +91,7 @@
public void taskProperlyScaled_landscape_noRotation_sameInsets2() {
new TaskMatrixVerifier()
.withLauncherSize(2450, 1250)
+ .withDensityDpi(420)
.withInsets(new Rect(0, 80, 120, 0))
.verifyNoTransforms();
}
@@ -93,6 +100,7 @@
public void taskProperlyScaled_landscape_noRotation_sameInsets3() {
new TaskMatrixVerifier()
.withLauncherSize(2450, 1250)
+ .withDensityDpi(420)
.withInsets(new Rect(55, 80, 55, 120))
.verifyNoTransforms();
}
@@ -101,6 +109,7 @@
public void taskProperlyScaled_landscape_rotated() {
new TaskMatrixVerifier()
.withLauncherSize(1200, 2450)
+ .withDensityDpi(420)
.withInsets(new Rect(0, 80, 0, 120))
.withAppBounds(
new Rect(0, 0, 2450, 1200),
@@ -112,6 +121,7 @@
private static class TaskMatrixVerifier extends TransformParams {
private Point mDisplaySize = new Point();
+ private int mDensityDpi = DisplayMetrics.DENSITY_DEFAULT;
private Rect mDisplayInsets = new Rect();
private Rect mAppBounds = new Rect();
private Rect mLauncherInsets = new Rect();
@@ -129,6 +139,11 @@
return this;
}
+ TaskMatrixVerifier withDensityDpi(int densityDpi) {
+ mDensityDpi = densityDpi;
+ return this;
+ }
+
TaskMatrixVerifier withInsets(Rect insets) {
mDisplayInsets.set(insets);
mLauncherInsets.set(insets);
@@ -173,13 +188,17 @@
new ArrayMap<>();
perDisplayBoundsCache.put(cdi.normalize(), allBounds);
- DisplayController.Info mockInfo = new Info(
- helper.sandboxContext, wmProxy, perDisplayBoundsCache);
+ Configuration configuration = new Configuration();
+ configuration.densityDpi = mDensityDpi;
+ Context configurationContext = helper.sandboxContext.createConfigurationContext(
+ configuration);
- DisplayController controller =
- DisplayController.INSTANCE.get(helper.sandboxContext);
- controller.close();
- ReflectionHelpers.setField(controller, "mInfo", mockInfo);
+ DisplayController.Info info = new Info(
+ configurationContext, wmProxy, perDisplayBoundsCache);
+
+ DisplayController mockController = mock(DisplayController.class);
+ when(mockController.getInfo()).thenReturn(info);
+ helper.sandboxContext.putObject(DisplayController.INSTANCE, mockController);
mDeviceProfile = InvariantDeviceProfile.INSTANCE.get(helper.sandboxContext)
.getBestMatch(mAppBounds.width(), mAppBounds.height(), rotation);
@@ -189,7 +208,7 @@
FallbackActivityInterface.INSTANCE);
tvs.setDp(mDeviceProfile);
- int launcherRotation = mockInfo.rotation;
+ int launcherRotation = info.rotation;
if (mAppRotation < 0) {
mAppRotation = launcherRotation;
}