1 /*
2  * Copyright (C) 2022 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 package com.android.quickstep;
17 
18 import static androidx.test.InstrumentationRegistry.getInstrumentation;
19 
20 import static junit.framework.TestCase.assertEquals;
21 
22 import android.content.Context;
23 import android.content.Intent;
24 
25 import com.android.launcher3.tapl.LauncherInstrumentation;
26 import com.android.launcher3.tapl.Taskbar;
27 import com.android.launcher3.ui.AbstractLauncherUiTest;
28 import com.android.launcher3.util.DisplayController;
29 import com.android.launcher3.util.LauncherLayoutBuilder;
30 import com.android.launcher3.util.TestUtil;
31 
32 import org.junit.After;
33 import org.junit.Assume;
34 
35 import java.util.List;
36 
37 public class AbstractTaplTestsTaskbar extends AbstractQuickStepTest {
38 
39     protected static final String TEST_APP_PACKAGE =
40             getInstrumentation().getContext().getPackageName();
41     protected static final String CALCULATOR_APP_PACKAGE =
42             resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR);
43 
44     protected AutoCloseable mLauncherLayout;
45     protected boolean mTaskbarWasInTransientMode;
46 
47 
48     @Override
setUp()49     public void setUp() throws Exception {
50         Assume.assumeTrue(mLauncher.isTablet());
51         super.setUp();
52 
53         LauncherLayoutBuilder layoutBuilder = new LauncherLayoutBuilder().atHotseat(0).putApp(
54                 "com.google.android.apps.nexuslauncher.tests",
55                 "com.android.launcher3.testcomponent.BaseTestingActivity");
56         mLauncherLayout = TestUtil.setLauncherDefaultLayout(mTargetContext, layoutBuilder);
57         AbstractLauncherUiTest.initialize(this);
58         startAppFast(CALCULATOR_APP_PACKAGE);
59         mLauncher.enableBlockTimeout(true);
60         mLauncher.showTaskbarIfHidden();
61     }
62 
63     @After
tearDown()64     public void tearDown() throws Exception {
65         mLauncher.enableBlockTimeout(false);
66         if (mLauncherLayout != null) {
67             mLauncherLayout.close();
68         }
69     }
70 
isTaskbarInTransientMode(Context context)71     protected static boolean isTaskbarInTransientMode(Context context) {
72         return DisplayController.isTransientTaskbar(context);
73     }
74 
getTaskbar()75     protected Taskbar getTaskbar() {
76         Taskbar taskbar = mLauncher.getLaunchedAppState().getTaskbar();
77         List<String> taskbarIconNames = taskbar.getIconNames();
78         List<String> hotseatIconNames = mLauncher.getHotseatIconNames();
79 
80         assertEquals("Taskbar and hotseat icon counts do not match",
81                 taskbarIconNames.size(), hotseatIconNames.size());
82 
83         for (int i = 0; i < taskbarIconNames.size(); i++) {
84             assertEquals("Taskbar and Hotseat icons do not match",
85                     taskbarIconNames, hotseatIconNames);
86         }
87 
88         return taskbar;
89     }
90 
setTaskbarMode(LauncherInstrumentation launcher, boolean expectTransientTaskbar)91     protected static void setTaskbarMode(LauncherInstrumentation launcher,
92             boolean expectTransientTaskbar) {
93         launcher.enableTransientTaskbar(expectTransientTaskbar);
94         launcher.recreateTaskbar();
95         launcher.checkForAnomaly(true, true);
96         AbstractLauncherUiTest.checkDetectedLeaks(launcher, true);
97     }
98 }
99