Update tests for ENABLE_TWOLINE_ALLAPPS and ENABLE_TWOLINE_DEVICESEARCH

PM said we can enable ENABLE_TWOLINE_ALLAPPS and ENABLE_TWOLINE_DEVICESEARCH flags.

Since I am enabling two-line text for all apps, it's possible that the text would have other texts within the app name itself. For example, if a title of an app is long for example "Amazon Shopping" the title can now be like "Amazon\nShopping". For tests to recognize its "Amazon shopping", I am resorting to identifying the app title based on the content description.

Turn on the two feature flags in another CL

bug: 287307252
test: manual
Change-Id: I8bdc3db710514c9098ccb5d9781a100ac9b35eab
This commit is contained in:
Brandon Dayauon
2023-06-13 10:55:35 -07:00
parent 3ce64d592b
commit df4dfdba4d
6 changed files with 72 additions and 8 deletions

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 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 static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class TaplUtilityTests {
@Test
public void testNewStringWithRegex() {
assertTrue(AppIcon.makeMultilinePattern("Play Store")
.matcher("Play Store has 7 notifications").matches());
assertTrue(AppIcon.makeMultilinePattern("Play Store")
.matcher("Play Store!").matches());
assertFalse(AppIcon.makeMultilinePattern("Play Store")
.matcher("play store").matches());
assertFalse(AppIcon.makeMultilinePattern("Play Store")
.matcher("").matches());
assertTrue(AppIcon.makeMultilinePattern("Play Store")
.matcher("Play \n Store").matches());
}
}

View File

@@ -683,8 +683,8 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
try {
HomeAppIcon icon = allApps.getAppIcon(APP_NAME);
assertEquals("Wrong app icon name.", icon.getIconName(), APP_NAME);
// getAppIcon() already verifies that the icon is not null and is the correct icon name.
allApps.getAppIcon(APP_NAME);
} finally {
allApps.unfreeze();
}

View File

@@ -147,9 +147,8 @@ public class ThemeIconsTest extends AbstractLauncherUiTest {
for (int i = parent.getChildCount() - 1; i >= 0; i--) {
viewQueue.add(parent.getChildAt(i));
}
} else if (view instanceof BubbleTextView) {
BubbleTextView btv = (BubbleTextView) view;
if (title.equals(btv.getText())) {
} else if (view instanceof BubbleTextView btv) {
if (title.equals(btv.getContentDescription().toString())) {
icon = btv;
break;
}

View File

@@ -210,6 +210,9 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer {
public AppIcon getAppIcon(String appName) {
AppIcon appIcon = tryGetAppIcon(appName);
mLauncher.assertNotNull("Unable to scroll to a clickable icon: " + appName, appIcon);
// appIcon.getAppName() checks for content description, so it is possible that it can have
// trailing words. So check if the content description contains the appName.
mLauncher.assertTrue("Wrong app icon name.", appIcon.getAppName().contains(appName));
return appIcon;
}

View File

@@ -37,10 +37,14 @@ public abstract class AppIcon extends Launchable {
}
static BySelector getAppIconSelector(String appName, LauncherInstrumentation launcher) {
return By.clazz(TextView.class).textContains(appName)
return By.clazz(TextView.class).desc(makeMultilinePattern(appName))
.pkg(launcher.getLauncherPackageName());
}
static BySelector getMenuItemSelector(String text, LauncherInstrumentation launcher) {
return By.clazz(TextView.class).text(text).pkg(launcher.getLauncherPackageName());
}
static BySelector getAnyAppIconSelector() {
return By.clazz(TextView.class);
}
@@ -94,4 +98,24 @@ public abstract class AppIcon extends Launchable {
public String getIconName() {
return getObject().getText();
}
/**
* Return the app name of a icon by the content description. This should be used when trying to
* get the name of an app where the text of it is multiline.
*/
@NonNull
String getAppName() {
return getObject().getContentDescription();
}
/**
* Create a regular expression pattern that matches strings starting with the app name, where
* spaces in the app name are replaced with zero or more occurrences of the "\s" character
* (which represents a whitespace character in regular expressions), followed by any characters
* after the app name.
*/
static Pattern makeMultilinePattern(String appName) {
return Pattern.compile(appName.replaceAll("\\s+", "\\\\s*") + ".*",
Pattern.DOTALL);
}
}

View File

@@ -50,7 +50,7 @@ public abstract class AppIconMenu {
*/
public AppIconMenuItem getMenuItem(String shortcutText) {
final UiObject2 menuItem = mLauncher.waitForObjectInContainer(mDeepShortcutsContainer,
AppIcon.getAppIconSelector(shortcutText, mLauncher));
AppIcon.getMenuItemSelector(shortcutText, mLauncher));
return createMenuItem(menuItem);
}
@@ -59,7 +59,7 @@ public abstract class AppIconMenu {
*/
public SplitScreenMenuItem getSplitScreenMenuItem() {
final UiObject2 menuItem = mLauncher.waitForObjectInContainer(mDeepShortcutsContainer,
AppIcon.getAppIconSelector("Split screen", mLauncher));
AppIcon.getMenuItemSelector("Split screen", mLauncher));
return new SplitScreenMenuItem(mLauncher, menuItem);
}