2018-05-31 14:33:09 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2018 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;
|
|
|
|
|
|
2019-08-14 15:38:34 -07:00
|
|
|
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
|
|
|
|
|
|
2019-06-20 12:31:01 -07:00
|
|
|
import android.graphics.Rect;
|
|
|
|
|
|
2018-08-15 15:28:47 -07:00
|
|
|
import androidx.test.uiautomator.UiObject2;
|
2019-05-28 12:03:05 -07:00
|
|
|
|
2020-01-22 18:00:37 -08:00
|
|
|
import com.android.launcher3.testing.TestProtocol;
|
|
|
|
|
|
2020-01-23 19:12:19 -08:00
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
2018-05-31 14:33:09 -07:00
|
|
|
/**
|
|
|
|
|
* A recent task in the overview panel carousel.
|
|
|
|
|
*/
|
|
|
|
|
public final class OverviewTask {
|
2020-01-23 19:12:19 -08:00
|
|
|
static final Pattern TASK_START_EVENT =
|
|
|
|
|
Pattern.compile("startActivityFromRecentsAsync");
|
2018-06-18 19:14:44 -07:00
|
|
|
private final LauncherInstrumentation mLauncher;
|
2018-05-31 14:33:09 -07:00
|
|
|
private final UiObject2 mTask;
|
2018-10-05 16:19:38 -07:00
|
|
|
private final BaseOverview mOverview;
|
2018-05-31 14:33:09 -07:00
|
|
|
|
2018-10-05 16:19:38 -07:00
|
|
|
OverviewTask(LauncherInstrumentation launcher, UiObject2 task, BaseOverview overview) {
|
2018-05-31 14:33:09 -07:00
|
|
|
mLauncher = launcher;
|
|
|
|
|
mTask = task;
|
2018-06-18 19:14:44 -07:00
|
|
|
mOverview = overview;
|
|
|
|
|
verifyActiveContainer();
|
2018-05-31 14:33:09 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-18 19:14:44 -07:00
|
|
|
private void verifyActiveContainer() {
|
|
|
|
|
mOverview.verifyActiveContainer();
|
2018-05-31 14:33:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Swipes the task up.
|
|
|
|
|
*/
|
|
|
|
|
public void dismiss() {
|
2019-12-19 18:27:36 -08:00
|
|
|
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
|
|
|
|
|
LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
|
|
|
|
|
"want to dismiss a task")) {
|
2019-03-22 18:15:35 -07:00
|
|
|
verifyActiveContainer();
|
|
|
|
|
// Dismiss the task via flinging it up.
|
2020-03-31 14:03:00 -07:00
|
|
|
final Rect taskBounds = mLauncher.getVisibleBounds(mTask);
|
2019-06-20 12:31:01 -07:00
|
|
|
final int centerX = taskBounds.centerX();
|
|
|
|
|
final int centerY = taskBounds.centerY();
|
2021-07-16 18:26:54 +01:00
|
|
|
mLauncher.executeAndWaitForLauncherEvent(
|
|
|
|
|
() -> mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false,
|
|
|
|
|
LauncherInstrumentation.GestureScope.INSIDE),
|
|
|
|
|
event -> TestProtocol.DISMISS_ANIMATION_ENDS_MESSAGE.equals(
|
|
|
|
|
event.getClassName()),
|
|
|
|
|
() -> "Didn't receive a dismiss animation ends message: " + centerX + ", "
|
|
|
|
|
+ centerY,
|
|
|
|
|
"swiping to dismiss");
|
2019-03-22 18:15:35 -07:00
|
|
|
}
|
2018-05-31 14:33:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clicks at the task.
|
|
|
|
|
*/
|
2018-06-18 19:14:44 -07:00
|
|
|
public Background open() {
|
2019-12-19 18:27:36 -08:00
|
|
|
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
|
|
|
|
|
verifyActiveContainer();
|
2021-07-01 18:27:05 -07:00
|
|
|
mLauncher.executeAndWaitForEvent(
|
|
|
|
|
() -> mLauncher.clickLauncherObject(mTask),
|
|
|
|
|
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
|
|
|
|
|
() -> "Launching task didn't open a new window: "
|
|
|
|
|
+ mTask.getParent().getContentDescription(),
|
|
|
|
|
"clicking an overview task");
|
|
|
|
|
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT);
|
2019-12-19 18:27:36 -08:00
|
|
|
return new Background(mLauncher);
|
2019-05-28 12:03:05 -07:00
|
|
|
}
|
2018-05-31 14:33:09 -07:00
|
|
|
}
|
|
|
|
|
}
|