1 /*
2  * Copyright (C) 2024 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.util
18 
19 import androidx.test.uiautomator.By
20 import com.android.launcher3.tapl.LauncherInstrumentation
21 import com.android.launcher3.tapl.Overview
22 import com.android.launcher3.tapl.OverviewTask
23 import com.android.launcher3.ui.AbstractLauncherUiTest
24 
25 object SplitScreenTestUtils {
26 
27     /** Creates 2 tasks and makes a split mode pair. Also asserts the accessibility labels. */
28     @JvmStatic
createAndLaunchASplitPairInOverviewnull29     fun createAndLaunchASplitPairInOverview(launcher: LauncherInstrumentation): Overview {
30         clearAllRecentTasks(launcher)
31 
32         AbstractLauncherUiTest.startTestActivity(2)
33         AbstractLauncherUiTest.startTestActivity(3)
34 
35         val overView = launcher.goHome().switchToOverview()
36         if (launcher.isTablet && !launcher.isGridOnlyOverviewEnabled) {
37             overView.overviewActions.clickSplit().getTestActivityTask(2).open()
38         } else {
39             overView.currentTask.tapMenu().tapSplitMenuItem().currentTask.open()
40         }
41 
42         val overviewWithSplitPair = launcher.goHome().switchToOverview()
43         val currentTask = overviewWithSplitPair.currentTask
44         currentTask.containsContentDescription(
45             By.pkg(AbstractLauncherUiTest.getAppPackageName()).text("TestActivity3").toString(),
46             OverviewTask.OverviewTaskContainer.SPLIT_TOP_OR_LEFT,
47         )
48         currentTask.containsContentDescription(
49             By.pkg(AbstractLauncherUiTest.getAppPackageName()).text("TestActivity2").toString(),
50             OverviewTask.OverviewTaskContainer.SPLIT_BOTTOM_OR_RIGHT,
51         )
52         return overviewWithSplitPair
53     }
54 
clearAllRecentTasksnull55     private fun clearAllRecentTasks(launcher: LauncherInstrumentation) {
56         if (launcher.recentTasks.isNotEmpty()) {
57             launcher.goHome().switchToOverview().dismissAllTasks()
58         }
59     }
60 }
61