Home | History | Annotate | Download | only in janktests
      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.wearable.sysapp.janktests;
     18 
     19 import android.os.Bundle;
     20 import android.support.test.jank.GfxMonitor;
     21 import android.support.test.jank.JankTest;
     22 import android.support.test.jank.JankTestBase;
     23 import android.support.test.uiautomator.UiDevice;
     24 import android.util.Log;
     25 
     26 /**
     27  * Jank tests for watchFace picker on clockwork device
     28  */
     29 public class WatchFacePickerJankTest extends JankTestBase {
     30 
     31     private static final String WEARABLE_APP_PACKAGE = "com.google.android.wearable.app";
     32     private static final String WATCHFACE_PICKER_FAVORITE_LIST_NAME = "watch_face_picker_list";
     33     private static final String TAG = "WatchFacePickerJankTest";
     34     private UiDevice mDevice;
     35     private SysAppTestHelper mHelper;
     36     private WatchFaceHelper mWfHelper;
     37 
     38     /*
     39      * (non-Javadoc)
     40      * @see junit.framework.TestCase#setUp()
     41      */
     42     @Override
     43     protected void setUp() throws Exception {
     44         mDevice = UiDevice.getInstance(getInstrumentation());
     45         mHelper = SysAppTestHelper.getInstance(mDevice, getInstrumentation());
     46         mWfHelper = WatchFaceHelper.getInstance(mDevice, getInstrumentation());
     47         mDevice.wakeUp();
     48         super.setUp();
     49     }
     50 
     51     /**
     52      * Test the jank by open watchface picker (favorites)
     53      */
     54     @JankTest(beforeLoop = "startFromHome", afterTest = "goBackHome",
     55             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_WATCHFACE_PICKER_TEST)
     56     @GfxMonitor(processName = WEARABLE_APP_PACKAGE)
     57     public void testOpenWatchFacePicker() {
     58         mWfHelper.openPicker();
     59     }
     60 
     61     /**
     62      * Test the jank by adding watch face to favorites.
     63      */
     64     @JankTest(beforeLoop = "startFromWatchFacePickerFull",
     65             afterTest = "removeAllButOneWatchFace",
     66             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_WATCHFACE_PICKER_TEST_ADD_FAVORITE)
     67     @GfxMonitor(processName = WEARABLE_APP_PACKAGE)
     68     public void testSelectWatchFaceFromFullList() {
     69         mWfHelper.selectWatchFaceFromFullList(0);
     70     }
     71 
     72     /**
     73      * Test the jank by removing watch face from favorites.
     74      */
     75     @JankTest(beforeLoop = "startWithTwoWatchFaces", afterLoop = "resetToTwoWatchFaces",
     76             afterTest = "removeAllButOneWatchFace",
     77             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_WATCHFACE_PICKER_TEST)
     78     @GfxMonitor(processName = WEARABLE_APP_PACKAGE)
     79     public void testRemoveWatchFaceFromFavorites() {
     80         removeWatchFaceFromFavorites();
     81     }
     82 
     83     /**
     84      * Test the jank on flinging watch face picker.
     85      */
     86     @JankTest(beforeTest = "startWithFourWatchFaces", beforeLoop = "resetToWatchFacePicker",
     87             afterTest = "removeAllButOneWatchFace",
     88             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_WATCHFACE_PICKER_TEST)
     89     @GfxMonitor(processName = WEARABLE_APP_PACKAGE)
     90     public void testWatchFacePickerFling() {
     91         flingWatchFacePicker(5);
     92     }
     93 
     94     /**
     95      * Test the jank of flinging watch face full list picker.
     96      */
     97     @JankTest(beforeLoop = "startFromWatchFacePickerFull",
     98             afterLoop = "resetToWatchFacePickerFull",
     99             afterTest = "removeAllButOneWatchFace",
    100             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_WATCHFACE_PICKER_TEST)
    101     @GfxMonitor(processName = WEARABLE_APP_PACKAGE)
    102     public void testWatchFacePickerFullListFling() {
    103         flingWatchFacePickerFullList(5);
    104     }
    105 
    106     public void startFromHome() {
    107         mHelper.goBackHome();
    108     }
    109 
    110     public void startFromWatchFacePicker() {
    111         mWfHelper.startFromWatchFacePicker();
    112     }
    113 
    114     public void startFromWatchFacePickerFull() {
    115         Log.v(TAG, "Starting from watchface picker full list ...");
    116         startFromHome();
    117         mWfHelper.openPicker();
    118         mWfHelper.openPickerAllList();
    119     }
    120 
    121     public void startWithTwoWatchFaces() {
    122         Log.v(TAG, "Starting with two watchfaces ...");
    123         for (int i = 0; i < 2; ++i) {
    124             startFromHome();
    125             mWfHelper.openPicker();
    126             mWfHelper.openPickerAllList();
    127             mWfHelper.selectWatchFaceFromFullList(i);
    128         }
    129     }
    130 
    131     public void startWithFourWatchFaces() {
    132         Log.v(TAG, "Starting with four watchfaces ...");
    133         for (int i = 0; i < 4; ++i) {
    134             startFromHome();
    135             mWfHelper.openPicker();
    136             mWfHelper.openPickerAllList();
    137             mWfHelper.selectWatchFaceFromFullList(i);
    138         }
    139     }
    140 
    141     public void removeAllButOneWatchFace(Bundle metrics) {
    142         mWfHelper.removeAllButOneWatchFace();
    143         super.afterTest(metrics);
    144     }
    145 
    146     public void resetToWatchFacePicker() {
    147         Log.v(TAG, "Resetting to watchface picker screen ...");
    148         startFromWatchFacePicker();
    149     }
    150 
    151     public void resetToWatchFacePickerFull() {
    152         Log.v(TAG, "Resetting to watchface picker full list screen ...");
    153         startFromWatchFacePickerFull();
    154     }
    155 
    156     public void resetToTwoWatchFaces() {
    157         Log.v(TAG, "Resetting to two watchfaces in favorites ...");
    158         startWithTwoWatchFaces();
    159     }
    160 
    161     public void removeWatchFaceFromFavorites() {
    162         mWfHelper.removeWatchFaceFromFavorites();
    163     }
    164 
    165     // Ensuring that we head back to the first screen before launching the app again
    166     public void goBackHome(Bundle metrics) {
    167         Log.v(TAG, "Going back Home ...");
    168         startFromHome();
    169         super.afterTest(metrics);
    170     }
    171 
    172     private void flingWatchFacePicker(int iterations) {
    173         for (int i = 0; i < iterations; ++i) {
    174             // Start fling to right, then left, alternatively.
    175             if (i % 2 == 0) {
    176                 mHelper.flingRight();
    177             } else {
    178                 mHelper.flingLeft();
    179             }
    180         }
    181     }
    182 
    183     private void flingWatchFacePickerFullList(int iterations) {
    184         for (int i = 0; i < iterations; ++i) {
    185             // Start fling up, then down, alternatively.
    186             if (i % 2 == 0) {
    187                 mHelper.flingUp();
    188             } else {
    189                 mHelper.flingDown();
    190             }
    191         }
    192     }
    193 }
    194