am 4dbc35b9: am 6421f1ce: Merge "Add Leanback CTS testcases as required for Leanback Settings and Launcher. This CL includes the tests to see whether:" into lmp-dev
* commit '4dbc35b97b1991be02ac2364ecb8b5610e849f54':
Add Leanback CTS testcases as required for Leanback Settings and Launcher. This CL includes the tests to see whether:
diff --git a/tests/tests/tv/AndroidManifest.xml b/tests/tests/tv/AndroidManifest.xml
index fb84509..dc5d30a 100644
--- a/tests/tests/tv/AndroidManifest.xml
+++ b/tests/tests/tv/AndroidManifest.xml
@@ -81,6 +81,12 @@
<category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
</intent-filter>
</activity>
+ <activity android:name="android.tv.settings.cts.SettingsLeanbackStubActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+ </intent-filter>
+ </activity>
</application>
<instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/tests/tests/tv/src/android/tv/settings/cts/SettingsLeanbackStubActivity.java b/tests/tests/tv/src/android/tv/settings/cts/SettingsLeanbackStubActivity.java
new file mode 100644
index 0000000..171f709
--- /dev/null
+++ b/tests/tests/tv/src/android/tv/settings/cts/SettingsLeanbackStubActivity.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 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 android.tv.settings.cts;
+
+import android.app.Activity;
+
+public class SettingsLeanbackStubActivity extends Activity {
+
+}
diff --git a/tests/tests/tv/src/android/tv/settings/cts/SettingsLeanbackTest.java b/tests/tests/tv/src/android/tv/settings/cts/SettingsLeanbackTest.java
new file mode 100644
index 0000000..c8b4a1b
--- /dev/null
+++ b/tests/tests/tv/src/android/tv/settings/cts/SettingsLeanbackTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2014 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 android.tv.settings.cts;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.test.ActivityInstrumentationTestCase2;
+
+import java.util.List;
+
+public class SettingsLeanbackTest extends
+ ActivityInstrumentationTestCase2<SettingsLeanbackStubActivity> {
+
+ private static final String TAG = "SettingsLeanbackTest";
+
+ private static final String LEANBACK_SETTINGS_CATEGORY =
+ "android.intent.category.LEANBACK_SETTINGS";
+
+ private Activity mActivity;
+
+ public SettingsLeanbackTest() {
+ super(SettingsLeanbackStubActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ getInstrumentation().waitForIdleSync();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mActivity = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test if there is at least one activity that can handle LEANBACK_LAUNCHER
+ * category intent.
+ *
+ * @throws Exception
+ */
+ public void testLeanbackLauncherIntentCategory() throws Exception {
+ if (!Utils.hasLeanback(mActivity)) {
+ return;
+ }
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
+ assertIntentCanBeHandled(intent);
+ }
+
+ /**
+ * Test if there is at least one activity that can handle LEANBACK_SETTINGS
+ * category intent.
+ *
+ * @throws Exception
+ */
+ public void testLeanbackSettingsIntentCategory() throws Exception {
+ if (!Utils.hasLeanback(mActivity)) {
+ return;
+ }
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(LEANBACK_SETTINGS_CATEGORY);
+ assertIntentCanBeHandled(intent);
+ }
+
+ private void assertIntentCanBeHandled(final Intent intent) {
+ PackageManager packageManager = getActivity().getPackageManager();
+ List<ResolveInfo> resolveInfoList =
+ packageManager.queryIntentActivities(intent, 0);
+ assertNotNull(resolveInfoList);
+ // one or more activity can handle this intent.
+ assertTrue(resolveInfoList.size() > 0);
+ }
+}
diff --git a/tests/tests/tv/src/android/tv/settings/cts/Utils.java b/tests/tests/tv/src/android/tv/settings/cts/Utils.java
new file mode 100644
index 0000000..95ce795
--- /dev/null
+++ b/tests/tests/tv/src/android/tv/settings/cts/Utils.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2014 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 android.tv.settings.cts;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+public class Utils {
+ private Utils() { }
+
+ public static boolean hasFeature(Context context, String feature) {
+ return context.getPackageManager().hasSystemFeature(feature);
+ }
+
+ public static boolean hasLeanback(Context context) {
+ return hasFeature(context, PackageManager.FEATURE_LEANBACK);
+ }
+}