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

Commit 58aac31d authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge "Reset cascading position to center if snapped to left/right" into main

parents 6f57572b e612008c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -116,10 +116,10 @@ fun canChangeTaskPosition(taskInfo: TaskInfo): Boolean {
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
fun Rect.getDesktopTaskPosition(bounds: Rect): DesktopTaskPosition {
    return when {
        top == bounds.top && left == bounds.left -> TopLeft
        top == bounds.top && right == bounds.right -> TopRight
        bottom == bounds.bottom && left == bounds.left -> BottomLeft
        bottom == bounds.bottom && right == bounds.right -> BottomRight
        top == bounds.top && left == bounds.left && bottom != bounds.bottom -> TopLeft
        top == bounds.top && right == bounds.right && bottom != bounds.bottom -> TopRight
        bottom == bounds.bottom && left == bounds.left && top != bounds.top -> BottomLeft
        bottom == bounds.bottom && right == bounds.right && top != bounds.top -> BottomRight
        else -> Center
    }
}
+58 −0
Original line number Diff line number Diff line
@@ -729,6 +729,64 @@ class DesktopTasksControllerTest : ShellTestCase() {
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_lastWindowSnapLeft_positionResetsToCenter() {
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    // Add freeform task with half display size snap bounds at left side.
    setUpFreeformTask(bounds = Rect(stableBounds.left, stableBounds.top, 500, stableBounds.bottom))

    val task = setUpFullscreenTask()
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    val finalBounds = findBoundsChange(wct, task)
    assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_lastWindowSnapRight_positionResetsToCenter() {
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    // Add freeform task with half display size snap bounds at right side.
    setUpFreeformTask(bounds = Rect(
      stableBounds.right - 500, stableBounds.top, stableBounds.right, stableBounds.bottom))

    val task = setUpFullscreenTask()
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    val finalBounds = findBoundsChange(wct, task)
    assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_lastWindowMaximised_positionResetsToCenter() {
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    // Add maximised freeform task.
    setUpFreeformTask(bounds = Rect(stableBounds))

    val task = setUpFullscreenTask()
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    val finalBounds = findBoundsChange(wct, task)
    assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_defaultToCenterIfFree() {