1 /* 2 * Copyright (C) 2016 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.sysapp.janktests; 18 19 import android.os.Bundle; 20 import android.os.SystemClock; 21 import android.support.test.jank.GfxMonitor; 22 import android.support.test.jank.JankTest; 23 import android.support.test.jank.JankTestBase; 24 import android.support.test.jank.WindowAnimationFrameStatsMonitor; 25 import android.support.test.uiautomator.By; 26 import android.support.test.uiautomator.Direction; 27 import android.support.test.uiautomator.UiDevice; 28 import android.support.test.uiautomator.UiObject2; 29 import android.support.test.uiautomator.Until; 30 import java.util.concurrent.TimeoutException; 31 32 /** 33 * Jank tests to fling through Settings app on clockwork device 34 */ 35 public class SettingsFlingJankTest extends JankTestBase { 36 37 // Settings app resources 38 private static final String CLOCK_SETTINGS_PACKAGE = 39 "com.google.android.apps.wearable.settings"; 40 private static final String CLOCK_SETTINGS_ACTIVITY = 41 "com.google.android.clockwork.settings.MainSettingsActivity"; 42 private UiDevice mDevice; 43 private SysAppTestHelper mHelper; 44 45 /* 46 * (non-Javadoc) 47 * @see junit.framework.TestCase#setUp() 48 */ 49 @Override 50 protected void setUp() throws Exception { 51 mDevice = UiDevice.getInstance(getInstrumentation()); 52 mHelper = SysAppTestHelper.getInstance(mDevice, this.getInstrumentation()); 53 mDevice.wakeUp(); 54 super.setUp(); 55 } 56 57 // Prepare device to launch Settings app and scroll through bottom to start fling test 58 public void openSettingsApp() { 59 mHelper.launchActivity(CLOCK_SETTINGS_PACKAGE, CLOCK_SETTINGS_ACTIVITY); 60 SystemClock.sleep(SysAppTestHelper.SHORT_TIMEOUT); 61 } 62 63 /** 64 * Test the jank by flinging in settings screen. 65 */ 66 @JankTest(beforeTest = "openSettingsApp", afterTest = "goBackHome", 67 expectedFrames = SysAppTestHelper.EXPECTED_FRAMES) 68 @GfxMonitor(processName = CLOCK_SETTINGS_PACKAGE) 69 public void testSettingsApp() throws TimeoutException { 70 UiObject2 listViewContents = mDevice.wait(Until.findObject( 71 By.res("android", "list")), 72 SysAppTestHelper.SHORT_TIMEOUT); 73 for (int i = 0; i < 3; i++) { 74 listViewContents.fling(Direction.DOWN, SysAppTestHelper.FLING_SPEED); 75 listViewContents.fling(Direction.UP, SysAppTestHelper.FLING_SPEED); 76 } 77 } 78 79 @JankTest(beforeLoop = "openSettingsApp", afterTest = "goBackHome", 80 expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_SWIPERIGHT_TO_DISMISS_TEST) 81 @WindowAnimationFrameStatsMonitor 82 public void testSwipeRightToDismissApp() { 83 mHelper.swipeRight(); 84 } 85 86 // Ensuring that we head back to the first screen before launching the app again 87 public void goBackHome(Bundle metrics) { 88 mHelper.goBackHome(); 89 super.afterTest(metrics); 90 } 91 92 /* 93 * (non-Javadoc) 94 * @see android.test.InstrumentationTestCase#tearDown() 95 */ 96 @Override 97 protected void tearDown() throws Exception { 98 super.tearDown(); 99 } 100 } 101