#include <stddef.h>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/strings/stringprintf.h"
#include "base/test/gmock_expected_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/browser/webrtc/webrtc_content_browsertest_base.h"
#include "content/browser/webrtc/webrtc_internals.h"
#include "content/public/browser/audio_service.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "media/audio/audio_manager.h"
#include "media/audio/fake_audio_input_stream.h"
#include "media/base/media_switches.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/audio/public/mojom/testing_api.mojom.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#endif
namespace {
static const char kGetUserMediaAndStop[] = …;
static const char kGetUserMediaAndAnalyseAndStop[] = …;
static const char kGetUserMediaAndExpectFailure[] = …;
static const char kRenderSameTrackMediastreamAndStop[] = …;
static const char kRenderClonedMediastreamAndStop[] = …;
static const char kRenderClonedTrackMediastreamAndStop[] = …;
static const char kRenderDuplicatedMediastreamAndStop[] = …;
std::string GenerateGetUserMediaWithMandatorySourceID(
const std::string& function_name,
const std::string& audio_source_id,
const std::string& video_source_id) { … }
std::string GenerateGetUserMediaWithOptionalSourceID(
const std::string& function_name,
const std::string& audio_source_id,
const std::string& video_source_id) { … }
#if 0
std::string GenerateGetUserMediaWithDisableLocalEcho(
const std::string& function_name,
const std::string& disable_local_echo) {
const std::string audio_constraint =
"audio:{mandatory: { chromeMediaSource : 'system', disableLocalEcho : " +
disable_local_echo + " }},";
const std::string video_constraint =
"video: { mandatory: { chromeMediaSource:'screen' }}";
return function_name + "({" + audio_constraint + video_constraint + "});";
}
bool VerifyDisableLocalEcho(bool expect_value,
const blink::StreamControls& controls) {
return expect_value == controls.disable_local_echo;
}
#endif
}
namespace content {
class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase { … };
#if defined(MEMORY_SANITIZER)
#define MAYBE_GetVideoStreamAndStop …
#else
#define MAYBE_GetVideoStreamAndStop …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_GetVideoStreamAndStop) { … }
#if defined(MEMORY_SANITIZER)
#define MAYBE_RenderSameTrackMediastreamAndStop …
#else
#define MAYBE_RenderSameTrackMediastreamAndStop …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_RenderSameTrackMediastreamAndStop) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
RenderClonedMediastreamAndStop) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
kRenderClonedTrackMediastreamAndStop) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
kRenderDuplicatedMediastreamAndStop) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioAndVideoStreamAndStop) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioAndVideoStreamAndClone) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_RenderVideoTrackInMultipleTagsAndPause) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC)
#define MAYBE_GetUserMediaWithMandatorySourceID …
#else
#define MAYBE_GetUserMediaWithMandatorySourceID …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_GetUserMediaWithMandatorySourceID) { … }
#undef MAYBE_GetUserMediaWithMandatorySourceID
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaWithInvalidMandatorySourceID) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_GetUserMediaWithInvalidOptionalSourceID …
#else
#define MAYBE_GetUserMediaWithInvalidOptionalSourceID …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_GetUserMediaWithInvalidOptionalSourceID) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaAndStop) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithEqualConstraints) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithSecondVideoCropped) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithFirstHdSecondVga) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaWithFirst1080pSecondVga) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaWithTooHighVideoConstraintsValues) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaFailToAccessAudioDevice) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TwoGetUserMediaAndCheckCallbackAfterFailure) { … }
#if defined(THREAD_SANITIZER) || BUILDFLAG(IS_MAC) || \
BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_TestGetUserMediaAspectRatio4To3 …
#else
#define MAYBE_TestGetUserMediaAspectRatio4To3 …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_TestGetUserMediaAspectRatio4To3) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_TestGetUserMediaAspectRatio16To9) { … }
#if defined(THREAD_SANITIZER) || BUILDFLAG(IS_MAC) || \
BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_TestGetUserMediaAspectRatio1To1 …
#else
#define MAYBE_TestGetUserMediaAspectRatio1To1 …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_TestGetUserMediaAspectRatio1To1) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_AudioInIFrameAndCloseInSuccessCb) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_VideoInIFrameAndCloseInSuccessCb) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_MAC)
#define MAYBE_VideoWithBadConstraintsInIFrameAndCloseInFailureCb …
#else
#define MAYBE_VideoWithBadConstraintsInIFrameAndCloseInFailureCb …
#endif
IN_PROC_BROWSER_TEST_F(
WebRtcGetUserMediaBrowserTest,
MAYBE_VideoWithBadConstraintsInIFrameAndCloseInFailureCb) { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#define MAYBE_InvalidSourceIdInIFrameAndCloseInFailureCb …
#else
#define MAYBE_InvalidSourceIdInIFrameAndCloseInFailureCb …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_InvalidSourceIdInIFrameAndCloseInFailureCb) { … }
#if 0
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DisableLocalEchoParameter) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
MediaStreamManager* manager =
BrowserMainLoop::GetInstance()->media_stream_manager();
manager->SetGenerateStreamsCallbackForTesting(
base::BindOnce(&VerifyDisableLocalEcho, false));
std::string call = GenerateGetUserMediaWithDisableLocalEcho(
"getUserMediaAndExpectSuccess", "false");
EXPECT_TRUE(ExecJs(shell(), call));
manager->SetGenerateStreamsCallbackForTesting(
base::BindOnce(&VerifyDisableLocalEcho, true));
call = GenerateGetUserMediaWithDisableLocalEcho(
"getUserMediaAndExpectSuccess", "true");
EXPECT_TRUE(ExecJs(shell(), call));
manager->SetGenerateStreamsCallbackForTesting(
MediaStreamManager::GenerateStreamTestCallback());
}
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, GetAudioSettingsDefault) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioSettingsNoEchoCancellation) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetAudioSettingsDeviceId) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, SrcObjectAddVideoTrack) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_SrcObjectReplaceInactiveTracks) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_SrcObjectRemoveVideoTrack) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_SrcObjectRemoveFirstOfTwoVideoTracks) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
SrcObjectReassignSameObject) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, ApplyConstraintsVideo) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_ApplyConstraintsVideoTwoStreams) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
ApplyConstraintsVideoOverconstrained) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_ApplyConstraintsNonDevice …
#else
#define MAYBE_ApplyConstraintsNonDevice …
#endif
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
MAYBE_ApplyConstraintsNonDevice) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
ConcurrentGetUserMediaStop) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_GetUserMediaAfterStopElementCapture) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
GetUserMediaEchoCancellationOnAndOff) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
DISABLED_GetUserMediaEchoCancellationOnAndOffAndVideo) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
EnumerationAfterSameDocumentNavigation) { … }
IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
RecoverFromCrashInAudioService) { … }
}