mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 09:56:49 +00:00
[Toast] Create one search tapl tests for opening qsb and calculator app.
Test design doc: https://docs.google.com/document/d/1aPtMvegzn4hdwC0CNuIkfkalqG7v0FNCfyoO7qIOfN4/edit?usp=sharing&resourcekey=0-71oNHp1KKOdDKxr7Vd4dGQ Bug: 225935921 Bug: 225935929 Test: ran test in android studio Change-Id: I74197a9d81fc75a44269ab3bc1bba910de5e17fe
This commit is contained in:
@@ -62,6 +62,7 @@ import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.logger.LauncherAtom;
|
||||
import com.android.launcher3.logger.LauncherAtom.ContainerInfo;
|
||||
import com.android.launcher3.logger.LauncherAtom.FolderContainer;
|
||||
@@ -116,7 +117,8 @@ public class AppEventProducer implements StatsLogConsumer {
|
||||
@AnyThread
|
||||
private void sendEvent(AppTarget target, LauncherAtom.ItemInfo locationInfo, int eventId,
|
||||
int targetPredictor) {
|
||||
if (target != null) {
|
||||
// TODO: remove the running test check when b/231648228 is fixed.
|
||||
if (target != null && !Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
AppTargetEvent event = new AppTargetEvent.Builder(target, eventId)
|
||||
.setLaunchLocation(getContainer(locationInfo))
|
||||
.build();
|
||||
|
||||
@@ -130,7 +130,7 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
if (IS_VERBOSE) {
|
||||
Log.d(TAG, String.format("\nwriteSnapshot(%d):\n%s", instanceId.getId(), info));
|
||||
}
|
||||
if (!Utilities.ATLEAST_R) {
|
||||
if (!Utilities.ATLEAST_R || Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return;
|
||||
}
|
||||
SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_SNAPSHOT,
|
||||
@@ -415,6 +415,10 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
consumer.consume(event, atomInfo);
|
||||
}
|
||||
|
||||
// TODO: remove this when b/231648228 is fixed.
|
||||
if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return;
|
||||
}
|
||||
SysUiStatsLog.write(
|
||||
SysUiStatsLog.LAUNCHER_EVENT,
|
||||
SysUiStatsLog.LAUNCHER_UICHANGED__ACTION__DEFAULT_ACTION /* deprecated */,
|
||||
@@ -510,6 +514,9 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
}
|
||||
|
||||
private static int getCardinality(LauncherAtom.ItemInfo info) {
|
||||
if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return 0;
|
||||
}
|
||||
switch (info.getContainerInfo().getContainerCase()) {
|
||||
case PREDICTED_HOTSEAT_CONTAINER:
|
||||
return info.getContainerInfo().getPredictedHotseatContainer().getCardinality();
|
||||
@@ -625,6 +632,9 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
}
|
||||
|
||||
private static int getHierarchy(LauncherAtom.ItemInfo info) {
|
||||
if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return 0;
|
||||
}
|
||||
if (info.getContainerInfo().getContainerCase() == FOLDER) {
|
||||
return info.getContainerInfo().getFolder().getParentContainerCase().getNumber()
|
||||
+ FOLDER_HIERARCHY_OFFSET;
|
||||
@@ -665,6 +675,9 @@ public class StatsLogCompatManager extends StatsLogManager {
|
||||
}
|
||||
|
||||
private static int getSearchAttributes(LauncherAtom.ItemInfo info) {
|
||||
if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
|
||||
return 0;
|
||||
}
|
||||
ContainerInfo containerInfo = info.getContainerInfo();
|
||||
if (containerInfo.getContainerCase() == EXTENDED_CONTAINERS
|
||||
&& containerInfo.getExtendedContainers().getContainerCase()
|
||||
|
||||
@@ -52,6 +52,8 @@ import org.junit.runner.RunWith;
|
||||
public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
|
||||
private static final String APP_NAME = "LauncherTestApp";
|
||||
private static final String CALCULATOR_APP_PACKAGE =
|
||||
resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -73,7 +75,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
|
||||
public static void startTestApps() throws Exception {
|
||||
startAppFast(getAppPackageName());
|
||||
startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
|
||||
startAppFast(CALCULATOR_APP_PACKAGE);
|
||||
startTestActivity(2);
|
||||
}
|
||||
|
||||
@@ -207,7 +209,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
@NavigationModeSwitch
|
||||
@PortraitLandscape
|
||||
public void testBackground() throws Exception {
|
||||
startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
|
||||
startAppFast(CALCULATOR_APP_PACKAGE);
|
||||
final LaunchedAppState launchedAppState = getAndAssertLaunchedApp();
|
||||
|
||||
assertNotNull("Background.switchToOverview() returned null",
|
||||
@@ -302,7 +304,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
mLauncher.getWorkspace();
|
||||
waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
|
||||
|
||||
startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
|
||||
startAppFast(CALCULATOR_APP_PACKAGE);
|
||||
mLauncher.pressBack();
|
||||
mLauncher.getWorkspace();
|
||||
waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
|
||||
|
||||
45
tests/tapl/com/android/launcher3/tapl/HomeQsb.java
Normal file
45
tests/tapl/com/android/launcher3/tapl/HomeQsb.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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;
|
||||
|
||||
/**
|
||||
* Operations on home screen qsb.
|
||||
*/
|
||||
public class HomeQsb {
|
||||
|
||||
private final LauncherInstrumentation mLauncher;
|
||||
|
||||
HomeQsb(LauncherInstrumentation launcher) {
|
||||
mLauncher = launcher;
|
||||
mLauncher.waitForLauncherObject("search_container_hotseat");
|
||||
}
|
||||
|
||||
/**
|
||||
* Show search result page from tapping qsb.
|
||||
*/
|
||||
public SearchResultFromQsb showSearchResult() {
|
||||
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
|
||||
"want to open search result page");
|
||||
LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
|
||||
mLauncher.clickLauncherObject(
|
||||
mLauncher.waitForLauncherObject("search_container_hotseat"));
|
||||
try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer(
|
||||
"clicked qsb to open search result page")) {
|
||||
return new SearchResultFromQsb(mLauncher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import com.android.launcher3.testing.TestProtocol;
|
||||
/**
|
||||
* Ancestor for AppIcon and AppMenuItem.
|
||||
*/
|
||||
abstract class Launchable {
|
||||
public abstract class Launchable {
|
||||
|
||||
protected static final int DEFAULT_DRAG_STEPS = 10;
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 android.widget.TextView;
|
||||
|
||||
import androidx.test.uiautomator.By;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
|
||||
/**
|
||||
* Operations on search result page opened from home screen qsb.
|
||||
*/
|
||||
public class SearchResultFromQsb {
|
||||
// The input resource id in the search box.
|
||||
private static final String INPUT_RES = "input";
|
||||
private final LauncherInstrumentation mLauncher;
|
||||
|
||||
SearchResultFromQsb(LauncherInstrumentation launcher) {
|
||||
mLauncher = launcher;
|
||||
mLauncher.waitForLauncherObject("search_container_all_apps");
|
||||
}
|
||||
|
||||
/** Set the input to the search input edit text and update search results. */
|
||||
public void searchForInput(String input) {
|
||||
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
|
||||
"want to search for result with an input");
|
||||
LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
|
||||
mLauncher.waitForLauncherObject(INPUT_RES).setText(input);
|
||||
}
|
||||
}
|
||||
|
||||
/** Find the app from search results with app name. */
|
||||
public Launchable findAppIcon(String appName) {
|
||||
UiObject2 icon = mLauncher.waitForLauncherObject(By.clazz(TextView.class).text(appName));
|
||||
return new AllAppsAppIcon(mLauncher, icon);
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,18 @@ public final class Workspace extends Home {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the home qsb.
|
||||
*
|
||||
* The qsb must already be visible when calling this method.
|
||||
*/
|
||||
public HomeQsb getQsb() {
|
||||
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
|
||||
"want to get the home qsb")) {
|
||||
return new HomeQsb(mLauncher);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an icon for the app, if currently visible.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user