Commit 6f15f17c authored by Thoren Paulson's avatar Thoren Paulson Committed by Commit Bot

[Chromecast] Decouple cast app lifetime from activity lifetime.

This CL allows CastWebContentsActivity to be re-launched multiple times
for a single session, while re-attaching the existing WebContents.

Bug: internal b/151099227
Test: back out of cast app and resume with NowPlaying or WatchNext

Change-Id: I280cf45f1153ad9238e8006c01349c1c6798ae0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161729Reviewed-by: default avatarSimeon Anfinrud <sanfin@chromium.org>
Commit-Queue: Thoren Paulson <thoren@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763595}
parent 52f1906f
...@@ -125,6 +125,12 @@ generate_product_config_srcjar("chromecast_product_config") { ...@@ -125,6 +125,12 @@ generate_product_config_srcjar("chromecast_product_config") {
java_package = "org.chromium.chromecast.shell" java_package = "org.chromium.chromecast.shell"
} }
android_library("resume_intents_java") {
java_src_dir = "//chromecast/browser/android/apk/src"
sources = [ "$java_src_dir/org/chromium/chromecast/shell/ResumeIntents.java" ]
deps = [ "//chromecast/base:base_java" ]
}
android_library("cast_shell_java") { android_library("cast_shell_java") {
java_src_dir = "//chromecast/browser/android/apk/src" java_src_dir = "//chromecast/browser/android/apk/src"
sources = [ sources = [
...@@ -150,6 +156,7 @@ android_library("cast_shell_java") { ...@@ -150,6 +156,7 @@ android_library("cast_shell_java") {
"$java_src_dir/org/chromium/chromecast/shell/ElidedLogcatProvider.java", "$java_src_dir/org/chromium/chromecast/shell/ElidedLogcatProvider.java",
"$java_src_dir/org/chromium/chromecast/shell/ExternalServiceDeviceLogcatProvider.java", "$java_src_dir/org/chromium/chromecast/shell/ExternalServiceDeviceLogcatProvider.java",
"$java_src_dir/org/chromium/chromecast/shell/LogcatElision.java", "$java_src_dir/org/chromium/chromecast/shell/LogcatElision.java",
"$java_src_dir/org/chromium/chromecast/shell/WebContentsRegistry.java",
] ]
android_manifest_for_lint = cast_shell_android_manifest android_manifest_for_lint = cast_shell_android_manifest
...@@ -170,6 +177,7 @@ android_library("cast_shell_java") { ...@@ -170,6 +177,7 @@ android_library("cast_shell_java") {
":cast_shell_android_resources", ":cast_shell_android_resources",
":cast_shell_manifest", ":cast_shell_manifest",
":reactive_android_java", ":reactive_android_java",
":resume_intents_java",
"//base:base_java", "//base:base_java",
"//base:jni_java", "//base:jni_java",
"//chromecast/base:base_java", "//chromecast/base:base_java",
......
...@@ -156,17 +156,6 @@ public class CastWebContentsActivity extends Activity { ...@@ -156,17 +156,6 @@ public class CastWebContentsActivity extends Activity {
audioManager.releaseStreamMuteIfNecessary(AudioManager.STREAM_MUSIC); audioManager.releaseStreamMuteIfNecessary(AudioManager.STREAM_MUSIC);
})); }));
final Observable<CastAudioFocusRequest> audioFocusRequestState = mCreatedState.map(x
-> new CastAudioFocusRequest.Builder()
.setFocusGain(AudioManager.AUDIOFOCUS_GAIN)
.build());
mAudioManagerState.subscribe((CastAudioManager audioManager) -> {
return audioManager.requestAudioFocusWhen(audioFocusRequestState)
.filter(state -> state == CastAudioManager.AudioFocusLoss.NORMAL)
.subscribe(Observers.onEnter(x -> mIsFinishingState.set("Lost audio focus.")));
});
// Handle each new Intent. // Handle each new Intent.
Controller<CastWebContentsSurfaceHelper.StartParams> startParamsState = new Controller<>(); Controller<CastWebContentsSurfaceHelper.StartParams> startParamsState = new Controller<>();
mGotIntentState.and(Observable.not(mIsFinishingState)) mGotIntentState.and(Observable.not(mIsFinishingState))
...@@ -245,6 +234,7 @@ public class CastWebContentsActivity extends Activity { ...@@ -245,6 +234,7 @@ public class CastWebContentsActivity extends Activity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
if (DEBUG) Log.d(TAG, "onDestroy"); if (DEBUG) Log.d(TAG, "onDestroy");
mCreatedState.reset(); mCreatedState.reset();
super.onDestroy(); super.onDestroy();
} }
......
...@@ -9,14 +9,18 @@ import android.content.Context; ...@@ -9,14 +9,18 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.IBinder; import android.os.IBinder;
import android.os.PatternMatcher; import android.os.PatternMatcher;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.chromecast.base.Controller; import org.chromium.chromecast.base.Controller;
import org.chromium.chromecast.base.Observable;
import org.chromium.chromecast.base.Observers;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
/** /**
...@@ -132,6 +136,7 @@ public class CastWebContentsComponent { ...@@ -132,6 +136,7 @@ public class CastWebContentsComponent {
Intent intent = CastWebContentsIntentUtils.requestStartCastActivity( Intent intent = CastWebContentsIntentUtils.requestStartCastActivity(
context, webContents, enableTouch, isRemoteControlMode, turnOnScreen, mSessionId); context, webContents, enableTouch, isRemoteControlMode, turnOnScreen, mSessionId);
if (DEBUG) Log.d(TAG, "start activity by intent: " + intent); if (DEBUG) Log.d(TAG, "start activity by intent: " + intent);
ResumeIntents.addResumeIntent(mSessionId, intent);
context.startActivity(intent); context.startActivity(intent);
} }
...@@ -139,6 +144,7 @@ public class CastWebContentsComponent { ...@@ -139,6 +144,7 @@ public class CastWebContentsComponent {
Intent intent = CastWebContentsIntentUtils.requestStopWebContents(mSessionId); Intent intent = CastWebContentsIntentUtils.requestStopWebContents(mSessionId);
if (DEBUG) Log.d(TAG, "stop: send STOP_WEB_CONTENT intent: " + intent); if (DEBUG) Log.d(TAG, "stop: send STOP_WEB_CONTENT intent: " + intent);
sendIntentSync(intent); sendIntentSync(intent);
ResumeIntents.removeResumeIntent(mSessionId);
} }
private class ServiceDelegate implements Delegate { private class ServiceDelegate implements Delegate {
...@@ -184,6 +190,8 @@ public class CastWebContentsComponent { ...@@ -184,6 +190,8 @@ public class CastWebContentsComponent {
private final boolean mIsRemoteControlMode; private final boolean mIsRemoteControlMode;
private final boolean mTurnOnScreen; private final boolean mTurnOnScreen;
private final Controller<CastAudioFocusRequest> mAudioFocusRequestState = new Controller<>();
public CastWebContentsComponent(String sessionId, public CastWebContentsComponent(String sessionId,
OnComponentClosedHandler onComponentClosedHandler, OnComponentClosedHandler onComponentClosedHandler,
SurfaceEventHandler surfaceEventHandler, boolean isHeadless, boolean enableTouchInput, SurfaceEventHandler surfaceEventHandler, boolean isHeadless, boolean enableTouchInput,
...@@ -201,6 +209,13 @@ public class CastWebContentsComponent { ...@@ -201,6 +209,13 @@ public class CastWebContentsComponent {
mSurfaceEventHandler = surfaceEventHandler; mSurfaceEventHandler = surfaceEventHandler;
mIsRemoteControlMode = isRemoteControlMode; mIsRemoteControlMode = isRemoteControlMode;
mTurnOnScreen = turnOnScreen; mTurnOnScreen = turnOnScreen;
CastAudioManager audioManager =
CastAudioManager.getAudioManager(ContextUtils.getApplicationContext());
Observable<CastAudioManager.AudioFocusLoss> focusLoss =
audioManager.requestAudioFocusWhen(mAudioFocusRequestState)
.filter(state -> state == CastAudioManager.AudioFocusLoss.NORMAL);
mAudioFocusRequestState.andThen(focusLoss).subscribe(
Observers.onEnter(x -> mComponentClosedHandler.onComponentClosed()));
if (BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE || isHeadless) { if (BuildConfig.DISPLAY_WEB_CONTENTS_IN_SERVICE || isHeadless) {
if (DEBUG) Log.d(TAG, "Creating service delegate..."); if (DEBUG) Log.d(TAG, "Creating service delegate...");
...@@ -285,6 +300,9 @@ public class CastWebContentsComponent { ...@@ -285,6 +300,9 @@ public class CastWebContentsComponent {
+ "; Visibility Priority: " + params.visibilityPriority); + "; Visibility Priority: " + params.visibilityPriority);
} }
mHasWebContentsState.set(params.webContents); mHasWebContentsState.set(params.webContents);
mAudioFocusRequestState.set(new CastAudioFocusRequest.Builder()
.setFocusGain(AudioManager.AUDIOFOCUS_GAIN)
.build());
mDelegate.start(params); mDelegate.start(params);
mStarted = true; mStarted = true;
} }
...@@ -296,6 +314,7 @@ public class CastWebContentsComponent { ...@@ -296,6 +314,7 @@ public class CastWebContentsComponent {
+ "; Instance ID: " + mSessionId); + "; Instance ID: " + mSessionId);
} }
if (mStarted) { if (mStarted) {
mAudioFocusRequestState.reset();
mHasWebContentsState.reset(); mHasWebContentsState.reset();
if (DEBUG) Log.d(TAG, "Call delegate to stop"); if (DEBUG) Log.d(TAG, "Call delegate to stop");
mDelegate.stop(context); mDelegate.stop(context);
......
...@@ -96,10 +96,6 @@ public class CastWebContentsIntentUtils { ...@@ -96,10 +96,6 @@ public class CastWebContentsIntentUtils {
/** Key of extra value of the intent to start a web content, value is session ID of cast app */ /** Key of extra value of the intent to start a web content, value is session ID of cast app */
static final String INTENT_EXTRA_SESSION_ID = "content_session_id"; static final String INTENT_EXTRA_SESSION_ID = "content_session_id";
/** Key of extra value of the intent to start a web content, value is object of WebContents */
static final String INTENT_EXTRA_WEB_CONTENTS =
"com.google.android.apps.castshell.intent.extra.WEB_CONTENTS";
/** Key of extra value of the intent to start a web content, value is true if cast app supports /** Key of extra value of the intent to start a web content, value is true if cast app supports
* touch input. * touch input.
*/ */
...@@ -325,10 +321,11 @@ public class CastWebContentsIntentUtils { ...@@ -325,10 +321,11 @@ public class CastWebContentsIntentUtils {
public static Intent requestStartCastActivity(Context context, WebContents webContents, public static Intent requestStartCastActivity(Context context, WebContents webContents,
boolean enableTouch, boolean isRemoteControlMode, boolean turnOnScreen, boolean enableTouch, boolean isRemoteControlMode, boolean turnOnScreen,
String instanceId) { String instanceId) {
WebContentsRegistry.addWebContents(instanceId, webContents);
Intent intent = Intent intent =
new Intent(Intent.ACTION_VIEW, null, context, CastWebContentsActivity.class); new Intent(Intent.ACTION_VIEW, null, context, CastWebContentsActivity.class);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString()); intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
intent.putExtra(INTENT_EXTRA_WEB_CONTENTS, webContents); intent.putExtra(INTENT_EXTRA_SESSION_ID, instanceId);
intent.putExtra(INTENT_EXTRA_TOUCH_INPUT_ENABLED, enableTouch); intent.putExtra(INTENT_EXTRA_TOUCH_INPUT_ENABLED, enableTouch);
intent.putExtra(INTENT_EXTRA_TURN_ON_SCREEN, turnOnScreen); intent.putExtra(INTENT_EXTRA_TURN_ON_SCREEN, turnOnScreen);
intent.putExtra(INTENT_EXTRA_REMOTE_CONTROL_MODE, isRemoteControlMode); intent.putExtra(INTENT_EXTRA_REMOTE_CONTROL_MODE, isRemoteControlMode);
...@@ -341,6 +338,7 @@ public class CastWebContentsIntentUtils { ...@@ -341,6 +338,7 @@ public class CastWebContentsIntentUtils {
public static Intent requestStartCastFragment(WebContents webContents, String appId, public static Intent requestStartCastFragment(WebContents webContents, String appId,
@VisibilityPriority int visibilityPriority, boolean enableTouch, String instanceId, @VisibilityPriority int visibilityPriority, boolean enableTouch, String instanceId,
boolean isRemoteControlMode, boolean turnOnScreen) { boolean isRemoteControlMode, boolean turnOnScreen) {
WebContentsRegistry.addWebContents(instanceId, webContents);
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(CastIntents.ACTION_SHOW_WEB_CONTENT); intent.setAction(CastIntents.ACTION_SHOW_WEB_CONTENT);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString()); intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
...@@ -349,7 +347,6 @@ public class CastWebContentsIntentUtils { ...@@ -349,7 +347,6 @@ public class CastWebContentsIntentUtils {
intent.putExtra(INTENT_EXTRA_VISIBILITY_PRIORITY, visibilityPriority); intent.putExtra(INTENT_EXTRA_VISIBILITY_PRIORITY, visibilityPriority);
intent.putExtra(INTENT_EXTRA_TOUCH_INPUT_ENABLED, enableTouch); intent.putExtra(INTENT_EXTRA_TOUCH_INPUT_ENABLED, enableTouch);
intent.putExtra(INTENT_EXTRA_TURN_ON_SCREEN, turnOnScreen); intent.putExtra(INTENT_EXTRA_TURN_ON_SCREEN, turnOnScreen);
intent.putExtra(INTENT_EXTRA_WEB_CONTENTS, webContents);
intent.putExtra(INTENT_EXTRA_REMOTE_CONTROL_MODE, isRemoteControlMode); intent.putExtra(INTENT_EXTRA_REMOTE_CONTROL_MODE, isRemoteControlMode);
return intent; return intent;
} }
...@@ -357,14 +354,16 @@ public class CastWebContentsIntentUtils { ...@@ -357,14 +354,16 @@ public class CastWebContentsIntentUtils {
// CastWebContentsComponent.Receiver -> CastWebContentsService // CastWebContentsComponent.Receiver -> CastWebContentsService
public static Intent requestStartCastService( public static Intent requestStartCastService(
Context context, WebContents webContents, String instanceId) { Context context, WebContents webContents, String instanceId) {
WebContentsRegistry.addWebContents(instanceId, webContents);
Intent intent = new Intent(Intent.ACTION_VIEW, getInstanceUri(instanceId), context, Intent intent = new Intent(Intent.ACTION_VIEW, getInstanceUri(instanceId), context,
CastWebContentsService.class); CastWebContentsService.class);
intent.putExtra(INTENT_EXTRA_WEB_CONTENTS, webContents); intent.putExtra(INTENT_EXTRA_SESSION_ID, instanceId);
return intent; return intent;
} }
// CastWebContentsComponent.Delegate -> CastWebContentsSurfaceHelper // CastWebContentsComponent.Delegate -> CastWebContentsSurfaceHelper
public static Intent requestStopWebContents(String instanceId) { public static Intent requestStopWebContents(String instanceId) {
WebContentsRegistry.removeWebContents(instanceId);
Intent intent = new Intent(CastIntents.ACTION_STOP_WEB_CONTENT); Intent intent = new Intent(CastIntents.ACTION_STOP_WEB_CONTENT);
intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString()); intent.putExtra(INTENT_EXTRA_URI, getInstanceUri(instanceId).toString());
return intent; return intent;
...@@ -392,7 +391,8 @@ public class CastWebContentsIntentUtils { ...@@ -392,7 +391,8 @@ public class CastWebContentsIntentUtils {
// Used by ACTION_VIEW, ACTION_SHOW_WEB_CONTENT // Used by ACTION_VIEW, ACTION_SHOW_WEB_CONTENT
public static WebContents getWebContents(Bundle bundle) { public static WebContents getWebContents(Bundle bundle) {
return (WebContents) bundle.getParcelable(INTENT_EXTRA_WEB_CONTENTS); String sessionId = bundle.getString(INTENT_EXTRA_SESSION_ID);
return WebContentsRegistry.getWebContents(sessionId);
} }
// Used by ACTION_VIEW, ACTION_SHOW_WEB_CONTENT // Used by ACTION_VIEW, ACTION_SHOW_WEB_CONTENT
......
...@@ -18,7 +18,6 @@ import org.chromium.components.embedder_support.view.ContentView; ...@@ -18,7 +18,6 @@ import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.components.embedder_support.view.ContentViewRenderView; import org.chromium.components.embedder_support.view.ContentViewRenderView;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
class CastWebContentsScopes { class CastWebContentsScopes {
...@@ -71,9 +70,7 @@ class CastWebContentsScopes { ...@@ -71,9 +70,7 @@ class CastWebContentsScopes {
layout.addView(contentViewRenderView, matchParent); layout.addView(contentViewRenderView, matchParent);
ContentView contentView = ContentView.createContentView(context, webContents); ContentView contentView = ContentView.createContentView(context, webContents);
// TODO(derekjchow): productVersion WebContentsRegistry.initializeWebContents(webContents, contentView, window);
webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(contentView),
contentView, window, WebContents.createDefaultInternalsHolder());
// Enable display of current webContents. // Enable display of current webContents.
webContents.onShow(); webContents.onShow();
...@@ -86,6 +83,7 @@ class CastWebContentsScopes { ...@@ -86,6 +83,7 @@ class CastWebContentsScopes {
layout.setForeground(new ColorDrawable(backgroundColor)); layout.setForeground(new ColorDrawable(backgroundColor));
layout.removeView(contentView); layout.removeView(contentView);
layout.removeView(contentViewRenderView); layout.removeView(contentViewRenderView);
webContents.setTopLevelNativeWindow(null);
contentViewRenderView.destroy(); contentViewRenderView.destroy();
window.destroy(); window.destroy();
}; };
...@@ -96,9 +94,7 @@ class CastWebContentsScopes { ...@@ -96,9 +94,7 @@ class CastWebContentsScopes {
return (WebContents webContents) -> { return (WebContents webContents) -> {
WindowAndroid window = new WindowAndroid(context); WindowAndroid window = new WindowAndroid(context);
ContentView contentView = ContentView.createContentView(context, webContents); ContentView contentView = ContentView.createContentView(context, webContents);
// TODO(derekjchow): productVersion WebContentsRegistry.initializeWebContents(webContents, contentView, window);
webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(contentView),
contentView, window, WebContents.createDefaultInternalsHolder());
// Enable display of current webContents. // Enable display of current webContents.
webContents.onShow(); webContents.onShow();
return () -> { return () -> {
......
...@@ -169,12 +169,6 @@ class CastWebContentsSurfaceHelper { ...@@ -169,12 +169,6 @@ class CastWebContentsSurfaceHelper {
.map(params -> mMediaSessionGetter.get(params.webContents)) .map(params -> mMediaSessionGetter.get(params.webContents))
.subscribe(Observers.onEnter(MediaSessionImpl::requestSystemAudioFocus)); .subscribe(Observers.onEnter(MediaSessionImpl::requestSystemAudioFocus));
// Miscellaneous actions responding to WebContents lifecycle.
webContentsState.subscribe((WebContents webContents) -> {
// Notify CastWebContentsComponent when closed.
return () -> CastWebContentsComponent.onComponentClosed(mSessionId);
});
// When onDestroy() is called after onNewStartParams(), log and reset StartParams states. // When onDestroy() is called after onNewStartParams(), log and reset StartParams states.
uriState.andThen(Observable.not(mCreatedState)) uriState.andThen(Observable.not(mCreatedState))
.map(Both::getFirst) .map(Both::getFirst)
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chromecast.shell;
import android.content.Intent;
import org.chromium.chromecast.base.Controller;
import org.chromium.chromecast.base.Observable;
import java.util.HashMap;
/**
* This class stores intents that can be used to resume a Cast Activity, for use by Play Next cards
* and other services.
*/
public class ResumeIntents {
private static final HashMap<String, Controller<Intent>> sSesionIdToIntent = new HashMap<>();
static void addResumeIntent(String sessionId, Intent i) {
Intent intent = new Intent(i);
Controller<Intent> controller = sSesionIdToIntent.get(sessionId);
if (controller == null) {
controller = new Controller<>();
sSesionIdToIntent.put(sessionId, controller);
}
controller.set(intent);
}
static void removeResumeIntent(String sessionId) {
Controller<Intent> controller = sSesionIdToIntent.remove(sessionId);
if (controller != null) {
controller.reset();
}
}
public static Observable<Intent> getResumeIntent(String sessionId) {
Controller<Intent> controller = sSesionIdToIntent.get(sessionId);
if (controller == null) {
controller = new Controller<>();
sSesionIdToIntent.put(sessionId, controller);
}
return controller;
}
}
\ No newline at end of file
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chromecast.shell;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid;
import java.util.HashMap;
/**
* This class associates a session id with a web contents in order to allow new activity instances
* to get the WebContents. This is necessary instead of parceling because other apps cannot use an
* Intent with a parceled WebContents.
*/
public class WebContentsRegistry {
private static class WebContentsHolder {
public WebContents webContents;
public boolean initialized;
public WebContentsHolder(WebContents webContents) {
this.webContents = webContents;
this.initialized = false;
}
}
private static final HashMap<String, WebContentsHolder> sSesionIdToWebContents =
new HashMap<>();
static void addWebContents(String sessionId, WebContents contents) {
sSesionIdToWebContents.put(sessionId, new WebContentsHolder(contents));
}
static void removeWebContents(String sessionId) {
sSesionIdToWebContents.remove(sessionId);
}
public static WebContents getWebContents(String sessionId) {
return sSesionIdToWebContents.get(sessionId).webContents;
}
public static void initializeWebContents(
WebContents webContents, ContentView contentView, WindowAndroid window) {
for (WebContentsHolder holder : sSesionIdToWebContents.values()) {
if (holder.webContents.equals(webContents)) {
if (!holder.initialized) {
// TODO(derekjchow): productVersion
webContents.initialize("", ViewAndroidDelegate.createBasicDelegate(contentView),
contentView, window, WebContents.createDefaultInternalsHolder());
} else {
webContents.getViewAndroidDelegate().setContainerView(contentView);
webContents.setTopLevelNativeWindow(window);
}
holder.initialized = true;
return;
}
}
}
}
\ No newline at end of file
...@@ -16,9 +16,7 @@ import static org.mockito.Mockito.verify; ...@@ -16,9 +16,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri; import android.net.Uri;
import android.os.PatternMatcher;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -37,9 +35,6 @@ import org.chromium.chromecast.shell.CastWebContentsSurfaceHelper.StartParams; ...@@ -37,9 +35,6 @@ import org.chromium.chromecast.shell.CastWebContentsSurfaceHelper.StartParams;
import org.chromium.content.browser.MediaSessionImpl; import org.chromium.content.browser.MediaSessionImpl;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList;
import java.util.List;
/** /**
* Tests for CastWebContentsSurfaceHelper. * Tests for CastWebContentsSurfaceHelper.
*/ */
...@@ -84,31 +79,6 @@ public class CastWebContentsSurfaceHelperTest { ...@@ -84,31 +79,6 @@ public class CastWebContentsSurfaceHelperTest {
} }
} }
private static class BroadcastAsserter {
private final Intent mExpectedIntent;
private final List<Intent> mReceivedIntents = new ArrayList<>();
private final LocalBroadcastReceiverScope mReceiver;
public BroadcastAsserter(Intent looksLike) {
mExpectedIntent = looksLike;
IntentFilter filter = new IntentFilter();
Uri instanceUri = looksLike.getData();
filter.addDataScheme(instanceUri.getScheme());
filter.addDataAuthority(instanceUri.getAuthority(), null);
filter.addDataPath(instanceUri.getPath(), PatternMatcher.PATTERN_LITERAL);
filter.addAction(looksLike.getAction());
mReceiver = new LocalBroadcastReceiverScope(filter, mReceivedIntents::add);
}
public void verify() {
assertEquals(1, mReceivedIntents.size());
Intent receivedIntent = mReceivedIntents.get(0);
assertEquals(mExpectedIntent.getAction(), receivedIntent.getAction());
assertEquals(mExpectedIntent.getData(), receivedIntent.getData());
mReceiver.close();
}
}
private void sendBroadcastSync(Intent intent) { private void sendBroadcastSync(Intent intent) {
CastWebContentsIntentUtils.getLocalBroadcastManager().sendBroadcastSync(intent); CastWebContentsIntentUtils.getLocalBroadcastManager().sendBroadcastSync(intent);
} }
...@@ -284,18 +254,6 @@ public class CastWebContentsSurfaceHelperTest { ...@@ -284,18 +254,6 @@ public class CastWebContentsSurfaceHelperTest {
assertFalse(mSurfaceHelper.isTouchInputEnabled()); assertFalse(mSurfaceHelper.isTouchInputEnabled());
} }
@Test
public void testSendsComponentClosedBroadcastWhenWebContentsViewIsClosedAlt() {
StartParams params1 = new StartParamsBuilder().withId("1").build();
StartParams params2 = new StartParamsBuilder().withId("2").build();
mSurfaceHelper.onNewStartParams(params1);
// Listen for notification from surface helper that web contents closed.
BroadcastAsserter intentWasSent =
new BroadcastAsserter(CastWebContentsIntentUtils.onActivityStopped("1"));
mSurfaceHelper.onNewStartParams(params2);
intentWasSent.verify();
}
@Test @Test
public void testFinishLaterCallbackIsRunAfterStopWebContents() { public void testFinishLaterCallbackIsRunAfterStopWebContents() {
StartParams params = new StartParamsBuilder().withId("0").build(); StartParams params = new StartParamsBuilder().withId("0").build();
......
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