blob: 06f4f6f8451b5932b48b1d1c4bf9b4432e3d99d0 [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
Dongwon Kangaa1e8032015-06-01 15:13:06 +090028import java.util.List;
29
Wonsik Kim0215fde2014-10-30 00:47:57 +090030/**
Wonsik Kimd71946a2014-11-20 23:11:16 +090031 * Tests for verifying TV app behavior for third-party TV input apps.
Wonsik Kim0215fde2014-10-30 00:47:57 +090032 */
33public class TvInputDiscoveryTestActivity extends TvAppVerifierActivity
34 implements View.OnClickListener {
35 private static final String TAG = "TvInputDiscoveryTestActivity";
36
Wonsik Kimd71946a2014-11-20 23:11:16 +090037 private static final Intent TV_APP_INTENT = new Intent(Intent.ACTION_VIEW,
Dongwon Kang98453952015-05-13 19:00:07 +090038 TvContract.Channels.CONTENT_URI);
Dongwon Kang2ad14c92015-05-13 18:46:13 +090039 private static final Intent EPG_INTENT = new Intent(Intent.ACTION_VIEW,
40 TvContract.Programs.CONTENT_URI);
Wonsik Kimd71946a2014-11-20 23:11:16 +090041
Wonsik Kim0215fde2014-10-30 00:47:57 +090042 private static final long TIMEOUT_MS = 5l * 60l * 1000l; // 5 mins.
43
44 private View mGoToSetupItem;
45 private View mVerifySetupItem;
46 private View mTuneToChannelItem;
47 private View mVerifyTuneItem;
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090048 private View mVerifyOverlayViewItem;
Dongwon Kangaa1e8032015-06-01 15:13:06 +090049 private View mVerifyGlobalSearchItem;
Dongwon Kang2ad14c92015-05-13 18:46:13 +090050 private View mGoToEpgItem;
51 private View mVerifyEpgItem;
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090052 private boolean mTuneVerified;
53 private boolean mOverlayViewVerified;
Dongwon Kangaa1e8032015-06-01 15:13:06 +090054 private boolean mGlobalSearchVerified;
Wonsik Kim0215fde2014-10-30 00:47:57 +090055
56 @Override
57 public void onClick(View v) {
58 final View postTarget = getPostTarget();
59
60 if (containsButton(mGoToSetupItem, v)) {
61 final Runnable failCallback = new Runnable() {
62 @Override
63 public void run() {
64 setPassState(mVerifySetupItem, false);
65 }
66 };
67 postTarget.postDelayed(failCallback, TIMEOUT_MS);
68 MockTvInputSetupActivity.expectLaunch(postTarget, new Runnable() {
69 @Override
70 public void run() {
71 postTarget.removeCallbacks(failCallback);
72 setPassState(mGoToSetupItem, true);
73 setPassState(mVerifySetupItem, true);
74 setButtonEnabled(mTuneToChannelItem, true);
75 }
76 });
Dongwon Kang2ad14c92015-05-13 18:46:13 +090077 startActivity(TV_APP_INTENT);
Wonsik Kim0215fde2014-10-30 00:47:57 +090078 } else if (containsButton(mTuneToChannelItem, v)) {
79 final Runnable failCallback = new Runnable() {
80 @Override
81 public void run() {
82 setPassState(mVerifyTuneItem, false);
83 }
84 };
85 postTarget.postDelayed(failCallback, TIMEOUT_MS);
86 MockTvInputService.expectTune(postTarget, new Runnable() {
87 @Override
88 public void run() {
Wonsik Kim0215fde2014-10-30 00:47:57 +090089 setPassState(mTuneToChannelItem, true);
90 setPassState(mVerifyTuneItem, true);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090091
92 mTuneVerified = true;
Dongwon Kang2ad14c92015-05-13 18:46:13 +090093 goToNextState(postTarget, failCallback);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +090094 }
95 });
96 MockTvInputService.expectOverlayView(postTarget, new Runnable() {
97 @Override
98 public void run() {
99 postTarget.removeCallbacks(failCallback);
100 setPassState(mVerifyOverlayViewItem, true);
101
102 mOverlayViewVerified = true;
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900103 goToNextState(postTarget, failCallback);
Wonsik Kim0215fde2014-10-30 00:47:57 +0900104 }
105 });
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900106 verifyGlobalSearch(postTarget, failCallback);
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900107 startActivity(TV_APP_INTENT);
108 } else if (containsButton(mGoToEpgItem, v)) {
109 startActivity(EPG_INTENT);
110 setPassState(mGoToEpgItem, true);
111 setButtonEnabled(mVerifyEpgItem, true);
112 } else if (containsButton(mVerifyEpgItem, v)) {
113 setPassState(mVerifyEpgItem, true);
114 getPassButton().setEnabled(true);
Wonsik Kim0215fde2014-10-30 00:47:57 +0900115 }
Wonsik Kim0215fde2014-10-30 00:47:57 +0900116 }
117
118 @Override
119 protected void createTestItems() {
120 mGoToSetupItem = createUserItem(R.string.tv_input_discover_test_go_to_setup,
121 R.string.tv_launch_tv_app, this);
122 setButtonEnabled(mGoToSetupItem, true);
123 mVerifySetupItem = createAutoItem(R.string.tv_input_discover_test_verify_setup);
124 mTuneToChannelItem = createUserItem(R.string.tv_input_discover_test_tune_to_channel,
125 R.string.tv_launch_tv_app, this);
126 mVerifyTuneItem = createAutoItem(R.string.tv_input_discover_test_verify_tune);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900127 mVerifyOverlayViewItem = createAutoItem(
128 R.string.tv_input_discover_test_verify_overlay_view);
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900129 mVerifyGlobalSearchItem = createAutoItem(
130 R.string.tv_input_discover_test_verify_global_search);
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900131 mGoToEpgItem = createUserItem(R.string.tv_input_discover_test_go_to_epg,
132 R.string.tv_launch_epg, this);
133 mVerifyEpgItem = createUserItem(R.string.tv_input_discover_test_verify_epg,
134 R.string.tv_input_discover_test_yes, this);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900135 }
136
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900137 @Override
138 protected void setInfoResources() {
139 setInfoResources(R.string.tv_input_discover_test,
140 R.string.tv_input_discover_test_info, -1);
141 }
142
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900143 private void goToNextState(View postTarget, Runnable failCallback) {
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900144 if (mTuneVerified && mOverlayViewVerified && mGlobalSearchVerified) {
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900145 postTarget.removeCallbacks(failCallback);
Dongwon Kang2ad14c92015-05-13 18:46:13 +0900146 setButtonEnabled(mGoToEpgItem, true);
Dongwon Kang9bbf0ca2014-12-01 15:51:03 +0900147 }
Wonsik Kim0215fde2014-10-30 00:47:57 +0900148 }
Wonsik Kimd71946a2014-11-20 23:11:16 +0900149
Dongwon Kangaa1e8032015-06-01 15:13:06 +0900150 private void verifyGlobalSearch(final View postTarget, final Runnable failCallback) {
151 new AsyncTask<Void, Void, Boolean>() {
152 @Override
153 protected Boolean doInBackground(Void... params) {
154 Context context = TvInputDiscoveryTestActivity.this;
155 for (SearchableInfo info : SearchUtil.getSearchableInfos(context)) {
156 if (SearchUtil.verifySearchResult(context, info,
157 MockTvInputSetupActivity.CHANNEL_NAME,
158 MockTvInputSetupActivity.PROGRAM_TITLE)
159 && SearchUtil.verifySearchResult(context, info,
160 MockTvInputSetupActivity.PROGRAM_TITLE,
161 MockTvInputSetupActivity.PROGRAM_TITLE)) {
162 return true;
163 }
164 }
165 return false;
166 }
167
168 @Override
169 protected void onPostExecute(Boolean result) {
170 super.onPostExecute(result);
171 setPassState(mVerifyGlobalSearchItem, result);
172 mGlobalSearchVerified = result;
173 goToNextState(postTarget, failCallback);
174 }
175 }.execute();
Wonsik Kimd71946a2014-11-20 23:11:16 +0900176 }
Wonsik Kim0215fde2014-10-30 00:47:57 +0900177}