• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.ui;
2 
3 import android.support.test.uiautomator.By;
4 import android.support.test.uiautomator.UiObject2;
5 import android.test.suitebuilder.annotation.LargeTest;
6 import android.view.View;
7 
8 import com.android.launcher3.CellLayout;
9 import com.android.launcher3.ItemInfo;
10 import com.android.launcher3.Launcher;
11 import com.android.launcher3.LauncherAppWidgetInfo;
12 import com.android.launcher3.LauncherAppWidgetProviderInfo;
13 import com.android.launcher3.Workspace.ItemOperator;
14 import com.android.launcher3.util.Condition;
15 import com.android.launcher3.util.Wait;
16 import com.android.launcher3.widget.WidgetCell;
17 
18 /**
19  * Test to add widget from widget tray
20  */
21 @LargeTest
22 public class AddWidgetTest extends LauncherInstrumentationTestCase {
23 
24     private LauncherAppWidgetProviderInfo widgetInfo;
25 
26     @Override
setUp()27     protected void setUp() throws Exception {
28         super.setUp();
29 
30         widgetInfo = findWidgetProvider(false /* hasConfigureScreen */);
31     }
32 
testDragIcon_portrait()33     public void testDragIcon_portrait() throws Throwable {
34         lockRotation(true);
35         performTest();
36     }
37 
testDragIcon_landscape()38     public void testDragIcon_landscape() throws Throwable {
39         lockRotation(false);
40         performTest();
41     }
42 
performTest()43     private void performTest() throws Throwable {
44         clearHomescreen();
45         Launcher launcher = startLauncher();
46 
47         // Open widget tray and wait for load complete.
48         final UiObject2 widgetContainer = openWidgetsTray();
49         assertTrue(Wait.atMost(Condition.minChildCount(widgetContainer, 2), DEFAULT_UI_TIMEOUT));
50 
51         // Drag widget to homescreen
52         UiObject2 widget = scrollAndFind(widgetContainer, By.clazz(WidgetCell.class)
53                 .hasDescendant(By.text(widgetInfo.getLabel(mTargetContext.getPackageManager()))));
54         dragToWorkspace(widget);
55 
56         assertNotNull(launcher.getWorkspace().getFirstMatch(new ItemOperator() {
57             @Override
58             public boolean evaluate(ItemInfo info, View view) {
59                 return info instanceof LauncherAppWidgetInfo &&
60                         ((LauncherAppWidgetInfo) info).providerName.equals(widgetInfo.provider);
61             }
62         }));
63     }
64 }
65