1 /* 2 * Copyright (C) 2017 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.uibench.janktests; 18 19 import android.os.Bundle; 20 import android.support.test.jank.GfxMonitor; 21 import android.support.test.jank.GfxFrameStatsMonitor; 22 import android.support.test.jank.JankTest; 23 import android.support.test.jank.JankTestBase; 24 import android.support.test.uiautomator.UiDevice; 25 import android.text.TextUtils; 26 import android.view.KeyEvent; 27 28 import static com.android.uibench.janktests.UiBenchJankTestsHelper.SHORT_EXPECTED_FRAMES; 29 import static com.android.uibench.janktests.UiBenchJankTestsHelper.PACKAGE_NAME; 30 31 import java.lang.annotation.ElementType; 32 import java.lang.annotation.Retention; 33 import java.lang.annotation.RetentionPolicy; 34 import java.lang.annotation.Target; 35 import java.lang.reflect.Constructor; 36 import java.lang.reflect.InvocationTargetException; 37 import java.lang.reflect.Method; 38 import java.lang.reflect.Modifier; 39 40 /** 41 * Jank benchmark tests for leanback 42 */ 43 public class UiBenchLeanbackJankTests extends JankTestBase { 44 45 public static final String EXTRA_BITMAP_UPLOAD = "extra_bitmap_upload"; 46 public static final String EXTRA_SHOW_FAST_LANE = "extra_show_fast_lane"; 47 48 /** Annotation for test option */ 49 @Retention(RetentionPolicy.RUNTIME) 50 @Target(ElementType.METHOD) 51 public @interface Option { 52 /** 53 * Name of the activity to launch "e.g. "leanback.BrowseActivity" 54 */ activity()55 String activity(); 56 57 /** 58 * Bitmap upload is enabled 59 */ extraBitmapUpload()60 boolean extraBitmapUpload() default true; 61 62 /** 63 * Initially show fast lane 64 */ extraShowFastLane()65 boolean extraShowFastLane() default true; 66 67 /** 68 * Expected text component indicate the activity is loaded 69 */ expectedText()70 String expectedText() default "Row"; 71 } 72 73 protected UiDevice mDevice; 74 protected UiBenchJankTestsHelper mHelper; 75 76 @Override setUp()77 public void setUp() throws Exception { 78 super.setUp(); 79 mDevice = UiDevice.getInstance(getInstrumentation()); 80 mDevice.setOrientationNatural(); 81 mHelper = UiBenchJankTestsHelper.getInstance( 82 this.getInstrumentation().getContext(), mDevice); 83 } 84 85 @Override tearDown()86 protected void tearDown() throws Exception { 87 mDevice.unfreezeRotation(); 88 super.tearDown(); 89 } 90 scrollDownAndUp()91 void scrollDownAndUp() { 92 for (int i = 0; i < 3; i++) { 93 mHelper.pressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN); 94 } 95 for (int i = 0; i < 3; i++) { 96 mHelper.pressKeyCode(KeyEvent.KEYCODE_DPAD_UP); 97 } 98 } 99 100 @Override beforeTest()101 public void beforeTest() throws Exception { 102 Method method = getClass().getMethod(getName()); 103 Option option = method.getAnnotation(Option.class); 104 Bundle extrasBundle = new Bundle(); 105 extrasBundle.putBoolean(EXTRA_BITMAP_UPLOAD, option.extraBitmapUpload()); 106 extrasBundle.putBoolean(EXTRA_SHOW_FAST_LANE, option.extraShowFastLane()); 107 mHelper.launchActivity(option.activity(), extrasBundle, option.expectedText()); 108 } 109 110 /** 111 * Vertically scroll BrowseFragment in the fast lane 112 */ 113 @JankTest(expectedFrames = SHORT_EXPECTED_FRAMES) 114 @Option(activity = "leanback.BrowseActivity") 115 @GfxMonitor(processName = PACKAGE_NAME) 116 @GfxFrameStatsMonitor(processName = PACKAGE_NAME) testBrowseFastLaneScroll()117 public void testBrowseFastLaneScroll() { 118 scrollDownAndUp(); 119 } 120 121 /** 122 * Vertically scroll BrowseFragment in the content (fast lane closed) 123 */ 124 @JankTest(expectedFrames = SHORT_EXPECTED_FRAMES) 125 @Option(activity = "leanback.BrowseActivity", extraShowFastLane = false) 126 @GfxMonitor(processName = PACKAGE_NAME) 127 @GfxFrameStatsMonitor(processName = PACKAGE_NAME) testBrowseContentScroll()128 public void testBrowseContentScroll() { 129 scrollDownAndUp(); 130 } 131 132 /** 133 * Vertically scroll BrowseFragment in the fast lane 134 * option: no bitmap upload 135 */ 136 @JankTest(expectedFrames = SHORT_EXPECTED_FRAMES) 137 @Option(activity = "leanback.BrowseActivity", extraBitmapUpload = false) 138 @GfxMonitor(processName = PACKAGE_NAME) 139 @GfxFrameStatsMonitor(processName = PACKAGE_NAME) testBrowseFastLaneScrollNoBitmapUpload()140 public void testBrowseFastLaneScrollNoBitmapUpload() { 141 scrollDownAndUp(); 142 } 143 144 /** 145 * Vertically scroll BrowseFragment in the content (fast lane closed) 146 * option: no bitmap upload 147 */ 148 @JankTest(expectedFrames = SHORT_EXPECTED_FRAMES) 149 @Option(activity = "leanback.BrowseActivity", extraBitmapUpload = false, 150 extraShowFastLane = false) 151 @GfxMonitor(processName = PACKAGE_NAME) 152 @GfxFrameStatsMonitor(processName = PACKAGE_NAME) testBrowseContentScrollNoBitmapUpload()153 public void testBrowseContentScrollNoBitmapUpload() { 154 scrollDownAndUp(); 155 } 156 157 } 158