Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6bdd4046 authored by Omar Elmekkawy's avatar Omar Elmekkawy
Browse files

[8/n] Fix failing unit tests after introducing tiling

Some unit tests are no longer compiling due to API changes around
tiling and DragResizeWindowGeometry and other tests were failing due to
the tiling bounds changing to accommodate for the divider bounds by being
slightly smaller.

Those were fixed by just flipping the flag for the Tiling feature

Flag: com.android.window.flags.enable_tile_resizing
Test: atest <FailingTestFile>
Bug: 29581729
Change-Id: I8c7eada036dbfb5741a77cced0e7d4cd1b786845
parent c94ba127
Loading
Loading
Loading
Loading
+25 −8
Original line number Original line Diff line number Diff line
@@ -128,6 +128,8 @@ import com.android.wm.shell.transition.TestRemoteTransition
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions.ENABLE_SHELL_TRANSITIONS
import com.android.wm.shell.transition.Transitions.ENABLE_SHELL_TRANSITIONS
import com.android.wm.shell.transition.Transitions.TransitionHandler
import com.android.wm.shell.transition.Transitions.TransitionHandler
import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration
import com.android.wm.shell.windowdecor.tiling.DesktopTilingDecorViewModel
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import com.google.common.truth.Truth.assertWithMessage
import java.util.function.Consumer
import java.util.function.Consumer
@@ -223,6 +225,10 @@ class DesktopTasksControllerTest : ShellTestCase() {
  @Mock lateinit var motionEvent: MotionEvent
  @Mock lateinit var motionEvent: MotionEvent


  private lateinit var mockitoSession: StaticMockitoSession
  private lateinit var mockitoSession: StaticMockitoSession
  @Mock
  private lateinit var desktopTilingDecorViewModel: DesktopTilingDecorViewModel
  @Mock
  private lateinit var desktopWindowDecoration: DesktopModeWindowDecoration
  private lateinit var controller: DesktopTasksController
  private lateinit var controller: DesktopTasksController
  private lateinit var shellInit: ShellInit
  private lateinit var shellInit: ShellInit
  private lateinit var taskRepository: DesktopRepository
  private lateinit var taskRepository: DesktopRepository
@@ -336,6 +342,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
        mockInputManager,
        mockInputManager,
        mockFocusTransitionObserver,
        mockFocusTransitionObserver,
        desktopModeEventLogger,
        desktopModeEventLogger,
        desktopTilingDecorViewModel,
      )
      )
  }
  }


@@ -2835,7 +2842,9 @@ class DesktopTasksControllerTest : ShellTestCase() {
        Rect(100, -100, 500, 1000), /* currentDragBounds */
        Rect(100, -100, 500, 1000), /* currentDragBounds */
        Rect(0, 50, 2000, 2000), /* validDragArea */
        Rect(0, 50, 2000, 2000), /* validDragArea */
        Rect() /* dragStartBounds */,
        Rect() /* dragStartBounds */,
        motionEvent)
        motionEvent,
        desktopWindowDecoration,
        )
    val rectAfterEnd = Rect(100, 50, 500, 1150)
    val rectAfterEnd = Rect(100, 50, 500, 1150)
    verify(transitions)
    verify(transitions)
        .startTransition(
        .startTransition(
@@ -2871,7 +2880,9 @@ class DesktopTasksControllerTest : ShellTestCase() {
      currentDragBounds, /* currentDragBounds */
      currentDragBounds, /* currentDragBounds */
      Rect(0, 50, 2000, 2000) /* validDragArea */,
      Rect(0, 50, 2000, 2000) /* validDragArea */,
      Rect() /* dragStartBounds */,
      Rect() /* dragStartBounds */,
      motionEvent)
      motionEvent,
      desktopWindowDecoration,
      )




    verify(transitions)
    verify(transitions)
@@ -3135,6 +3146,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
  }
  }


  @Test
  @Test
  @DisableFlags(Flags.FLAG_ENABLE_TILE_RESIZING)
  fun snapToHalfScreen_getSnapBounds_calculatesBoundsForResizable() {
  fun snapToHalfScreen_getSnapBounds_calculatesBoundsForResizable() {
    val bounds = Rect(100, 100, 300, 300)
    val bounds = Rect(100, 100, 300, 300)
    val task = setUpFreeformTask(DEFAULT_DISPLAY, bounds).apply {
    val task = setUpFreeformTask(DEFAULT_DISPLAY, bounds).apply {
@@ -3150,7 +3162,8 @@ class DesktopTasksControllerTest : ShellTestCase() {
      STABLE_BOUNDS.left, STABLE_BOUNDS.top, STABLE_BOUNDS.right / 2, STABLE_BOUNDS.bottom
      STABLE_BOUNDS.left, STABLE_BOUNDS.top, STABLE_BOUNDS.right / 2, STABLE_BOUNDS.bottom
    )
    )


    controller.snapToHalfScreen(task, mockSurface, currentDragBounds, SnapPosition.LEFT, ResizeTrigger.SNAP_LEFT_MENU, motionEvent)
    controller.snapToHalfScreen(task, mockSurface, currentDragBounds, SnapPosition.LEFT,
      ResizeTrigger.SNAP_LEFT_MENU, motionEvent, desktopWindowDecoration)
    // Assert bounds set to stable bounds
    // Assert bounds set to stable bounds
    val wct = getLatestToggleResizeDesktopTaskWct(currentDragBounds)
    val wct = getLatestToggleResizeDesktopTaskWct(currentDragBounds)
    assertThat(findBoundsChange(wct, task)).isEqualTo(expectedBounds)
    assertThat(findBoundsChange(wct, task)).isEqualTo(expectedBounds)
@@ -3165,6 +3178,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
  }
  }


  @Test
  @Test
  @DisableFlags(Flags.FLAG_ENABLE_TILE_RESIZING)
  fun snapToHalfScreen_snapBoundsWhenAlreadySnapped_animatesSurfaceWithoutWCT() {
  fun snapToHalfScreen_snapBoundsWhenAlreadySnapped_animatesSurfaceWithoutWCT() {
    // Set up task to already be in snapped-left bounds
    // Set up task to already be in snapped-left bounds
    val bounds = Rect(
    val bounds = Rect(
@@ -3180,8 +3194,8 @@ class DesktopTasksControllerTest : ShellTestCase() {


    // Attempt to snap left again
    // Attempt to snap left again
    val currentDragBounds = Rect(bounds).apply { offset(-100, 0) }
    val currentDragBounds = Rect(bounds).apply { offset(-100, 0) }
    controller.snapToHalfScreen(task, mockSurface, currentDragBounds, SnapPosition.LEFT, ResizeTrigger.SNAP_LEFT_MENU, motionEvent)
    controller.snapToHalfScreen(task, mockSurface, currentDragBounds, SnapPosition.LEFT,

      ResizeTrigger.SNAP_LEFT_MENU, motionEvent, desktopWindowDecoration)
    // Assert that task is NOT updated via WCT
    // Assert that task is NOT updated via WCT
    verify(toggleResizeDesktopTaskTransitionHandler, never()).startTransition(any(), any())
    verify(toggleResizeDesktopTaskTransitionHandler, never()).startTransition(any(), any())


@@ -3204,7 +3218,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
  }
  }


  @Test
  @Test
  @DisableFlags(Flags.FLAG_DISABLE_NON_RESIZABLE_APP_SNAP_RESIZING)
  @DisableFlags(Flags.FLAG_DISABLE_NON_RESIZABLE_APP_SNAP_RESIZING, Flags.FLAG_ENABLE_TILE_RESIZING)
  fun handleSnapResizingTask_nonResizable_snapsToHalfScreen() {
  fun handleSnapResizingTask_nonResizable_snapsToHalfScreen() {
    val task = setUpFreeformTask(DEFAULT_DISPLAY, Rect(0, 0, 200, 100)).apply {
    val task = setUpFreeformTask(DEFAULT_DISPLAY, Rect(0, 0, 200, 100)).apply {
      isResizeable = false
      isResizeable = false
@@ -3215,7 +3229,9 @@ class DesktopTasksControllerTest : ShellTestCase() {
      Rect(STABLE_BOUNDS.left, STABLE_BOUNDS.top, STABLE_BOUNDS.right / 2, STABLE_BOUNDS.bottom)
      Rect(STABLE_BOUNDS.left, STABLE_BOUNDS.top, STABLE_BOUNDS.right / 2, STABLE_BOUNDS.bottom)


    controller.handleSnapResizingTask(
    controller.handleSnapResizingTask(
      task, SnapPosition.LEFT, mockSurface, currentDragBounds, preDragBounds, motionEvent

      task, SnapPosition.LEFT, mockSurface, currentDragBounds, preDragBounds, motionEvent,
      desktopWindowDecoration
    )
    )
    val wct = getLatestToggleResizeDesktopTaskWct(currentDragBounds)
    val wct = getLatestToggleResizeDesktopTaskWct(currentDragBounds)
    assertThat(findBoundsChange(wct, task)).isEqualTo(
    assertThat(findBoundsChange(wct, task)).isEqualTo(
@@ -3239,7 +3255,8 @@ class DesktopTasksControllerTest : ShellTestCase() {
    val currentDragBounds = Rect(0, 100, 300, 500)
    val currentDragBounds = Rect(0, 100, 300, 500)


    controller.handleSnapResizingTask(
    controller.handleSnapResizingTask(
      task, SnapPosition.LEFT, mockSurface, currentDragBounds, preDragBounds, motionEvent)
      task, SnapPosition.LEFT, mockSurface, currentDragBounds, preDragBounds, motionEvent,
      desktopWindowDecoration)
    verify(mReturnToDragStartAnimator).start(
    verify(mReturnToDragStartAnimator).start(
      eq(task.taskId),
      eq(task.taskId),
      eq(mockSurface),
      eq(mockSurface),
+14 −6
Original line number Original line Diff line number Diff line
@@ -665,7 +665,8 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
            eq(currentBounds),
            eq(currentBounds),
            eq(SnapPosition.LEFT),
            eq(SnapPosition.LEFT),
            eq(ResizeTrigger.SNAP_LEFT_MENU),
            eq(ResizeTrigger.SNAP_LEFT_MENU),
            eq(null)
            eq(null),
            eq(decor)
        )
        )
        assertEquals(taskSurfaceCaptor.firstValue, decor.mTaskSurface)
        assertEquals(taskSurfaceCaptor.firstValue, decor.mTaskSurface)
    }
    }
@@ -705,7 +706,8 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
            eq(currentBounds),
            eq(currentBounds),
            eq(SnapPosition.LEFT),
            eq(SnapPosition.LEFT),
            eq(ResizeTrigger.SNAP_LEFT_MENU),
            eq(ResizeTrigger.SNAP_LEFT_MENU),
            eq(null)
            eq(null),
            eq(decor),
        )
        )
        assertEquals(decor.mTaskSurface, taskSurfaceCaptor.firstValue)
        assertEquals(decor.mTaskSurface, taskSurfaceCaptor.firstValue)
    }
    }
@@ -726,7 +728,9 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
        verify(mockDesktopTasksController, never())
        verify(mockDesktopTasksController, never())
            .snapToHalfScreen(eq(decor.mTaskInfo), any(), eq(currentBounds), eq(SnapPosition.LEFT),
            .snapToHalfScreen(eq(decor.mTaskInfo), any(), eq(currentBounds), eq(SnapPosition.LEFT),
                eq(ResizeTrigger.MAXIMIZE_BUTTON),
                eq(ResizeTrigger.MAXIMIZE_BUTTON),
                eq(null))
                eq(null),
                eq(decor),
            )
        verify(mockToast).show()
        verify(mockToast).show()
    }
    }


@@ -749,7 +753,8 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
            eq(currentBounds),
            eq(currentBounds),
            eq(SnapPosition.RIGHT),
            eq(SnapPosition.RIGHT),
            eq(ResizeTrigger.SNAP_RIGHT_MENU),
            eq(ResizeTrigger.SNAP_RIGHT_MENU),
            eq(null)
            eq(null),
            eq(decor),
        )
        )
        assertEquals(decor.mTaskSurface, taskSurfaceCaptor.firstValue)
        assertEquals(decor.mTaskSurface, taskSurfaceCaptor.firstValue)
    }
    }
@@ -789,7 +794,8 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
            eq(currentBounds),
            eq(currentBounds),
            eq(SnapPosition.RIGHT),
            eq(SnapPosition.RIGHT),
            eq(ResizeTrigger.SNAP_RIGHT_MENU),
            eq(ResizeTrigger.SNAP_RIGHT_MENU),
            eq(null)
            eq(null),
            eq(decor),
        )
        )
        assertEquals(decor.mTaskSurface, taskSurfaceCaptor.firstValue)
        assertEquals(decor.mTaskSurface, taskSurfaceCaptor.firstValue)
    }
    }
@@ -810,7 +816,9 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() {
        verify(mockDesktopTasksController, never())
        verify(mockDesktopTasksController, never())
            .snapToHalfScreen(eq(decor.mTaskInfo), any(), eq(currentBounds), eq(SnapPosition.RIGHT),
            .snapToHalfScreen(eq(decor.mTaskInfo), any(), eq(currentBounds), eq(SnapPosition.RIGHT),
                eq(ResizeTrigger.MAXIMIZE_BUTTON),
                eq(ResizeTrigger.MAXIMIZE_BUTTON),
                eq(null))
                eq(null),
                eq(decor),
        )
        verify(mockToast).show()
        verify(mockToast).show()
    }
    }


+8 −6
Original line number Original line Diff line number Diff line
@@ -65,7 +65,7 @@ public class DragResizeWindowGeometryTests extends ShellTestCase {
    private static final int LARGE_CORNER_SIZE = FINE_CORNER_SIZE + 10;
    private static final int LARGE_CORNER_SIZE = FINE_CORNER_SIZE + 10;
    private static final DragResizeWindowGeometry GEOMETRY = new DragResizeWindowGeometry(
    private static final DragResizeWindowGeometry GEOMETRY = new DragResizeWindowGeometry(
            TASK_CORNER_RADIUS, TASK_SIZE, EDGE_RESIZE_THICKNESS, EDGE_RESIZE_HANDLE_INSET,
            TASK_CORNER_RADIUS, TASK_SIZE, EDGE_RESIZE_THICKNESS, EDGE_RESIZE_HANDLE_INSET,
            FINE_CORNER_SIZE, LARGE_CORNER_SIZE);
            FINE_CORNER_SIZE, LARGE_CORNER_SIZE, DragResizeWindowGeometry.DisabledEdge.NONE);
    // Points in the edge resize handle. Note that coordinates start from the top left.
    // Points in the edge resize handle. Note that coordinates start from the top left.
    private static final Point TOP_EDGE_POINT = new Point(TASK_SIZE.getWidth() / 2,
    private static final Point TOP_EDGE_POINT = new Point(TASK_SIZE.getWidth() / 2,
            -EDGE_RESIZE_THICKNESS / 2);
            -EDGE_RESIZE_THICKNESS / 2);
@@ -100,23 +100,25 @@ public class DragResizeWindowGeometryTests extends ShellTestCase {
                        GEOMETRY,
                        GEOMETRY,
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS, EDGE_RESIZE_HANDLE_INSET, FINE_CORNER_SIZE,
                                EDGE_RESIZE_THICKNESS, EDGE_RESIZE_HANDLE_INSET, FINE_CORNER_SIZE,
                                LARGE_CORNER_SIZE))
                                LARGE_CORNER_SIZE, DragResizeWindowGeometry.DisabledEdge.NONE))
                .addEqualityGroup(
                .addEqualityGroup(
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE, LARGE_CORNER_SIZE),
                                FINE_CORNER_SIZE, LARGE_CORNER_SIZE,
                                DragResizeWindowGeometry.DisabledEdge.NONE),
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE, LARGE_CORNER_SIZE))
                                FINE_CORNER_SIZE, LARGE_CORNER_SIZE,
                                DragResizeWindowGeometry.DisabledEdge.NONE))
                .addEqualityGroup(
                .addEqualityGroup(
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE,
                                FINE_CORNER_SIZE,
                                LARGE_CORNER_SIZE + 5),
                                LARGE_CORNER_SIZE + 5, DragResizeWindowGeometry.DisabledEdge.NONE),
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                        new DragResizeWindowGeometry(TASK_CORNER_RADIUS, TASK_SIZE,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                EDGE_RESIZE_THICKNESS + 10, EDGE_RESIZE_HANDLE_INSET,
                                FINE_CORNER_SIZE,
                                FINE_CORNER_SIZE,
                                LARGE_CORNER_SIZE + 5))
                                LARGE_CORNER_SIZE + 5, DragResizeWindowGeometry.DisabledEdge.NONE))
                .testEquals();
                .testEquals();
    }
    }