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 Rendering tests for UiBench app 41 */ 42 43 public class UiBenchRenderingJankTests 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 mDevice.setOrientationNatural(); 53 mHelper = UiBenchJankTestsHelper.getInstance(mDevice, 54 this.getInstrumentation().getContext()); 55 } 56 57 @Override 58 protected void tearDown() throws Exception { 59 mDevice.unfreezeRotation(); 60 super.tearDown(); 61 } 62 63 // Open Rendering Components 64 public void openRenderingComponents(String componentName) { 65 mHelper.launchUiBench(); 66 mHelper.openTextInList("Rendering"); 67 mHelper.openTextInList(componentName); 68 } 69 70 // Open Bitmap Upload 71 public void openBitmapUpload() { 72 openRenderingComponents("Bitmap Upload"); 73 } 74 75 // Test Bitmap Upload jank 76 @JankTest(beforeTest="openBitmapUpload", afterTest="goBackHome", 77 expectedFrames=EXPECTED_FRAMES) 78 @GfxMonitor(processName=PACKAGE_NAME) 79 public void testBitmapUploadJank() { 80 SystemClock.sleep(mHelper.LONG_TIMEOUT); 81 } 82 83 // Open Shadow Grid 84 public void openRenderingList() { 85 openRenderingComponents("Shadow Grid"); 86 } 87 88 // Test Shadow Grid fling 89 @JankTest(beforeTest="openRenderingList", afterTest="goBackHome", 90 expectedFrames=EXPECTED_FRAMES) 91 @GfxMonitor(processName=PACKAGE_NAME) 92 public void testShadowGridListFling() { 93 UiObject2 shadowGridContents = mDevice.wait(Until.findObject( 94 By.clazz(ListView.class)), mHelper.TIMEOUT); 95 Assert.assertNotNull("Shadow Grid list isn't found", shadowGridContents); 96 97 for (int i = 0; i < mHelper.INNER_LOOP; i++) { 98 shadowGridContents = mDevice.wait(Until.findObject( 99 By.clazz(ListView.class)), mHelper.TIMEOUT); 100 shadowGridContents.fling(Direction.DOWN, 5000); 101 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 102 shadowGridContents = mDevice.wait(Until.findObject( 103 By.clazz(ListView.class)), mHelper.TIMEOUT); 104 shadowGridContents.fling(Direction.UP, 5000); 105 SystemClock.sleep(mHelper.SHORT_TIMEOUT); 106 } 107 } 108 109 // Ensuring that we head back to the first screen before launching the app again 110 public void goBackHome(Bundle metrics) throws UiObjectNotFoundException { 111 mHelper.goBackHome(); 112 super.afterTest(metrics); 113 } 114 } 115