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