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

Commit 6dc98ad8 authored by Brandon Dayauon's avatar Brandon Dayauon Committed by Android (Google) Code Review
Browse files

Merge "Update tests for ENABLE_TWOLINE_ALLAPPS and ENABLE_TWOLINE_DEVICESEARCH" into udc-qpr-dev

parents c56c01c3 df4dfdba
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
/*
 * 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());
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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();
        }
+2 −3
Original line number Diff line number Diff line
@@ -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;
                }
+3 −0
Original line number Diff line number Diff line
@@ -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;
    }

+25 −1
Original line number Diff line number Diff line
@@ -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);
    }
}
Loading