1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.quickstep; 18 19 import static com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON; 20 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assume.assumeTrue; 23 24 import android.app.Instrumentation; 25 26 import androidx.test.filters.LargeTest; 27 import androidx.test.platform.app.InstrumentationRegistry; 28 import androidx.test.runner.AndroidJUnit4; 29 30 import com.android.launcher3.tapl.LauncherInstrumentation.TrackpadGestureType; 31 import com.android.launcher3.tapl.Workspace; 32 import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape; 33 import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch; 34 35 import org.junit.After; 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 40 @LargeTest 41 @RunWith(AndroidJUnit4.class) 42 public class TaplTestsTrackpad extends AbstractQuickStepTest { 43 44 private static final String READ_DEVICE_CONFIG_PERMISSION = 45 "android.permission.READ_DEVICE_CONFIG"; 46 47 @Before setup()48 public void setup() { 49 mLauncher.injectFakeTrackpad(); 50 } 51 52 @After tearDown()53 public void tearDown() { 54 mLauncher.ejectFakeTrackpad(); 55 mLauncher.setTrackpadGestureType(TrackpadGestureType.NONE); 56 } 57 58 @Test 59 @PortraitLandscape 60 @NavigationModeSwitch goHome()61 public void goHome() throws Exception { 62 assumeTrue(mLauncher.isTablet()); 63 64 mLauncher.setTrackpadGestureType(TrackpadGestureType.THREE_FINGER); 65 startTestActivity(2); 66 mLauncher.goHome(); 67 } 68 69 @Test 70 @PortraitLandscape 71 // TODO(b/291944684): Support back in 3-button mode. It requires triggering the logic to enable 72 // trackpad gesture back in SysUI. Normally it's triggered by the attachment of a trackpad. We 73 // need to figure out a way to emulate that in the test, or bypass the logic altogether. 74 @NavigationModeSwitch(mode = ZERO_BUTTON) pressBack()75 public void pressBack() throws Exception { 76 assumeTrue(mLauncher.isTablet()); 77 Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 78 79 try { 80 instrumentation.getUiAutomation().adoptShellPermissionIdentity( 81 READ_DEVICE_CONFIG_PERMISSION); 82 mLauncher.setTrackpadGestureType(TrackpadGestureType.THREE_FINGER); 83 84 startTestActivity(2); 85 mLauncher.getLaunchedAppState().pressBackToWorkspace(); 86 } finally { 87 instrumentation.getUiAutomation().dropShellPermissionIdentity(); 88 } 89 } 90 91 @Test 92 @PortraitLandscape 93 @NavigationModeSwitch switchToOverview()94 public void switchToOverview() throws Exception { 95 assumeTrue(mLauncher.isTablet()); 96 97 mLauncher.setTrackpadGestureType(TrackpadGestureType.THREE_FINGER); 98 startTestActivity(2); 99 mLauncher.goHome().switchToOverview(); 100 } 101 102 @Test 103 @PortraitLandscape 104 @NavigationModeSwitch testAllAppsFromHome()105 public void testAllAppsFromHome() throws Exception { 106 assumeTrue(mLauncher.isTablet()); 107 108 mLauncher.setTrackpadGestureType(TrackpadGestureType.TWO_FINGER); 109 assertNotNull("switchToAllApps() returned null", 110 mLauncher.getWorkspace().switchToAllApps()); 111 } 112 113 @Test 114 @PortraitLandscape 115 @NavigationModeSwitch testQuickSwitchFromHome()116 public void testQuickSwitchFromHome() throws Exception { 117 assumeTrue(mLauncher.isTablet()); 118 119 startTestActivity(2); 120 Workspace workspace = mLauncher.goHome(); 121 mLauncher.setTrackpadGestureType(TrackpadGestureType.FOUR_FINGER); 122 workspace.quickSwitchToPreviousApp(); 123 assertTestActivityIsRunning(2, 124 "The most recent task is not running after quick switching from home"); 125 getAndAssertLaunchedApp(); 126 } 127 } 128