• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.launcher3.ui.widget;
17 
18 import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL;
19 import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT;
20 
21 import static org.junit.Assert.assertNotNull;
22 
23 import android.platform.test.annotations.PlatinumTest;
24 
25 import androidx.test.ext.junit.runners.AndroidJUnit4;
26 import androidx.test.filters.LargeTest;
27 
28 import com.android.launcher3.Launcher;
29 import com.android.launcher3.celllayout.FavoriteItemsTransaction;
30 import com.android.launcher3.tapl.Widget;
31 import com.android.launcher3.tapl.WidgetResizeFrame;
32 import com.android.launcher3.ui.AbstractLauncherUiTest;
33 import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
34 import com.android.launcher3.ui.TestViewHelpers;
35 import com.android.launcher3.util.rule.ShellCommandRule;
36 import com.android.launcher3.util.rule.TestStabilityRule.Stability;
37 import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
38 
39 import org.junit.Assume;
40 import org.junit.Rule;
41 import org.junit.Test;
42 import org.junit.runner.RunWith;
43 
44 /**
45  * Test to add widget from widget tray
46  */
47 @LargeTest
48 @RunWith(AndroidJUnit4.class)
49 public class TaplAddWidgetTest extends AbstractLauncherUiTest<Launcher> {
50 
51     @Rule
52     public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
53 
54     @Test
55     @PortraitLandscape
testDragIcon()56     public void testDragIcon() throws Throwable {
57         mLauncher.enableDebugTracing(); // b/289161193
58         commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext));
59 
60         waitForLauncherCondition("Workspace didn't finish loading", l -> !l.isWorkspaceLoading());
61 
62         final LauncherAppWidgetProviderInfo widgetInfo =
63                 TestViewHelpers.findWidgetProvider(false /* hasConfigureScreen */);
64 
65         WidgetResizeFrame resizeFrame = mLauncher
66                 .getWorkspace()
67                 .openAllWidgets()
68                 .getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager()))
69                 .dragWidgetToWorkspace();
70 
71         assertNotNull("Widget resize frame not shown after widget add", resizeFrame);
72         resizeFrame.dismiss();
73 
74         final Widget widget = mLauncher.getWorkspace().tryGetWidget(widgetInfo.label,
75                 DEFAULT_UI_TIMEOUT);
76         assertNotNull("Widget not found on the workspace", widget);
77         widget.launch(getAppPackageName());
78         mLauncher.disableDebugTracing(); // b/289161193
79     }
80 
81     /**
82      * Test dragging a custom shortcut to the workspace and launch it.
83      *
84      * A custom shortcut is a 1x1 widget that launches a specific intent when user tap on it.
85      * Custom shortcuts are replaced by deep shortcuts after api 25.
86      */
87     @Test
88     @PortraitLandscape
testDragCustomShortcut()89     public void testDragCustomShortcut() throws Throwable {
90         // TODO(b/322820039): Enable test for tablets - the picker UI has changed and test needs to
91         //  be updated to look for appropriate UI elements.
92         Assume.assumeFalse(mLauncher.isTablet());
93         commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext));
94 
95         mLauncher.getWorkspace().openAllWidgets()
96                 .getWidget("com.android.launcher3.testcomponent.CustomShortcutConfigActivity")
97                 .dragToWorkspace(false, true);
98         mLauncher.getWorkspace().getWorkspaceAppIcon("Shortcut")
99                 .launch(getAppPackageName());
100     }
101 
102     /**
103      * Test dragging a widget to the workspace and resize it.
104      */
105     @Stability(flavors = LOCAL | PLATFORM_POSTSUBMIT) // b/316910614
106     @PlatinumTest(focusArea = "launcher")
107     @Test
testResizeWidget()108     public void testResizeWidget() throws Throwable {
109         commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext));
110 
111         waitForLauncherCondition("Workspace didn't finish loading", l -> !l.isWorkspaceLoading());
112 
113         final LauncherAppWidgetProviderInfo widgetInfo =
114                 TestViewHelpers.findWidgetProvider(false /* hasConfigureScreen */);
115 
116         WidgetResizeFrame resizeFrame = mLauncher
117                 .getWorkspace()
118                 .openAllWidgets()
119                 .getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager()))
120                 .dragWidgetToWorkspace();
121 
122         assertNotNull("Widget resize frame not shown after widget add", resizeFrame);
123         resizeFrame.resize();
124     }
125 }
126