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

Commit 16eca550 authored by vadimt's avatar vadimt
Browse files

Enabling event verification for Launcher3

Will help investigating otherwise mysterious failures.

Change-Id: I805ed136baf6d86921fdb4782304fcdafbd3af5c
parent 74e78e95
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -42,11 +42,14 @@ public class AddToHomeScreenPrompt {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
            if (mLauncher.getNavigationModel()
                    != LauncherInstrumentation.NavigationModel.THREE_BUTTON) {
                if (!mLauncher.isLauncher3()) {
                    mLauncher.expectEvent(
                        TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_DOWN_TIS);
                            TestProtocol.SEQUENCE_TIS,
                            LauncherInstrumentation.EVENT_TOUCH_DOWN_TIS);
                    mLauncher.expectEvent(
                            TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_UP_TIS);
                }
            }
            mLauncher.waitForObjectInContainer(
                    mWidgetCell.getParent().getParent().getParent().getParent(),
                    By.text(ADD_AUTOMATICALLY)).click();
+10 −10
Original line number Diff line number Diff line
@@ -677,7 +677,7 @@ public final class LauncherInstrumentation {
                try (LauncherInstrumentation.Closable c = addContextLayer(action)) {
                    mDevice.waitForIdle();

                    if (getNavigationModel() == NavigationModel.TWO_BUTTON) {
                    if (!isLauncher3() && getNavigationModel() == NavigationModel.TWO_BUTTON) {
                        expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
                        expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
                    }
@@ -962,7 +962,7 @@ public final class LauncherInstrumentation {
    void clickLauncherObject(UiObject2 object) {
        expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_TOUCH_DOWN);
        expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_TOUCH_UP);
        if (getNavigationModel() != NavigationModel.THREE_BUTTON) {
        if (!isLauncher3() && getNavigationModel() != NavigationModel.THREE_BUTTON) {
            expectEvent(TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_DOWN_TIS);
            expectEvent(TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_UP_TIS);
        }
@@ -1104,24 +1104,25 @@ public final class LauncherInstrumentation {

    public void sendPointer(long downTime, long currentTime, int action, Point point,
            GestureScope gestureScope) {
        final boolean notLauncher3 = !isLauncher3();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                if (gestureScope != GestureScope.OUTSIDE) {
                    expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_TOUCH_DOWN);
                }
                if (getNavigationModel() != NavigationModel.THREE_BUTTON) {
                if (notLauncher3 && getNavigationModel() != NavigationModel.THREE_BUTTON) {
                    expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
                }
                break;
            case MotionEvent.ACTION_UP:
                if (gestureScope != GestureScope.INSIDE) {
                if (notLauncher3 && gestureScope != GestureScope.INSIDE) {
                    expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_PILFER_POINTERS);
                }
                if (gestureScope != GestureScope.OUTSIDE) {
                    expectEvent(TestProtocol.SEQUENCE_MAIN, gestureScope == GestureScope.INSIDE
                            ? EVENT_TOUCH_UP : EVENT_TOUCH_CANCEL);
                }
                if (getNavigationModel() != NavigationModel.THREE_BUTTON) {
                if (notLauncher3 && getNavigationModel() != NavigationModel.THREE_BUTTON) {
                    expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
                }
                break;
@@ -1276,11 +1277,6 @@ public final class LauncherInstrumentation {

    public Closable eventsCheck() {
        Assert.assertTrue("Nested event checking", !sCheckingEvents);
        if ("com.android.launcher3".equals(getLauncherPackageName())) {
            // Not checking specific Launcher3 event sequences.
            return () -> {
            };
        }
        sCheckingEvents = true;
        mExpectedPid = getPid();
        if (sEventChecker == null) sEventChecker = new LogEventChecker();
@@ -1304,6 +1300,10 @@ public final class LauncherInstrumentation {
        };
    }

    boolean isLauncher3() {
        return "com.android.launcher3".equals(getLauncherPackageName());
    }

    void expectEvent(String sequence, Pattern expected) {
        if (sCheckingEvents) sEventChecker.expectPattern(sequence, expected);
    }