chromium/chrome/browser/ui/media_router/media_route_starter_unittest.cc

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

#include "chrome/browser/ui/media_router/media_route_starter.h"

#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/media/router/chrome_media_router_factory.h"
#include "chrome/browser/media/router/test/provider_test_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sessions/session_tab_helper_factory.h"
#include "chrome/browser/ui/global_media_controls/test_helper.h"
#include "chrome/browser/ui/media_router/media_cast_mode.h"
#include "chrome/browser/ui/media_router/query_result_manager.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/media_router/browser/logger_impl.h"
#include "components/media_router/browser/media_router_factory.h"
#include "components/media_router/browser/media_sinks_observer.h"
#include "components/media_router/browser/presentation/web_contents_presentation_manager.h"
#include "components/media_router/browser/test/mock_media_router.h"
#include "components/media_router/browser/test/test_helper.h"
#include "components/media_router/common/discovery/media_sink_internal.h"
#include "components/media_router/common/media_sink.h"
#include "components/media_router/common/route_request_result.h"
#include "components/media_router/common/test/test_helper.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/sessions/core/session_id.h"
#include "content/public/browser/presentation_request.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"

#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#include "ui/base/cocoa/permissions_utils.h"
#endif

_;
Invoke;
NiceMock;
Return;

namespace media_router {

namespace {
constexpr char kPresentationId[] =;
constexpr char kLoggerComponent[] =;

const CastModeSet kDefaultModes =;
const CastModeSet kMirroringOnly =;
const CastModeSet kPresentationOnly =;
const CastModeSet kDestkopMirrorOnly =;
const CastModeSet kRemotePlaybackOnly =;

constexpr char kDefaultPresentationUrl[] =;
constexpr char kDefaultOriginUrl[] =;

constexpr char kStartPresentationUrl[] =;
constexpr char kStartOriginUrl[] =;

constexpr char kRemotePlaybackUrl[] =;

class MockPresentationRequestSourceObserver
    : public PresentationRequestSourceObserver {};

// For demonstrating that presentation mode callbacks are made from the MRS
// d'tor
class PresentationRequestCallbacks {};

}  // namespace

class MediaRouteStarterTest : public ChromeRenderViewHostTestHarness {};

// Demonstrates that when initialized with webcontents but no presentation
// source the supported modes are mirroring only.
TEST_F(MediaRouteStarterTest, Defaults_NoPresentation) {}

// Demonstrates that when initialized with webcontents that has a default
// presentation that presentation mode is supported.
TEST_F(MediaRouteStarterTest, Defaults_WebContentPresentation) {}

// Demonstrates that if caller doesn't request mirroring that it is not
// available.
TEST_F(MediaRouteStarterTest, Defaults_WebContentPresentationOnly) {}

// Demonstrates that when initialized with a presentation request that
// presentation mode is supported - even if the web contents has no default
// presentation.
TEST_F(MediaRouteStarterTest, Defaults_StartPresentationContext) {}

// Demonstrates that when initialized with Remote Playback mode
TEST_F(MediaRouteStarterTest, Defaults_RemotePlayback) {}

// Demonstrates that when initialized with no webcontent or presentation source
// the supported modes are desktop mirroring only.
TEST_F(MediaRouteStarterTest, Defaults_NoWebContent) {}

// Demonstrates that when MediaRouteStarter is notified that the presentation
// request source has changed, that it alerts observers with the name of that
// presentation request source.
TEST_F(MediaRouteStarterTest, OnPresentationRequestSourceUpdated) {}

// Demonstrates that when MediaRouteStarter is notified that there is no
// presentation request source that it alerts observers that the name of the
// presentation source is empty.
TEST_F(MediaRouteStarterTest, OnPresentationRequestSourceRemoved) {}

// Demonstrates that if MediaRouteStarter is destroyed without an attempt to
// create a route with the presentation source, that the expected error is
// reported to the presentation source.
TEST_F(MediaRouteStarterTest, Dtor_NotFoundError_NoSinks) {}

// Same as above, but demonstrates the same error reporting even if sinks exist,
// so long as none of the sinks were compatible with the presentation source.
TEST_F(MediaRouteStarterTest, Dtor_NotFoundError_NoCompatibleSinks) {}

// Same as above, but demonstrates that if a compatible sink was present, then
// the error that is reported indicates that the request was cancelled.
TEST_F(MediaRouteStarterTest, Dtor_AbortError) {}

// Demonstrates that if there are no sources available for the desired mode
// CreateRouteParameters returns nothing.
TEST_F(MediaRouteStarterTest, CreateRouteParameters_NoValidSource) {}

// Demonstrates that when desktop mirroring is available and requested that the
// RouteParameters are properly filled out.
TEST_F(MediaRouteStarterTest, CreateRouteParameters_DesktopMirroring) {}

// Demonstrates that when tab mirroring is available and requested that the
// RouteParameters are properly filled out.
TEST_F(MediaRouteStarterTest, CreateRouteParameters_TabMirroring) {}

// Demonstrates that when presentation mode is available for the default
// presentation and requested that the RouteParameters are properly filled out.
TEST_F(MediaRouteStarterTest, CreateRouteParameters_WebContentPresentation) {}

// Demonstrates that when presentation mode is requested and a start
// presentation context is available that the RouteParameters are correctly
// filled out.
TEST_F(MediaRouteStarterTest, CreateRouteParameters_StartPresentationContext) {}

// Demonstrates that desktop mirroring routes are created correctly.
TEST_F(MediaRouteStarterTest, StartRoute_DesktopMirroring) {}

// Demonstrates that failures to create desktop mirroring routes are propagated.
TEST_F(MediaRouteStarterTest, StartRoute_DesktopMirroringError) {}

// Demonstrates that tab mirroring routes are created correctly.
TEST_F(MediaRouteStarterTest, StartRoute_TabMirroring) {}

// Demonstrates that failures to create tab mirroring routes are propagated.
TEST_F(MediaRouteStarterTest, StartRoute_TabMirroringError) {}

// Demonstrates that presentations routes from web content are created
// correctly.
TEST_F(MediaRouteStarterTest, StartRoute_WebContentPresentation) {}

// Demonstrates that failures to create presentation routes from web content are
// propagated correctly.
TEST_F(MediaRouteStarterTest, StartRoute_WebContentPresentationError) {}

// Demonstrates that presentations routes from start presentation contexts are
// created correctly.
TEST_F(MediaRouteStarterTest, StartRoute_StartPresentationContext_Cast) {}

TEST_F(MediaRouteStarterTest,
       StartRoute_StartPresentationContext_RemotePlayback) {}

// Demonstrates that failures to create presentation routes from start
// presentation contexts are created correctly.
TEST_F(MediaRouteStarterTest, StartRoute_StartPresentationContextError) {}

TEST_F(MediaRouteStarterTest, GetScreenCapturePermission) {}

}  // namespace media_router