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

Commit 4823dca4 authored by Sebastián Franco's avatar Sebastián Franco Committed by Android (Google) Code Review
Browse files

Merge "Moving tests form TaplTestsLauncher3 to TaplTestsAllAppsIconsWorking" into main

parents 86efdfb9 547ddd48
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ filegroup {
    name: "launcher-oop-tests-src",
    srcs: [
      "src/com/android/launcher3/allapps/TaplOpenCloseAllApps.java",
      "src/com/android/launcher3/allapps/TaplTestsAllAppsIconsWorking.java",
      "src/com/android/launcher3/appiconmenu/TaplAppIconMenuTest.java",
      "src/com/android/launcher3/dragging/TaplDragTest.java",
      "src/com/android/launcher3/dragging/TaplUninstallRemove.java",
@@ -62,7 +63,6 @@ filegroup {
      "src/com/android/launcher3/util/rule/ShellCommandRule.java",
      "src/com/android/launcher3/util/rule/TestIsolationRule.java",
      "src/com/android/launcher3/util/rule/TestStabilityRule.java",
      "src/com/android/launcher3/util/rule/TISBindRule.java",
      "src/com/android/launcher3/util/viewcapture_analysis/*.java",
      "src/com/android/launcher3/testcomponent/BaseTestingActivity.java",
      "src/com/android/launcher3/testcomponent/OtherBaseTestingActivity.java",
+66 −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.allapps;

import static com.android.launcher3.ui.TaplTestsLauncher3.initialize;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.android.launcher3.LauncherState;
import com.android.launcher3.tapl.AppIcon;
import com.android.launcher3.tapl.HomeAllApps;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;

import org.junit.Before;
import org.junit.Test;

/**
 * The test runs in Out of process (Oop) and in process.
 * Makes sure the basic behaviors of Icons on AllApps are working.
 */
public class TaplTestsAllAppsIconsWorking extends AbstractLauncherUiTest {

    @Before
    public void setUp() throws Exception {
        super.setUp();
        initialize(this);
    }

    /**
     * Makes sure we can launch an icon from All apps
     */
    @Test
    @PortraitLandscape
    public void testAppIconLaunchFromAllAppsFromHome() {
        final HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
        assertTrue("Launcher internal state is not All Apps",
                isInState(() -> LauncherState.ALL_APPS));

        allApps.freeze();
        try {
            final AppIcon app = allApps.getAppIcon("TestActivity7");
            assertNotNull("AppIcon.launch returned null", app.launch(getAppPackageName()));
            executeOnLauncher(launcher -> assertTrue(
                    "Launcher activity is the top activity; expecting another activity to be the "
                            + "top one",
                    isInLaunchedApp(launcher)));
        } finally {
            allApps.unfreeze();
        }
    }
}
+0 −44
Original line number Diff line number Diff line
@@ -23,14 +23,9 @@ import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.LauncherState;
import com.android.launcher3.tapl.AllApps;
import com.android.launcher3.tapl.AppIcon;
import com.android.launcher3.tapl.HomeAllApps;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
import com.android.launcher3.util.rule.TISBindRule;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -43,9 +38,6 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
    public static final String STORE_APP_NAME = "Play Store";
    public static final String GMAIL_APP_NAME = "Gmail";

    @Rule
    public TISBindRule mTISBindRule = new TISBindRule();

    @Before
    public void setUp() throws Exception {
        super.setUp();
@@ -91,30 +83,6 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
        mLauncher.goHome();
    }

    public static void runIconLaunchFromAllAppsTest(AbstractLauncherUiTest test, AllApps allApps) {
        allApps.freeze();
        try {
            final AppIcon app = allApps.getAppIcon("TestActivity7");
            assertNotNull("AppIcon.launch returned null", app.launch(getAppPackageName()));
            test.executeOnLauncher(launcher -> assertTrue(
                    "Launcher activity is the top activity; expecting another activity to be the "
                            + "top one",
                    test.isInLaunchedApp(launcher)));
        } finally {
            allApps.unfreeze();
        }
    }

    @Test
    @PortraitLandscape
    public void testAppIconLaunchFromAllAppsFromHome() throws Exception {
        final HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
        assertTrue("Launcher internal state is not All Apps",
                isInState(() -> LauncherState.ALL_APPS));

        runIconLaunchFromAllAppsTest(this, allApps);
    }

    @Test
    @PortraitLandscape
    public void testAddDeleteShortcutOnHotseat() {
@@ -126,16 +94,4 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
        mLauncher.getWorkspace().deleteAppIcon(
                mLauncher.getWorkspace().getHotseatAppIcon(APP_NAME));
    }

    @Test
    public void testGetAppIconName() {
        HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
        allApps.freeze();
        try {
            // getAppIcon() already verifies that the icon is not null and is the correct icon name.
            allApps.getAppIcon(APP_NAME);
        } finally {
            allApps.unfreeze();
        }
    }
}
+0 −81
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.util.rule;

import android.app.UiAutomation;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class TISBindRule implements TestRule {
    public static String TAG = "TISBindRule";
    public static String INTENT_FILTER = "android.intent.action.QUICKSTEP_SERVICE";
    public static String TIS_PERMISSIONS = "android.permission.STATUS_BAR_SERVICE";

    private String getLauncherPackageName(Context context) {
        return ComponentName.unflattenFromString(context.getString(
                com.android.internal.R.string.config_recentsComponentName)).getPackageName();
    }

    private ServiceConnection createConnection() {
        return new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                Log.d(TAG, "Connected to TouchInteractionService");
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {
                Log.d(TAG, "Disconnected from TouchInteractionService");
            }
        };
    }

    @NonNull
    @Override
    public Statement apply(@NonNull Statement base, @NonNull Description description) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
                final ServiceConnection connection = createConnection();
                UiAutomation uiAutomation =
                        InstrumentationRegistry.getInstrumentation().getUiAutomation();
                uiAutomation.adoptShellPermissionIdentity(TIS_PERMISSIONS);
                Intent launchIntent = new Intent(INTENT_FILTER);
                launchIntent.setPackage(getLauncherPackageName(context));
                context.bindService(launchIntent, connection, Context.BIND_AUTO_CREATE);
                uiAutomation.dropShellPermissionIdentity();
                try {
                    base.evaluate();
                } finally {
                    context.unbindService(connection);
                }
            }
        };
    }
}