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