chromium/content/browser/media/session/media_session_impl_service_routing_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/memory/raw_ptr.h"
#include "content/browser/media/session/media_session_impl.h"

#include <map>
#include <memory>
#include <string>

#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "content/browser/media/session/media_session_player_observer.h"
#include "content/browser/media/session/mock_media_session_service_impl.h"
#include "content/public/test/test_media_session_client.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "media/base/media_content_type.h"
#include "services/media_session/public/cpp/media_metadata.h"
#include "services/media_session/public/cpp/test/mock_media_session.h"
#include "services/media_session/public/mojom/constants.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/mediasession/media_session.mojom.h"

_;
AnyNumber;
Eq;
InvokeWithoutArgs;
NiceMock;

MediaAudioVideoState;
MediaSessionAction;
MediaSessionImageType;

namespace {
std::u16string hidden_metadata_placeholder_title =;
std::u16string hidden_metadata_placeholder_source_title =;
std::u16string hidden_metadata_placeholder_artist =;
std::u16string hidden_metadata_placeholder_album =;
}  // namespace

namespace content {

namespace {

constexpr base::TimeDelta kDefaultSeekTime =;

static const int kPlayerId =;

class MockMediaSessionPlayerObserver : public MediaSessionPlayerObserver {};

}  // anonymous namespace

class MediaSessionImplServiceRoutingTest
    : public RenderViewHostImplTestHarness {};

TEST_F(MediaSessionImplServiceRoutingTest, NoFrameProducesAudio) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       OnlyMainFrameProducesAudioButHasNoService) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       OnlySubFrameProducesAudioButHasNoService) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       OnlyMainFrameProducesAudioButHasDestroyedService) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       OnlySubFrameProducesAudioButHasDestroyedService) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       OnlyMainFrameProducesAudioAndServiceIsCreatedAfterwards) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       OnlySubFrameProducesAudioAndServiceIsCreatedAfterwards) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       BothFrameProducesAudioButOnlySubFrameHasService) {}

TEST_F(MediaSessionImplServiceRoutingTest, PreferTopMostFrame) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       RoutedServiceUpdatedAfterRemovingPlayer) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       DontNotifyMetadataAndActionsChangeWhenUncontrollable) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyMetadataAndActionsChangeWhenControllable) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyActionsAndMetadataChangeWhenUncontrollableForMainFrame) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       RoutesTopMostFrameWhenNoFrameIsHasPlayers) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestPauseBehaviorWhenMainFrameIsRouted) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestPauseBehaviorWhenSubFrameIsRouted) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestReceivingPauseActionWhenNoServiceRouted) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestPreviousTrackBehaviorWhenMainFrameIsRouted) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestNextTrackBehaviorWhenMainFrameIsRouted) {}

TEST_F(MediaSessionImplServiceRoutingTest, TestSeekBackwardBehaviourDefault) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestSeekBackwardBehaviourWhenActionEnabled) {}

TEST_F(MediaSessionImplServiceRoutingTest, TestSeekForwardBehaviourDefault) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestSeekForwardBehaviourWhenActionEnabled) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestSeekToBehaviorWhenMainFrameIsRouted) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       TestScrubToBehaviorWhenMainFrameIsRouted) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverMetadataWhenControllable) {}

// We hide the media metadata only from CrOS' media controls by replacing the
// metadata in the MediaSessionImpl with some placeholder metadata.
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(MediaSessionImplServiceRoutingTest, HideMediaMetadataInCrOS) {
  client_.SetShouldHideMetadata(true);

  media_session::MediaMetadata expected_metadata;
  expected_metadata.title = hidden_metadata_placeholder_title;
  expected_metadata.artist = hidden_metadata_placeholder_artist;
  expected_metadata.album = hidden_metadata_placeholder_album;
  expected_metadata.source_title = hidden_metadata_placeholder_source_title;

  CreateServiceForFrame(main_frame_);
  StartPlayerForFrame(main_frame_);

  {
    media_session::test::MockMediaSessionMojoObserver observer(
        *GetMediaSession());

    blink::mojom::SpecMediaMetadataPtr spec_metadata(
        blink::mojom::SpecMediaMetadata::New());
    spec_metadata->title = u"title";
    spec_metadata->artist = u"artist";
    spec_metadata->album = u"album";

    services_[main_frame_]->SetMetadata(std::move(spec_metadata));

    observer.WaitForExpectedMetadata(expected_metadata);
  }
}
#else  // !BUILDFLAG(IS_CHROMEOS)
TEST_F(MediaSessionImplServiceRoutingTest, DontHideMediaMetadataInNonCrOS) {}
#endif

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverMetadataEmptyWhenControllable) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWhenTurningUncontrollable) {}

TEST_F(MediaSessionImplServiceRoutingTest, NotifyObserverWhenActionsChange) {}

TEST_F(MediaSessionImplServiceRoutingTest, DefaultActionsAlwaysSupported) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       DefaultActionsRemovedIfUncontrollable) {}

TEST_F(MediaSessionImplServiceRoutingTest, NotifyObserverOnNavigation) {}

TEST_F(MediaSessionImplServiceRoutingTest, NotifyObserverOnTitleChange) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithActionsOnAddWhenServiceNotPresent) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithActionsOnAddWhenServicePresent) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithActionsOnAddWhenServiceDestroyed) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithEmptyImagesWhenServiceNotPresent) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithImagesWhenServicePresent) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithImagesWhenMultipleServicesPresent) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithImages_HideMetadata) {}

TEST_F(MediaSessionImplServiceRoutingTest, StopBehaviourDefault) {}

TEST_F(MediaSessionImplServiceRoutingTest, StopBehaviourWhenActionEnabled) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       PositionFromServiceShouldOverridePlayer) {}

TEST_F(MediaSessionImplServiceRoutingTest, PositionFromServiceCanBeReset) {}

TEST_F(MediaSessionImplServiceRoutingTest, RouteAudioVideoState) {}

TEST_F(MediaSessionImplServiceRoutingTest,
       NotifyObserverWithChaptersWhenServicePresent) {}

// Test duration duration update throttle behavior for routed service.
// TODO (jazzhsu): Remove these tests once media session supports livestream.
class MediaSessionImplServiceRoutingThrottleTest
    : public MediaSessionImplServiceRoutingTest {};

TEST_F(MediaSessionImplServiceRoutingThrottleTest,
       ShouldNotThrottleRoutedService) {}

class MediaSessionImplServiceRoutingFencedFrameTest
    : public MediaSessionImplServiceRoutingTest {};

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest, NoFrameProducesAudio) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest,
       OnlyFencedFrameProducesAudioButHasNoService) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest,
       OnlyFencedFrameProducesAudioButHasDestroyedService) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest,
       OnlyFencedFrameProducesAudioAndServiceIsCreatedAfterwards) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest,
       BothFrameProducesAudioButOnlyFencedFrameHasService) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest, PreferTopMostFrame) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest,
       RoutedServiceUpdatedAfterRemovingPlayer) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest, PreferSubFrame) {}

TEST_F(MediaSessionImplServiceRoutingFencedFrameTest,
       AllFrameProducesAudioButSubFrameAndFencedFrameHaveService) {}

}  // namespace content