Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 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 | |
Ben Lin | fa1e136 | 2016-09-14 17:57:25 -0700 | [diff] [blame] | 27 | import android.app.UiAutomation; |
Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 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 | |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 37 | import com.android.documentsui.bots.SidebarBot; |
Steve McKay | b6006b2 | 2016-09-29 09:23:45 -0700 | [diff] [blame] | 38 | import com.android.documentsui.files.FilesActivity; |
Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 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 | |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 47 | private SidebarBot mRootsListBot; |
Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 48 | 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 Lin | fa1e136 | 2016-09-14 17:57:25 -0700 | [diff] [blame] | 54 | final UiAutomation automation = getInstrumentation().getUiAutomation(); |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 55 | mRootsListBot = new SidebarBot(device, context, BOT_TIMEOUT); |
Ben Lin | fa1e136 | 2016-09-14 17:57:25 -0700 | [diff] [blame] | 56 | mDirListBot = new DirectoryListBot(device, automation, context, BOT_TIMEOUT); |
Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 57 | |
Steve McKay | b6006b2 | 2016-09-29 09:23:45 -0700 | [diff] [blame] | 58 | final Intent intent = new Intent(context, FilesActivity.class); |
Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 59 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 60 | mActivity = getInstrumentation().startActivitySync(intent); |
Ben Lin | fe5cd2e | 2016-07-20 18:24:29 -0700 | [diff] [blame] | 61 | try { |
| 62 | device.setOrientationNatural(); |
| 63 | } catch (RemoteException e) { |
| 64 | } |
Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | public void tearDownInLoop() { |
| 68 | if (mActivity != null) { |
| 69 | mActivity.finish(); |
| 70 | mActivity = null; |
| 71 | } |
Ben Lin | fe5cd2e | 2016-07-20 18:24:29 -0700 | [diff] [blame] | 72 | try { |
| 73 | final UiDevice device = UiDevice.getInstance(getInstrumentation()); |
| 74 | device.unfreezeRotation(); |
| 75 | } catch (RemoteException e) { |
| 76 | } |
Tomasz Mikolajewski | 811777e | 2016-03-28 12:13:43 +0900 | [diff] [blame] | 77 | } |
| 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 | } |