blob: 04dfc7882b87fad1e090bd043256d7d89a0e8cc6 [file] [log] [blame]
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +09001/*
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
17package com.android.documentsui;
18
19import static com.android.documentsui.StressProvider.DEFAULT_AUTHORITY;
20import static com.android.documentsui.StressProvider.STRESS_ROOT_0_ID;
21import static com.android.documentsui.StressProvider.STRESS_ROOT_2_ID;
22
23import android.app.Activity;
24import android.os.RemoteException;
25import android.test.suitebuilder.annotation.LargeTest;
26
Ben Linfa1e1362016-09-14 17:57:25 -070027import android.app.UiAutomation;
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +090028import android.content.Intent;
29import android.content.Context;
30import android.support.test.jank.JankTest;
31import android.support.test.jank.JankTestBase;
32import android.support.test.uiautomator.UiDevice;
33import android.support.test.jank.GfxMonitor;
34import android.support.test.uiautomator.UiScrollable;
35import android.util.Log;
36
Steve McKayd0805062016-09-15 14:30:38 -070037import com.android.documentsui.bots.SidebarBot;
Steve McKayb6006b22016-09-29 09:23:45 -070038import com.android.documentsui.files.FilesActivity;
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +090039import com.android.documentsui.bots.DirectoryListBot;
40
41@LargeTest
42public 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
Steve McKayd0805062016-09-15 14:30:38 -070047 private SidebarBot mRootsListBot;
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +090048 private DirectoryListBot mDirListBot;
49 private Activity mActivity = null;
50
51 public void setUpInLoop() {
52 final UiDevice device = UiDevice.getInstance(getInstrumentation());
53 final Context context = getInstrumentation().getTargetContext();
Ben Linfa1e1362016-09-14 17:57:25 -070054 final UiAutomation automation = getInstrumentation().getUiAutomation();
Steve McKayd0805062016-09-15 14:30:38 -070055 mRootsListBot = new SidebarBot(device, context, BOT_TIMEOUT);
Ben Linfa1e1362016-09-14 17:57:25 -070056 mDirListBot = new DirectoryListBot(device, automation, context, BOT_TIMEOUT);
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +090057
Steve McKayb6006b22016-09-29 09:23:45 -070058 final Intent intent = new Intent(context, FilesActivity.class);
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +090059 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
60 mActivity = getInstrumentation().startActivitySync(intent);
Ben Linfe5cd2e2016-07-20 18:24:29 -070061 try {
62 device.setOrientationNatural();
63 } catch (RemoteException e) {
64 }
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +090065 }
66
67 public void tearDownInLoop() {
68 if (mActivity != null) {
69 mActivity.finish();
70 mActivity = null;
71 }
Ben Linfe5cd2e2016-07-20 18:24:29 -070072 try {
73 final UiDevice device = UiDevice.getInstance(getInstrumentation());
74 device.unfreezeRotation();
75 } catch (RemoteException e) {
76 }
Tomasz Mikolajewski811777e2016-03-28 12:13:43 +090077 }
78
79 public void setupAndOpenInLoop() throws Exception {
80 setUpInLoop();
81 openRoot();
82 }
83
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)
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)
97 public void testFlingJankPerformance() throws Exception {
98 new UiScrollable(mDirListBot.findDocumentsList().getSelector()).flingToEnd(MAX_FLINGS);
99 getInstrumentation().waitForIdleSync();
100 }
101}