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.ui.TaplTestsLauncher3.getAppPackageName; 19 20 import static org.junit.Assert.assertNotNull; 21 import static org.junit.Assert.assertTrue; 22 23 import androidx.test.filters.LargeTest; 24 import androidx.test.runner.AndroidJUnit4; 25 26 import com.android.launcher3.model.data.LauncherAppWidgetInfo; 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.TestViewHelpers; 31 import com.android.launcher3.util.rule.ShellCommandRule; 32 import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; 33 34 import org.junit.Rule; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 38 /** 39 * Test to add widget from widget tray 40 */ 41 @LargeTest 42 @RunWith(AndroidJUnit4.class) 43 public class AddWidgetTest extends AbstractLauncherUiTest { 44 45 @Rule 46 public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); 47 48 @Test 49 @PortraitLandscape testDragIcon()50 public void testDragIcon() throws Throwable { 51 clearHomescreen(); 52 mDevice.pressHome(); 53 54 final LauncherAppWidgetProviderInfo widgetInfo = 55 TestViewHelpers.findWidgetProvider(this, false /* hasConfigureScreen */); 56 57 WidgetResizeFrame resizeFrame = mLauncher. 58 getWorkspace(). 59 openAllWidgets(). 60 getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager())). 61 dragWidgetToWorkspace(); 62 63 assertTrue(mActivityMonitor.itemExists( 64 (info, view) -> info instanceof LauncherAppWidgetInfo && 65 ((LauncherAppWidgetInfo) info).providerName.getClassName().equals( 66 widgetInfo.provider.getClassName())).call()); 67 68 assertNotNull("Widget resize frame not shown after widget add", resizeFrame); 69 resizeFrame.dismiss(); 70 71 final Widget widget = mLauncher.getWorkspace().tryGetWidget(widgetInfo.label, 72 DEFAULT_UI_TIMEOUT); 73 assertNotNull("Widget not found on the workspace", widget); 74 widget.launch(getAppPackageName()); 75 } 76 77 /** 78 * Test dragging a custom shortcut to the workspace and launch it. 79 * 80 * A custom shortcut is a 1x1 widget that launches a specific intent when user tap on it. 81 * Custom shortcuts are replaced by deep shortcuts after api 25. 82 */ 83 @Test 84 @PortraitLandscape testDragCustomShortcut()85 public void testDragCustomShortcut() throws Throwable { 86 clearHomescreen(); 87 mDevice.pressHome(); 88 mLauncher.getWorkspace().openAllWidgets() 89 .getWidget("com.android.launcher3.testcomponent.CustomShortcutConfigActivity") 90 .dragToWorkspace(false, true); 91 mLauncher.getWorkspace().getWorkspaceAppIcon("Shortcut") 92 .launch(getAppPackageName()); 93 } 94 } 95