aboutsummaryrefslogtreecommitdiff
path: root/tests/func/src/com/android/tv/tests/ui/dvr/DvrLibraryTest.java
blob: d88e67ad2fa3e43074891298844f939c323c5bfb (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 * 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.dvr;

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

import android.os.Build;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SdkSuppress;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;

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

import java.util.regex.Pattern;

@MediumTest
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.N)
public class DvrLibraryTest extends LiveChannelsTestCase {
    private static final String PROGRAM_NAME_PREFIX = "Title(";

    private BySelector mRecentRow;
    private BySelector mScheduledRow;
    private BySelector mSeriesRow;
    private BySelector mFullScheduleCard;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mRecentRow = By.hasDescendant(ByResource.text(mTargetResources, R.string.dvr_main_recent));
        mScheduledRow = By.hasDescendant(
                ByResource.text(mTargetResources, R.string.dvr_main_scheduled));
        mSeriesRow = By.hasDescendant(ByResource.text(mTargetResources, R.string.dvr_main_series));
        mFullScheduleCard = By.focusable(true).hasDescendant(
                ByResource.text(mTargetResources, R.string.dvr_full_schedule_card_view_title));
        mLiveChannelsHelper.assertAppStarted();
    }

    public void testCancel() {
        mMenuHelper.assertPressDvrLibrary();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
        assertHas(mDevice, Constants.MENU, false);
    }

    public void testEmptyLibrary() {
        mMenuHelper.assertPressDvrLibrary();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));

        // DVR Library is empty, only Scheduled row and Full schedule card should be displayed.
        assertHas(mDevice, mRecentRow, false);
        assertHas(mDevice, mScheduledRow, true);
        assertHas(mDevice, mSeriesRow, false);

        mDevice.pressDPadCenter();
        assertWaitUntilFocused(mDevice, mFullScheduleCard);
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));

        // Empty schedules screen should be shown.
        assertHas(mDevice, Constants.DVR_SCHEDULES, true);
        assertHas(mDevice, ByResource.text(mTargetResources, R.string.dvr_schedules_empty_state),
                true);

        // Close the DVR library.
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
    }

    public void testScheduleRecordings() {
        BySelector newScheduleCard = By.focusable(true).hasDescendant(
                By.textStartsWith(PROGRAM_NAME_PREFIX)).hasDescendant(By.textEndsWith("today"));
        BySelector seriesCardWithOneSchedule = By.focusable(true).hasDescendant(
                By.textStartsWith(PROGRAM_NAME_PREFIX)).hasDescendant(By.text(mTargetResources
                        .getQuantityString(R.plurals.dvr_count_scheduled_recordings, 1, 1)));
        BySelector seriesCardWithOneRecordedProgram = By.focusable(true).hasDescendant(
                By.textStartsWith(PROGRAM_NAME_PREFIX)).hasDescendant(By.text(mTargetResources
                        .getQuantityString(R.plurals.dvr_count_new_recordings, 1, 1)));
        Pattern watchButton = Pattern.compile("^" + mTargetResources
                .getString(R.string.dvr_detail_watch).toUpperCase() + "\n.*$");

        mMenuHelper.showMenu();
        mMenuHelper.assertNavigateToPlayControlsRow();
        mDevice.pressDPadRight();
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.hasObject(
                ByResource.text(mTargetResources, R.string.dvr_action_record_episode)));
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(
                ByResource.text(mTargetResources, R.string.dvr_action_record_episode)));

        mMenuHelper.assertPressDvrLibrary();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));

        // Schedule should be automatically added to the series.
        assertHas(mDevice, mRecentRow, false);
        assertHas(mDevice, mScheduledRow, true);
        assertHas(mDevice, mSeriesRow, true);
        String programName = mDevice.findObject(By.textStartsWith(PROGRAM_NAME_PREFIX)).getText();

        // Move to scheduled row, there should be one new schedule and one full schedule card.
        mDevice.pressDPadRight();
        assertWaitUntilFocused(mDevice, newScheduleCard);
        mDevice.pressDPadRight();
        assertWaitUntilFocused(mDevice, mFullScheduleCard);

        // Enters the full schedule, there should be one schedule in the full schedule.
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
        assertHas(mDevice, Constants.DVR_SCHEDULES, true);
        assertHas(mDevice, ByResource.text(mTargetResources, R.string.dvr_schedules_empty_state),
                false);
        assertHas(mDevice, By.textStartsWith(programName), true);

        // Moves to the series card, clicks it, the detail page should be shown with "View schedule"
        // button.
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));
        mDevice.pressDPadLeft();
        assertWaitUntilFocused(mDevice, newScheduleCard);
        mDevice.pressDPadDown();
        assertWaitUntilFocused(mDevice, seriesCardWithOneSchedule);
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
        assertHas(mDevice, By.text(mTargetResources
                        .getString(R.string.dvr_detail_view_schedule).toUpperCase()), true);
        assertHas(mDevice, By.text(watchButton), false);
        assertHas(mDevice, By.text(mTargetResources
                        .getString(R.string.dvr_detail_series_delete).toUpperCase()), false);

        // Clicks the new schedule, the detail page should be shown with "Stop recording" button.
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));
        assertWaitUntilFocused(mDevice, seriesCardWithOneSchedule);
        mDevice.pressDPadUp();
        assertWaitUntilFocused(mDevice, newScheduleCard);
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
        assertHas(mDevice, By.text(mTargetResources
                .getString(R.string.dvr_detail_stop_recording).toUpperCase()), true);

        // Stops the recording
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.hasObject(
                ByResource.text(mTargetResources, R.string.dvr_action_stop)));
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(
                ByResource.text(mTargetResources, R.string.dvr_action_stop)));
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));
        assertWaitUntilFocused(mDevice, mFullScheduleCard);

        // Moves to series' detail page again, now it should have two more buttons
        mDevice.pressDPadDown();
        assertWaitUntilFocused(mDevice, seriesCardWithOneRecordedProgram);
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
        assertHas(mDevice, By.text(watchButton), true);
        assertHas(mDevice, By.text(mTargetResources
                .getString(R.string.dvr_detail_view_schedule).toUpperCase()), true);
        assertHas(mDevice, By.text(mTargetResources
                .getString(R.string.dvr_detail_series_delete).toUpperCase()), true);

        // Moves to the recent row and clicks the recent recorded program.
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));
        assertWaitUntilFocused(mDevice, seriesCardWithOneRecordedProgram);
        mDevice.pressDPadUp();
        assertWaitUntilFocused(mDevice, mFullScheduleCard);
        mDevice.pressDPadUp();
        assertWaitUntilFocused(mDevice, By.focusable(true).hasDescendant(By.text(programName)));
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
        assertHas(mDevice, By.text(mTargetResources
                .getString(R.string.dvr_detail_watch).toUpperCase()), true);
        assertHas(mDevice, By.text(mTargetResources
                .getString(R.string.dvr_detail_delete).toUpperCase()), true);

        // Moves to the delete button and clicks to remove the recorded program.
        mDevice.pressDPadRight();
        assertWaitUntilFocused(mDevice, By.text(mTargetResources
                .getString(R.string.dvr_detail_delete).toUpperCase()));
        mDevice.pressDPadCenter();
        assertWaitForCondition(mDevice, Until.hasObject(Constants.DVR_LIBRARY));
        assertWaitUntilFocused(mDevice, mFullScheduleCard);

        // DVR Library should be empty now.
        assertHas(mDevice, mRecentRow, false);
        assertHas(mDevice, mScheduledRow, true);
        assertHas(mDevice, mSeriesRow, false);

        // Close the DVR library.
        mDevice.pressBack();
        assertWaitForCondition(mDevice, Until.gone(Constants.DVR_LIBRARY));
    }
}