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