#include "content/browser/media/capture/web_contents_video_capture_device.h"
#include <optional>
#include <tuple>
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "cc/test/pixel_test_utils.h"
#include "content/browser/media/capture/content_capture_device_browsertest_base.h"
#include "content/browser/media/capture/fake_video_capture_stack.h"
#include "content/browser/media/capture/frame_test_util.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/shell/browser/shell.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
#include "media/base/video_types.h"
#include "media/base/video_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gl/gl_switches.h"
#if BUILDFLAG(IS_WIN)
#include "ui/aura/test/aura_test_utils.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ui_base_features.h"
#endif
namespace content {
namespace {
class WebContentsVideoCaptureDeviceBrowserTest
: public ContentCaptureDeviceBrowserTestBase,
public FrameTestUtil { … };
#if defined(MEMORY_SANITIZER)
#define MAYBE_ErrorsOutIfWebContentsHasGoneBeforeDeviceStart …
#else
#define MAYBE_ErrorsOutIfWebContentsHasGoneBeforeDeviceStart …
#endif
IN_PROC_BROWSER_TEST_F(WebContentsVideoCaptureDeviceBrowserTest,
MAYBE_ErrorsOutIfWebContentsHasGoneBeforeDeviceStart) { … }
#if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_MAC)
#define MAYBE_ErrorsOutWhenWebContentsIsDestroyed …
#else
#define MAYBE_ErrorsOutWhenWebContentsIsDestroyed …
#endif
IN_PROC_BROWSER_TEST_F(WebContentsVideoCaptureDeviceBrowserTest,
MAYBE_ErrorsOutWhenWebContentsIsDestroyed) { … }
#if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_MAC)
#define MAYBE_ChangesTargettedRenderView …
#else
#define MAYBE_ChangesTargettedRenderView …
#endif
IN_PROC_BROWSER_TEST_F(WebContentsVideoCaptureDeviceBrowserTest,
MAYBE_ChangesTargettedRenderView) { … }
#if BUILDFLAG(IS_WIN)
class WebContentsVideoCaptureDeviceBrowserTestAura
: public WebContentsVideoCaptureDeviceBrowserTest {
public:
void SetUp() override {
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kApplyNativeOcclusionToCompositor,
{{features::kApplyNativeOcclusionToCompositorType.name,
features::kApplyNativeOcclusionToCompositorTypeRelease}});
WebContentsVideoCaptureDeviceBrowserTest::SetUp();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(WebContentsVideoCaptureDeviceBrowserTestAura,
CapturesWhenOccluded) {
aura::WindowTreeHost* window_tree_host = shell()->window()->GetHost();
aura::test::DisableNativeWindowOcclusionTracking(window_tree_host);
NavigateToInitialDocument();
AllocateAndStartAndWaitForFirstFrame();
EXPECT_TRUE(shell()->web_contents()->IsBeingCaptured());
ChangePageContentColor(SK_ColorRED);
WaitForFrameWithColor(SK_ColorRED);
window_tree_host->SetNativeWindowOcclusionState(
aura::Window::OcclusionState::OCCLUDED, {});
EXPECT_TRUE(shell()->web_contents()->IsBeingCaptured());
ChangePageContentColor(SK_ColorGREEN);
WaitForFrameWithColor(SK_ColorGREEN);
}
#endif
#if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_MAC)
#define MAYBE_RecoversAfterRendererCrash …
#else
#define MAYBE_RecoversAfterRendererCrash …
#endif
IN_PROC_BROWSER_TEST_F(WebContentsVideoCaptureDeviceBrowserTest,
MAYBE_RecoversAfterRendererCrash) { … }
#if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_MAC)
#define MAYBE_SuspendsAndResumes …
#else
#define MAYBE_SuspendsAndResumes …
#endif
IN_PROC_BROWSER_TEST_F(WebContentsVideoCaptureDeviceBrowserTest,
MAYBE_SuspendsAndResumes) { … }
#if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_MAC)
#define MAYBE_DeliversRefreshFramesUponRequest …
#else
#define MAYBE_DeliversRefreshFramesUponRequest …
#endif
IN_PROC_BROWSER_TEST_F(WebContentsVideoCaptureDeviceBrowserTest,
MAYBE_DeliversRefreshFramesUponRequest) { … }
class WebContentsVideoCaptureDeviceBrowserTestP
: public WebContentsVideoCaptureDeviceBrowserTest,
public testing::WithParamInterface<
std::tuple<bool, bool, bool, media::VideoPixelFormat>> { … };
#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_ANDROID)
INSTANTIATE_TEST_SUITE_P(
All,
WebContentsVideoCaptureDeviceBrowserTestP,
testing::Combine(
testing::Values(false ),
testing::Values(false ,
true ),
testing::Values(false ,
true ),
testing::Values(media::VideoPixelFormat::PIXEL_FORMAT_I420)),
&WebContentsVideoCaptureDeviceBrowserTestP::GetDescription);
#elif BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
INSTANTIATE_TEST_SUITE_P(
All,
WebContentsVideoCaptureDeviceBrowserTestP,
testing::Combine(
testing::Values(false ,
true ),
testing::Values(false ,
true ),
testing::Values(false ,
true ),
testing::Values(media::VideoPixelFormat::PIXEL_FORMAT_I420,
media::VideoPixelFormat::PIXEL_FORMAT_UNKNOWN)),
&WebContentsVideoCaptureDeviceBrowserTestP::GetDescription);
#else
INSTANTIATE_TEST_SUITE_P(…);
#endif
#if defined(MEMORY_SANITIZER) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
(BUILDFLAG(IS_CHROMEOS) && defined(ADDRESS_SANITIZER)) || \
(BUILDFLAG(IS_CHROMEOS_ASH) && !defined(NDEBUG))
#define MAYBE_CapturesContentChanges …
#else
#define MAYBE_CapturesContentChanges …
#endif
IN_PROC_BROWSER_TEST_P(WebContentsVideoCaptureDeviceBrowserTestP,
MAYBE_CapturesContentChanges) { … }
}
}