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

Commit 9cf1cd17 authored by Schneider Victor-tulias's avatar Schneider Victor-tulias Committed by Automerger Merge Worker
Browse files

Merge "Removing redundant waiting for window change event and adding debug...

Merge "Removing redundant waiting for window change event and adding debug logging for dragging and dropping." into tm-dev am: d4909d30 am: 062f5573

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/18206592



Change-Id: I0f28e78eae71ca634c9ab4f443cb8040cb2912ad
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents dda9a843 062f5573
Loading
Loading
Loading
Loading
+5 −17
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.launcher3.tapl;

import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;

import static com.android.launcher3.testing.TestProtocol.SPRING_LOADED_STATE_ORDINAL;

import android.graphics.Point;
@@ -64,35 +62,25 @@ public abstract class Launchable {
    protected abstract String launchableType();

    private LaunchedAppState launch(BySelector selector) {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
        try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
                "want to launch an app from " + launchableType())) {
            LauncherInstrumentation.log("Launchable.launch before click "
                    + mObject.getVisibleCenter() + " in " + mLauncher.getVisibleBounds(mObject));
            final String label = mObject.getText();

            executeAndWaitForWindowChange(() -> {
            mLauncher.clickLauncherObject(mObject);
                expectActivityStartEvents();
            }, label, "clicking " + launchableType());

            try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("clicked")) {
            try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer("clicked")) {
                expectActivityStartEvents();
                return assertAppLaunched(label, selector);
            }
        }
    }

    protected void executeAndWaitForWindowChange(Runnable command, String label, String action) {
        mLauncher.executeAndWaitForEvent(
                command,
                event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
                () -> "Launching an app didn't open a new window: " + label,
                action);
    }

    protected LaunchedAppState assertAppLaunched(String label, BySelector selector) {
        mLauncher.assertTrue(
                "App didn't start: " + label + " (" + selector + ")",
                TestHelpers.wait(Until.hasObject(selector),
                mLauncher.getDevice().wait(Until.hasObject(selector),
                        LauncherInstrumentation.WAIT_TIME_MS));
        return new LaunchedAppState(mLauncher);
    }
+17 −34
Original line number Diff line number Diff line
@@ -129,42 +129,25 @@ public final class LaunchedAppState extends Background {

                try (LauncherInstrumentation.Closable c3 = launcher.addContextLayer(
                        "moved pointer to drop point")) {
                    dropDraggedItem(
                            launcher,
                            launchable,
                            expectedNewPackageName,
                            endPoint, downTime,
                            itemVisibleCenter,
                            itemVisibleBounds,
                            itemLabel,
                            expectedExistingPackageName);
                }
            }
        }
    }

    private static void dropDraggedItem(
            LauncherInstrumentation launcher, Launchable launchable, String expectedNewPackageName,
            Point endPoint, long downTime, Point itemVisibleCenter, Rect itemVisibleBounds,
            String itemLabel, String expectedExistingPackageName) {
        LauncherInstrumentation.log("SplitscreenDragSource.dragToSplitscreen before drop "
                + itemVisibleCenter + " in " + itemVisibleBounds);

        launchable.executeAndWaitForWindowChange(() -> {
                    LauncherInstrumentation.log("SplitscreenDragSource.dragToSplitscreen: "
                            + "before drop " + itemVisibleCenter + " in " + itemVisibleBounds);
                    launcher.sendPointer(
                            downTime,
                            SystemClock.uptimeMillis(),
                            MotionEvent.ACTION_UP,
                            endPoint,
                            LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE_WITHOUT_PILFER);
            LauncherInstrumentation.log("SplitscreenDragSource.dragToSplitscreen: after "
                    + "drop");
        }, itemLabel, "dropping taskbar item");
                    LauncherInstrumentation.log("SplitscreenDragSource.dragToSplitscreen: "
                            + "after drop");

        try (LauncherInstrumentation.Closable c = launcher.addContextLayer("dropped item")) {
                    try (LauncherInstrumentation.Closable c4 = launcher.addContextLayer(
                            "dropped item")) {
                        launchable.assertAppLaunched(itemLabel, By.pkg(expectedNewPackageName));
            launcher.checkPackagesVisible(
                    new String[] {expectedNewPackageName, expectedExistingPackageName});
                        launchable.assertAppLaunched(
                                itemLabel, By.pkg(expectedExistingPackageName));
                    }
                }
            }
        }
    }
}
+6 −21
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
@@ -92,7 +91,6 @@ import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * The main tapl object. The only object that can be explicitly constructed by the using code. It
@@ -501,29 +499,16 @@ public final class LauncherInstrumentation {
        }
    }

    void checkPackagesVisible(String[] expectedVisiblePackages) {
        Set<String> actualVisiblePackages =
                getVisiblePackagesStream().collect(Collectors.toSet());

        for (String expectedVisible : expectedVisiblePackages) {
            assertTrue("Expected package not visible: " + expectedVisible,
                    actualVisiblePackages.contains(expectedVisible));
        }
    }

    private String getVisiblePackages() {
        final String apps = getVisiblePackagesStream().collect(Collectors.joining(", "));
        return !apps.isEmpty()
                ? "active app: " + apps
                : "the test doesn't see views from any app, including Launcher";
    }

    private Stream<String> getVisiblePackagesStream() {
        return mDevice.findObjects(getAnyObjectSelector())
        final String apps = mDevice.findObjects(getAnyObjectSelector())
                .stream()
                .map(LauncherInstrumentation::getApplicationPackageSafe)
                .distinct()
                .filter(pkg -> pkg != null && !SYSTEMUI_PACKAGE.equals(pkg));
                .filter(pkg -> pkg != null && !SYSTEMUI_PACKAGE.equals(pkg))
                .collect(Collectors.joining(", "));
        return !apps.isEmpty()
                ? "active app: " + apps
                : "the test doesn't see views from any app, including Launcher";
    }

    private static String getApplicationPackageSafe(UiObject2 object) {
+0 −51
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.launcher3.tapl;

import androidx.annotation.NonNull;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;

import com.android.launcher3.testing.TestProtocol;

public class OptionsPopupMenuItem {

    private final LauncherInstrumentation mLauncher;
    private final UiObject2 mObject;

    OptionsPopupMenuItem(@NonNull LauncherInstrumentation launcher, @NonNull UiObject2 shortcut) {
        mLauncher = launcher;
        mObject = shortcut;
    }

    /**
     * Clicks the option.
     */
    @NonNull
    public void launch(@NonNull String expectedPackageName) {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
            LauncherInstrumentation.log("OptionsPopupMenuItem before click "
                    + mObject.getVisibleCenter() + " in " + mLauncher.getVisibleBounds(mObject));
            mLauncher.clickLauncherObject(mObject);
            mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_START);
            mLauncher.assertTrue(
                    "App didn't start: " + By.pkg(expectedPackageName),
                    mLauncher.getDevice().wait(Until.hasObject(By.pkg(expectedPackageName)),
                            LauncherInstrumentation.WAIT_TIME_MS));
        }
    }
}