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 package com.android.wearable.sysapp.janktests; 17 18 import android.content.Context; 19 import android.os.Bundle; 20 import android.os.RemoteException; 21 import android.os.PowerManager; 22 import android.os.PowerManager.WakeLock; 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.Until; 31 32 import java.util.concurrent.TimeoutException; 33 34 /** 35 * Jank tests to fling through apps available in the launcher [1st page] 36 */ 37 public class AppLauncherFlingJankTest extends JankTestBase { 38 39 private UiDevice mDevice; 40 private SysAppTestHelper mHelper; 41 private PowerManager mPm; 42 private WakeLock mWakeLock; 43 44 /* 45 * (non-Javadoc) 46 * @see junit.framework.TestCase#setUp() 47 */ 48 @Override 49 protected void setUp() throws Exception { 50 super.setUp(); 51 mDevice = UiDevice.getInstance(getInstrumentation()); 52 mHelper = SysAppTestHelper.getInstance(mDevice, this.getInstrumentation()); 53 mPm = (PowerManager) getInstrumentation(). 54 getContext().getSystemService(Context.POWER_SERVICE); 55 mWakeLock = mPm.newWakeLock(PowerManager.FULL_WAKE_LOCK, 56 AppLauncherFlingJankTest.class.getSimpleName()); 57 mWakeLock.acquire(); 58 } 59 60 /** 61 * This method ensures the device is taken to Home and launch the apps page (also known as 1st 62 * page) before running the fling test on apps. 63 * @throws RemoteException 64 * @throws TimeoutException 65 */ 66 public void openLauncher() throws RemoteException, TimeoutException { 67 mHelper.gotoAppLauncher(); 68 } 69 70 /** 71 * Test the jank by flinging in apps screen. 72 * @throws TimeoutException 73 * 74 */ 75 @JankTest(beforeTest = "openLauncher", afterTest = "goBackHome", 76 expectedFrames = SysAppTestHelper.EXPECTED_FRAMES) 77 @GfxMonitor(processName = "com.google.android.wearable.app") 78 public void testFlingApps() throws TimeoutException { 79 UiObject2 recyclerViewContents = mDevice.wait(Until.findObject( 80 By.res("com.google.android.wearable.app","launcher_view")), SysAppTestHelper.SHORT_TIMEOUT); 81 for (int i = 0; i < 3; i++) { 82 recyclerViewContents.fling(Direction.DOWN, SysAppTestHelper.FLING_SPEED); 83 recyclerViewContents.fling(Direction.UP, SysAppTestHelper.FLING_SPEED); 84 } 85 } 86 87 // Ensuring that we head back to the first screen before launching the app again 88 public void goBackHome(Bundle metrics) throws RemoteException { 89 mHelper.goBackHome(); 90 super.afterTest(metrics); 91 } 92 93 /* 94 * (non-Javadoc) 95 * @see android.test.InstrumentationTestCase#tearDown() 96 */ 97 @Override 98 protected void tearDown() throws Exception { 99 super.tearDown(); 100 mWakeLock.release(); 101 } 102 } 103