Merge "fix(#Magnification): flaky presubmit error on FullScreenMagnificationGestureHandlerTest" into udc-qpr-dev

This commit is contained in:
Roy Chou
2023-07-15 03:09:25 +00:00
committed by Android (Google) Code Review

View File

@@ -44,8 +44,10 @@ import android.annotation.NonNull;
import android.graphics.PointF; import android.graphics.PointF;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.UserHandle;
import android.os.VibrationEffect; import android.os.VibrationEffect;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings;
import android.testing.TestableContext; import android.testing.TestableContext;
import android.util.DebugUtils; import android.util.DebugUtils;
import android.view.InputDevice; import android.view.InputDevice;
@@ -140,8 +142,6 @@ public class FullScreenMagnificationGestureHandlerTest {
@Mock @Mock
WindowMagnificationPromptController mWindowMagnificationPromptController; WindowMagnificationPromptController mWindowMagnificationPromptController;
@Mock @Mock
AccessibilityManagerService mMockAccessibilityManagerService;
@Mock
AccessibilityTraceManager mMockTraceManager; AccessibilityTraceManager mMockTraceManager;
@Rule @Rule
@@ -153,6 +153,8 @@ public class FullScreenMagnificationGestureHandlerTest {
private long mLastDownTime = Integer.MIN_VALUE; private long mLastDownTime = Integer.MIN_VALUE;
private float mOriginalMagnificationPersistedScale;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
@@ -166,6 +168,13 @@ public class FullScreenMagnificationGestureHandlerTest {
when(mockController.newValueAnimator()).thenReturn(new ValueAnimator()); when(mockController.newValueAnimator()).thenReturn(new ValueAnimator());
when(mockController.getAnimationDuration()).thenReturn(1000L); when(mockController.getAnimationDuration()).thenReturn(1000L);
when(mockWindowManager.setMagnificationCallbacks(eq(DISPLAY_0), any())).thenReturn(true); when(mockWindowManager.setMagnificationCallbacks(eq(DISPLAY_0), any())).thenReturn(true);
mOriginalMagnificationPersistedScale = Settings.Secure.getFloatForUser(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 2.0f,
UserHandle.USER_SYSTEM);
Settings.Secure.putFloatForUser(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 2.0f,
UserHandle.USER_SYSTEM);
mFullScreenMagnificationController = new FullScreenMagnificationController( mFullScreenMagnificationController = new FullScreenMagnificationController(
mockController, mockController,
new Object(), new Object(),
@@ -192,6 +201,10 @@ public class FullScreenMagnificationGestureHandlerTest {
mMgh.onDestroy(); mMgh.onDestroy();
mFullScreenMagnificationController.unregister(DISPLAY_0); mFullScreenMagnificationController.unregister(DISPLAY_0);
verify(mWindowMagnificationPromptController).onDestroy(); verify(mWindowMagnificationPromptController).onDestroy();
Settings.Secure.putFloatForUser(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
mOriginalMagnificationPersistedScale,
UserHandle.USER_SYSTEM);
} }
@NonNull @NonNull
@@ -525,10 +538,9 @@ public class FullScreenMagnificationGestureHandlerTest {
final float threshold = FullScreenMagnificationGestureHandler.PanningScalingState final float threshold = FullScreenMagnificationGestureHandler.PanningScalingState
.CHECK_DETECTING_PASS_PERSISTED_SCALE_THRESHOLD; .CHECK_DETECTING_PASS_PERSISTED_SCALE_THRESHOLD;
final float persistedScale = (1.0f + threshold) * scale + 1.0f; final float persistedScale = (1.0f + threshold) * scale + 1.0f;
mFullScreenMagnificationController.setScale(DISPLAY_0, persistedScale, DEFAULT_X, Settings.Secure.putFloatForUser(mContext.getContentResolver(),
DEFAULT_Y, /* animate= */ false, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, persistedScale,
AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); UserHandle.USER_SYSTEM);
mFullScreenMagnificationController.persistScale(DISPLAY_0);
mFullScreenMagnificationController.setScale(DISPLAY_0, scale, DEFAULT_X, mFullScreenMagnificationController.setScale(DISPLAY_0, scale, DEFAULT_X,
DEFAULT_Y, /* animate= */ false, DEFAULT_Y, /* animate= */ false,
AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
@@ -547,10 +559,9 @@ public class FullScreenMagnificationGestureHandlerTest {
final float threshold = FullScreenMagnificationGestureHandler.PanningScalingState final float threshold = FullScreenMagnificationGestureHandler.PanningScalingState
.CHECK_DETECTING_PASS_PERSISTED_SCALE_THRESHOLD; .CHECK_DETECTING_PASS_PERSISTED_SCALE_THRESHOLD;
final float persistedScale = (1.0f + threshold) * scale - 0.1f; final float persistedScale = (1.0f + threshold) * scale - 0.1f;
mFullScreenMagnificationController.setScale(DISPLAY_0, persistedScale, DEFAULT_X, Settings.Secure.putFloatForUser(mContext.getContentResolver(),
DEFAULT_Y, /* animate= */ false, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, persistedScale,
AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); UserHandle.USER_SYSTEM);
mFullScreenMagnificationController.persistScale(DISPLAY_0);
mFullScreenMagnificationController.setScale(DISPLAY_0, scale, DEFAULT_X, mFullScreenMagnificationController.setScale(DISPLAY_0, scale, DEFAULT_X,
DEFAULT_Y, /* animate= */ false, DEFAULT_Y, /* animate= */ false,
AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);