• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.content.Intent;
28 import android.content.Context;
29 import android.support.test.jank.JankTest;
30 import android.support.test.jank.JankTestBase;
31 import android.support.test.uiautomator.UiDevice;
32 import android.support.test.jank.GfxMonitor;
33 import android.support.test.uiautomator.UiScrollable;
34 import android.util.Log;
35 
36 import com.android.documentsui.FilesActivity;
37 import com.android.documentsui.bots.RootsListBot;
38 import com.android.documentsui.bots.DirectoryListBot;
39 
40 @LargeTest
41 public class FilesJankPerfTest extends JankTestBase {
42     private static final String DOCUMENTSUI_PACKAGE = "com.android.documentsui";
43     private static final int MAX_FLINGS = 10;
44     private static final int BOT_TIMEOUT = 5000;
45 
46     private RootsListBot mRootsListBot;
47     private DirectoryListBot mDirListBot;
48     private Activity mActivity = null;
49 
setUpInLoop()50     public void setUpInLoop() {
51         final UiDevice device = UiDevice.getInstance(getInstrumentation());
52         final Context context = getInstrumentation().getTargetContext();
53         mRootsListBot = new RootsListBot(device, context, BOT_TIMEOUT);
54         mDirListBot = new DirectoryListBot(device, context, BOT_TIMEOUT);
55 
56         final Intent intent = new Intent(context, FilesActivity.class);
57         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
58         mActivity = getInstrumentation().startActivitySync(intent);
59     }
60 
tearDownInLoop()61     public void tearDownInLoop() {
62         if (mActivity != null) {
63             mActivity.finish();
64             mActivity = null;
65         }
66     }
67 
setupAndOpenInLoop()68     public void setupAndOpenInLoop() throws Exception {
69         setUpInLoop();
70         openRoot();
71     }
72 
openRoot()73     public void openRoot() throws Exception {
74         mRootsListBot.openRoot(STRESS_ROOT_2_ID);
75     }
76 
77     @JankTest(expectedFrames=0, beforeLoop="setUpInLoop", afterLoop="tearDownInLoop")
78     @GfxMonitor(processName=DOCUMENTSUI_PACKAGE)
testOpenRootJankPerformance()79     public void testOpenRootJankPerformance() throws Exception {
80         openRoot();
81         getInstrumentation().waitForIdleSync();
82     }
83 
84     @JankTest(expectedFrames=0, beforeLoop="setupAndOpenInLoop", afterLoop="tearDownInLoop")
85     @GfxMonitor(processName=DOCUMENTSUI_PACKAGE)
testFlingJankPerformance()86     public void testFlingJankPerformance() throws Exception {
87         new UiScrollable(mDirListBot.findDocumentsList().getSelector()).flingToEnd(MAX_FLINGS);
88         getInstrumentation().waitForIdleSync();
89     }
90 }
91