• 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 org.junit.Assert.assertTrue;
19 
20 import androidx.test.filters.LargeTest;
21 import androidx.test.runner.AndroidJUnit4;
22 import androidx.test.uiautomator.By;
23 import androidx.test.uiautomator.UiObject2;
24 import android.view.View;
25 
26 import com.android.launcher3.ItemInfo;
27 import com.android.launcher3.LauncherAppWidgetInfo;
28 import com.android.launcher3.LauncherAppWidgetProviderInfo;
29 import com.android.launcher3.Workspace.ItemOperator;
30 import com.android.launcher3.ui.AbstractLauncherUiTest;
31 import com.android.launcher3.ui.TestViewHelpers;
32 import com.android.launcher3.util.Condition;
33 import com.android.launcher3.util.Wait;
34 import com.android.launcher3.util.rule.ShellCommandRule;
35 import com.android.launcher3.widget.WidgetCell;
36 
37 import org.junit.Ignore;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 
42 /**
43  * Test to add widget from widget tray
44  */
45 @LargeTest
46 @RunWith(AndroidJUnit4.class)
47 public class AddWidgetTest extends AbstractLauncherUiTest {
48 
49     @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
50 
51     @Test
testDragIcon_portrait()52     public void testDragIcon_portrait() throws Throwable {
53         lockRotation(true);
54         performTest();
55     }
56 
57     @Test
58     @Ignore // b/121280703
testDragIcon_landscape()59     public void testDragIcon_landscape() throws Throwable {
60         lockRotation(false);
61         performTest();
62     }
63 
64     // Convert to TAPL b/131116002
performTest()65     private void performTest() throws Throwable {
66         clearHomescreen();
67         mActivityMonitor.startLauncher();
68 
69         final LauncherAppWidgetProviderInfo widgetInfo =
70                 TestViewHelpers.findWidgetProvider(this, false /* hasConfigureScreen */);
71 
72         // Open widget tray and wait for load complete.
73         final UiObject2 widgetContainer = TestViewHelpers.openWidgetsTray();
74         Wait.atMost(null, Condition.minChildCount(widgetContainer, 2), DEFAULT_UI_TIMEOUT);
75 
76         // Drag widget to homescreen
77         UiObject2 widget = scrollAndFind(widgetContainer, By.clazz(WidgetCell.class)
78                 .hasDescendant(By.text(widgetInfo.getLabel(mTargetContext.getPackageManager()))));
79         TestViewHelpers.dragToWorkspace(widget, false);
80 
81         assertTrue(mActivityMonitor.itemExists(new ItemOperator() {
82             @Override
83             public boolean evaluate(ItemInfo info, View view) {
84                 return info instanceof LauncherAppWidgetInfo &&
85                         ((LauncherAppWidgetInfo) info).providerName.getClassName().equals(
86                                 widgetInfo.provider.getClassName());
87             }
88         }).call());
89     }
90 }
91