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 org.junit.Assert.assertNotNull; 19 20 import android.platform.test.annotations.PlatinumTest; 21 22 import androidx.test.ext.junit.runners.AndroidJUnit4; 23 import androidx.test.filters.LargeTest; 24 25 import com.android.launcher3.Launcher; 26 import com.android.launcher3.celllayout.FavoriteItemsTransaction; 27 import com.android.launcher3.tapl.Widget; 28 import com.android.launcher3.tapl.WidgetResizeFrame; 29 import com.android.launcher3.ui.AbstractLauncherUiTest; 30 import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape; 31 import com.android.launcher3.ui.TestViewHelpers; 32 import com.android.launcher3.util.TestUtil; 33 import com.android.launcher3.util.rule.ShellCommandRule; 34 import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; 35 36 import org.junit.Assume; 37 import org.junit.Rule; 38 import org.junit.Test; 39 import org.junit.runner.RunWith; 40 41 /** 42 * Test to add widget from widget tray 43 */ 44 @LargeTest 45 @RunWith(AndroidJUnit4.class) 46 public class TaplAddWidgetTest extends AbstractLauncherUiTest<Launcher> { 47 48 @Rule 49 public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); 50 51 @Test 52 @PortraitLandscape testDragIcon()53 public void testDragIcon() throws Throwable { 54 commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext)); 55 56 waitForLauncherCondition("Workspace didn't finish loading", l -> !l.isWorkspaceLoading()); 57 58 final LauncherAppWidgetProviderInfo widgetInfo = 59 TestViewHelpers.findWidgetProvider(false /* hasConfigureScreen */); 60 61 WidgetResizeFrame resizeFrame = mLauncher 62 .getWorkspace() 63 .openAllWidgets() 64 .getWidget(widgetInfo.getLabel()) 65 .dragWidgetToWorkspace(); 66 67 assertNotNull("Widget resize frame not shown after widget add", resizeFrame); 68 resizeFrame.dismiss(); 69 70 final Widget widget = mLauncher.getWorkspace().tryGetWidget(widgetInfo.label, 71 TestUtil.DEFAULT_UI_TIMEOUT); 72 assertNotNull("Widget not found on the workspace", widget); 73 widget.launch(getAppPackageName()); 74 } 75 76 /** 77 * Test dragging a custom shortcut to the workspace and launch it. 78 * 79 * A custom shortcut is a 1x1 widget that launches a specific intent when user tap on it. 80 * Custom shortcuts are replaced by deep shortcuts after api 25. 81 */ 82 @Test 83 @PortraitLandscape testDragCustomShortcut()84 public void testDragCustomShortcut() throws Throwable { 85 // TODO(b/322820039): Enable test for tablets - the picker UI has changed and test needs to 86 // be updated to look for appropriate UI elements. 87 Assume.assumeFalse(mLauncher.isTablet()); 88 commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext)); 89 90 mLauncher.getWorkspace().openAllWidgets() 91 .getWidget("com.android.launcher3.testcomponent.CustomShortcutConfigActivity") 92 .dragToWorkspace(false, true); 93 mLauncher.getWorkspace().getWorkspaceAppIcon("Shortcut") 94 .launch(getAppPackageName()); 95 } 96 97 /** 98 * Test dragging a widget to the workspace and resize it. 99 */ 100 @PlatinumTest(focusArea = "launcher") 101 @Test testResizeWidget()102 public void testResizeWidget() throws Throwable { 103 commitTransactionAndLoadHome(new FavoriteItemsTransaction(mTargetContext)); 104 105 waitForLauncherCondition("Workspace didn't finish loading", l -> !l.isWorkspaceLoading()); 106 107 final LauncherAppWidgetProviderInfo widgetInfo = 108 TestViewHelpers.findWidgetProvider(false /* hasConfigureScreen */); 109 110 WidgetResizeFrame resizeFrame = mLauncher 111 .getWorkspace() 112 .openAllWidgets() 113 .getWidget(widgetInfo.getLabel()) 114 .dragWidgetToWorkspace(); 115 116 assertNotNull("Widget resize frame not shown after widget add", resizeFrame); 117 resizeFrame.resize(); 118 } 119 } 120