1/*
2 * Copyright (C) 2015 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.ui;
17
18import static com.android.tv.testing.uihelper.UiDeviceAsserts.assertWaitForCondition;
19
20import android.support.test.filters.LargeTest;
21import android.support.test.uiautomator.BySelector;
22import android.support.test.uiautomator.Until;
23
24import com.android.tv.R;
25import com.android.tv.testing.uihelper.ByResource;
26import com.android.tv.testing.uihelper.UiDeviceUtils;
27
28/**
29 * Tests for channel sources.
30 */
31@LargeTest
32public class ChannelSourcesTest extends LiveChannelsTestCase {
33    private BySelector mBySettingsSidePanel;
34
35    @Override
36    protected void setUp() throws Exception {
37        super.setUp();
38        mBySettingsSidePanel = mSidePanelHelper.bySidePanelTitled(
39                R.string.side_panel_title_settings);
40    }
41
42    //TODO: create a cancelable test channel setup.
43
44    public void testSetup_cancel() {
45        mLiveChannelsHelper.assertAppStarted();
46        mMenuHelper.assertPressOptionsSettings();
47        assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel));
48
49        mSidePanelHelper.assertNavigateToItem(R.string.settings_channel_source_item_setup);
50        mDevice.pressDPadCenter();
51
52        assertWaitForCondition(mDevice,
53                Until.hasObject(ByResource.text(mTargetResources, R.string.setup_sources_text)));
54        mDevice.pressBack();
55    }
56
57    // SetupSourcesFragment should have no errors if side fragment item is clicked multiple times.
58    public void testSetupTwice_cancel() {
59        mLiveChannelsHelper.assertAppStarted();
60        mMenuHelper.assertPressOptionsSettings();
61        assertWaitForCondition(mDevice, Until.hasObject(mBySettingsSidePanel));
62
63        mSidePanelHelper.assertNavigateToItem(R.string.settings_channel_source_item_setup);
64        UiDeviceUtils.pressDPadCenter(getInstrumentation(), 2);
65
66        assertWaitForCondition(mDevice,
67                Until.hasObject(ByResource.text(mTargetResources, R.string.setup_sources_text)));
68        mDevice.pressBack();
69    }
70}
71