Skip to content

Commit

Permalink
Updated/Added Test Cases + minor updates
Browse files Browse the repository at this point in the history
Change-Id: I841932ba5e7562efe1f7db4394a239e92b8bfa9d
  • Loading branch information
c0d3base committed Jun 23, 2020
1 parent e88b44e commit 14adffd
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.Until;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
Expand All @@ -60,6 +62,7 @@ public class BasicCastUITest {
TimeUnit.SECONDS.toMillis(resources.getInteger(R.integer.cast_test_short_timeout));
private static final long MAX_TIMEOUT_MS =
TimeUnit.SECONDS.toMillis(resources.getInteger(R.integer.cast_test_max_timeout));
private static final String NOTIFICATION_TITLE = "Cast Videos Sample";

private UiDevice mDevice;
private TestUtils mTestUtils = new TestUtils();
Expand Down Expand Up @@ -156,20 +159,21 @@ public void testNotification() throws UiObjectNotFoundException, InterruptedExce

mDevice.pressHome();
mDevice.openNotification();
mDevice.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)),MAX_TIMEOUT_MS);

mDevice.findObject(new UiSelector()
.className("android.widget.ImageButton")
.resourceId("android:id/action0").description("Pause")).click();
.description("Pause"))
.click();
mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PAUSED, MAX_TIMEOUT_MS);

mDevice.findObject(new UiSelector()
.className("android.widget.ImageButton")
.resourceId("android:id/action0").description("Play")).click();
.description("Play"))
.click();
mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);

mDevice.findObject(new UiSelector()
.className("android.widget.TextView")
.resourceId("android:id/title").text(VIDEO_TITLE)).click();
mDevice.findObject(By.text(VIDEO_TITLE)).click();
mTestUtils.verifyExpandedController();

mDevice.pressBack();
Expand Down
65 changes: 64 additions & 1 deletion androidTest/com/google/sample/cast/refplayer/QueueingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.res.Resources;

import com.google.android.gms.cast.MediaStatus;
import com.google.sample.cast.refplayer.queue.ui.QueueListViewActivity;

import org.json.JSONException;
import org.junit.Before;
Expand All @@ -28,12 +29,15 @@

import java.util.concurrent.TimeUnit;

import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.Until;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
Expand All @@ -59,7 +63,8 @@ public class QueueingTest {
resources.getString(R.string.cast_test_video_3);
private static final long MAX_TIMEOUT_MS =
TimeUnit.SECONDS.toMillis(resources.getInteger(R.integer.cast_test_max_timeout));

private static final String NOTIFICATION_TITLE = "Cast Videos Sample";
private static final int QUEUE_TEST_COUNT = 100;
private UiDevice mDevice;
private TestUtils mTestUtils = new TestUtils();

Expand Down Expand Up @@ -111,6 +116,63 @@ public void testQueuePlayback() throws UiObjectNotFoundException, InterruptedExc
mTestUtils.disconnectFromCastDevice();
}

/**
* Tests Ending Session from the Notification
* @throws Exception
*/
@Test
public void testEndSession() throws Exception{
mTestUtils.connectToCastDevice();
mDevice.findObject(new UiSelector().text(VIDEO_ITEM_1)).click();
mDevice.findObject(new UiSelector().resourceId(resources.getResourceName(R.id.play_circle))).click();
mDevice.findObject(new UiSelector().text("Play Now")).click();
mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);

mDevice.pressHome();
mDevice.openNotification();
mDevice.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)),MAX_TIMEOUT_MS);
mDevice.findObject(new UiSelector().className("android.widget.ImageButton").description("Disconnect")).click();
mTestUtils.assertCastStateIsDisconnected(MAX_TIMEOUT_MS);
}

@Rule
public ActivityTestRule<QueueListViewActivity> mActivityTestRule =
new ActivityTestRule<>(QueueListViewActivity.class);

@Test
public void longQueueVerification() throws Exception{
mTestUtils.connectToCastDevice();
createLongQueue();
mDevice.findObject(new UiSelector().resourceId(resources.getResourceName(R.id.action_show_queue))).click();
onView(withId(R.id.recycler_view)).perform(RecyclerViewActions.scrollToPosition(QUEUE_TEST_COUNT));
mDevice.findObject(new UiSelector().text(VIDEO_ITEM_2)).click();
mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);

mDevice.openNotification();
mDevice.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)),MAX_TIMEOUT_MS);
mDevice.findObject(new UiSelector().className("android.widget.ImageButton").description("Disconnect")).click();

mTestUtils.assertCastStateIsDisconnected(MAX_TIMEOUT_MS);
}

private void createLongQueue() throws Exception{
int count = 0;
mDevice.findObject(new UiSelector().text(VIDEO_ITEM_1)).click();

while(count<QUEUE_TEST_COUNT){

mDevice.findObject(new UiSelector().resourceId(resources.getResourceName(R.id.play_circle))).click();
mDevice.findObject(new UiSelector().text("Add to Queue")).click();
count++;
}
mDevice.pressBack();
mDevice.findObject(new UiSelector().text(VIDEO_ITEM_2)).click();
mDevice.findObject(new UiSelector().resourceId(resources.getResourceName(R.id.play_circle))).click();
mDevice.findObject(new UiSelector().text("Add to Queue")).click();
}



/**
* To add content and create queue
*/
Expand All @@ -137,3 +199,4 @@ private void createQueue() throws UiObjectNotFoundException, InterruptedExceptio
mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);
}
}

23 changes: 23 additions & 0 deletions androidTest/com/google/sample/cast/refplayer/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TestUtils {
private boolean isCastConnected;
private int actualState;

private boolean isCastDisconnected;
/**
* Connecting to Cast device
* - Open Cast menu dialog when tapping the Cast icon
Expand Down Expand Up @@ -171,6 +172,28 @@ public void run() {

}

/**
* Check Cast is Disconnected
*/
protected void assertCastStateIsDisconnected(long timeout) throws Exception{
long startTime = SystemClock.uptimeMillis();
isCastDisconnected = false;
getCastInfo();

while(!isCastDisconnected && SystemClock.uptimeMillis() - startTime < timeout){
Thread.sleep(500);
InstrumentationRegistry.getInstrumentation().runOnMainSync(
new Runnable() {
@Override
public void run() {
isCastDisconnected = mCastSession.isDisconnected();
}
}
);
}
assertTrue(isCastDisconnected);
}

/**
* Click and play a video
* Assert player state is playing
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation 'com.android.volley:volley:1.1.1'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
Expand Down
4 changes: 2 additions & 2 deletions res/values/cast_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
-->
<resources>
<!-- For Testing -->
<string name="cast_test_target_device">Office TV</string>
<integer name="cast_test_short_timeout">3</integer>
<string name="cast_test_target_device">Den TV</string>
<integer name="cast_test_short_timeout">5</integer>
<integer name="cast_test_max_timeout">20</integer>
<string name="cast_test_video_1">Big Buck Bunny</string>
<string name="cast_test_video_2">Casting To The Future</string>
Expand Down
3 changes: 2 additions & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<resources>

<string name="app_name">Cast Videos Sample</string>
<string name="app_id">4F8B3483</string>
<string name="app_id">CC1AD845</string>
<string name="action_settings">Settings</string>
<string name="cast_app_name">GoogleCastPlayer</string>
<string name="media_route_menu_title">Play on&#8230;</string>
Expand Down Expand Up @@ -100,4 +100,5 @@
<string name="action_clear_queue">Clear Queue</string>
<string name="queue_item_added_to_play_next">An item was added to play next</string>
<string name="queue_item_added_to_queue">An item was added to the queue</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.android.gms.cast.framework.OptionsProvider;
import com.google.android.gms.cast.framework.SessionProvider;
import com.google.android.gms.cast.framework.media.CastMediaOptions;
import com.google.android.gms.cast.framework.media.ImageHints;
import com.google.android.gms.cast.framework.media.ImagePicker;
import com.google.android.gms.cast.framework.media.MediaIntentReceiver;
import com.google.android.gms.cast.framework.media.NotificationOptions;
Expand Down Expand Up @@ -64,7 +65,8 @@ public List<SessionProvider> getAdditionalSessionProviders(Context appContext) {
private static class ImagePickerImpl extends ImagePicker {

@Override
public WebImage onPickImage(MediaMetadata mediaMetadata, int type) {
public WebImage onPickImage(MediaMetadata mediaMetadata, ImageHints hints) {
int type = hints.getType();
if ((mediaMetadata == null) || !mediaMetadata.hasImages()) {
return null;
}
Expand Down

1 comment on commit 14adffd

@mnr54318950
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

androidTest/com/google/sample/cast/refplayer/BasicCastUITest.java

Please sign in to comment.