| Index: chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java
|
| index f1b70d18b607139fd3c096d3b40c165bc45c44f9..2cdd8c5da5f2e5c2d70f97647ed35d34617299a4 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaSessionTabHelper.java
|
| @@ -41,14 +41,16 @@ public class MediaSessionTabHelper implements MediaImageCallback {
|
| private static final String TAG = "MediaSession";
|
|
|
| private static final String UNICODE_PLAY_CHARACTER = "\u25B6";
|
| - private static final int HIDE_NOTIFICATION_DELAY_MILLIS = 1000;
|
| + @VisibleForTesting
|
| + static final int HIDE_NOTIFICATION_DELAY_MILLIS = 1000;
|
|
|
| private Tab mTab;
|
| private Bitmap mPageMediaImage;
|
| private Bitmap mFavicon;
|
| private Bitmap mCurrentMediaImage;
|
| private String mOrigin;
|
| - private MediaSessionObserver mMediaSessionObserver;
|
| + @VisibleForTesting
|
| + MediaSessionObserver mMediaSessionObserver;
|
| private int mPreviousVolumeControlStream = AudioManager.USE_DEFAULT_STREAM_TYPE;
|
| private MediaNotificationInfo.Builder mNotificationInfoBuilder;
|
| // The fallback title if |mPageMetadata| is null or its title is empty.
|
| @@ -65,6 +67,11 @@ public class MediaSessionTabHelper implements MediaImageCallback {
|
| // showing or immediate hiding.
|
| private Runnable mHideNotificationDelayedTask;
|
|
|
| + // Used to override the MediaSession object get from WebContents. This is to work around the
|
| + // static getter {@link MediaSession#fromWebContents()}.
|
| + @VisibleForTesting
|
| + static MediaSession sOverriddenMediaSession;
|
| +
|
| @VisibleForTesting
|
| @Nullable
|
| MediaSessionObserver getMediaSessionObserverForTesting() {
|
| @@ -244,7 +251,7 @@ public class MediaSessionTabHelper implements MediaImageCallback {
|
| }
|
|
|
| private void setWebContents(WebContents webContents) {
|
| - MediaSession mediaSession = MediaSession.fromWebContents(webContents);
|
| + MediaSession mediaSession = getMediaSession(webContents);
|
| if (mMediaSessionObserver != null
|
| && mediaSession == mMediaSessionObserver.getMediaSession()) {
|
| return;
|
| @@ -264,7 +271,8 @@ public class MediaSessionTabHelper implements MediaImageCallback {
|
| mMediaSessionActions = null;
|
| }
|
|
|
| - private final TabObserver mTabObserver = new EmptyTabObserver() {
|
| + @VisibleForTesting
|
| + final TabObserver mTabObserver = new EmptyTabObserver() {
|
| @Override
|
| public void onContentChanged(Tab tab) {
|
| assert tab == mTab;
|
| @@ -292,7 +300,9 @@ public class MediaSessionTabHelper implements MediaImageCallback {
|
| String origin = mTab.getUrl();
|
| try {
|
| origin = UrlFormatter.formatUrlForSecurityDisplay(new URI(origin), true);
|
| - } catch (URISyntaxException e) {
|
| + } catch (URISyntaxException | UnsatisfiedLinkError e) {
|
| + // UnstatisfiedLinkError can only happen in tests as the natives are not initialized
|
| + // yet.
|
| Log.e(TAG, "Unable to parse the origin from the URL. "
|
| + "Using the full URL instead.");
|
| }
|
| @@ -348,7 +358,8 @@ public class MediaSessionTabHelper implements MediaImageCallback {
|
| }
|
| };
|
|
|
| - private MediaSessionTabHelper(Tab tab) {
|
| + @VisibleForTesting
|
| + MediaSessionTabHelper(Tab tab) {
|
| mTab = tab;
|
| mTab.addObserver(mTabObserver);
|
| mMediaImageManager =
|
| @@ -498,4 +509,9 @@ public class MediaSessionTabHelper implements MediaImageCallback {
|
| private boolean isNotificationHiddingOrHidden() {
|
| return mNotificationInfoBuilder == null;
|
| }
|
| +
|
| + private MediaSession getMediaSession(WebContents contents) {
|
| + return (sOverriddenMediaSession != null) ? sOverriddenMediaSession
|
| + : MediaSession.fromWebContents(contents);
|
| + }
|
| }
|
|
|