#include <memory>
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/permissions/permission_request_manager.h"
#include "content/public/browser/web_contents.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_base.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/prerender_test_util.h"
#include "ui/gl/gl_switches.h"
WebContents;
namespace {
const char kCapturedTabTitle[] = …;
const char kCapturingPageMain[] = …;
const char kCapturingPageEmbedded[] = …;
const char kCapturedPageMain[] = …;
const char kCapturedPageOther[] = …;
const char* kArbitraryOrigin = …;
const char* kNoEmbeddedCaptureHandle = …;
enum class BrowserType { … };
std::string StringifyPermittedOrigins(
const std::vector<std::string>& permitted_origins) { … }
std::string StringifyCaptureHandle(WebContents* web_contents,
bool expose_origin,
const std::string& handle) { … }
struct TabInfo { … };
TabInfo MakeTabInfoFromActiveTab(Browser* browser) { … }
}
class CaptureHandleBrowserTest : public WebRtcTestBase { … };
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
HandleAndOriginExposedIfAllPermitted) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
HandleAndOriginExposedIfCapturerOriginPermitted) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
HandleAndOriginNotExposedIfCapturerOriginNotPermitted) { … }
#if BUILDFLAG(IS_MAC)
#define MAYBE_HandleNotExposedIfTopLevelAllowlistedButCallingFrameNotAllowlisted …
#else
#define MAYBE_HandleNotExposedIfTopLevelAllowlistedButCallingFrameNotAllowlisted …
#endif
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
MAYBE_HandleNotExposedIfTopLevelAllowlistedButCallingFrameNotAllowlisted) { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_WIN)
#define MAYBE_HandleExposedIfCallingFrameAllowlistedEvenIfTopLevelNotAllowlisted …
#else
#define MAYBE_HandleExposedIfCallingFrameAllowlistedEvenIfTopLevelNotAllowlisted …
#endif
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
MAYBE_HandleExposedIfCallingFrameAllowlistedEvenIfTopLevelNotAllowlisted) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest, CanExposeOnlyHandle) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
CanExposeEmptyHandleIfExposingOrigin) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
EmptyCaptureHandleConfigMeansCaptureHandleNotExposed) { … }
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
CallingSetCaptureHandleConfigWithEmptyConfigFiresEventAndClearsValue) { … }
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
CallingSetCaptureHandleConfigWithNewHandleChangesConfigAndFiresEvent) { … }
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
CallingSetCaptureHandleConfigWithNewOriginValueChangesConfigAndFiresEvent) { … }
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
PermittedOriginsChangeThatRemovesCapturerCausesEventAndEmptyConfig) { … }
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
PermittedOriginsChangeThatAddsCapturerCausesEventAndConfigExposure) { … }
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
PermittedOriginsChangeThatDoesNotAffectCapturerDoesNotCauseEventOrChange) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
SameDocumentNavigationDoesNotClearTheCaptureHandle) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
CrossDocumentNavigationClearsTheCaptureHandle) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
CrossOriginNavigationClearsTheCaptureHandle) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
SelfCaptureSanityWhenPermitted) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
SelfCaptureSanityWhenNotPermitted) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_RegularTabCannotReadIncognitoTabCaptureHandle …
#else
#define MAYBE_RegularTabCannotReadIncognitoTabCaptureHandle …
#endif
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
MAYBE_RegularTabCannotReadIncognitoTabCaptureHandle) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
DISABLED_IncognitoTabCannotReadRegularTabCaptureHandle) { … }
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTest,
IncognitoTabCannotReadIncognitoTabCaptureHandle) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_IncognitoTabCanReadIncognitoTabCaptureHandleIfSelfCapture …
#else
#define MAYBE_IncognitoTabCanReadIncognitoTabCaptureHandleIfSelfCapture …
#endif
IN_PROC_BROWSER_TEST_F(
CaptureHandleBrowserTest,
MAYBE_IncognitoTabCanReadIncognitoTabCaptureHandleIfSelfCapture) { … }
class CaptureHandleBrowserTestPrerender : public CaptureHandleBrowserTest { … };
IN_PROC_BROWSER_TEST_F(CaptureHandleBrowserTestPrerender,
EmptyConfigForCrossDocumentNavigations) { … }