aboutsummaryrefslogtreecommitdiff
path: root/tests/common/src/com/android/tv/testing/uihelper/LiveChannelsUiDeviceHelper.java
blob: 6757cf0191906ff6179e9cbf3c199ab21422762e (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
package com.android.tv.testing.uihelper;

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

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.Until;
import android.util.Log;

import junit.framework.Assert;

/**
 * Helper for testing the Live TV Application.
 */
public class LiveChannelsUiDeviceHelper extends BaseUiDeviceHelper {
    private static final String TAG = "LiveChannelsUiDevice";
    private static final int APPLICATION_START_TIMEOUT_MSEC = 5000;

    private final Context mContext;

    public LiveChannelsUiDeviceHelper(UiDevice uiDevice, Resources targetResources,
            Context context) {
        super(uiDevice, targetResources);
        mContext = context;
    }

    public void assertAppStarted() {
        Intent intent = mContext.getPackageManager()
                .getLaunchIntentForPackage(Constants.TV_APP_PACKAGE);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);    // Clear out any previous instances
        mContext.startActivity(intent);
        // Wait for idle state before checking the channel banner because waitForCondition() has
        // timeout.
        mUiDevice.waitForIdle();
        // Make sure that the activity is resumed.
        waitForCondition(mUiDevice, Until.hasObject(Constants.TV_VIEW));

        Assert.assertTrue(Constants.TV_APP_PACKAGE + " did not start", mUiDevice
                .wait(Until.hasObject(By.pkg(Constants.TV_APP_PACKAGE).depth(0)),
                        APPLICATION_START_TIMEOUT_MSEC));
        BySelector welcome = ByResource.id(mTargetResources, com.android.tv.R.id.intro);
        if (mUiDevice.hasObject(welcome)) {
            Log.i(TAG, "Welcome screen shown. Clearing dialog by pressing back");
            mUiDevice.pressBack();
        }
    }
}