Commit 949135e0 authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Extract MediaSource interface

Currently, MediaSource and RemotingMediaSource have no common ancestor.
This makes code reuse between CastMediaRouteProvider and
RemotingMediaRouteProvider difficult.

This CL renames MediaSource into CastMediaSource, adds a MediaSource
interface, and updates RemotingMediaSource and CastMediaSources to both
derive from this interface. This paves the way for the introduction of
a BaseMediaRouteProvider.

Bug: 790766
Change-Id: I3f8e46816a1e9f8f2f617a43b1099c8614204efc
Reviewed-on: https://chromium-review.googlesource.com/783836
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarAnton Vayvod <avayvod@chromium.org>
Reviewed-by: default avatarZhiqiang Zhang <zqzhang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521578}
parent fb4046a4
...@@ -10,6 +10,7 @@ import android.support.v7.media.MediaRouteSelector; ...@@ -10,6 +10,7 @@ import android.support.v7.media.MediaRouteSelector;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.media.router.cast.CastMediaSource;
import org.chromium.chrome.browser.media.router.cast.MediaSink; import org.chromium.chrome.browser.media.router.cast.MediaSink;
import org.chromium.chrome.browser.media.router.cast.MediaSource; import org.chromium.chrome.browser.media.router.cast.MediaSource;
import org.chromium.chrome.browser.media.router.cast.remoting.RemotingMediaSource; import org.chromium.chrome.browser.media.router.cast.remoting.RemotingMediaSource;
...@@ -45,30 +46,23 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega ...@@ -45,30 +46,23 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
public void openRouteChooserDialog(String[] sourceUrns) { public void openRouteChooserDialog(String[] sourceUrns) {
if (isShowingDialog()) return; if (isShowingDialog()) return;
String sourceId = null; MediaSource source = null;
MediaRouteSelector routeSelector = null;
for (String sourceUrn : sourceUrns) { for (String sourceUrn : sourceUrns) {
MediaSource source = MediaSource.from(sourceUrn); source = CastMediaSource.from(sourceUrn);
if (source != null) { if (source == null) source = RemotingMediaSource.from(sourceUrn);
sourceId = source.getUrn();
routeSelector = source.buildRouteSelector();
break;
}
RemotingMediaSource remotingSource = RemotingMediaSource.from(sourceUrn); if (source != null) break;
if (remotingSource != null) {
sourceId = remotingSource.getSourceId();
routeSelector = remotingSource.buildRouteSelector();
break;
}
} }
if (sourceId == null || routeSelector == null) { MediaRouteSelector routeSelector = source == null ? null : source.buildRouteSelector();
if (routeSelector == null) {
nativeOnMediaSourceNotSupported(mNativeDialogController); nativeOnMediaSourceNotSupported(mNativeDialogController);
return; return;
} }
mDialogManager = new MediaRouteChooserDialogManager(sourceId, routeSelector, this); mDialogManager =
new MediaRouteChooserDialogManager(source.getSourceId(), routeSelector, this);
mDialogManager.openDialog(); mDialogManager.openDialog();
} }
...@@ -81,28 +75,18 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega ...@@ -81,28 +75,18 @@ public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
public void openRouteControllerDialog(String sourceUrn, String mediaRouteId) { public void openRouteControllerDialog(String sourceUrn, String mediaRouteId) {
if (isShowingDialog()) return; if (isShowingDialog()) return;
String sourceId = null; MediaSource source = CastMediaSource.from(sourceUrn);
MediaRouteSelector routeSelector = null; if (source == null) source = RemotingMediaSource.from(sourceUrn);
MediaSource source = MediaSource.from(sourceUrn);
if (source != null) {
sourceId = source.getUrn();
routeSelector = source.buildRouteSelector();
} else {
RemotingMediaSource remotingSource = RemotingMediaSource.from(sourceUrn);
if (remotingSource != null) {
sourceId = remotingSource.getSourceId();
routeSelector = remotingSource.buildRouteSelector();
}
}
if (sourceId == null || routeSelector == null) { MediaRouteSelector routeSelector = source == null ? null : source.buildRouteSelector();
if (routeSelector == null) {
nativeOnMediaSourceNotSupported(mNativeDialogController); nativeOnMediaSourceNotSupported(mNativeDialogController);
return; return;
} }
mDialogManager = mDialogManager = new MediaRouteControllerDialogManager(
new MediaRouteControllerDialogManager(sourceId, routeSelector, mediaRouteId, this); source.getSourceId(), routeSelector, mediaRouteId, this);
mDialogManager.openDialog(); mDialogManager.openDialog();
} }
......
...@@ -166,7 +166,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -166,7 +166,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
@Override @Override
public boolean supportsSource(String sourceId) { public boolean supportsSource(String sourceId) {
return MediaSource.from(sourceId) != null; return CastMediaSource.from(sourceId) != null;
} }
@Override @Override
...@@ -178,7 +178,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -178,7 +178,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
return; return;
} }
MediaSource source = MediaSource.from(sourceId); MediaSource source = CastMediaSource.from(sourceId);
if (source == null) { if (source == null) {
// If the source is invalid, report no devices available. // If the source is invalid, report no devices available.
onSinksReceived(sourceId, new ArrayList<MediaSink>()); onSinksReceived(sourceId, new ArrayList<MediaSink>());
...@@ -218,7 +218,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -218,7 +218,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
public void stopObservingMediaSinks(String sourceId) { public void stopObservingMediaSinks(String sourceId) {
if (mAndroidMediaRouter == null) return; if (mAndroidMediaRouter == null) return;
MediaSource source = MediaSource.from(sourceId); MediaSource source = CastMediaSource.from(sourceId);
if (source == null) return; if (source == null) return;
String applicationId = source.getApplicationId(); String applicationId = source.getApplicationId();
...@@ -247,7 +247,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -247,7 +247,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
return; return;
} }
MediaSource source = MediaSource.from(sourceId); MediaSource source = CastMediaSource.from(sourceId);
if (source == null) { if (source == null) {
mManager.onRouteRequestError("Unsupported presentation URL", nativeRequestId); mManager.onRouteRequestError("Unsupported presentation URL", nativeRequestId);
return; return;
...@@ -270,15 +270,17 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -270,15 +270,17 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
MediaSink sink = request.getSink(); MediaSink sink = request.getSink();
MediaSource source = request.getSource(); MediaSource source = request.getSource();
MediaRoute route = new MediaRoute( MediaRoute route =
sink.getId(), source.getUrn(), request.getPresentationId()); new MediaRoute(sink.getId(), source.getSourceId(), request.getPresentationId());
addRoute(route, request.getOrigin(), request.getTabId()); addRoute(route, request.getOrigin(), request.getTabId());
mManager.onRouteCreated(route.id, route.sinkId, request.getNativeRequestId(), this, true); mManager.onRouteCreated(route.id, route.sinkId, request.getNativeRequestId(), this, true);
if (source.getClientId() != null) { String clientId = ((CastMediaSource) source).getClientId();
ClientRecord clientRecord = mClientRecords.get(source.getClientId());
if (clientId != null) {
ClientRecord clientRecord = mClientRecords.get(clientId);
if (clientRecord != null) { if (clientRecord != null) {
sendReceiverAction(clientRecord.routeId, sink, source.getClientId(), "cast"); sendReceiverAction(clientRecord.routeId, sink, clientId, "cast");
} }
} }
request.start(); request.start();
...@@ -287,7 +289,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -287,7 +289,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
@Override @Override
public void joinRoute(String sourceId, String presentationId, String origin, int tabId, public void joinRoute(String sourceId, String presentationId, String origin, int tabId,
int nativeRequestId) { int nativeRequestId) {
MediaSource source = MediaSource.from(sourceId); CastMediaSource source = CastMediaSource.from(sourceId);
if (source == null || source.getClientId() == null) { if (source == null || source.getClientId() == null) {
mManager.onRouteRequestError("Unsupported presentation URL", nativeRequestId); mManager.onRouteRequestError("Unsupported presentation URL", nativeRequestId);
return; return;
...@@ -420,10 +422,10 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -420,10 +422,10 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
// Send a "disconnect_session" message to all the clients that match with the leaving // Send a "disconnect_session" message to all the clients that match with the leaving
// client's auto join policy. // client's auto join policy.
for (ClientRecord client : mClientRecords.values()) { for (ClientRecord client : mClientRecords.values()) {
if ((MediaSource.AUTOJOIN_TAB_AND_ORIGIN_SCOPED.equals(leavingClient.autoJoinPolicy) if ((CastMediaSource.AUTOJOIN_TAB_AND_ORIGIN_SCOPED.equals(leavingClient.autoJoinPolicy)
&& isSameOrigin(client.origin, leavingClient.origin) && isSameOrigin(client.origin, leavingClient.origin)
&& client.tabId == leavingClient.tabId) && client.tabId == leavingClient.tabId)
|| (MediaSource.AUTOJOIN_ORIGIN_SCOPED.equals(leavingClient.autoJoinPolicy) || (CastMediaSource.AUTOJOIN_ORIGIN_SCOPED.equals(leavingClient.autoJoinPolicy)
&& isSameOrigin(client.origin, leavingClient.origin))) { && isSameOrigin(client.origin, leavingClient.origin))) {
onMessage(client.clientId, onMessage(client.clientId,
buildInternalMessage("disconnect_session", -1, client.clientId, sessionId)); buildInternalMessage("disconnect_session", -1, client.clientId, sessionId));
...@@ -451,10 +453,10 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -451,10 +453,10 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
mMessageHandler = new CastMessageHandler(this); mMessageHandler = new CastMessageHandler(this);
} }
private boolean canAutoJoin(MediaSource source, String origin, int tabId) { private boolean canAutoJoin(CastMediaSource source, String origin, int tabId) {
if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_PAGE_SCOPED)) return false; if (source.getAutoJoinPolicy().equals(CastMediaSource.AUTOJOIN_PAGE_SCOPED)) return false;
MediaSource currentSource = MediaSource.from(mSession.getSourceId()); CastMediaSource currentSource = CastMediaSource.from(mSession.getSourceId());
if (!currentSource.getApplicationId().equals(source.getApplicationId())) return false; if (!currentSource.getApplicationId().equals(source.getApplicationId())) return false;
ClientRecord client = null; ClientRecord client = null;
...@@ -467,17 +469,18 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -467,17 +469,18 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
if (client == null) return false; if (client == null) return false;
boolean sameOrigin = isSameOrigin(origin, client.origin); boolean sameOrigin = isSameOrigin(origin, client.origin);
if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_ORIGIN_SCOPED)) { if (source.getAutoJoinPolicy().equals(CastMediaSource.AUTOJOIN_ORIGIN_SCOPED)) {
return sameOrigin; return sameOrigin;
} else if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_TAB_AND_ORIGIN_SCOPED)) { } else if (source.getAutoJoinPolicy().equals(
CastMediaSource.AUTOJOIN_TAB_AND_ORIGIN_SCOPED)) {
return sameOrigin && tabId == client.tabId; return sameOrigin && tabId == client.tabId;
} }
return false; return false;
} }
private boolean canJoinExistingSession(String presentationId, String origin, int tabId, private boolean canJoinExistingSession(
MediaSource source) { String presentationId, String origin, int tabId, CastMediaSource source) {
if (AUTO_JOIN_PRESENTATION_ID.equals(presentationId)) { if (AUTO_JOIN_PRESENTATION_ID.equals(presentationId)) {
return canAutoJoin(source, origin, tabId); return canAutoJoin(source, origin, tabId);
} else if (presentationId.startsWith(PRESENTATION_ID_SESSION_ID_PREFIX)) { } else if (presentationId.startsWith(PRESENTATION_ID_SESSION_ID_PREFIX)) {
...@@ -503,7 +506,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele ...@@ -503,7 +506,7 @@ public class CastMediaRouteProvider implements MediaRouteProvider, DiscoveryDele
void addRoute(MediaRoute route, String origin, int tabId) { void addRoute(MediaRoute route, String origin, int tabId) {
mRoutes.put(route.id, route); mRoutes.put(route.id, route);
MediaSource source = MediaSource.from(route.sourceId); CastMediaSource source = CastMediaSource.from(route.sourceId);
final String clientId = source.getClientId(); final String clientId = source.getClientId();
if (clientId == null || mClientRecords.get(clientId) != null) return; if (clientId == null || mClientRecords.get(clientId) != null) return;
......
...@@ -268,7 +268,7 @@ public class CastSessionImpl implements MediaNotificationListener, CastSession { ...@@ -268,7 +268,7 @@ public class CastSessionImpl implements MediaNotificationListener, CastSession {
@Override @Override
public String getSourceId() { public String getSourceId() {
return mSource.getUrn(); return mSource.getSourceId();
} }
@Override @Override
......
...@@ -9,6 +9,7 @@ import android.util.Base64; ...@@ -9,6 +9,7 @@ import android.util.Base64;
import com.google.android.gms.cast.CastMediaControlIntent; import com.google.android.gms.cast.CastMediaControlIntent;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.chrome.browser.media.router.cast.MediaSource;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
...@@ -17,7 +18,7 @@ import javax.annotation.Nullable; ...@@ -17,7 +18,7 @@ import javax.annotation.Nullable;
/** /**
* Abstracts parsing the Cast application id and other parameters from the source id. * Abstracts parsing the Cast application id and other parameters from the source id.
*/ */
public class RemotingMediaSource { public class RemotingMediaSource implements MediaSource {
private static final String TAG = "MediaRemoting"; private static final String TAG = "MediaRemoting";
// Need to be in sync with third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp. // Need to be in sync with third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp.
...@@ -71,6 +72,7 @@ public class RemotingMediaSource { ...@@ -71,6 +72,7 @@ public class RemotingMediaSource {
* *
* @return an initialized route selector or null. * @return an initialized route selector or null.
*/ */
@Override
public MediaRouteSelector buildRouteSelector() { public MediaRouteSelector buildRouteSelector() {
return new MediaRouteSelector.Builder() return new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId)) .addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId))
...@@ -80,6 +82,7 @@ public class RemotingMediaSource { ...@@ -80,6 +82,7 @@ public class RemotingMediaSource {
/** /**
* @return the Cast application id corresponding to the source. Can be overridden downstream. * @return the Cast application id corresponding to the source. Can be overridden downstream.
*/ */
@Override
public String getApplicationId() { public String getApplicationId() {
return mApplicationId; return mApplicationId;
} }
...@@ -87,6 +90,7 @@ public class RemotingMediaSource { ...@@ -87,6 +90,7 @@ public class RemotingMediaSource {
/** /**
* @return the id identifying the media source * @return the id identifying the media source
*/ */
@Override
public String getSourceId() { public String getSourceId() {
return mSourceId; return mSourceId;
} }
......
...@@ -594,6 +594,7 @@ chrome_java_sources = [ ...@@ -594,6 +594,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/media/router/MediaRouteManager.java", "java/src/org/chromium/chrome/browser/media/router/MediaRouteManager.java",
"java/src/org/chromium/chrome/browser/media/router/MediaRouteProvider.java", "java/src/org/chromium/chrome/browser/media/router/MediaRouteProvider.java",
"java/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProvider.java", "java/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProvider.java",
"java/src/org/chromium/chrome/browser/media/router/cast/CastMediaSource.java",
"java/src/org/chromium/chrome/browser/media/router/cast/CastMessageHandler.java", "java/src/org/chromium/chrome/browser/media/router/cast/CastMessageHandler.java",
"java/src/org/chromium/chrome/browser/media/router/cast/CastRequestIdGenerator.java", "java/src/org/chromium/chrome/browser/media/router/cast/CastRequestIdGenerator.java",
"java/src/org/chromium/chrome/browser/media/router/cast/CastSession.java", "java/src/org/chromium/chrome/browser/media/router/cast/CastSession.java",
...@@ -1893,10 +1894,10 @@ chrome_junit_test_java_sources = [ ...@@ -1893,10 +1894,10 @@ chrome_junit_test_java_sources = [
"junit/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterSinkObservationTest.java", "junit/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterSinkObservationTest.java",
"junit/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterTestBase.java", "junit/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterTestBase.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProviderTest.java", "junit/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProviderTest.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/CastMediaSourceTest.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/CastMessageHandlerTest.java", "junit/src/org/chromium/chrome/browser/media/router/cast/CastMessageHandlerTest.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/DiscoveryCallbackTest.java", "junit/src/org/chromium/chrome/browser/media/router/cast/DiscoveryCallbackTest.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/JSONTestUtils.java", "junit/src/org/chromium/chrome/browser/media/router/cast/JSONTestUtils.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/MediaSourceTest.java",
"junit/src/org/chromium/chrome/browser/media/router/cast/TestUtils.java", "junit/src/org/chromium/chrome/browser/media/router/cast/TestUtils.java",
"junit/src/org/chromium/chrome/browser/media/ui/MediaImageManagerTest.java", "junit/src/org/chromium/chrome/browser/media/ui/MediaImageManagerTest.java",
"junit/src/org/chromium/chrome/browser/media/ui/MediaNotificationActionsUpdatedTest.java", "junit/src/org/chromium/chrome/browser/media/ui/MediaNotificationActionsUpdatedTest.java",
......
...@@ -34,7 +34,7 @@ public class CastMediaRouteProviderTest { ...@@ -34,7 +34,7 @@ public class CastMediaRouteProviderTest {
private static final String SUPPORTED_SOURCE = "cast:DEADBEEF"; private static final String SUPPORTED_SOURCE = "cast:DEADBEEF";
private static final String SUPPORTED_AUTOJOIN_SOURCE = "cast:DEADBEEF" private static final String SUPPORTED_AUTOJOIN_SOURCE = "cast:DEADBEEF"
+ "?clientId=12345&autoJoinPolicy=" + MediaSource.AUTOJOIN_TAB_AND_ORIGIN_SCOPED; + "?clientId=12345&autoJoinPolicy=" + CastMediaSource.AUTOJOIN_TAB_AND_ORIGIN_SCOPED;
// TODO(crbug.com/672704): Android does not currently support 1-UA mode. // TODO(crbug.com/672704): Android does not currently support 1-UA mode.
private static final String UNSUPPORTED_SOURCE = "https://example.com"; private static final String UNSUPPORTED_SOURCE = "https://example.com";
......
...@@ -16,22 +16,20 @@ import org.chromium.base.test.util.Feature; ...@@ -16,22 +16,20 @@ import org.chromium.base.test.util.Feature;
import org.chromium.testing.local.LocalRobolectricTestRunner; import org.chromium.testing.local.LocalRobolectricTestRunner;
/** /**
* Robolectric tests for {@link MediaSource} class. * Robolectric tests for {@link CastMediaSource} class.
*/ */
@RunWith(LocalRobolectricTestRunner.class) @RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
public class MediaSourceTest { public class CastMediaSourceTest {
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testCorrectSourceId() { public void testCorrectSourceId() {
final String sourceId = final String sourceId = "https://example.com/path?query"
"https://example.com/path?query"
+ "#__castAppId__=ABCD1234(video_out,audio_out)" + "#__castAppId__=ABCD1234(video_out,audio_out)"
+ "/__castClientId__=1234567890" + "/__castClientId__=1234567890"
+ "/__castAutoJoinPolicy__=tab_and_origin_scoped"; + "/__castAutoJoinPolicy__=tab_and_origin_scoped";
MediaSource source = MediaSource.from(sourceId); CastMediaSource source = CastMediaSource.from(sourceId);
assertNotNull(source); assertNotNull(source);
assertEquals("ABCD1234", source.getApplicationId()); assertEquals("ABCD1234", source.getApplicationId());
...@@ -43,38 +41,39 @@ public class MediaSourceTest { ...@@ -43,38 +41,39 @@ public class MediaSourceTest {
assertEquals("1234567890", source.getClientId()); assertEquals("1234567890", source.getClientId());
assertEquals("tab_and_origin_scoped", source.getAutoJoinPolicy()); assertEquals("tab_and_origin_scoped", source.getAutoJoinPolicy());
assertEquals(sourceId, source.getUrn()); assertEquals(sourceId, source.getSourceId());
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testNoFragment() { public void testNoFragment() {
assertNull(MediaSource.from("https://example.com/path?query")); assertNull(CastMediaSource.from("https://example.com/path?query"));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testEmptyFragment() { public void testEmptyFragment() {
assertNull(MediaSource.from("https://example.com/path?query#")); assertNull(CastMediaSource.from("https://example.com/path?query#"));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testNoAppId() { public void testNoAppId() {
assertNull(MediaSource.from("https://example.com/path?query#fragment")); assertNull(CastMediaSource.from("https://example.com/path?query#fragment"));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testNoValidAppId() { public void testNoValidAppId() {
// Invalid app id needs to indicate no availability so {@link MediaSource} needs to be // Invalid app id needs to indicate no availability so {@link CastMediaSource} needs to be
// created. // created.
MediaSource empty = MediaSource.from("https://example.com/path?query#__castAppId__="); CastMediaSource empty =
CastMediaSource.from("https://example.com/path?query#__castAppId__=");
assertNotNull(empty); assertNotNull(empty);
assertEquals("", empty.getApplicationId()); assertEquals("", empty.getApplicationId());
MediaSource invalid = MediaSource.from( CastMediaSource invalid =
"https://example.com/path?query#__castAppId__=INVALID-APP-ID"); CastMediaSource.from("https://example.com/path?query#__castAppId__=INVALID-APP-ID");
assertNotNull(invalid); assertNotNull(invalid);
assertEquals("INVALID-APP-ID", invalid.getApplicationId()); assertEquals("INVALID-APP-ID", invalid.getApplicationId());
} }
...@@ -82,33 +81,35 @@ public class MediaSourceTest { ...@@ -82,33 +81,35 @@ public class MediaSourceTest {
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testNoCapabilitiesSuffix() { public void testNoCapabilitiesSuffix() {
assertNull(MediaSource.from("https://example.com/path?query#__castAppId__=A(")); assertNull(CastMediaSource.from("https://example.com/path?query#__castAppId__=A("));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testCapabilitiesEmpty() { public void testCapabilitiesEmpty() {
assertNull(MediaSource.from("https://example.com/path?query#__castAppId__=A()")); assertNull(CastMediaSource.from("https://example.com/path?query#__castAppId__=A()"));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testInvalidCapability() { public void testInvalidCapability() {
assertNull(MediaSource.from("https://example.com/path?query#__castAppId__=A(a)")); assertNull(CastMediaSource.from("https://example.com/path?query#__castAppId__=A(a)"));
assertNull(MediaSource.from("https://example.com/path?query#__castAppId__=A(video_in,b)")); assertNull(
CastMediaSource.from("https://example.com/path?query#__castAppId__=A(video_in,b)"));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testInvalidAutoJoinPolicy() { public void testInvalidAutoJoinPolicy() {
assertNull(MediaSource.from("https://example.com/path?query#__castAppId__=A" assertNull(CastMediaSource.from("https://example.com/path?query#__castAppId__=A"
+ "/__castAutoJoinPolicy__=invalidPolicy")); + "/__castAutoJoinPolicy__=invalidPolicy"));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testOptionalParameters() { public void testOptionalParameters() {
MediaSource source = MediaSource.from("https://example.com/path?query#__castAppId__=A"); CastMediaSource source =
CastMediaSource.from("https://example.com/path?query#__castAppId__=A");
assertNotNull(source); assertNotNull(source);
assertEquals("A", source.getApplicationId()); assertEquals("A", source.getApplicationId());
...@@ -120,7 +121,7 @@ public class MediaSourceTest { ...@@ -120,7 +121,7 @@ public class MediaSourceTest {
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testBasicCastPresentationUrl() { public void testBasicCastPresentationUrl() {
MediaSource source = MediaSource.from("cast:ABCD1234"); CastMediaSource source = CastMediaSource.from("cast:ABCD1234");
assertNotNull(source); assertNotNull(source);
assertEquals("ABCD1234", source.getApplicationId()); assertEquals("ABCD1234", source.getApplicationId());
assertNull(source.getCapabilities()); assertNull(source.getCapabilities());
...@@ -131,7 +132,7 @@ public class MediaSourceTest { ...@@ -131,7 +132,7 @@ public class MediaSourceTest {
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testCastPresentationUrlWithParameters() { public void testCastPresentationUrlWithParameters() {
MediaSource source = MediaSource.from("cast:ABCD1234?clientId=1234" CastMediaSource source = CastMediaSource.from("cast:ABCD1234?clientId=1234"
+ "&capabilities=video_out,audio_out" + "&capabilities=video_out,audio_out"
+ "&autoJoinPolicy=tab_and_origin_scoped"); + "&autoJoinPolicy=tab_and_origin_scoped");
assertNotNull(source); assertNotNull(source);
...@@ -147,14 +148,14 @@ public class MediaSourceTest { ...@@ -147,14 +148,14 @@ public class MediaSourceTest {
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testCastPresentationUrlInvalidCapability() { public void testCastPresentationUrlInvalidCapability() {
assertNull(MediaSource.from("cast:ABCD1234?clientId=1234" assertNull(CastMediaSource.from("cast:ABCD1234?clientId=1234"
+ "&capabilities=invalidCapability")); + "&capabilities=invalidCapability"));
} }
@Test @Test
@Feature({"MediaRouter"}) @Feature({"MediaRouter"})
public void testCastPresentationUrlInvalidAutoJoinPolicy() { public void testCastPresentationUrlInvalidAutoJoinPolicy() {
assertNull(MediaSource.from("cast:ABCD1234?clientId=1234" assertNull(CastMediaSource.from("cast:ABCD1234?clientId=1234"
+ "&autoJoinPolicy=invalidPolicy")); + "&autoJoinPolicy=invalidPolicy"));
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment