aboutsummaryrefslogtreecommitdiff
path: root/tests/func/src/com/android/tv/tests/ui/sidepanel/CustomizeChannelListFragmentTest.java
blob: deeb9bfde030845dc447995912a0fbef674dc1dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.tv.tests.ui.sidepanel;

import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition;

import android.graphics.Point;
import android.support.test.filters.LargeTest;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.Direction;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;

import com.android.tv.R;
import com.android.tv.testing.uihelper.Constants;
import com.android.tv.tests.ui.LiveChannelsTestCase;

@LargeTest
public class CustomizeChannelListFragmentTest extends LiveChannelsTestCase {
    private BySelector mBySettingsSidePanel;
    private UiObject2 mTvView;
    private Point mNormalTvViewCenter;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mLiveChannelsHelper.assertAppStarted();
        mTvView = mDevice.findObject(Constants.TV_VIEW);
        mNormalTvViewCenter = mTvView.getVisibleCenter();
        assertNotNull(mNormalTvViewCenter);
        pressKeysForChannel(com.android.tv.testing.testinput.TvTestInputConstants.CH_2);
        // Wait until KeypadChannelSwitchView closes.
        assertWaitForCondition(mDevice, Until.hasObject(Constants.CHANNEL_BANNER));
        mBySettingsSidePanel = mSidePanelHelper.bySidePanelTitled(
                R.string.side_panel_title_settings);
    }

    private void assertShrunkenTvView(boolean shrunkenExpected) {
        Point currentTvViewCenter = mTvView.getVisibleCenter();
        if (shrunkenExpected) {
            assertFalse(mNormalTvViewCenter.equals(currentTvViewCenter));
        } else {
            assertTrue(mNormalTvViewCenter.equals(currentTvViewCenter));
        }
    }

    public void testCustomizeChannelList_noraml() {
        // Show customize channel list fragment
        mMenuHelper.assertPressOptionsSettings();
        assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel));
        mSidePanelHelper.assertNavigateToItem(
                R.string.settings_channel_source_item_customize_channels);
        mDevice.pressDPadCenter();
        BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled(
                R.string.side_panel_title_edit_channels_for_an_input);
        assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
        assertShrunkenTvView(true);

        // Show group by fragment
        mSidePanelHelper.assertNavigateToItem(R.string.edit_channels_item_group_by, Direction.UP);
        mDevice.pressDPadCenter();
        bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.side_panel_title_group_by);
        assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
        assertShrunkenTvView(true);

        // Back to customize channel list fragment
        mDevice.pressBack();
        bySidePanel = mSidePanelHelper.bySidePanelTitled(
                R.string.side_panel_title_edit_channels_for_an_input);
        assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
        assertShrunkenTvView(true);

        // Return to the main menu.
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel));
        assertShrunkenTvView(false);
    }

    public void testCustomizeChannelList_timeout() {
        // Show customize channel list fragment
        mMenuHelper.assertPressOptionsSettings();
        assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel));
        mSidePanelHelper.assertNavigateToItem(
                R.string.settings_channel_source_item_customize_channels);
        mDevice.pressDPadCenter();
        BySelector bySidePanel = mSidePanelHelper.bySidePanelTitled(
                R.string.side_panel_title_edit_channels_for_an_input);
        assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
        assertShrunkenTvView(true);

        // Show group by fragment
        mSidePanelHelper.assertNavigateToItem(R.string.edit_channels_item_group_by, Direction.UP);
        mDevice.pressDPadCenter();
        bySidePanel = mSidePanelHelper.bySidePanelTitled(R.string.side_panel_title_group_by);
        assertWaitForCondition(mDevice, Until.hasObject(bySidePanel));
        assertShrunkenTvView(true);

        // Wait for time-out to return to the main menu.
        assertWaitForCondition(mDevice, Until.gone(bySidePanel),
                mTargetResources.getInteger(R.integer.side_panel_show_duration));
        assertShrunkenTvView(false);
    }
}