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
22/**
23 * Jank tests for channel zapping.
24 */
25@MediumTest
26public class ChannelZappingJankTest extends LiveChannelsTestCase {
27    private static final String TAG = "ChannelZappingJankTest";
28
29    private static final String STARTING_CHANNEL = "13";
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>At least 100 frams should be chosen so there will be enough frame
36     * for the 90th, 95th, and 98th percentile 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 = 100;
41    private static final int WARM_UP_CHANNEL_ZAPPING_COUNT = 2;
42
43    @Override
44    protected void setUp() throws Exception {
45        super.setUp();
46        Utils.pressKeysForChannelNumber(STARTING_CHANNEL, mDevice);
47    }
48
49    @JankTest(expectedFrames = EXPECTED_FRAMES,
50            beforeTest = "warmChannelZapping")
51    @GfxMonitor(processName = Utils.LIVE_CHANNELS_PROCESS_NAME)
52    public void testChannelZapping() {
53        int frameCountForOneChannelZapping = 40;  // measured by hand
54        int repeat = EXPECTED_FRAMES * 2 / frameCountForOneChannelZapping;
55        for (int i = 0; i < repeat; i++) {
56            mDevice.pressDPadUp();
57            mDevice.waitForIdle();
58            // Press BACK to close banner.
59            mDevice.pressBack();
60            mDevice.waitForIdle();
61        }
62    }
63
64    // It's public to be used with @JankTest annotation.
65    public void warmChannelZapping() {
66        for (int i = 0; i < WARM_UP_CHANNEL_ZAPPING_COUNT; ++i) {
67            mDevice.pressDPadUp();
68            mDevice.waitForIdle();
69        }
70        // Press BACK to close banner.
71        mDevice.pressBack();
72        mDevice.waitForIdle();
73    }
74}
75