#include <stddef.h>
#include <cstddef>
#include <memory>
#include <string_view>
#include <utility>
#include "base/base64.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/safe_sprintf.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/download/public/common/download_file_factory.h"
#include "components/download/public/common/download_file_impl.h"
#include "components/download/public/common/download_task_runner.h"
#include "components/services/storage/shared_storage/shared_storage_manager.h"
#include "content/browser/devtools/protocol/browser_handler.h"
#include "content/browser/devtools/protocol/devtools_download_manager_delegate.h"
#include "content/browser/devtools/protocol/devtools_protocol_test_support.h"
#include "content/browser/devtools/protocol/system_info.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h"
#include "content/browser/download/download_manager_impl.h"
#include "content/browser/host_zoom_map_impl.h"
#include "content/browser/preloading/prerender/prerender_final_status.h"
#include "content/browser/renderer_host/navigator.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/tracing_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/back_forward_cache_util.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/download_test_observer.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/slow_download_http_response.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "net/base/features.h"
#include "net/dns/dns_test_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/dns/public/secure_dns_mode.h"
#include "net/dns/public/util.h"
#include "net/test/ssl_test_util.h"
#include "net/test/test_doh_server.h"
#include "services/tracing/public/cpp/perfetto/perfetto_config.h"
#include "services/tracing/public/cpp/tracing_features.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/chrome_debug_urls.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/boringssl/src/include/openssl/nid.h"
#include "third_party/boringssl/src/include/openssl/ssl.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/display/screen.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/snapshot/snapshot.h"
#include "url/origin.h"
#if BUILDFLAG(IS_POSIX)
#include "base/task/deferred_sequenced_task_runner.h"
#include "base/tracing/perfetto_task_runner.h"
#include "services/tracing/perfetto/system_test_utils.h"
#endif
#define EXPECT_SIZE_EQ(expected, actual) …
ElementsAre;
Eq;
namespace content {
namespace {
const int kBudgetAllowed = …;
class TestJavaScriptDialogManager : public JavaScriptDialogManager,
public WebContentsDelegate { … };
}
class SitePerProcessDevToolsProtocolTest : public DevToolsProtocolTest { … };
class SyntheticKeyEventTest : public DevToolsProtocolTest { … };
class PrerenderDevToolsProtocolTest : public DevToolsProtocolTest { … };
class SyntheticMouseEventTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKey) { … }
IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, DISABLED_KeyboardEventAck) { … }
IN_PROC_BROWSER_TEST_F(SyntheticMouseEventTest, DISABLED_MouseEventAck) { … }
IN_PROC_BROWSER_TEST_F(SyntheticMouseEventTest, MouseEventCoordinates) { … }
IN_PROC_BROWSER_TEST_F(SyntheticMouseEventTest, MouseEventCoordinatesWithZoom) { … }
namespace {
bool DecodePNG(std::string base64_data, SkBitmap* bitmap) { … }
std::unique_ptr<SkBitmap> DecodeJPEG(std::string base64_data) { … }
int ColorsSquareDiff(SkColor color1, SkColor color2) { … }
bool ColorsMatchWithinLimit(SkColor color1, SkColor color2, int max_collor_diff) { … }
bool MatchesBitmap(const SkBitmap& expected_bmp,
const SkBitmap& actual_bmp,
const gfx::Rect& matching_mask,
float device_scale_factor,
int max_collor_diff) { … }
}
enum class ScreenshotEncoding { … };
std::string EncodingEnumToString(ScreenshotEncoding encoding) { … }
class CaptureScreenshotTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest,
CaptureScreenshotBeyondViewport_OutOfView) { … }
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest,
CaptureScreenshotBeyondViewport_IFrame) { … }
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS_ASH) || \
BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_MAC)
#define MAYBE_CaptureScreenshotBeyondViewport_InnerScrollbarsAreShown …
#else
#define MAYBE_CaptureScreenshotBeyondViewport_InnerScrollbarsAreShown …
#endif
IN_PROC_BROWSER_TEST_F(
CaptureScreenshotTest,
MAYBE_CaptureScreenshotBeyondViewport_InnerScrollbarsAreShown) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH) && !BUILDFLAG(IS_ANDROID)
class NoGPUCaptureScreenshotTest : public CaptureScreenshotTest { … };
#if BUILDFLAG(IS_LINUX)
#define MAYBE_LargeScreenshot …
#else
#define MAYBE_LargeScreenshot …
#endif
IN_PROC_BROWSER_TEST_F(NoGPUCaptureScreenshotTest, MAYBE_LargeScreenshot) { … }
#endif
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest, DISABLED_CaptureScreenshotArea) { … }
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest,
SetDefaultBackgroundColorOverride) { … }
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest, TransparentScreenshotsViewport) { … }
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest,
#if BUILDFLAG(IS_ANDROID)
DISABLED_TransparentScreenshotsBeyondViewport) { … }
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest, TransparentScreenshotsFull) { … }
#endif
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest,
CaptureScreenshotBeyondViewport_Emulation) { … }
#endif
IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest,
OnlyScreenshotsFromSurfaceWhenUnsafeNotAllowed) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
NoCrashDeviceMetricsOverrideAutoResize) { … }
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizePinchGesture) {
GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html");
NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1);
Attach();
int old_width = EvalJs(shell(), "window.innerWidth").ExtractInt();
int old_height = EvalJs(shell(), "window.innerHeight").ExtractInt();
base::Value::Dict params;
params.Set("x", old_width / 2);
params.Set("y", old_height / 2);
params.Set("scaleFactor", 2.0);
SendCommandSync("Input.synthesizePinchGesture", std::move(params));
int new_width = EvalJs(shell(), "window.innerWidth").ExtractInt();
ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_width) / new_width);
int new_height = EvalJs(shell(), "window.innerHeight").ExtractInt();
ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_height) / new_height);
}
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeScrollGesture) {
GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html");
NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1);
Attach();
ASSERT_EQ(0, EvalJs(shell(), "document.body.scrollTop"));
base::Value::Dict params;
params.Set("x", 0);
params.Set("y", 0);
params.Set("xDistance", 0);
params.Set("yDistance", -100);
SendCommandSync("Input.synthesizeScrollGesture", std::move(params));
ASSERT_EQ(100, EvalJs(shell(), "document.body.scrollTop"));
}
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeTapGesture) {
GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html");
NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1);
Attach();
ASSERT_EQ(0, EvalJs(shell(), "document.body.scrollTop"));
base::Value::Dict params;
params.Set("x", 16);
params.Set("y", 16);
params.Set("gestureSourceType", "touch");
SendCommandSync("Input.synthesizeTapGesture", std::move(params));
ASSERT_GT(EvalJs(shell(), "document.body.scrollTop").ExtractInt(), 0);
}
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_PageCrash) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_PageCrashInFrame …
#else
#define MAYBE_PageCrashInFrame …
#endif
IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsProtocolTest,
MAYBE_PageCrashInFrame) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageCrashClearsPendingCommands) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
DISABLED_NavigationPreservesMessages) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
NavigationToFileUrlRequiresFileAccess) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CrossSiteNoDetach) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_CrossSiteNavigation) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CrossSiteCrash) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, InspectorTargetCrashedNavigate) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, TargetGetTargetsAfterCrash) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
InspectorTargetCrashedNavigateCrossProcess) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_InspectorTargetCrashedReload …
#else
#define MAYBE_InspectorTargetCrashedReload …
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
MAYBE_InspectorTargetCrashedReload) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ReconnectPreservesState) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CrossSitePauseInBeforeUnload) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, InspectDuringFrameSwap) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DoubleCrash) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ReloadBlankPage) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, EvaluateInBlankPage) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
EvaluateInBlankPageAfterNavigation) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, JavaScriptDialogNotifications) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, JavaScriptDialogInterop) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageDisableWithOpenedDialog) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, PageDisableWithNoDialogManager) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BeforeUnloadDialog) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserCreateAndCloseTarget) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserGetTargets) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, VirtualTimeTest) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CertificateError) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
CertificateErrorRequestInterception) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CertificateErrorBrowserTarget) { … }
class CertificateErrorIgnoredBrowserTargetTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(CertificateErrorIgnoredBrowserTargetTest,
CertificateErrorBrowserTargetServiceWorkerFetch) { … }
IN_PROC_BROWSER_TEST_F(
CertificateErrorIgnoredBrowserTargetTest,
CertificateErrorBrowserTargetServiceWorkerImportScripts) { … }
IN_PROC_BROWSER_TEST_F(CertificateErrorIgnoredBrowserTargetTest,
CertificateErrorBrowserTargetServiceWorkerModuleImport) { … }
IN_PROC_BROWSER_TEST_F(CertificateErrorIgnoredBrowserTargetTest,
CertificateErrorBrowserTargetDedicatedWorker) { … }
IN_PROC_BROWSER_TEST_F(
CertificateErrorIgnoredBrowserTargetTest,
CertificateErrorBrowserTargetDedicatedWorkerImportClassic) { … }
IN_PROC_BROWSER_TEST_F(
CertificateErrorIgnoredBrowserTargetTest,
CertificateErrorBrowserTargetDedicatedWorkerImportModule) { … }
#if BUILDFLAG(IS_ANDROID)
constexpr bool kIsSharedWorkerEnabled = false;
#else
constexpr bool kIsSharedWorkerEnabled = …;
#endif
IN_PROC_BROWSER_TEST_F(CertificateErrorIgnoredBrowserTargetTest,
CertificateErrorBrowserTargetSharedWorker) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, SubresourceWithCertificateError) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, TargetDiscovery) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, SetAndGetCookies) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
ReturnsCookiesOnlyForAttachableUrls) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
AutoAttachToOOPIFAfterNavigationStarted) { … }
class DevToolsProtocolDeviceEmulationTest : public DevToolsProtocolTest { … };
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_DeviceSize …
#else
#define MAYBE_DeviceSize …
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProtocolDeviceEmulationTest, MAYBE_DeviceSize) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_RenderKillDoesNotCrashBrowser …
#else
#define MAYBE_RenderKillDoesNotCrashBrowser …
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProtocolDeviceEmulationTest,
MAYBE_RenderKillDoesNotCrashBrowser) { … }
class DevToolsProtocolDeviceEmulationPrerenderTest
: public DevToolsProtocolDeviceEmulationTest { … };
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_DeviceSize …
#else
#define MAYBE_DeviceSize …
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProtocolDeviceEmulationPrerenderTest,
MAYBE_DeviceSize) { … }
class DevToolsProtocolTouchTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTouchTest, EnableTouch) { … }
class DevToolsProtocolBackForwardCacheTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(DevToolsProtocolBackForwardCacheTest, Basic) { … }
#if !BUILDFLAG(IS_ANDROID)
namespace {
static DownloadManagerImpl* DownloadManagerForShell(Shell* shell) { … }
static void RemoveShellDelegate(Shell* shell) { … }
class CountingDownloadFile : public download::DownloadFileImpl { … };
int CountingDownloadFile::active_files_ = …;
class CountingDownloadFileFactory : public download::DownloadFileFactory { … };
class DownloadCreateObserver : DownloadManager::Observer { … };
bool IsDownloadInState(download::DownloadItem::DownloadState state,
download::DownloadItem* item) { … }
class DevToolsDownloadContentTest : public DevToolsProtocolTest { … };
}
IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest, SingleDownload) { … }
IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest, DownloadCancelled) { … }
IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest, DeniedDownload) { … }
IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest, DefaultDownload) { … }
IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest, DefaultDownloadHeadless) { … }
IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest,
SetDownloadBehaviorAccessChecks) { … }
IN_PROC_BROWSER_TEST_F(DevToolsDownloadContentTest, DISABLED_MultiDownload) { … }
#endif
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, UnsafeOperations) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, TracingWithPerfettoConfig) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, NavigateToAboutBlankLoaderId) { … }
class SystemTracingDevToolsProtocolTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(SystemTracingDevToolsProtocolTest,
StartSystemTracingFailsWhenSystemConsumerDisabled) { … }
#if BUILDFLAG(IS_POSIX)
class PosixSystemTracingDevToolsProtocolTest
: public SystemTracingDevToolsProtocolTest { … };
class InvalidSystemTracingDevToolsProtocolTest
: public PosixSystemTracingDevToolsProtocolTest { … };
#if defined(ADDRESS_SANITIZER)
#define MAYBE_StartTracingFailsWithInvalidSockets …
#else
#define MAYBE_StartTracingFailsWithInvalidSockets …
#endif
IN_PROC_BROWSER_TEST_F(InvalidSystemTracingDevToolsProtocolTest,
MAYBE_StartTracingFailsWithInvalidSockets) { … }
class FakeSystemTracingDevToolsProtocolTest
: public PosixSystemTracingDevToolsProtocolTest { … };
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_TracingWithFakeSystemBackend …
#else
#define MAYBE_TracingWithFakeSystemBackend …
#endif
IN_PROC_BROWSER_TEST_F(FakeSystemTracingDevToolsProtocolTest,
MAYBE_TracingWithFakeSystemBackend) { … }
class FakeSystemTracingForbiddenDevToolsProtocolTest
: public PosixSystemTracingDevToolsProtocolTest { … };
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_SystemConsumerForbidden …
#else
#define MAYBE_SystemConsumerForbidden …
#endif
IN_PROC_BROWSER_TEST_F(FakeSystemTracingForbiddenDevToolsProtocolTest,
MAYBE_SystemConsumerForbidden) { … }
#endif
class NetworkResponseProtocolTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(NetworkResponseProtocolTest, SecurityDetails) { … }
IN_PROC_BROWSER_TEST_F(NetworkResponseProtocolTest, SecurityDetailsTLS13) { … }
IN_PROC_BROWSER_TEST_F(NetworkResponseProtocolTest,
SecurityDetailsLegacyCipher) { … }
IN_PROC_BROWSER_TEST_F(NetworkResponseProtocolTest, SecurityDetailsSAN) { … }
class NetworkResponseProtocolECHTest : public NetworkResponseProtocolTest { … };
IN_PROC_BROWSER_TEST_F(NetworkResponseProtocolECHTest,
DISABLED_SecurityDetailsECH) { … }
IN_PROC_BROWSER_TEST_F(
PrerenderDevToolsProtocolTest,
PrerenderStatusUpdatedReportsFailureWithDisallowedMojoInterface) { … }
IN_PROC_BROWSER_TEST_F(
PrerenderDevToolsProtocolTest,
PrerenderStatusUpdatedReportsFailureWithPrerenderMismatchedHeaders) { … }
IN_PROC_BROWSER_TEST_F(PrerenderDevToolsProtocolTest,
RenderFrameDevToolsAgentHostCacheEvictionCrash) { … }
IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ResponseAfterReload) { … }
class SharedStorageDevToolsProtocolTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(SharedStorageDevToolsProtocolTest,
ResetSharedStorageBudget) { … }
}