Sysapp janktests fix launch via intent
Change-Id: I8f270252c98193eb125790ae52723316b694e8fe
diff --git a/jank/sysapp/Android.mk b/jank/sysapp/Android.mk
index 66073a7..2ba588d 100644
--- a/jank/sysapp/Android.mk
+++ b/jank/sysapp/Android.mk
@@ -19,7 +19,7 @@
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_MODULE_TAGS := tests
-LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator ub-janktesthelper launcher-helper-lib
+LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator ub-janktesthelper
LOCAK_SDK_VERSION := current
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/BooksJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/BooksJankTests.java
index 0973bc3..4406a4c 100644
--- a/jank/sysapp/src/com/android/sysapp/janktests/BooksJankTests.java
+++ b/jank/sysapp/src/com/android/sysapp/janktests/BooksJankTests.java
@@ -16,13 +16,13 @@
package com.android.sysapp.janktests;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.support.test.jank.GfxMonitor;
import android.support.test.jank.JankTest;
import android.support.test.jank.JankTestBase;
-import android.support.test.launcherhelper.ILauncherStrategy;
-import android.support.test.launcherhelper.LauncherStrategyFactory;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.Direction;
import android.support.test.uiautomator.UiDevice;
@@ -44,9 +44,7 @@
private static final int INNER_LOOP = 5;
private static final int EXPECTED_FRAMES = 100;
private static final String PACKAGE_NAME = "com.google.android.apps.books";
- private static final String APP_NAME = "Play Books";
private UiDevice mDevice;
- private ILauncherStrategy mLauncherStrategy = null;
@Override
public void setUp() throws Exception {
@@ -57,7 +55,6 @@
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
- mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
}
@Override
@@ -66,8 +63,16 @@
super.tearDown();
}
+ public void launchApp(String packageName) throws UiObjectNotFoundException{
+ PackageManager pm = getInstrumentation().getContext().getPackageManager();
+ Intent appIntent = pm.getLaunchIntentForPackage(packageName);
+ appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ getInstrumentation().getContext().startActivity(appIntent);
+ SystemClock.sleep(SHORT_TIMEOUT);
+ }
+
public void launchBooks () throws UiObjectNotFoundException {
- mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+ launchApp(PACKAGE_NAME);
dismissClings();
openMyLibrary();
Assert.assertTrue("Books haven't loaded yet", getNumberOfVisibleBooks() > 3);
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/CameraJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/CameraJankTests.java
deleted file mode 100644
index a1514cc..0000000
--- a/jank/sysapp/src/com/android/sysapp/janktests/CameraJankTests.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sysapp.janktests;
-
-import android.os.RemoteException;
-import android.support.test.jank.GfxMonitor;
-import android.support.test.jank.JankTest;
-import android.support.test.jank.JankTestBase;
-import android.support.test.launcherhelper.ILauncherStrategy;
-import android.support.test.launcherhelper.LauncherStrategyFactory;
-import android.support.test.uiautomator.By;
-import android.support.test.uiautomator.BySelector;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiObject2;
-import android.support.test.uiautomator.UiObjectNotFoundException;
-import android.support.test.uiautomator.Until;
-import android.widget.Button;
-
-import junit.framework.Assert;
-
-/**
- * Jank test for flipping front and back camera n times.
- */
-
-public class CameraJankTests extends JankTestBase {
- private static final int TIMEOUT = 3000;
- private static final int INNER_LOOP = 5;
- private static final int EXPECTED_FRAMES = 100;
- private static final String PACKAGE_NAME = "com.google.android.GoogleCamera";
- private static final String FRAMEWORK_PACKAGE_NAME = "com.android.camera2";
- private static final String APP_NAME = "Camera";
- private UiDevice mDevice;
- private ILauncherStrategy mLauncherStrategy = null;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mDevice = UiDevice.getInstance(getInstrumentation());
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientaion", e);
- }
- mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
- }
-
- @Override
- protected void tearDown() throws Exception {
- mDevice.unfreezeRotation();
- super.tearDown();
- }
-
- public void launchCamera () throws UiObjectNotFoundException {
- mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
- dismissClings();
- BySelector threeDotsSelector = By.res(
- FRAMEWORK_PACKAGE_NAME, "mode_options_toggle").desc("Options");
- UiObject2 threeDots = mDevice.wait(Until.findObject(threeDotsSelector), TIMEOUT);
- Assert.assertNotNull("Three dot icon is missing", threeDots);
- threeDots.click();
- // wait for next window to show up
- mDevice.wait(Until.gone(threeDotsSelector), TIMEOUT);
- }
-
- // Measures jank while fling YouTube recommendation
- @JankTest(beforeTest="launchCamera", expectedFrames=EXPECTED_FRAMES)
- @GfxMonitor(processName=PACKAGE_NAME)
- public void testFrontBackCameraFlip() {
- UiObject2 cameraToggle = null;
- BySelector cameraToggleSelector = By.res(FRAMEWORK_PACKAGE_NAME, "camera_toggle_button");
- for (int i = 0; i < INNER_LOOP; i++) {
- cameraToggle = mDevice.wait(Until.findObject(cameraToggleSelector), 3 * TIMEOUT);
- Assert.assertNotNull("Camera flipper icon is missing", cameraToggle);
- cameraToggle.click();
- mDevice.wait(Until.gone(cameraToggleSelector), TIMEOUT);
- }
- }
-
- private void dismissClings() {
- // Dismiss tag next screen. It's okay to timeout. These dialog screens might not exist..
- UiObject2 next = mDevice.wait(Until.findObject(
- By.clazz(Button.class).text("NEXT")), 2 * TIMEOUT);
- if (next != null) {
- next.click();
- }
- // Choose sensor size. It's okay to timeout. These dialog screens might not exist..
- UiObject2 sensor = mDevice.wait(Until.findObject(
- By.res(PACKAGE_NAME, "confirm_button").text("OK, GOT IT")), 2 * TIMEOUT);
- if (sensor != null) {
- sensor.click();
- }
- // Dismiss the photo location dialog box if exist.
- UiObject2 thanks = mDevice.wait(Until.findObject(
- By.text("No thanks")), 2 * TIMEOUT);
- if (thanks != null) {
- thanks.click();
- }
- // Dismiss dogfood dialog
- if (mDevice.wait(Until.hasObject(
- By.res(PACKAGE_NAME, "internal_release_dialog_title")), 2 * TIMEOUT)) {
- mDevice.findObject(By.res(FRAMEWORK_PACKAGE_NAME, "ok_button")).click();
- }
- }
-}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/ChromeJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/ChromeJankTests.java
index 7ef6407..f70cc0d 100644
--- a/jank/sysapp/src/com/android/sysapp/janktests/ChromeJankTests.java
+++ b/jank/sysapp/src/com/android/sysapp/janktests/ChromeJankTests.java
@@ -16,13 +16,13 @@
package com.android.sysapp.janktests;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.support.test.jank.GfxMonitor;
import android.support.test.jank.JankTest;
import android.support.test.jank.JankTestBase;
-import android.support.test.launcherhelper.ILauncherStrategy;
-import android.support.test.launcherhelper.LauncherStrategyFactory;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.Direction;
@@ -30,6 +30,7 @@
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.Until;
+
import junit.framework.Assert;
/**
@@ -43,9 +44,7 @@
private static final int INNER_LOOP = 5;
private static final int EXPECTED_FRAMES = 100;
private static final String PACKAGE_NAME = "com.android.chrome";
- private static final String APP_NAME = "Chrome";
private UiDevice mDevice;
- private ILauncherStrategy mLauncherStrategy = null;
@Override
public void setUp() throws Exception {
@@ -56,7 +55,6 @@
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
- mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
}
@Override
@@ -65,10 +63,16 @@
super.tearDown();
}
- public void launchChrome () throws UiObjectNotFoundException {
- mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
- mDevice.waitForIdle();
- // To infer that test is ready to be executed
+ public void launchApp(String packageName) throws UiObjectNotFoundException{
+ PackageManager pm = getInstrumentation().getContext().getPackageManager();
+ Intent appIntent = pm.getLaunchIntentForPackage(packageName);
+ appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ getInstrumentation().getContext().startActivity(appIntent);
+ SystemClock.sleep(SHORT_TIMEOUT);
+ }
+
+ public void launchChrome() throws UiObjectNotFoundException{
+ launchApp(PACKAGE_NAME);
getOverflowMenu();
}
@@ -85,9 +89,9 @@
}
public UiObject2 getOverflowMenu() {
- UiObject2 overflow = mDevice.wait(
- Until.findObject(By.desc("More options")), 5 * SHORT_TIMEOUT);
- Assert.assertNotNull("Failed to locate overflow menu", overflow);
- return overflow;
+ UiObject2 overflow = mDevice.wait(
+ Until.findObject(By.desc("More options")), 5 * SHORT_TIMEOUT);
+ Assert.assertNotNull("Failed to locate overflow menu", overflow);
+ return overflow;
}
}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/GMailJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/GMailJankTests.java
index 08cece5..c132a86 100644
--- a/jank/sysapp/src/com/android/sysapp/janktests/GMailJankTests.java
+++ b/jank/sysapp/src/com/android/sysapp/janktests/GMailJankTests.java
@@ -16,13 +16,13 @@
package com.android.sysapp.janktests;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.support.test.jank.GfxMonitor;
import android.support.test.jank.JankTest;
import android.support.test.jank.JankTestBase;
-import android.support.test.launcherhelper.ILauncherStrategy;
-import android.support.test.launcherhelper.LauncherStrategyFactory;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.Direction;
@@ -42,9 +42,7 @@
private static final int INNER_LOOP = 5;
private static final int EXPECTED_FRAMES = 100;
private static final String PACKAGE_NAME = "com.google.android.gm";
- private static final String APP_NAME = "Gmail";
private UiDevice mDevice;
- private ILauncherStrategy mLauncherStrategy = null;
@Override
public void setUp() throws Exception {
@@ -55,7 +53,6 @@
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
- mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
}
@Override
@@ -64,8 +61,16 @@
super.tearDown();
}
+ public void launchApp(String packageName) throws UiObjectNotFoundException{
+ PackageManager pm = getInstrumentation().getContext().getPackageManager();
+ Intent appIntent = pm.getLaunchIntentForPackage(packageName);
+ appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ getInstrumentation().getContext().startActivity(appIntent);
+ SystemClock.sleep(SHORT_TIMEOUT);
+ }
+
public void launchGMail () throws UiObjectNotFoundException {
- mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+ launchApp(PACKAGE_NAME);
dismissClings();
// Need any check for account-name??
waitForEmailSync();
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/MapsJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/MapsJankTests.java
deleted file mode 100644
index 61329db..0000000
--- a/jank/sysapp/src/com/android/sysapp/janktests/MapsJankTests.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.sysapp.janktests;
-
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.support.test.jank.GfxMonitor;
-import android.support.test.jank.JankTest;
-import android.support.test.jank.JankTestBase;
-import android.support.test.launcherhelper.ILauncherStrategy;
-import android.support.test.launcherhelper.LauncherStrategyFactory;
-import android.support.test.uiautomator.By;
-import android.support.test.uiautomator.BySelector;
-import android.support.test.uiautomator.Direction;
-import android.support.test.uiautomator.StaleObjectException;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiObject2;
-import android.support.test.uiautomator.UiObjectNotFoundException;
-import android.support.test.uiautomator.Until;
-import junit.framework.Assert;
-
-/**
- * Jank test for Map
- * click on search box to bring up ime window
- * click on back to go back to map
- */
-
-public class MapsJankTests extends JankTestBase {
- private static final int SHORT_TIMEOUT = 1000;
- private static final int LONG_TIMEOUT = 30000;
- private static final int INNER_LOOP = 5;
- private static final int EXPECTED_FRAMES = 100;
- private static final String PACKAGE_NAME = "com.google.android.apps.maps";
- public static final String RES_PACKAGE = "com.google.android.apps.gmm";
- private static final String APP_NAME = "Maps";
- private UiDevice mDevice;
- private ILauncherStrategy mLauncherStrategy = null;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- mDevice = UiDevice.getInstance(getInstrumentation());
- try {
- mDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException("failed to freeze device orientaion", e);
- }
- mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
- }
-
- @Override
- protected void tearDown() throws Exception {
- mDevice.unfreezeRotation();
- super.tearDown();
- }
-
- public void launchMaps () throws UiObjectNotFoundException {
- mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
- mDevice.waitForIdle();
- dismissCling();
- // To infer that test is ready to be executed
- int counter = 5;
- while (getSearchBox() == null && counter > 0){
- SystemClock.sleep(1000);
- --counter;
- }
- Assert.assertNotNull("Failed to find 'Search'", getSearchBox());
- }
-
-// @JankTest(beforeTest="launchMaps", expectedFrames=EXPECTED_FRAMES)
-// @GfxMonitor(processName=PACKAGE_NAME)
-// public void testMapsIMEPopupForSearchEntry() {
-// }
-
- private UiObject2 getSearchBox(){
- mDevice.wait(Until.findObject(By.desc("Search")), SHORT_TIMEOUT).click();
- UiObject2 search = mDevice.wait(Until.findObject(
- By.res(RES_PACKAGE, "search_omnibox_edit_text")), SHORT_TIMEOUT);
- if (search == null ) {
- search = mDevice.wait(Until.findObject(
- By.res(RES_PACKAGE, "search_omnibox_text_box")), SHORT_TIMEOUT);
- }
- Assert.assertNotNull("Search box is null", search);
- return search;
- }
-
- private void dismissCling(){
- // Accept terms
- UiObject2 terms = mDevice.wait(Until.findObject(By.text("Accept & continue")), 5000);
- if (terms != null) {
- terms.click();
- }
- // Enable location services
- UiObject2 location = mDevice.wait(Until.findObject(By.text("Yes, I'm in")), 5000);
- if (location != null) {
- location.click();
- }
- // Dismiss cling
- UiObject2 cling = mDevice.wait(
- Until.findObject(By.res(PACKAGE_NAME, "tapherehint_textbox")), 500);
- if (cling != null) {
- cling.click();
- }
- // Reset map view
- UiObject2 resetView = mDevice.findObject(By.res(PACKAGE_NAME, "mylocation_button"));
- if (resetView != null) {
- resetView.click();
- mDevice.waitForIdle(5000);
- }
- // dismiss yet another tutorial
- UiObject2 tutorial = mDevice.findObject(By.res(PACKAGE_NAME, "tutorial_side_menu_got_it"));
- if (tutorial != null) {
- tutorial.click();
- }
- }
-}
diff --git a/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java b/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java
index 2cfbdae..305a8ed 100644
--- a/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java
+++ b/jank/sysapp/src/com/android/sysapp/janktests/YouTubeJankTests.java
@@ -16,13 +16,13 @@
package com.android.sysapp.janktests;
+import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.support.test.jank.GfxMonitor;
import android.support.test.jank.JankTest;
import android.support.test.jank.JankTestBase;
-import android.support.test.launcherhelper.ILauncherStrategy;
-import android.support.test.launcherhelper.LauncherStrategyFactory;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.Direction;
import android.support.test.uiautomator.UiDevice;
@@ -36,14 +36,13 @@
*/
public class YouTubeJankTests extends JankTestBase {
- private static final int TIMEOUT = 5000;
+ private static final int LONG_TIMEOUT = 5000;
+ private static final int SHORT_TIMEOUT = 1000;
private static final int INNER_LOOP = 5;
private static final int EXPECTED_FRAMES = 100;
private static final String PACKAGE_NAME = "com.google.android.youtube";
- private static final String APP_NAME = "YouTube";
private UiDevice mDevice;
- private ILauncherStrategy mLauncherStrategy = null;
@Override
public void setUp() throws Exception {
@@ -54,7 +53,6 @@
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
- mLauncherStrategy = LauncherStrategyFactory.getInstance(mDevice).getLauncherStrategy();
}
@Override
@@ -63,9 +61,20 @@
super.tearDown();
}
+ public void launchApp(String packageName) throws UiObjectNotFoundException{
+ PackageManager pm = getInstrumentation().getContext().getPackageManager();
+ Intent appIntent = pm.getLaunchIntentForPackage(packageName);
+ appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ getInstrumentation().getContext().startActivity(appIntent);
+ SystemClock.sleep(SHORT_TIMEOUT);
+ }
+
public void launchYouTube () throws UiObjectNotFoundException {
- mLauncherStrategy.launch(APP_NAME, PACKAGE_NAME);
+ launchApp(PACKAGE_NAME);
dismissCling();
+ UiObject2 uiObject = mDevice.wait(
+ Until.findObject(By.res(PACKAGE_NAME, "pane_fragment_container")), LONG_TIMEOUT);
+ Assert.assertNotNull("Recommendation container is null", uiObject);
}
// Measures jank while fling YouTube recommendation
@@ -73,7 +82,7 @@
@GfxMonitor(processName=PACKAGE_NAME)
public void testYouTubeRecomendationWindowFling() {
UiObject2 uiObject = mDevice.wait(
- Until.findObject(By.res(PACKAGE_NAME, "pane_fragment_container")), TIMEOUT);
+ Until.findObject(By.res(PACKAGE_NAME, "pane_fragment_container")), LONG_TIMEOUT);
Assert.assertNotNull("Recommendation container is null", uiObject);
for (int i = 0; i < INNER_LOOP; i++) {
uiObject.scroll(Direction.DOWN, 1.0f);
@@ -85,20 +94,20 @@
private void dismissCling() {
// Dismiss the dogfood splash screen that might appear on first start
UiObject2 dialog_dismiss_btn = mDevice.wait(Until.findObject(
- By.res(PACKAGE_NAME, "dogfood_warning_dialog_dismiss_button").text("OK")), TIMEOUT);
+ By.res(PACKAGE_NAME, "dogfood_warning_dialog_dismiss_button").text("OK")), LONG_TIMEOUT);
if (dialog_dismiss_btn != null) {
dialog_dismiss_btn.click();
}
UiObject2 welcomeSkip = mDevice.wait(
- Until.findObject(By.res(PACKAGE_NAME, "skip_button").text("Skip")), TIMEOUT);
+ Until.findObject(By.res(PACKAGE_NAME, "skip_button").text("Skip")), LONG_TIMEOUT);
if (welcomeSkip != null) {
welcomeSkip.click();
}
UiObject2 musicFaster = mDevice.wait(
- Until.findObject(By.res(PACKAGE_NAME, "text").text("Find music faster")), TIMEOUT);
+ Until.findObject(By.res(PACKAGE_NAME, "text").text("Find music faster")), LONG_TIMEOUT);
if (musicFaster != null) {
UiObject2 ok = mDevice.wait(
- Until.findObject(By.res(PACKAGE_NAME, "ok").text("OK")), TIMEOUT);
+ Until.findObject(By.res(PACKAGE_NAME, "ok").text("OK")), LONG_TIMEOUT);
Assert.assertNotNull("No 'ok' button to bypass music", ok);
ok.click();
}