UiBench Jank Tests adapted for clockwork
Change-Id: I533cdcf6bdd2fd09858e8a70e2b0d322cd2707fb
diff --git a/tests/jank/uibench_wear/Android.mk b/tests/jank/uibench_wear/Android.mk
new file mode 100644
index 0000000..b21a640
--- /dev/null
+++ b/tests/jank/uibench_wear/Android.mk
@@ -0,0 +1,26 @@
+# Copyright 2015 Google Inc. All Rights Reserved.
+#
+# 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.
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := UiBenchJankTestsWear
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator ub-janktesthelper
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/jank/uibench_wear/AndroidManifest.xml b/tests/jank/uibench_wear/AndroidManifest.xml
new file mode 100644
index 0000000..9e71e81
--- /dev/null
+++ b/tests/jank/uibench_wear/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.wearable.uibench.janktests">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.wearable.uibench.janktests"
+ android:label="Wearable Platform UiBench Jank Tests" />
+</manifest>
diff --git a/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchJankTests.java b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchJankTests.java
new file mode 100644
index 0000000..de8c4fc
--- /dev/null
+++ b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchJankTests.java
@@ -0,0 +1,242 @@
+/*
+ * 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.wearable.uibench.janktests;
+
+import android.content.Intent;
+import android.os.Bundle;
+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.uiautomator.By;
+import android.support.test.uiautomator.Direction;
+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.ListView;
+
+import com.android.wearable.uibench.janktests.UiBenchJankTestsHelper;
+import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.PACKAGE_NAME;
+import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.EXPECTED_FRAMES;
+import junit.framework.Assert;
+
+/**
+ * Jank benchmark General tests for UiBench app
+ */
+
+public class UiBenchJankTests extends JankTestBase {
+
+ private UiDevice mDevice;
+ private UiBenchJankTestsHelper mHelper;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mDevice = UiDevice.getInstance(getInstrumentation());
+ mHelper = UiBenchJankTestsHelper.getInstance(mDevice,
+ this.getInstrumentation().getContext());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ // Open General Components
+ public void openGeneralComponents(String componentName) {
+ mHelper.launchUiBench();
+ mHelper.openTextInList("General");
+ mHelper.openTextInList(componentName);
+ }
+
+ // Open Fullscreen Overdraw from General
+ public void openFullscreenOverdraw() {
+ openGeneralComponents("Fullscreen Overdraw");
+ }
+
+ // Measure fullscreen overdraw jank
+ @JankTest(beforeTest="openFullscreenOverdraw", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testFullscreenOverdraw() {
+ UiObject2 fullscreenOverdrawScreen = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ Assert.assertNotNull("Fullscreen Overdraw isn't found", fullscreenOverdrawScreen);
+ SystemClock.sleep(mHelper.LONG_TIMEOUT);
+ }
+
+ // Open GL TextureView from General
+ public void openGLTextureView() {
+ openGeneralComponents("GL TextureView");
+ }
+
+ // Measure GL TextureView jank metrics
+ @JankTest(beforeTest="openGLTextureView", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testGLTextureView() {
+ SystemClock.sleep(mHelper.LONG_TIMEOUT);
+ }
+
+ // Open Invalidate from General
+ public void openInvalidate() {
+ openGeneralComponents("Invalidate");
+ }
+
+ // Measure Invalidate jank metrics
+ @JankTest(beforeTest="openInvalidate", afterTest="goBackHome", expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testInvalidate() {
+ UiObject2 invalidateScreen = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ Assert.assertNotNull("Invalidate screen isn't found", invalidateScreen);
+ SystemClock.sleep(mHelper.LONG_TIMEOUT);
+ }
+
+ // Open Trivial Animation from General
+ public void openTrivialAnimation() {
+ openGeneralComponents("Trivial Animation");
+ }
+
+ // Measure TrivialAnimation jank metrics
+ @JankTest(beforeTest="openTrivialAnimation", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testTrivialAnimation() {
+ UiObject2 trivialAnimationScreen = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ Assert.assertNotNull("Trivial Animation isn't found", trivialAnimationScreen);
+ SystemClock.sleep(mHelper.LONG_TIMEOUT);
+ }
+
+ // Open Trivial listview from General
+ public void openTrivialListView() {
+ openGeneralComponents("Trivial ListView");
+ }
+
+ // Test trivialListView fling
+ @JankTest(beforeTest="openTrivialListView", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testTrivialListViewFling() {
+ UiObject2 trivialListViewContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ Assert.assertNotNull("Trivial ListView isn't found in General", trivialListViewContents);
+ trivialListViewContents.setGestureMargins(mDevice.getDisplayWidth() / 2 - 40,
+ mDevice.getDisplayHeight() / 2 + 100,
+ mDevice.getDisplayWidth() / 2 + 40,
+ mDevice.getDisplayHeight() / 2 - 100);
+
+ for (int i = 0; i < mHelper.INNER_LOOP; i++) {
+ trivialListViewContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ trivialListViewContents.fling(Direction.DOWN, mHelper.CW_FLING_RATE);
+
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ trivialListViewContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ trivialListViewContents.fling(Direction.UP, mHelper.CW_FLING_RATE);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ }
+ }
+
+ // Open Trivial Recycler List View from General
+ public void openTrivialRecyclerListView() {
+ openGeneralComponents("Trivial Recycler ListView");
+ }
+
+ // Test trivialRecyclerListView fling
+ @JankTest(beforeTest="openTrivialRecyclerListView", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testTrivialRecyclerListViewFling() {
+ UiObject2 trivialRecyclerViewContents = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ Assert.assertNotNull("Trivial Recycler ListView isn't found in General",
+ trivialRecyclerViewContents);
+
+ trivialRecyclerViewContents.setGestureMargins(mDevice.getDisplayWidth() / 2 - 40,
+ mDevice.getDisplayHeight() / 2 + 100,
+ mDevice.getDisplayWidth() / 2 + 40,
+ mDevice.getDisplayHeight() / 2 - 100);
+
+ for (int i = 0; i < mHelper.INNER_LOOP; i++) {
+ trivialRecyclerViewContents = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ trivialRecyclerViewContents.fling(Direction.DOWN, mHelper.CW_FLING_RATE);
+
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ trivialRecyclerViewContents = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ trivialRecyclerViewContents.fling(Direction.UP, mHelper.CW_FLING_RATE);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ }
+ }
+
+ // Open Inflation Listview contents
+ public void openInflatingListView() {
+ mHelper.launchUiBench();
+ UiObject2 inflation = mDevice.wait(Until.findObject(
+ By.res(mHelper.RES_PACKAGE_NAME, "text1").text("Inflation")), mHelper.TIMEOUT);
+ Assert.assertNotNull("Inflation isn't found in UiBench", inflation);
+ inflation.click();
+ SystemClock.sleep(mHelper.TIMEOUT);
+ UiObject2 inflatingListView = mDevice.wait(Until.findObject(
+ By.res(mHelper.RES_PACKAGE_NAME, "text1").text("Inflating ListView")),
+ mHelper.TIMEOUT);
+ Assert.assertNotNull("Inflating ListView Contents isn't found in Inflation",
+ inflatingListView);
+ inflatingListView.click();
+ SystemClock.sleep(mHelper.TIMEOUT);
+ }
+
+ // Test Inflating List View fling
+ @JankTest(beforeTest="openInflatingListView", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testInflatingListViewFling() {
+ UiObject2 inflatingListViewContents = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ Assert.assertNotNull("Inflating ListView isn't found in Inflation",
+ inflatingListViewContents);
+
+ inflatingListViewContents.setGestureMargins(mDevice.getDisplayWidth() / 2 - 40,
+ mDevice.getDisplayHeight() / 2 + 100,
+ mDevice.getDisplayWidth() / 2 + 40,
+ mDevice.getDisplayHeight() / 2 - 100);
+
+ for (int i = 0; i < mHelper.INNER_LOOP; i++) {
+ inflatingListViewContents = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ inflatingListViewContents.fling(Direction.DOWN, mHelper.CW_FLING_RATE);
+
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ inflatingListViewContents = mDevice.wait(Until.findObject(
+ By.res("android", "content")), mHelper.TIMEOUT);
+ inflatingListViewContents.fling(Direction.UP, mHelper.CW_FLING_RATE);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ }
+ }
+
+ // Ensuring that we head back to the first screen before launching the app again
+ public void goBackHome(Bundle metrics) throws UiObjectNotFoundException {
+ mHelper.goBackHome();
+ super.afterTest(metrics);
+ }
+}
diff --git a/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchJankTestsHelper.java b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchJankTestsHelper.java
new file mode 100644
index 0000000..53876da
--- /dev/null
+++ b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchJankTestsHelper.java
@@ -0,0 +1,145 @@
+/*
+ * 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.wearable.uibench.janktests;
+
+import android.R;
+import android.content.Context;
+import android.content.Intent;
+import android.os.SystemClock;
+import android.support.test.uiautomator.By;
+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 benchmark tests helper for UiBench app
+ */
+
+public class UiBenchJankTestsHelper {
+ public static final int LONG_TIMEOUT = 5000;
+ public static final int TIMEOUT = 250;
+ public static final int SHORT_TIMEOUT = 250;
+ public static final int INNER_LOOP = 3;
+ public static final int EXPECTED_FRAMES = 100;
+ public static final int CW_FLING_RATE = 5000;
+
+ public static final String RES_PACKAGE_NAME = "android";
+ public static final String PACKAGE_NAME = "com.android.test.uibench";
+ public static final String CLOCK_BAR_NAME = "clock_bar";
+ public static final String TEXT_OBJECT_NAME = "text1";
+ public static final String UIBENCH_OBJECT_NAME = "UiBench";
+
+ private static UiBenchJankTestsHelper mInstance;
+ private UiDevice mDevice;
+ private Context mContext;
+
+ private UiBenchJankTestsHelper(UiDevice device, Context context) {
+ mDevice = device;
+ mContext = context;
+ }
+
+ public static UiBenchJankTestsHelper getInstance(UiDevice device) {
+ return new UiBenchJankTestsHelper(device, null);
+ }
+
+ public static UiBenchJankTestsHelper getInstance(UiDevice device, Context context) {
+ if (mInstance == null) {
+ mInstance = new UiBenchJankTestsHelper(device, context);
+ }
+ return mInstance;
+ }
+
+ // Launch UiBench app
+ public void launchUiBench() {
+ Intent intent = mContext.getPackageManager()
+ .getLaunchIntentForPackage(PACKAGE_NAME);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent);
+ mDevice.waitForIdle();
+ // ensure test starts from home despite last failed test left UiBench in weird state
+ UiObject2 initScreen = mDevice.wait(Until.findObject(By.text(UIBENCH_OBJECT_NAME)), 2000);
+ int counter = 3;
+ while (initScreen == null && --counter > 0) {
+ swipeRight();
+ initScreen = mDevice.wait(Until.findObject(By.text(UIBENCH_OBJECT_NAME)), 2000);
+ }
+ }
+
+ // Helper method to go back to home screen
+ public void goBackHome() throws UiObjectNotFoundException {
+
+ String launcherPackage = mDevice.getLauncherPackageName();
+ UiObject2 homeScreen = null;
+ int count = 0;
+ while (homeScreen == null && count < 5) {
+ swipeRight();
+ homeScreen = mDevice.findObject(By.res(launcherPackage,CLOCK_BAR_NAME));
+ count ++;
+ }
+ }
+
+ public void openTextInList(String itemName) {
+ int count = 0;
+ UiObject2 component = mDevice.wait(Until.findObject(
+ By.res(RES_PACKAGE_NAME, TEXT_OBJECT_NAME).text(itemName)), LONG_TIMEOUT);
+
+ while (component == null && count < 5) {
+ component = mDevice.wait(Until.findObject(
+ By.res(RES_PACKAGE_NAME, TEXT_OBJECT_NAME).text(itemName)), TIMEOUT);
+ swipeDown();
+ count ++;
+ }
+ while (component == null && count < 10) {
+ component = mDevice.wait(Until.findObject(
+ By.res(RES_PACKAGE_NAME, TEXT_OBJECT_NAME).text(itemName)), TIMEOUT);
+ swipeUp();
+ count ++;
+ }
+ Assert.assertNotNull(itemName + ": isn't found", component);
+ component.clickAndWait(Until.newWindow(), 500);
+ SystemClock.sleep(TIMEOUT);
+
+ }
+
+ public void swipeRight() {
+ mDevice.swipe(50,
+ mDevice.getDisplayHeight() / 2,
+ mDevice.getDisplayWidth() - 50,
+ mDevice.getDisplayHeight() / 2,
+ 40); // slow speed
+ }
+
+ public void swipeDown() {
+ mDevice.swipe(mDevice.getDisplayWidth() / 2,
+ mDevice.getDisplayHeight() / 2 + 100,
+ mDevice.getDisplayWidth() / 2,
+ mDevice.getDisplayHeight() / 2 - 100,
+ 40); // slow speed
+ }
+
+ public void swipeUp() {
+ mDevice.swipe(mDevice.getDisplayWidth() / 2,
+ mDevice.getDisplayHeight() / 2 - 50,
+ mDevice.getDisplayWidth() / 2,
+ mDevice.getDisplayHeight() / 2 + 100,
+ 40); // slow speed
+ }
+
+}
diff --git a/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchRenderingJankTests.java b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchRenderingJankTests.java
new file mode 100644
index 0000000..b893a0a
--- /dev/null
+++ b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchRenderingJankTests.java
@@ -0,0 +1,114 @@
+/*
+ * 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.wearable.uibench.janktests;
+
+import android.content.Intent;
+import android.os.Bundle;
+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.uiautomator.By;
+import android.support.test.uiautomator.Direction;
+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.ListView;
+
+import com.android.wearable.uibench.janktests.UiBenchJankTestsHelper;
+import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.PACKAGE_NAME;
+import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.EXPECTED_FRAMES;
+import junit.framework.Assert;
+
+/**
+ * Jank benchmark Rendering tests for UiBench app
+ */
+
+public class UiBenchRenderingJankTests extends JankTestBase {
+
+ private UiDevice mDevice;
+ private UiBenchJankTestsHelper mHelper;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mDevice = UiDevice.getInstance(getInstrumentation());
+ mDevice.setOrientationNatural();
+ mHelper = UiBenchJankTestsHelper.getInstance(mDevice,
+ this.getInstrumentation().getContext());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mDevice.unfreezeRotation();
+ super.tearDown();
+ }
+
+ // Open Rendering Components
+ public void openRenderingComponents(String componentName) {
+ mHelper.launchUiBench();
+ mHelper.openTextInList("Rendering");
+ mHelper.openTextInList(componentName);
+ }
+
+ // Open Bitmap Upload
+ public void openBitmapUpload() {
+ openRenderingComponents("Bitmap Upload");
+ }
+
+ // Test Bitmap Upload jank
+ @JankTest(beforeTest="openBitmapUpload", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testBitmapUploadJank() {
+ SystemClock.sleep(mHelper.LONG_TIMEOUT);
+ }
+
+ // Open Shadow Grid
+ public void openRenderingList() {
+ openRenderingComponents("Shadow Grid");
+ }
+
+ // Test Shadow Grid fling
+ @JankTest(beforeTest="openRenderingList", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testShadowGridListFling() {
+ UiObject2 shadowGridContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ Assert.assertNotNull("Shadow Grid list isn't found", shadowGridContents);
+
+ for (int i = 0; i < mHelper.INNER_LOOP; i++) {
+ shadowGridContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ shadowGridContents.fling(Direction.DOWN, 5000);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ shadowGridContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ shadowGridContents.fling(Direction.UP, 5000);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ }
+ }
+
+ // Ensuring that we head back to the first screen before launching the app again
+ public void goBackHome(Bundle metrics) throws UiObjectNotFoundException {
+ mHelper.goBackHome();
+ super.afterTest(metrics);
+ }
+}
diff --git a/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchTextJankTests.java b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchTextJankTests.java
new file mode 100644
index 0000000..1a2ee84
--- /dev/null
+++ b/tests/jank/uibench_wear/src/com/android/wearable/uibench/janktests/UiBenchTextJankTests.java
@@ -0,0 +1,153 @@
+/*
+ * 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.wearable.uibench.janktests;
+
+import android.content.Intent;
+import android.os.Bundle;
+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.uiautomator.By;
+import android.support.test.uiautomator.StaleObjectException;
+import android.support.test.uiautomator.Direction;
+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.ListView;
+
+import com.android.wearable.uibench.janktests.UiBenchJankTestsHelper;
+import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.PACKAGE_NAME;
+import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.EXPECTED_FRAMES;
+import junit.framework.Assert;
+
+/**
+ * Jank benchmark Text tests for UiBench app
+ */
+
+public class UiBenchTextJankTests extends JankTestBase {
+
+ private UiDevice mDevice;
+ private UiBenchJankTestsHelper mHelper;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mDevice = UiDevice.getInstance(getInstrumentation());
+ mDevice.setOrientationNatural();
+ mHelper = UiBenchJankTestsHelper.getInstance(mDevice,
+ this.getInstrumentation().getContext());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mDevice.unfreezeRotation();
+ super.tearDown();
+ }
+
+ // Open Text Components
+ public void openTextComponents(String componentName) {
+ mHelper.launchUiBench();
+ mHelper.openTextInList("Text");
+ mHelper.openTextInList(componentName);
+ }
+
+ // Open EditText Typing
+ public void openEditTextTyping() {
+ openTextComponents("EditText Typing");
+ }
+
+ // Measure jank metrics for EditText Typing
+ @JankTest(beforeTest="openEditTextTyping", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testEditTextTyping() {
+ SystemClock.sleep(mHelper.LONG_TIMEOUT);
+ }
+
+ // Open Layout Cache High Hitrate
+ public void openLayoutCacheHighHitrate() {
+ openTextComponents("Layout Cache High Hitrate");
+ }
+
+ // Test Layout Cache High Hitrate fling
+ @JankTest(beforeTest="openLayoutCacheHighHitrate", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testLayoutCacheHighHitrateFling() {
+ UiObject2 layoutCacheHighHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ Assert.assertNotNull("LayoutCacheHighHitrateContents isn't found", layoutCacheHighHitrateContents);
+
+ for (int i = 0; i < mHelper.INNER_LOOP; i++) {
+ try {
+ layoutCacheHighHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ layoutCacheHighHitrateContents.fling(Direction.DOWN, 5000);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+
+ layoutCacheHighHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ layoutCacheHighHitrateContents.fling(Direction.UP, 5000);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ } catch (StaleObjectException soex) {
+ layoutCacheHighHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ }
+ }
+ }
+
+ // Open Layout Cache Low Hitrate
+ public void openLayoutCacheLowHitrate() {
+ openTextComponents("Layout Cache Low Hitrate");
+ }
+
+ // Test Layout Cache Low Hitrate fling
+ @JankTest(beforeTest="openLayoutCacheLowHitrate", afterTest="goBackHome",
+ expectedFrames=EXPECTED_FRAMES)
+ @GfxMonitor(processName=PACKAGE_NAME)
+ public void testLayoutCacheLowHitrateFling() {
+ UiObject2 layoutCacheLowHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ Assert.assertNotNull("LayoutCacheLowHitrateContents isn't found", layoutCacheLowHitrateContents);
+
+ for (int i = 0; i < mHelper.INNER_LOOP; i++) {
+ try {
+ layoutCacheLowHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ layoutCacheLowHitrateContents.fling(Direction.DOWN, 5000);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+
+ layoutCacheLowHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ layoutCacheLowHitrateContents.fling(Direction.UP, 5000);
+ SystemClock.sleep(mHelper.SHORT_TIMEOUT);
+ } catch (StaleObjectException soex) {
+ layoutCacheLowHitrateContents = mDevice.wait(Until.findObject(
+ By.clazz(ListView.class)), mHelper.TIMEOUT);
+ }
+ }
+ }
+
+ // Ensuring that we head back to the first screen before launching the app again
+ public void goBackHome(Bundle metrics) throws UiObjectNotFoundException {
+ mHelper.goBackHome();
+ super.afterTest(metrics);
+ }
+}