blob: e8e2cee4200a9f53fe801b2163190aa14eb8e3e7 [file] [log] [blame]
Wonsik Kim0215fde2014-10-30 00:47:57 +09001/*
2 * Copyright (C) 2014 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 */
16
17package com.android.cts.verifier.tv;
18
Dongwon Kangaa1e8032015-06-01 15:13:06 +090019import android.app.SearchableInfo;
20import android.content.Context;
Wonsik Kimd71946a2014-11-20 23:11:16 +090021import android.content.Intent;
22import android.media.tv.TvContract;
Dongwon Kangaa1e8032015-06-01 15:13:06 +090023import android.os.AsyncTask;
Wonsik Kim0215fde2014-10-30 00:47:57 +090024import android.view.View;
25
Wonsik Kimd71946a2014-11-20 23:11:16 +090026import com.android.cts.verifier.R;
27
Wonsik Kim0215fde2014-10-30 00:47:57 +090028/**
Wonsik Kimd71946a2014-11-20 23:11:16 +090029 * Tests for verifying TV app behavior for third-party TV input apps.
Wonsik Kim0215fde2014-10-30 00:47:57 +090030 */
31public class TvInputDiscoveryTestActivity extends TvAppVerifierActivity
32 implements View.OnClickListener {
33 private static final String TAG = "TvInputDiscoveryTestActivity";
34
Wonsik Kimd71946a2014-11-20 23:11:16 +090035 private static final Intent TV_APP_INTENT = new Intent(Intent.ACTION_VIEW,
Dongwon Kang98453952015-05-13 19:00:07 +090036 TvContract.Channels.CONTENT_URI);
Dongwon Kang2ad14c92015-05-13 18:46:13 +090037 private static final Intent EPG_INTENT = new Intent(Intent.ACTION_VIEW,
38 TvContract.Programs.CONTENT_URI);
Wonsik Kimd71946a2014-11-20 23:11:16 +090039
Wonsik Kim0215fde2014-10-30 00:47:57 +090040 private static final long TIMEOUT_MS = 5l * 60l * 1000l; // 5 mins.
41
42 private View mGoToSetupItem;
43 private View mVerifySetupItem;
44 private View mTuneToChannelItem;
45 private View mVerifyTuneItem;
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090046 private View mVerifyOverlayViewItem;
Dongwon Kangaa1e8032015-06-01 15:13:06 +090047 private View mVerifyGlobalSearchItem;
Dongwon Kang2ad14c92015-05-13 18:46:13 +090048 private View mGoToEpgItem;
49 private View mVerifyEpgItem;
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090050 private boolean mTuneVerified;
51 private boolean mOverlayViewVerified;
Dongwon Kangaa1e8032015-06-01 15:13:06 +090052 private boolean mGlobalSearchVerified;
Wonsik Kim0215fde2014-10-30 00:47:57 +090053
54 @Override
55 public void onClick(View v) {
56 final View postTarget = getPostTarget();
57
58 if (containsButton(mGoToSetupItem, v)) {
59 final Runnable failCallback = new Runnable() {
60 @Override
61 public void run() {
62 setPassState(mVerifySetupItem, false);
63 }
64 };
65 postTarget.postDelayed(failCallback, TIMEOUT_MS);
66 MockTvInputSetupActivity.expectLaunch(postTarget, new Runnable() {
67 @Override
68 public void run() {
69 postTarget.removeCallbacks(failCallback);
70 setPassState(mGoToSetupItem, true);
71 setPassState(mVerifySetupItem, true);
72 setButtonEnabled(mTuneToChannelItem, true);
73 }
74 });
Dongwon Kang2ad14c92015-05-13 18:46:13 +090075 startActivity(TV_APP_INTENT);
Wonsik Kim0215fde2014-10-30 00:47:57 +090076 } else if (containsButton(mTuneToChannelItem, v)) {
77 final Runnable failCallback = new Runnable() {
78 @Override
79 public void run() {
80 setPassState(mVerifyTuneItem, false);
81 }
82 };
83 postTarget.postDelayed(failCallback, TIMEOUT_MS);
84 MockTvInputService.expectTune(postTarget, new Runnable() {
85 @Override
86 public void run() {
Wonsik Kim0215fde2014-10-30 00:47:57 +090087 setPassState(mTuneToChannelItem, true);
88 setPassState(mVerifyTuneItem, true);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090089
90 mTuneVerified = true;
Dongwon Kang2ad14c92015-05-13 18:46:13 +090091 goToNextState(postTarget, failCallback);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090092 }
93 });
94 MockTvInputService.expectOverlayView(postTarget, new Runnable() {
95 @Override
96 public void run() {
97 postTarget.removeCallbacks(failCallback);
98 setPassState(mVerifyOverlayViewItem, true);
99
100 mOverlayViewVerified = true;
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900101 goToNextState(postTarget, failCallback);
Wonsik Kim0215fde2014-10-30 00:47:57 +0900102 }
103 });
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900104 verifyGlobalSearch(postTarget, failCallback);
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900105 startActivity(TV_APP_INTENT);
106 } else if (containsButton(mGoToEpgItem, v)) {
107 startActivity(EPG_INTENT);
108 setPassState(mGoToEpgItem, true);
109 setButtonEnabled(mVerifyEpgItem, true);
110 } else if (containsButton(mVerifyEpgItem, v)) {
111 setPassState(mVerifyEpgItem, true);
112 getPassButton().setEnabled(true);
Wonsik Kim0215fde2014-10-30 00:47:57 +0900113 }
Wonsik Kim0215fde2014-10-30 00:47:57 +0900114 }
115
116 @Override
117 protected void createTestItems() {
118 mGoToSetupItem = createUserItem(R.string.tv_input_discover_test_go_to_setup,
119 R.string.tv_launch_tv_app, this);
120 setButtonEnabled(mGoToSetupItem, true);
121 mVerifySetupItem = createAutoItem(R.string.tv_input_discover_test_verify_setup);
122 mTuneToChannelItem = createUserItem(R.string.tv_input_discover_test_tune_to_channel,
123 R.string.tv_launch_tv_app, this);
124 mVerifyTuneItem = createAutoItem(R.string.tv_input_discover_test_verify_tune);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900125 mVerifyOverlayViewItem = createAutoItem(
126 R.string.tv_input_discover_test_verify_overlay_view);
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900127 mVerifyGlobalSearchItem = createAutoItem(
128 R.string.tv_input_discover_test_verify_global_search);
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900129 mGoToEpgItem = createUserItem(R.string.tv_input_discover_test_go_to_epg,
130 R.string.tv_launch_epg, this);
131 mVerifyEpgItem = createUserItem(R.string.tv_input_discover_test_verify_epg,
Sungsoo Limb773b242015-09-06 15:51:25 +0900132 android.R.string.yes, this);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900133 }
134
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900135 @Override
136 protected void setInfoResources() {
137 setInfoResources(R.string.tv_input_discover_test,
138 R.string.tv_input_discover_test_info, -1);
139 }
140
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900141 private void goToNextState(View postTarget, Runnable failCallback) {
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900142 if (mTuneVerified && mOverlayViewVerified && mGlobalSearchVerified) {
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900143 postTarget.removeCallbacks(failCallback);
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900144 setButtonEnabled(mGoToEpgItem, true);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900145 }
Wonsik Kim0215fde2014-10-30 00:47:57 +0900146 }
Wonsik Kimd71946a2014-11-20 23:11:16 +0900147
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900148 private void verifyGlobalSearch(final View postTarget, final Runnable failCallback) {
149 new AsyncTask<Void, Void, Boolean>() {
150 @Override
151 protected Boolean doInBackground(Void... params) {
152 Context context = TvInputDiscoveryTestActivity.this;
153 for (SearchableInfo info : SearchUtil.getSearchableInfos(context)) {
154 if (SearchUtil.verifySearchResult(context, info,
155 MockTvInputSetupActivity.CHANNEL_NAME,
156 MockTvInputSetupActivity.PROGRAM_TITLE)
157 && SearchUtil.verifySearchResult(context, info,
158 MockTvInputSetupActivity.PROGRAM_TITLE,
159 MockTvInputSetupActivity.PROGRAM_TITLE)) {
160 return true;
161 }
162 }
163 return false;
164 }
165
166 @Override
167 protected void onPostExecute(Boolean result) {
168 super.onPostExecute(result);
169 setPassState(mVerifyGlobalSearchItem, result);
170 mGlobalSearchVerified = result;
171 goToNextState(postTarget, failCallback);
172 }
173 }.execute();
Wonsik Kimd71946a2014-11-20 23:11:16 +0900174 }
Wonsik Kim0215fde2014-10-30 00:47:57 +0900175}