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.documentsui; 18 19 import static com.android.documentsui.StressProvider.DEFAULT_AUTHORITY; 20 import static com.android.documentsui.StressProvider.STRESS_ROOT_0_ID; 21 import static com.android.documentsui.StressProvider.STRESS_ROOT_2_ID; 22 23 import android.app.Activity; 24 import android.os.RemoteException; 25 import android.test.suitebuilder.annotation.LargeTest; 26 27 import android.app.UiAutomation; 28 import android.content.Intent; 29 import android.content.Context; 30 import android.support.test.jank.JankTest; 31 import android.support.test.jank.JankTestBase; 32 import android.support.test.uiautomator.UiDevice; 33 import android.support.test.jank.GfxMonitor; 34 import android.support.test.uiautomator.UiScrollable; 35 import android.util.Log; 36 37 import com.android.documentsui.bots.SidebarBot; 38 import com.android.documentsui.files.FilesActivity; 39 import com.android.documentsui.bots.DirectoryListBot; 40 41 @LargeTest 42 public class FilesJankPerfTest extends JankTestBase { 43 private static final String DOCUMENTSUI_PACKAGE = "com.android.documentsui"; 44 private static final int MAX_FLINGS = 10; 45 private static final int BOT_TIMEOUT = 5000; 46 47 private SidebarBot mRootsListBot; 48 private DirectoryListBot mDirListBot; 49 private Activity mActivity = null; 50 setUpInLoop()51 public void setUpInLoop() { 52 final UiDevice device = UiDevice.getInstance(getInstrumentation()); 53 final Context context = getInstrumentation().getTargetContext(); 54 final UiAutomation automation = getInstrumentation().getUiAutomation(); 55 mRootsListBot = new SidebarBot(device, context, BOT_TIMEOUT); 56 mDirListBot = new DirectoryListBot(device, automation, context, BOT_TIMEOUT); 57 58 final Intent intent = new Intent(context, FilesActivity.class); 59 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 60 mActivity = getInstrumentation().startActivitySync(intent); 61 try { 62 device.setOrientationNatural(); 63 } catch (RemoteException e) { 64 } 65 } 66 tearDownInLoop()67 public void tearDownInLoop() { 68 if (mActivity != null) { 69 mActivity.finish(); 70 mActivity = null; 71 } 72 try { 73 final UiDevice device = UiDevice.getInstance(getInstrumentation()); 74 device.unfreezeRotation(); 75 } catch (RemoteException e) { 76 } 77 } 78 setupAndOpenInLoop()79 public void setupAndOpenInLoop() throws Exception { 80 setUpInLoop(); 81 openRoot(); 82 } 83 openRoot()84 public void openRoot() throws Exception { 85 mRootsListBot.openRoot(STRESS_ROOT_2_ID); 86 } 87 88 @JankTest(expectedFrames=0, beforeLoop="setUpInLoop", afterLoop="tearDownInLoop") 89 @GfxMonitor(processName=DOCUMENTSUI_PACKAGE) testOpenRootJankPerformance()90 public void testOpenRootJankPerformance() throws Exception { 91 openRoot(); 92 getInstrumentation().waitForIdleSync(); 93 } 94 95 @JankTest(expectedFrames=0, beforeLoop="setupAndOpenInLoop", afterLoop="tearDownInLoop") 96 @GfxMonitor(processName=DOCUMENTSUI_PACKAGE) testFlingJankPerformance()97 public void testFlingJankPerformance() throws Exception { 98 new UiScrollable(mDirListBot.findDocumentsList().getSelector()).flingToEnd(MAX_FLINGS); 99 getInstrumentation().waitForIdleSync(); 100 } 101 } 102