blob: 3659dda58b7dab5a433858cb8cff48543b30b3cd [file] [log] [blame]
Md Haqueaec7abc2015-06-10 18:31:28 -07001/*
2 * Copyright (C) 2015 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.sysapp.janktests;
18
Gopinathfe6f8132015-09-13 17:23:36 -070019import java.io.File;
20import java.io.IOException;
21
Md Haquee3080cb2015-06-23 14:41:15 -070022import android.content.Intent;
23import android.content.pm.PackageManager;
Gopinathfe6f8132015-09-13 17:23:36 -070024import android.os.Bundle;
25import android.os.Environment;
Md Haqueaec7abc2015-06-10 18:31:28 -070026import android.os.RemoteException;
27import android.os.SystemClock;
28import android.support.test.jank.GfxMonitor;
29import android.support.test.jank.JankTest;
30import android.support.test.jank.JankTestBase;
Md Haqueaec7abc2015-06-10 18:31:28 -070031import android.support.test.uiautomator.By;
32import android.support.test.uiautomator.BySelector;
33import android.support.test.uiautomator.Direction;
34import android.support.test.uiautomator.UiDevice;
35import android.support.test.uiautomator.UiObject2;
36import android.support.test.uiautomator.UiObjectNotFoundException;
37import android.support.test.uiautomator.Until;
38import junit.framework.Assert;
Gopinathfe6f8132015-09-13 17:23:36 -070039import android.support.test.timeresulthelper.TimeResultLogger;
Md Haqueaec7abc2015-06-10 18:31:28 -070040
41/**
42 * Jank test for Chorme apps
43 * Open overflow menu
44 */
45
46public class ChromeJankTests extends JankTestBase {
47 private static final int SHORT_TIMEOUT = 1000;
48 private static final int LONG_TIMEOUT = 30000;
49 private static final int INNER_LOOP = 5;
50 private static final int EXPECTED_FRAMES = 100;
51 private static final String PACKAGE_NAME = "com.android.chrome";
Md Haqueaec7abc2015-06-10 18:31:28 -070052 private UiDevice mDevice;
Gopinathfe6f8132015-09-13 17:23:36 -070053 private static final File TIMESTAMP_FILE = new File(Environment.getExternalStorageDirectory()
54 .getAbsolutePath(), "autotester.log");
55 private static final File RESULTS_FILE = new File(Environment.getExternalStorageDirectory()
56 .getAbsolutePath(), "results.log");
Md Haqueaec7abc2015-06-10 18:31:28 -070057
58 @Override
59 public void setUp() throws Exception {
60 super.setUp();
61 mDevice = UiDevice.getInstance(getInstrumentation());
62 try {
63 mDevice.setOrientationNatural();
64 } catch (RemoteException e) {
65 throw new RuntimeException("failed to freeze device orientaion", e);
66 }
Md Haqueaec7abc2015-06-10 18:31:28 -070067 }
68
69 @Override
70 protected void tearDown() throws Exception {
71 mDevice.unfreezeRotation();
72 super.tearDown();
73 }
74
Md Haquee3080cb2015-06-23 14:41:15 -070075 public void launchApp(String packageName) throws UiObjectNotFoundException{
76 PackageManager pm = getInstrumentation().getContext().getPackageManager();
77 Intent appIntent = pm.getLaunchIntentForPackage(packageName);
78 appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
79 getInstrumentation().getContext().startActivity(appIntent);
80 SystemClock.sleep(SHORT_TIMEOUT);
81 }
82
Gopinathfe6f8132015-09-13 17:23:36 -070083 public void launchChrome() throws UiObjectNotFoundException, IOException{
Md Haquee3080cb2015-06-23 14:41:15 -070084 launchApp(PACKAGE_NAME);
Md Haqueaec7abc2015-06-10 18:31:28 -070085 getOverflowMenu();
Gopinathfe6f8132015-09-13 17:23:36 -070086 TimeResultLogger.writeTimeStampLogStart(String.format("%s-%s",
87 getClass().getSimpleName(), getName()), TIMESTAMP_FILE);
88 }
89
90 public void afterTestChromeOverflowMenuTap(Bundle metrics) throws IOException {
91 TimeResultLogger.writeTimeStampLogEnd(String.format("%s-%s",
92 getClass().getSimpleName(), getName()), TIMESTAMP_FILE);
93 TimeResultLogger.writeResultToFile(String.format("%s-%s",
94 getClass().getSimpleName(), getName()), RESULTS_FILE, metrics);
95 super.afterTest(metrics);
Md Haqueaec7abc2015-06-10 18:31:28 -070096 }
97
98 // Measures jank window render for overflow menu tap
Gopinathfe6f8132015-09-13 17:23:36 -070099 @JankTest(beforeTest="launchChrome", expectedFrames=EXPECTED_FRAMES,
100 afterTest="afterTestChromeOverflowMenuTap")
Md Haqueaec7abc2015-06-10 18:31:28 -0700101 @GfxMonitor(processName=PACKAGE_NAME)
102 public void testChromeOverflowMenuTap() {
103 for (int i = 0; i < INNER_LOOP; i++) {
104 UiObject2 overflow = getOverflowMenu();
105 overflow.click();
106 SystemClock.sleep(100);
107 mDevice.pressBack();
108 }
109 }
110
111 public UiObject2 getOverflowMenu() {
Md Haquee3080cb2015-06-23 14:41:15 -0700112 UiObject2 overflow = mDevice.wait(
113 Until.findObject(By.desc("More options")), 5 * SHORT_TIMEOUT);
114 Assert.assertNotNull("Failed to locate overflow menu", overflow);
115 return overflow;
Md Haqueaec7abc2015-06-10 18:31:28 -0700116 }
117}