summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyungtae Kim <hyungtaekim@google.com>2016-09-07 18:00:24 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-09-07 18:00:25 +0000
commitb218db774754991c7c6592dd5e4b072e46663949 (patch)
tree86241bf8649ee65aba69bbf4d40f5c89585a6e44
parent71d5ac89ca74f9c5705881b4e1065471e8fd6ec2 (diff)
parentbff66c3cefd39ef0ac4b68c30b04e92057ac59d4 (diff)
downloadplatform_testing-b218db774754991c7c6592dd5e4b072e46663949.tar.gz
Merge "TV YouTube functional tests" into nyc-mr1-dev
-rw-r--r--tests/functional/tv/YouTubeTests/Android.mk27
-rw-r--r--tests/functional/tv/YouTubeTests/AndroidManifest.xml34
-rw-r--r--tests/functional/tv/YouTubeTests/src/android/test/functional/tv/youtube/YouTubeTests.java146
3 files changed, 207 insertions, 0 deletions
diff --git a/tests/functional/tv/YouTubeTests/Android.mk b/tests/functional/tv/YouTubeTests/Android.mk
new file mode 100644
index 000000000..ecf13ce4a
--- /dev/null
+++ b/tests/functional/tv/YouTubeTests/Android.mk
@@ -0,0 +1,27 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+# ------------------------------------------------
+# build a test apk for YouTube functional testing
+
+LOCAL_PACKAGE_NAME := YouTubeFuncTests
+LOCAL_MODULE_TAGS := tests
+LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator leanback-app-helpers android-support-test
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+include $(BUILD_PACKAGE)
+
diff --git a/tests/functional/tv/YouTubeTests/AndroidManifest.xml b/tests/functional/tv/YouTubeTests/AndroidManifest.xml
new file mode 100644
index 000000000..1c3a2ede3
--- /dev/null
+++ b/tests/functional/tv/YouTubeTests/AndroidManifest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.test.functional.tv.youtube">
+
+ <uses-sdk android:minSdkVersion="21"
+ android:targetSdkVersion="24"/>
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation
+ android:name="android.support.test.runner.AndroidJUnitRunner"
+ android:targetPackage="android.test.functional.tv.youtube"
+ android:label="TV YouTube Functional Tests" />
+
+</manifest>
+
+
diff --git a/tests/functional/tv/YouTubeTests/src/android/test/functional/tv/youtube/YouTubeTests.java b/tests/functional/tv/YouTubeTests/src/android/test/functional/tv/youtube/YouTubeTests.java
new file mode 100644
index 000000000..196e4d56c
--- /dev/null
+++ b/tests/functional/tv/YouTubeTests/src/android/test/functional/tv/youtube/YouTubeTests.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2016 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.test.functional.tv.youtube;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.platform.test.helpers.tv.YouTubeHelperImpl;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.launcherhelper.ILeanbackLauncherStrategy;
+import android.support.test.launcherhelper.LauncherStrategyFactory;
+import android.support.test.launcherhelper.LeanbackLauncherStrategy;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.UiDevice;
+import android.util.Log;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Functional verification tests for YouTube on TV.
+ *
+ * adb shell am instrument -w -r \
+ * -e class android.test.functional.tv.youtube.YouTubeTests \
+ * android.test.functional.tv.youtube/android.support.test.runner.AndroidJUnitRunner
+ */
+@RunWith(AndroidJUnit4.class)
+public class YouTubeTests {
+
+ private static final String TAG = YouTubeTests.class.getSimpleName();
+ private static final String DEFAULT_SEARCH_QUERY = "never gonna give you up";
+ private static final long DEFAULT_SEARCH_PLAY_DURATION_MS = 30 * 1000; // 30 seconds
+
+ private UiDevice mDevice;
+ private Instrumentation mInstrumentation;
+ private Context mContext;
+ private Bundle mArguments;
+
+ private LeanbackLauncherStrategy mLauncherStrategy;
+ private YouTubeHelperImpl mYouTubeHelper;
+
+
+ public YouTubeTests() {
+ initialize(InstrumentationRegistry.getInstrumentation());
+ }
+
+ private void initialize(Instrumentation instrumentation) {
+ // Initialize instances of testing support library
+ mInstrumentation = instrumentation;
+ mContext = getInstrumentation().getContext();
+ mDevice = UiDevice.getInstance(getInstrumentation());
+ mArguments = InstrumentationRegistry.getArguments();
+
+ // Initialize instances of leanback and app helpers
+ ILeanbackLauncherStrategy launcherStrategy = LauncherStrategyFactory.getInstance(
+ mDevice).getLeanbackLauncherStrategy();
+ if (launcherStrategy instanceof LeanbackLauncherStrategy) {
+ mLauncherStrategy = (LeanbackLauncherStrategy) launcherStrategy;
+ }
+ mYouTubeHelper = new YouTubeHelperImpl(getInstrumentation());
+ }
+
+ protected Instrumentation getInstrumentation() {
+ return mInstrumentation;
+ }
+
+ @Before
+ public void setUp() {
+ mLauncherStrategy.open();
+ }
+
+ @After
+ public void tearDown() {
+ mYouTubeHelper.exit();
+ }
+
+
+ /**
+ * Objective: Able to play the first video on Home section.
+ */
+ @Test
+ public void testPlayVideoAtHome() {
+ mYouTubeHelper.open();
+ mYouTubeHelper.openHome();
+
+ Log.i(TAG, "found a video: " + mYouTubeHelper.getFocusedVideoTitleText());
+ long durationMs = mYouTubeHelper.getFocusedVideoDuration();
+ if (durationMs > DEFAULT_SEARCH_PLAY_DURATION_MS) {
+ durationMs = DEFAULT_SEARCH_PLAY_DURATION_MS;
+ }
+ Assert.assertTrue(mYouTubeHelper.playFocusedVideo(durationMs));
+ }
+
+ /**
+ * Objective: Able to search for videos and play.
+ */
+ @Test
+ public void testSearchVideoAndPlay() {
+ // Search for a video
+ mYouTubeHelper.open();
+ mYouTubeHelper.search(DEFAULT_SEARCH_QUERY);
+
+ long durationMs = mYouTubeHelper.getFocusedVideoDuration();
+ if (durationMs > DEFAULT_SEARCH_PLAY_DURATION_MS) {
+ durationMs = DEFAULT_SEARCH_PLAY_DURATION_MS;
+ }
+
+ // Select the first video in the search results and play
+ mYouTubeHelper.openFirstSearchResult();
+
+ // Play the video for a given period of time
+ SystemClock.sleep(durationMs);
+ Assert.assertTrue(mYouTubeHelper.isInVideoPlayback());
+ }
+
+ /**
+ * Objective: Able to launch YouTube video in the Notification row
+ */
+ @Test
+ public void testLaunchVideoInNotificationRow() {
+ Assert.assertTrue(mLauncherStrategy.launchNotification(mYouTubeHelper.getLauncherName()));
+
+ // Play the video for a given period of time
+ SystemClock.sleep(5000);
+ Assert.assertTrue(mYouTubeHelper.isInVideoPlayback());
+ }
+}
+