OverviewTask.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.android.launcher3.tapl;
  17. import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
  18. import android.graphics.Rect;
  19. import androidx.test.uiautomator.UiObject2;
  20. import com.android.launcher3.testing.TestProtocol;
  21. import java.util.regex.Pattern;
  22. /**
  23. * A recent task in the overview panel carousel.
  24. */
  25. public final class OverviewTask {
  26. static final Pattern TASK_START_EVENT =
  27. Pattern.compile("startActivityFromRecentsAsync");
  28. private final LauncherInstrumentation mLauncher;
  29. private final UiObject2 mTask;
  30. private final BaseOverview mOverview;
  31. OverviewTask(LauncherInstrumentation launcher, UiObject2 task, BaseOverview overview) {
  32. mLauncher = launcher;
  33. mTask = task;
  34. mOverview = overview;
  35. verifyActiveContainer();
  36. }
  37. private void verifyActiveContainer() {
  38. mOverview.verifyActiveContainer();
  39. }
  40. /**
  41. * Swipes the task up.
  42. */
  43. public void dismiss() {
  44. try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
  45. LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
  46. "want to dismiss a task")) {
  47. verifyActiveContainer();
  48. // Dismiss the task via flinging it up.
  49. final Rect taskBounds = mLauncher.getVisibleBounds(mTask);
  50. final int centerX = taskBounds.centerX();
  51. final int centerY = taskBounds.centerY();
  52. mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false,
  53. LauncherInstrumentation.GestureScope.INSIDE);
  54. mLauncher.waitForIdle();
  55. }
  56. }
  57. /**
  58. * Clicks at the task.
  59. */
  60. public Background open() {
  61. try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
  62. verifyActiveContainer();
  63. try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
  64. "clicking an overview task")) {
  65. mLauncher.executeAndWaitForEvent(
  66. () -> mLauncher.clickLauncherObject(mTask),
  67. event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
  68. () -> "Launching task didn't open a new window: "
  69. + mTask.getParent().getContentDescription());
  70. mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT);
  71. }
  72. return new Background(mLauncher);
  73. }
  74. }
  75. }