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

Commit 9af34a7b authored by vadimt's avatar vadimt
Browse files

TAPL: verify input events

This will catch cases, for example, when the platform stops delivering
injected events to Launcher, or injects unexpected events, like Back
Button.

Also optimizing and fixing incorrect behavior of calculating the start
time for the event collection.

Change-Id: I2ba0108e6bfa112f2905a05bcb327b148ec08f77
parent d44326c2
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import android.view.KeyboardShortcutGroup;
import android.view.KeyboardShortcutInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
@@ -121,6 +122,7 @@ import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.qsb.QsbContainerView;
import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.testing.TestLogging;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.AllAppsSwipeController;
import com.android.launcher3.touch.ItemClickHandler;
@@ -1778,9 +1780,20 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
            TestLogging.recordEvent("Key event: " + event);
        }
        return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (Utilities.IS_RUNNING_IN_TEST_HARNESS && ev.getAction() != MotionEvent.ACTION_MOVE) {
            TestLogging.recordEvent("Touch event: " + ev);
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public void onBackPressed() {
        if (finishAutoCancelActionMode()) {
+2 −1
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ public final class AllAppsFromOverview extends AllApps {

            final int endY = start.y + swipeHeight;
            LauncherInstrumentation.log("AllAppsFromOverview.switchBackToOverview before swipe");
            mLauncher.swipeToState(start.x, start.y, start.x, endY, 60, OVERVIEW_STATE_ORDINAL);
            mLauncher.swipeToState(start.x, start.y, start.x, endY, 60, OVERVIEW_STATE_ORDINAL,
                    LauncherInstrumentation.GestureScope.INSIDE);

            try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("swiped down")) {
                return new Overview(mLauncher);
+22 −5
Original line number Diff line number Diff line
@@ -62,6 +62,10 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
        }
    }

    protected boolean zeroButtonToOverviewGestureStartsInLauncher() {
        return false;
    }

    protected void goToOverviewUnchecked() {
        switch (mLauncher.getNavigationModel()) {
            case ZERO_BUTTON: {
@@ -74,19 +78,26 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
                        new Point(centerX, startY - swipeHeight - mLauncher.getTouchSlop());

                final long downTime = SystemClock.uptimeMillis();
                mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start);
                final LauncherInstrumentation.GestureScope gestureScope =
                        zeroButtonToOverviewGestureStartsInLauncher()
                                ? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
                                : LauncherInstrumentation.GestureScope.OUTSIDE;
                mLauncher.sendPointer(
                        downTime, downTime, MotionEvent.ACTION_DOWN, start, gestureScope);
                mLauncher.executeAndWaitForEvent(
                        () -> mLauncher.movePointer(
                                downTime,
                                downTime,
                                ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION,
                                start,
                                end),
                                end,
                                gestureScope),
                        event -> TestProtocol.PAUSE_DETECTED_MESSAGE.equals(event.getClassName()),
                        () -> "Pause wasn't detected");
                mLauncher.runToState(
                        () -> mLauncher.sendPointer(
                                downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, end),
                                downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, end,
                                gestureScope),
                        OVERVIEW_STATE_ORDINAL);
                break;
            }
@@ -109,7 +120,8 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
                    startY = endY = mLauncher.getDevice().getDisplayHeight() / 2;
                }

                mLauncher.swipeToState(startX, startY, endX, endY, 10, OVERVIEW_STATE_ORDINAL);
                mLauncher.swipeToState(startX, startY, endX, endY, 10, OVERVIEW_STATE_ORDINAL,
                        LauncherInstrumentation.GestureScope.OUTSIDE);
                break;
            }

@@ -162,7 +174,12 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
                    endX = startX;
                    endY = 0;
                }
                mLauncher.swipeToState(startX, startY, endX, endY, 20, expectedState);
                mLauncher.swipeToState(startX, startY, endX, endY, 20, expectedState,
                        mLauncher.getNavigationModel()
                                == LauncherInstrumentation.NavigationModel.ZERO_BUTTON
                                ? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
                                : LauncherInstrumentation.GestureScope.OUTSIDE
                );
                break;
            }

+2 −1
Original line number Diff line number Diff line
@@ -82,7 +82,8 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
                flingForwardImpl();
            }

            mLauncher.waitForObjectInContainer(verifyActiveContainer(), clearAllSelector).click();
            mLauncher.clickLauncherObject(
                    mLauncher.waitForObjectInContainer(verifyActiveContainer(), clearAllSelector));
        }
    }

+5 −0
Original line number Diff line number Diff line
@@ -60,6 +60,11 @@ public abstract class Home extends Background {
        }
    }

    @Override
    protected boolean zeroButtonToOverviewGestureStartsInLauncher() {
        return true;
    }

    @Override
    protected int getExpectedStateForQuickSwitch() {
        return QUICK_SWITCH_STATE_ORDINAL;
Loading