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 */
16package com.android.tv.tests.jank;
17
18import android.support.test.filters.MediumTest;
19import android.support.test.jank.GfxMonitor;
20import android.support.test.jank.JankTest;
21
22import com.android.tv.testing.uihelper.MenuHelper;
23
24/**
25 * Jank tests for the program guide.
26 */
27@MediumTest
28public class MenuJankTest extends LiveChannelsTestCase {
29    private static final String STARTING_CHANNEL = "1";
30
31    /**
32     * The minimum number of frames expected during each jank test.
33     * If there is less the test will fail.  To be safe we loop the action in each test to create
34     * twice this many frames under normal conditions.
35     * <p>200 is chosen so there will be enough frame for the 90th, 95th, and 98th percentile
36     * measurements are significant.
37     *
38     * @see <a href="http://go/janktesthelper-best-practices">Jank Test Helper Best Practices</a>
39     */
40    private static final int EXPECTED_FRAMES = 200;
41    protected MenuHelper mMenuHelper;
42
43    @Override
44    protected void setUp() throws Exception {
45        super.setUp();
46        mMenuHelper = new MenuHelper(mDevice, mTargetResources);
47        Utils.pressKeysForChannelNumber(STARTING_CHANNEL, mDevice);
48    }
49
50    @JankTest(expectedFrames = EXPECTED_FRAMES,
51            beforeTest = "fillTheMenuRowWithPreviousChannels")
52    @GfxMonitor(processName = Utils.LIVE_CHANNELS_PROCESS_NAME)
53    public void testShowMenu() {
54        int frames = 40; // measured by hand.
55        int repeat = EXPECTED_FRAMES * 2 / frames;
56        for (int i = 0; i < repeat; i++) {
57            mMenuHelper.showMenu();
58            mDevice.pressBack();
59            mDevice.waitForIdle();
60        }
61    }
62
63    public void fillTheMenuRowWithPreviousChannels() {
64        int cardViewCount = 6;
65        for (int i = 0; i < cardViewCount; i++) {
66            mDevice.pressDPadUp();
67            mDevice.waitForIdle();
68        }
69    }
70}
71