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 
     25 /**
     26  * Jank tests for scrolling & swiping off notification cards on wear
     27  */
     28 public class CardsJankTest extends JankTestBase {
     29 
     30     private UiDevice mDevice;
     31     private SysAppTestHelper mHelper;
     32 
     33     /*
     34      * (non-Javadoc)
     35      * @see junit.framework.TestCase#setUp()
     36      */
     37     @Override
     38     protected void setUp() throws Exception {
     39         super.setUp();
     40         mDevice = UiDevice.getInstance(getInstrumentation());
     41         mHelper = SysAppTestHelper.getInstance(mDevice, this.getInstrumentation());
     42         mDevice.wakeUp();
     43     }
     44 
     45     // Prepare device to start scrolling by tapping on the screen
     46     // As this is done using demo cards a tap on screen will stop animation and show
     47     // home screen
     48     public void openScrollCard() throws Exception {
     49         mHelper.hasDemoCards();
     50         mHelper.swipeUp();
     51     }
     52 
     53     // Measure card scroll jank
     54 
     55     @JankTest(beforeLoop = "openScrollCard", afterTest = "goBackHome",
     56             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_CARDS_TEST)
     57     @GfxMonitor(processName = "com.google.android.wearable.app")
     58     public void testScrollCard() {
     59         mHelper.swipeUp();
     60     }
     61 
     62     // Preparing the cards to full view before dismissing them
     63 
     64     public void openSwipeCard() throws Exception {
     65         mHelper.hasDemoCards();
     66         mHelper.swipeUp();
     67     }
     68 
     69     // Measure jank when dismissing a card
     70 
     71     @JankTest(beforeLoop = "openSwipeCard", afterTest = "goBackHome",
     72             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_CARDS_TEST)
     73     @GfxMonitor(processName = "com.google.android.wearable.app")
     74     public void testSwipeCard() {
     75         mHelper.swipeRight();
     76     }
     77 
     78     // Ensuring that we head back to the first screen before launching the app again
     79     public void goBackHome(Bundle metrics) {
     80         mHelper.goBackHome();
     81         super.afterTest(metrics);
     82     }
     83 
     84     // Measure jank when dismissing on an expanded card
     85     @JankTest(beforeLoop = "openSwipeExpandedCard", afterTest = "goBackHome",
     86             expectedFrames = SysAppTestHelper.EXPECTED_FRAMES_DISMISS_EXPANDED_CARDS_TEST)
     87     @GfxMonitor(processName = "com.google.android.wearable.app")
     88     public void testSwipeExpandedCard() {
     89         mHelper.swipeRight();
     90     }
     91 
     92     // Preparing the expanded card
     93     public void openSwipeExpandedCard() throws Exception {
     94         openSwipeCard();
     95         mHelper.clickScreenCenter();
     96     }
     97 
     98     /*
     99      * (non-Javadoc)
    100      * @see android.test.InstrumentationTestCase#tearDown()
    101      */
    102     @Override
    103     protected void tearDown() throws Exception {
    104         super.tearDown();
    105     }
    106 
    107 }
    108