From 0646238ab40a43f8db7c9c1dcb3029db2348e41c Mon Sep 17 00:00:00 2001 From: linalex Date: Wed, 25 Nov 2020 10:12:07 +0800 Subject: [PATCH] [DO NOT MERGE ANYWHERE] Add swipes left method in Background.java Bug: 153276032 Test: TF_GLOBAL_CONFIG=/google/src/cloud///google3/wireless/android/test_tools/forrest/configs/local-host-config.xml \ pts-tradefed run commandAndExit cuj/ \ --primary-abi-only \ --log-level verbose --log-level-display verbose \ --wifi-network GoogleGuest Change-Id: Ib1cbc609f47a547f173e8170f00af9e8bdfa77bb (cherry picked from commit 8492c6763915ef06cd463ffedfcaf106dc832b23) --- .../android/launcher3/tapl/Background.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 0c4e5a9461..816cd7d3eb 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -210,6 +210,64 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT); } + /** Swipes left to switch to the previous app. */ + public Background quickSwitchToPreviousAppSwipeLeft() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = + mLauncher.addContextLayer("want to quick switch to the previous app")) { + verifyActiveContainer(); + quickSwitchToPreviousAppSwipeLeft(getExpectedStateForQuickSwitch()); + return new Background(mLauncher); + } + } + + protected void quickSwitchToPreviousAppSwipeLeft(int expectedState) { + final boolean launcherWasVisible = mLauncher.isLauncherVisible(); + boolean transposeInLandscape = false; + switch (mLauncher.getNavigationModel()) { + case TWO_BUTTON: + transposeInLandscape = true; + // Fall through, zero button and two button modes behave the same. + case ZERO_BUTTON: { + final int startX; + final int startY; + final int endX; + final int endY; + if (mLauncher.getDevice().isNaturalOrientation() || !transposeInLandscape) { + // Swipe from the bottom right to the bottom left of the screen. + startX = mLauncher.getDevice().getDisplayWidth(); + startY = getSwipeStartY(); + endX = 0; + endY = startY; + } else { + // Swipe from the bottom right to the top right of the screen. + startX = getSwipeStartX(); + startY = mLauncher.getRealDisplaySize().y - 1; + endX = startX; + endY = 0; + } + final boolean isZeroButton = + mLauncher.getNavigationModel() + == LauncherInstrumentation.NavigationModel.ZERO_BUTTON; + mLauncher.swipeToState(startX, startY, endX, endY, 20, expectedState, + launcherWasVisible && isZeroButton + ? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE + : LauncherInstrumentation.GestureScope.OUTSIDE_WITH_PILFER); + break; + } + + case THREE_BUTTON: + // Double press the recents button. + UiObject2 recentsButton = mLauncher.waitForSystemUiObject("recent_apps"); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT); + mLauncher.runToState(() -> recentsButton.click(), OVERVIEW_STATE_ORDINAL); + mLauncher.getOverview(); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT); + recentsButton.click(); + break; + } + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT); + } protected String getSwipeHeightRequestName() { return TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT;