Merge "Removing redundant waiting for window change event and adding debug logging for dragging and dropping." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d4909d3047
@@ -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());
|
||||
mLauncher.clickLauncherObject(mObject);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
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");
|
||||
|
||||
try (LauncherInstrumentation.Closable c4 = launcher.addContextLayer(
|
||||
"dropped item")) {
|
||||
launchable.assertAppLaunched(itemLabel, By.pkg(expectedNewPackageName));
|
||||
launchable.assertAppLaunched(
|
||||
itemLabel, By.pkg(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(() -> {
|
||||
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");
|
||||
|
||||
try (LauncherInstrumentation.Closable c = launcher.addContextLayer("dropped item")) {
|
||||
launchable.assertAppLaunched(itemLabel, By.pkg(expectedNewPackageName));
|
||||
launcher.checkPackagesVisible(
|
||||
new String[] {expectedNewPackageName, expectedExistingPackageName});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user