Home | History | Annotate | Download | only in ui
      1 package com.android.launcher3.ui;
      2 
      3 import android.content.pm.LauncherActivityInfo;
      4 import android.graphics.Point;
      5 import android.support.test.filters.LargeTest;
      6 import android.support.test.runner.AndroidJUnit4;
      7 import android.support.test.uiautomator.By;
      8 import android.support.test.uiautomator.UiObject2;
      9 import android.support.test.uiautomator.Until;
     10 import android.view.MotionEvent;
     11 
     12 import com.android.launcher3.R;
     13 import com.android.launcher3.util.Condition;
     14 import com.android.launcher3.util.Wait;
     15 import com.android.launcher3.util.rule.LauncherActivityRule;
     16 import com.android.launcher3.util.rule.ShellCommandRule;
     17 
     18 import org.junit.Rule;
     19 import org.junit.Test;
     20 import org.junit.runner.RunWith;
     21 
     22 import static org.junit.Assert.assertNotNull;
     23 import static org.junit.Assert.assertTrue;
     24 
     25 /**
     26  * Test for verifying that shortcuts are shown and can be launched after long pressing an app
     27  */
     28 @LargeTest
     29 @RunWith(AndroidJUnit4.class)
     30 public class ShortcutsLaunchTest extends AbstractLauncherUiTest {
     31 
     32     @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
     33     @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher();
     34 
     35     @Test
     36     public void testAppLauncher_portrait() throws Exception {
     37         lockRotation(true);
     38         performTest();
     39     }
     40 
     41     @Test
     42     public void testAppLauncher_landscape() throws Exception {
     43         lockRotation(false);
     44         performTest();
     45     }
     46 
     47     private void performTest() throws Exception {
     48         mActivityMonitor.startLauncher();
     49         LauncherActivityInfo settingsApp = getSettingsApp();
     50 
     51         // Open all apps and wait for load complete
     52         final UiObject2 appsContainer = openAllApps();
     53         assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));
     54 
     55         // Find settings app and verify shortcuts appear when long pressed
     56         UiObject2 icon = scrollAndFind(appsContainer, By.text(settingsApp.getLabel().toString()));
     57         // Press icon center until shortcuts appear
     58         Point iconCenter = icon.getVisibleCenter();
     59         sendPointer(MotionEvent.ACTION_DOWN, iconCenter);
     60         UiObject2 deepShortcutsContainer = findViewById(R.id.deep_shortcuts_container);
     61         assertNotNull(deepShortcutsContainer);
     62         sendPointer(MotionEvent.ACTION_UP, iconCenter);
     63 
     64         // Verify that launching a shortcut opens a page with the same text
     65         assertTrue(deepShortcutsContainer.getChildCount() > 0);
     66         UiObject2 shortcut = deepShortcutsContainer.getChildren().get(0)
     67                 .findObject(getSelectorForId(R.id.bubble_text));
     68         shortcut.click();
     69         assertTrue(mDevice.wait(Until.hasObject(By.pkg(
     70                 settingsApp.getComponentName().getPackageName())
     71                 .text(shortcut.getText())), DEFAULT_UI_TIMEOUT));
     72     }
     73 }
     74