1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.wearable.uibench.janktests; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.os.RemoteException; 22 import android.os.SystemClock; 23 import android.support.test.jank.GfxMonitor; 24 import android.support.test.jank.JankTest; 25 import android.support.test.jank.JankTestBase; 26 import android.support.test.uiautomator.By; 27 import android.support.test.uiautomator.Direction; 28 import android.support.test.uiautomator.UiDevice; 29 import android.support.test.uiautomator.UiObject2; 30 import android.support.test.uiautomator.UiObjectNotFoundException; 31 import android.support.test.uiautomator.Until; 32 import android.widget.ListView; 33 34 import com.android.wearable.uibench.janktests.UiBenchJankTestsHelper; 35 import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.PACKAGE_NAME; 36 import static com.android.wearable.uibench.janktests.UiBenchJankTestsHelper.EXPECTED_FRAMES; 37 import junit.framework.Assert; 38 39 /** 40 * Jank benchmark General tests for UiBench app 41 */ 42 43 public class UiBenchJankTests extends JankTestBase { 44 45 private UiDevice mDevice; 46 private UiBenchJankTestsHelper mHelper; 47 48 @Override 49 public void setUp() throws Exception { 50 super.setUp(); 51 mDevice = UiDevice.getInstance(getInstrumentation()); 52 mHelper = UiBenchJankTestsHelper.getInstance(mDevice, 53 this.getInstrumentation().getContext()); 54 mDevice.wakeUp(); 55 } 56 57 @Override 58 protected void tearDown() throws Exception { 59 super.tearDown(); 60 } 61 62 // Open General Components 63 public void openGeneralComponents(String componentName) { 64 mHelper.launchUiBench(); 65 mHelper.openTextInList("General"); 66 mHelper.openTextInList(componentName); 67 } 68 69 // Open Fullscreen Overdraw from General 70 public void openFullscreenOverdraw() { 71 openGeneralComponents("Fullscreen Overdraw"); 72 } 73 74 // Measure fullscreen overdraw jank 75 @JankTest(beforeTest="openFullscreenOverdraw", afterTest="goBackHome", 76 expectedFrames=EXPECTED_FRAMES) 77 @GfxMonitor(processName=PACKAGE_NAME) 78 public void testFullscreenOverdraw() { 79 UiObject2 fullscreenOverdrawScreen = mDevice.wait(Until.findObject( 80 By.res("android", "content")), mHelper.TIMEOUT); 81 Assert.assertNotNull("Fullscreen Overdraw isn't found", fullscreenOverdrawScreen); 82 SystemClock.sleep(mHelper.LONG_TIMEOUT); 83 } 84 85 // Open GL TextureView from General 86 public void openGLTextureView() { 87 openGeneralComponents("GL TextureView"); 88 } 89 90 // Measure GL TextureView jank metrics 91 @JankTest(beforeTest="openGLTextureView", afterTest="goBackHome", 92 expectedFrames=EXPECTED_FRAMES) 93 @GfxMonitor(processName=PACKAGE_NAME) 94 public void testGLTextureView() { 95 SystemClock.sleep(mHelper.LONG_TIMEOUT); 96 } 97 98 // Open Invalidate from General 99 public void openInvalidate() { 100 openGeneralComponents("Invalidate"); 101 } 102 103 // Measure Invalidate jank metrics 104 @JankTest(beforeTest="openInvalidate", afterTest="goBackHome", expectedFrames=EXPECTED_FRAMES) 105 @GfxMonitor(processName=PACKAGE_NAME) 106 public void testInvalidate() { 107 UiObject2 invalidateScreen = mDevice.wait(Until.findObject( 108 By.res("android", "content")), mHelper.TIMEOUT); 109 Assert.assertNotNull("Invalidate screen isn't found", invalidateScreen); 110 SystemClock.sleep(mHelper.LONG_TIMEOUT); 111 } 112 113 // Open Trivial Animation from General 114 public void openTrivialAnimation() { 115 openGeneralComponents("Trivial Animation"); 116 } 117 118 // Measure TrivialAnimation jank metrics 119 @JankTest(beforeTest="openTrivialAnimation", afterTest="goBackHome", 120 expectedFrames=EXPECTED_FRAMES) 121 @GfxMonitor(processName=PACKAGE_NAME) 122 public void testTrivialAnimation() { 123 UiObject2 trivialAnimationScreen = mDevice.wait(Until.findObject( 124 By.res("android", "content")), mHelper.TIMEOUT); 125 Assert.assertNotNull("Trivial Animation isn't found", trivialAnimationScreen); 126 SystemClock.sleep(mHelper.LONG_TIMEOUT); 127 } 128 129 // Open Trivial listview from General 130 public void openTrivialListView() { 131 openGeneralComponents("Trivial ListView"); 132 } 133 134 // Test trivialListView fling 135 @JankTest(beforeTest="openTrivialListView", afterTest="goBackHome", 136 expectedFrames=EXPECTED_FRAMES) 137 @GfxMonitor(processName=PACKAGE_NAME) 138 public void testTrivialListViewFling() { 139 UiObject2 trivialListViewContents = mDevice.wait(Until.findObject( 140 By.clazz(ListView.class)), mHelper.TIMEOUT); 141 Assert.assertNotNull("Trivial ListView isn't found in General", trivialListViewContents); 142 trivialListViewContents.setGestureMargins(mDevice.getDisplayWidth() / 2 - 40, 143 mDevice.getDisplayHeight() / 2 + 100, 144 mDevice.getDisplayWidth() / 2 + 40, 145 mDevice.getDisplayHeight() / 2 - 100); 146 147 for (int i = 0; i < mHelper.INNER_LOOP; i++) { 148 trivialListViewContents = mDevice.wait(Until.findObject( 149 By.clazz(ListView.class)), mHelper.TIMEOUT); 150 trivialListViewContents.fling(Direction.DOWN, mHelper.CW_FLING_RATE); 151 152 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 153 trivialListViewContents = mDevice.wait(Until.findObject( 154 By.clazz(ListView.class)), mHelper.TIMEOUT); 155 trivialListViewContents.fling(Direction.UP, mHelper.CW_FLING_RATE); 156 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 157 } 158 } 159 160 // Open Trivial Recycler List View from General 161 public void openTrivialRecyclerListView() { 162 openGeneralComponents("Trivial Recycler ListView"); 163 } 164 165 // Test trivialRecyclerListView fling 166 @JankTest(beforeTest="openTrivialRecyclerListView", afterTest="goBackHome", 167 expectedFrames=EXPECTED_FRAMES) 168 @GfxMonitor(processName=PACKAGE_NAME) 169 public void testTrivialRecyclerListViewFling() { 170 UiObject2 trivialRecyclerViewContents = mDevice.wait(Until.findObject( 171 By.res("android", "content")), mHelper.TIMEOUT); 172 Assert.assertNotNull("Trivial Recycler ListView isn't found in General", 173 trivialRecyclerViewContents); 174 175 trivialRecyclerViewContents.setGestureMargins(mDevice.getDisplayWidth() / 2 - 40, 176 mDevice.getDisplayHeight() / 2 + 100, 177 mDevice.getDisplayWidth() / 2 + 40, 178 mDevice.getDisplayHeight() / 2 - 100); 179 180 for (int i = 0; i < mHelper.INNER_LOOP; i++) { 181 trivialRecyclerViewContents = mDevice.wait(Until.findObject( 182 By.res("android", "content")), mHelper.TIMEOUT); 183 trivialRecyclerViewContents.fling(Direction.DOWN, mHelper.CW_FLING_RATE); 184 185 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 186 trivialRecyclerViewContents = mDevice.wait(Until.findObject( 187 By.res("android", "content")), mHelper.TIMEOUT); 188 trivialRecyclerViewContents.fling(Direction.UP, mHelper.CW_FLING_RATE); 189 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 190 } 191 } 192 193 // Open Inflation Listview contents 194 public void openInflatingListView() { 195 mHelper.launchUiBench(); 196 mHelper.openTextInList("Inflation"); 197 mHelper.openTextInList("Inflating ListView"); 198 } 199 200 // Test Inflating List View fling 201 @JankTest(beforeTest="openInflatingListView", afterTest="goBackHome", 202 expectedFrames=EXPECTED_FRAMES) 203 @GfxMonitor(processName=PACKAGE_NAME) 204 public void testInflatingListViewFling() { 205 UiObject2 inflatingListViewContents = mDevice.wait(Until.findObject( 206 By.res("android", "content")), mHelper.TIMEOUT); 207 Assert.assertNotNull("Inflating ListView isn't found in Inflation", 208 inflatingListViewContents); 209 210 inflatingListViewContents.setGestureMargins(mDevice.getDisplayWidth() / 2 - 40, 211 mDevice.getDisplayHeight() / 2 + 100, 212 mDevice.getDisplayWidth() / 2 + 40, 213 mDevice.getDisplayHeight() / 2 - 100); 214 215 for (int i = 0; i < mHelper.INNER_LOOP; i++) { 216 inflatingListViewContents = mDevice.wait(Until.findObject( 217 By.res("android", "content")), mHelper.TIMEOUT); 218 inflatingListViewContents.fling(Direction.DOWN, mHelper.CW_FLING_RATE); 219 220 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 221 inflatingListViewContents = mDevice.wait(Until.findObject( 222 By.res("android", "content")), mHelper.TIMEOUT); 223 inflatingListViewContents.fling(Direction.UP, mHelper.CW_FLING_RATE); 224 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 225 } 226 } 227 228 // Ensuring that we head back to the first screen before launching the app again 229 public void goBackHome(Bundle metrics) throws UiObjectNotFoundException { 230 mHelper.goBackHome(); 231 super.afterTest(metrics); 232 } 233 } 234