0

headless: Use BUILDFLAG for OS checking

Use BUILDFLAG(IS_XXX) instead of defined(OS_XXX).

Generated by `os_buildflag_migration.py` (https://crrev.com/c/3311983).

R=thakis@chromium.org

Bug: 1234043
Test: No functionality change
Change-Id: I2ffbdc2bf509d3d16217fbc8f9171cb5ee2184c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3371757
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#956764}
This commit is contained in:
Xiaohan Wang
2022-01-08 01:34:16 +00:00
committed by Chromium LUCI CQ
parent c0823763b0
commit 2d5a55ece0
29 changed files with 156 additions and 153 deletions

@@ -21,7 +21,7 @@
#include "headless/public/headless_web_contents.h" #include "headless/public/headless_web_contents.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/app/sandbox_helper_win.h" #include "content/public/app/sandbox_helper_win.h"
#include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/sandbox_types.h"
@@ -149,7 +149,7 @@ void OnHeadlessBrowserStarted(headless::HeadlessBrowser* browser) {
browser->Shutdown(); browser->Shutdown();
return; return;
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
GURL url(base::WideToUTF16(args[0])); GURL url(base::WideToUTF16(args[0]));
#else #else
GURL url(args[0]); GURL url(args[0]);
@@ -171,7 +171,7 @@ void OnHeadlessBrowserStarted(headless::HeadlessBrowser* browser) {
} }
int main(int argc, const char** argv) { int main(int argc, const char** argv) {
#if !defined(OS_WIN) #if !BUILDFLAG(IS_WIN)
// This function must be the first thing we call to make sure child processes // This function must be the first thing we call to make sure child processes
// such as the renderer are started properly. The headless library starts // such as the renderer are started properly. The headless library starts
// child processes by forking and exec'ing the main application. // child processes by forking and exec'ing the main application.
@@ -182,7 +182,7 @@ int main(int argc, const char** argv) {
// and it can only be initialized once. // and it can only be initialized once.
headless::HeadlessBrowser::Options::Builder builder(argc, argv); headless::HeadlessBrowser::Options::Builder builder(argc, argv);
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// In windows, you must initialize and set the sandbox, or pass it along // In windows, you must initialize and set the sandbox, or pass it along
// if it has already been initialized. // if it has already been initialized.
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr}; sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};

@@ -52,13 +52,13 @@
#include "third_party/blink/public/common/switches.h" #include "third_party/blink/public/common/switches.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "components/crash/core/app/crash_switches.h" // nogncheck #include "components/crash/core/app/crash_switches.h" // nogncheck
#include "components/crash/core/app/run_as_crashpad_handler_win.h" #include "components/crash/core/app/run_as_crashpad_handler_win.h"
#include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/sandbox_types.h"
#endif #endif
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
#include "components/os_crypt/os_crypt_switches.h" // nogncheck #include "components/os_crypt/os_crypt_switches.h" // nogncheck
#endif #endif
@@ -110,7 +110,7 @@ bool ParseFontRenderHinting(
} }
GURL ConvertArgumentToURL(const base::CommandLine::StringType& arg) { GURL ConvertArgumentToURL(const base::CommandLine::StringType& arg) {
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
GURL url(base::WideToUTF8(arg)); GURL url(base::WideToUTF8(arg));
#else #else
GURL url(arg); GURL url(arg);
@@ -145,7 +145,7 @@ base::FilePath GetSSLKeyLogFile(const base::CommandLine* command_line) {
std::unique_ptr<base::Environment> env(base::Environment::Create()); std::unique_ptr<base::Environment> env(base::Environment::Create());
std::string path_str; std::string path_str;
env->GetVar("SSLKEYLOGFILE", &path_str); env->GetVar("SSLKEYLOGFILE", &path_str);
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// base::Environment returns environment variables in UTF-8 on Windows. // base::Environment returns environment variables in UTF-8 on Windows.
return base::FilePath(base::UTF8ToWide(path_str)); return base::FilePath(base::UTF8ToWide(path_str));
#else #else
@@ -157,12 +157,12 @@ int RunContentMain(
HeadlessBrowser::Options options, HeadlessBrowser::Options options,
base::OnceCallback<void(HeadlessBrowser*)> on_browser_start_callback) { base::OnceCallback<void(HeadlessBrowser*)> on_browser_start_callback) {
content::ContentMainParams params(nullptr); content::ContentMainParams params(nullptr);
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// Sandbox info has to be set and initialized. // Sandbox info has to be set and initialized.
CHECK(options.sandbox_info); CHECK(options.sandbox_info);
params.instance = options.instance; params.instance = options.instance;
params.sandbox_info = std::move(options.sandbox_info); params.sandbox_info = std::move(options.sandbox_info);
#elif !defined(OS_ANDROID) #elif !BUILDFLAG(IS_ANDROID)
params.argc = options.argc; params.argc = options.argc;
params.argv = options.argv; params.argv = options.argv;
#endif #endif
@@ -270,7 +270,7 @@ void HeadlessShell::OnStart(HeadlessBrowser* browser) {
// driven by debugger. // driven by debugger.
if (args.empty() && !base::CommandLine::ForCurrentProcess()->HasSwitch( if (args.empty() && !base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kRemoteDebuggingPipe)) { switches::kRemoteDebuggingPipe)) {
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
args.push_back(L"about:blank"); args.push_back(L"about:blank");
#else #else
args.push_back("about:blank"); args.push_back("about:blank");
@@ -676,7 +676,7 @@ bool HeadlessShell::RemoteDebuggingEnabled() const {
command_line.HasSwitch(switches::kRemoteDebuggingPipe)); command_line.HasSwitch(switches::kRemoteDebuggingPipe));
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
int HeadlessShellMain(HINSTANCE instance, int HeadlessShellMain(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info) { sandbox::SandboxInterfaceInfo* sandbox_info) {
base::CommandLine::Init(0, nullptr); base::CommandLine::Init(0, nullptr);
@@ -699,10 +699,10 @@ int HeadlessShellMain(int argc, const char** argv) {
base::CommandLine::Init(argc, argv); base::CommandLine::Init(argc, argv);
RunChildProcessIfNeeded(argc, argv); RunChildProcessIfNeeded(argc, argv);
HeadlessBrowser::Options::Builder builder(argc, argv); HeadlessBrowser::Options::Builder builder(argc, argv);
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
HeadlessShell shell; HeadlessShell shell;
#if defined(OS_FUCHSIA) #if BUILDFLAG(IS_FUCHSIA)
// TODO(fuchsia): Remove this when GPU accelerated compositing is ready. // TODO(fuchsia): Remove this when GPU accelerated compositing is ready.
base::CommandLine::ForCurrentProcess()->AppendSwitch(::switches::kDisableGpu); base::CommandLine::ForCurrentProcess()->AppendSwitch(::switches::kDisableGpu);
#endif #endif
@@ -711,7 +711,7 @@ int HeadlessShellMain(int argc, const char** argv) {
if (!ValidateCommandLine(command_line)) if (!ValidateCommandLine(command_line))
return EXIT_FAILURE; return EXIT_FAILURE;
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
command_line.AppendSwitch(os_crypt::switches::kUseMockKeychain); command_line.AppendSwitch(os_crypt::switches::kUseMockKeychain);
#endif #endif
@@ -845,14 +845,14 @@ int HeadlessShellMain(int argc, const char** argv) {
} }
int HeadlessShellMain(const content::ContentMainParams& params) { int HeadlessShellMain(const content::ContentMainParams& params) {
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
return HeadlessShellMain(params.instance, params.sandbox_info); return HeadlessShellMain(params.instance, params.sandbox_info);
#else #else
return HeadlessShellMain(params.argc, params.argv); return HeadlessShellMain(params.argc, params.argv);
#endif #endif
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
void RunChildProcessIfNeeded(HINSTANCE instance, void RunChildProcessIfNeeded(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info) { sandbox::SandboxInterfaceInfo* sandbox_info) {
base::CommandLine::Init(0, nullptr); base::CommandLine::Init(0, nullptr);
@@ -863,7 +863,7 @@ void RunChildProcessIfNeeded(HINSTANCE instance,
void RunChildProcessIfNeeded(int argc, const char** argv) { void RunChildProcessIfNeeded(int argc, const char** argv) {
base::CommandLine::Init(argc, argv); base::CommandLine::Init(argc, argv);
HeadlessBrowser::Options::Builder builder(argc, argv); HeadlessBrowser::Options::Builder builder(argc, argv);
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
const base::CommandLine& command_line( const base::CommandLine& command_line(
*base::CommandLine::ForCurrentProcess()); *base::CommandLine::ForCurrentProcess());

@@ -5,29 +5,29 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "headless/public/headless_shell.h" #include "headless/public/headless_shell.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "content/public/app/sandbox_helper_win.h" #include "content/public/app/sandbox_helper_win.h"
#include "sandbox/win/src/sandbox_types.h" // nogncheck #include "sandbox/win/src/sandbox_types.h" // nogncheck
#elif defined(OS_MAC) #elif BUILDFLAG(IS_MAC)
#include "base/check.h" #include "base/check.h"
#include "sandbox/mac/seatbelt_exec.h" #include "sandbox/mac/seatbelt_exec.h"
#endif #endif
int main(int argc, const char** argv) { int main(int argc, const char** argv) {
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
sandbox::SandboxInterfaceInfo sandbox_info = {nullptr}; sandbox::SandboxInterfaceInfo sandbox_info = {nullptr};
content::InitializeSandboxInfo(&sandbox_info); content::InitializeSandboxInfo(&sandbox_info);
return headless::HeadlessShellMain(0, &sandbox_info); return headless::HeadlessShellMain(0, &sandbox_info);
#else #else
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
sandbox::SeatbeltExecServer::CreateFromArgumentsResult seatbelt = sandbox::SeatbeltExecServer::CreateFromArgumentsResult seatbelt =
sandbox::SeatbeltExecServer::CreateFromArguments( sandbox::SeatbeltExecServer::CreateFromArguments(
argv[0], argc, const_cast<char**>(argv)); argv[0], argc, const_cast<char**>(argv));
if (seatbelt.sandbox_required) { if (seatbelt.sandbox_required) {
CHECK(seatbelt.server->InitializeSandbox()); CHECK(seatbelt.server->InitializeSandbox());
} }
#endif // defined(OS_MAC) #endif // BUILDFLAG(IS_MAC)
return headless::HeadlessShellMain(argc, argv); return headless::HeadlessShellMain(argc, argv);
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
} }

@@ -7,6 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include "base/debug/alias.h" #include "base/debug/alias.h"
#include "build/build_config.h"
#include "content/public/common/result_codes.h" #include "content/public/common/result_codes.h"
#include "headless/app/headless_shell_switches.h" #include "headless/app/headless_shell_switches.h"
#include "headless/lib/browser/headless_browser_context_impl.h" #include "headless/lib/browser/headless_browser_context_impl.h"
@@ -28,11 +29,11 @@
#include "headless/lib/browser/policy/headless_policies.h" #include "headless/lib/browser/policy/headless_policies.h"
#endif #endif
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/geolocation/geolocation_manager.h" #include "services/device/public/cpp/geolocation/geolocation_manager.h"
#endif #endif
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "base/command_line.h" #include "base/command_line.h"
#endif #endif
@@ -88,7 +89,7 @@ void HeadlessBrowserMainParts::PostMainMessageLoopRun() {
#endif #endif
} }
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
device::GeolocationManager* HeadlessBrowserMainParts::GetGeolocationManager() { device::GeolocationManager* HeadlessBrowserMainParts::GetGeolocationManager() {
return geolocation_manager_.get(); return geolocation_manager_.get();
} }
@@ -148,7 +149,7 @@ void HeadlessBrowserMainParts::CreatePrefService() {
} }
auto pref_registry = base::MakeRefCounted<user_prefs::PrefRegistrySyncable>(); auto pref_registry = base::MakeRefCounted<user_prefs::PrefRegistrySyncable>();
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
OSCrypt::RegisterLocalPrefs(pref_registry.get()); OSCrypt::RegisterLocalPrefs(pref_registry.get());
#endif #endif
@@ -170,13 +171,13 @@ void HeadlessBrowserMainParts::CreatePrefService() {
factory.set_user_prefs(pref_store); factory.set_user_prefs(pref_store);
local_state_ = factory.Create(std::move(pref_registry)); local_state_ = factory.Create(std::move(pref_registry));
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switches::kDisableCookieEncryption) && if (!command_line->HasSwitch(switches::kDisableCookieEncryption) &&
OSCrypt::InitWithExistingKey(local_state_.get()) != OSCrypt::kSuccess) { OSCrypt::InitWithExistingKey(local_state_.get()) != OSCrypt::kSuccess) {
command_line->AppendSwitch(switches::kDisableCookieEncryption); command_line->AppendSwitch(switches::kDisableCookieEncryption);
} }
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
} }
#endif // defined(HEADLESS_USE_PREFS) #endif // defined(HEADLESS_USE_PREFS)

@@ -47,15 +47,15 @@ class HEADLESS_EXPORT HeadlessBrowserMainParts
void WillRunMainMessageLoop( void WillRunMainMessageLoop(
std::unique_ptr<base::RunLoop>& run_loop) override; std::unique_ptr<base::RunLoop>& run_loop) override;
void PostMainMessageLoopRun() override; void PostMainMessageLoopRun() override;
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
void PreCreateMainMessageLoop() override; void PreCreateMainMessageLoop() override;
#endif #endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void PostCreateMainMessageLoop() override; void PostCreateMainMessageLoop() override;
#endif #endif
void QuitMainMessageLoop(); void QuitMainMessageLoop();
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
device::GeolocationManager* GetGeolocationManager(); device::GeolocationManager* GetGeolocationManager();
void SetGeolocationManagerForTesting( void SetGeolocationManagerForTesting(
std::unique_ptr<device::GeolocationManager> fake_geolocation_manager); std::unique_ptr<device::GeolocationManager> fake_geolocation_manager);
@@ -88,7 +88,7 @@ class HEADLESS_EXPORT HeadlessBrowserMainParts
bool devtools_http_handler_started_ = false; bool devtools_http_handler_started_ = false;
base::OnceClosure quit_main_message_loop_; base::OnceClosure quit_main_message_loop_;
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
std::unique_ptr<device::GeolocationManager> geolocation_manager_; std::unique_ptr<device::GeolocationManager> geolocation_manager_;
#endif #endif
}; };

@@ -8,7 +8,7 @@
#include "build/chromeos_buildflags.h" #include "build/chromeos_buildflags.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h" #include "device/bluetooth/dbus/bluez_dbus_manager.h"
#if !defined(OS_CHROMEOS) #if !BUILDFLAG(IS_CHROMEOS)
#include "base/command_line.h" #include "base/command_line.h"
#include "components/os_crypt/key_storage_config_linux.h" #include "components/os_crypt/key_storage_config_linux.h"
#include "components/os_crypt/os_crypt.h" #include "components/os_crypt/os_crypt.h"
@@ -19,7 +19,7 @@
namespace headless { namespace headless {
#if !defined(OS_CHROMEOS) #if !BUILDFLAG(IS_CHROMEOS)
constexpr char kProductName[] = "HeadlessChrome"; constexpr char kProductName[] = "HeadlessChrome";
#endif #endif
@@ -28,7 +28,7 @@ void HeadlessBrowserMainParts::PostCreateMainMessageLoop() {
bluez::BluezDBusManager::Initialize(/*system_bus=*/nullptr); bluez::BluezDBusManager::Initialize(/*system_bus=*/nullptr);
#endif #endif
#if !defined(OS_CHROMEOS) #if !BUILDFLAG(IS_CHROMEOS)
// Set up crypt config. This needs to be done before anything starts the // Set up crypt config. This needs to be done before anything starts the
// network service, as the raw encryption key needs to be shared with the // network service, as the raw encryption key needs to be shared with the
// network service for encrypted cookie storage. // network service for encrypted cookie storage.
@@ -46,7 +46,7 @@ void HeadlessBrowserMainParts::PostCreateMainMessageLoop() {
config->should_use_preference = false; config->should_use_preference = false;
config->user_data_path = base::FilePath(); config->user_data_path = base::FilePath();
OSCrypt::SetConfig(std::move(config)); OSCrypt::SetConfig(std::move(config));
#endif // !defined(OS_CHROMEOS) #endif // !BUILDFLAG(IS_CHROMEOS)
} }
} // namespace headless } // namespace headless

@@ -48,11 +48,11 @@
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "ui/gfx/switches.h" #include "ui/gfx/switches.h"
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crash_switches.h" #include "components/crash/core/app/crash_switches.h"
#include "components/crash/core/app/crashpad.h" #include "components/crash/core/app/crashpad.h"
#include "content/public/common/content_descriptors.h" #include "content/public/common/content_descriptors.h"
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if defined(HEADLESS_USE_POLICY) #if defined(HEADLESS_USE_POLICY)
#include "components/policy/content/policy_blocklist_navigation_throttle.h" #include "components/policy/content/policy_blocklist_navigation_throttle.h"
@@ -67,7 +67,7 @@
namespace headless { namespace headless {
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
namespace { namespace {
int GetCrashSignalFD(const base::CommandLine& command_line, int GetCrashSignalFD(const base::CommandLine& command_line,
@@ -78,7 +78,7 @@ int GetCrashSignalFD(const base::CommandLine& command_line,
} }
} // namespace } // namespace
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Implements a stub BadgeService. This implementation does nothing, but is // Implements a stub BadgeService. This implementation does nothing, but is
// required because inbound Mojo messages which do not have a registered // required because inbound Mojo messages which do not have a registered
@@ -181,7 +181,7 @@ HeadlessContentBrowserClient::GetGeneratedCodeCacheSettings(
return content::GeneratedCodeCacheSettings(true, 0, context->GetPath()); return content::GeneratedCodeCacheSettings(true, 0, context->GetPath());
} }
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void HeadlessContentBrowserClient::GetAdditionalMappedFilesForChildProcess( void HeadlessContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line, const base::CommandLine& command_line,
int child_process_id, int child_process_id,
@@ -190,7 +190,7 @@ void HeadlessContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
if (crash_signal_fd >= 0) if (crash_signal_fd >= 0)
mappings->Share(kCrashDumpSignal, crash_signal_fd); mappings->Share(kCrashDumpSignal, crash_signal_fd);
} }
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void HeadlessContentBrowserClient::AppendExtraCommandLineSwitches( void HeadlessContentBrowserClient::AppendExtraCommandLineSwitches(
base::CommandLine* command_line, base::CommandLine* command_line,
@@ -207,7 +207,7 @@ void HeadlessContentBrowserClient::AppendExtraCommandLineSwitches(
old_command_line.GetSwitchValueNative(switches::kUserAgent)); old_command_line.GetSwitchValueNative(switches::kUserAgent));
} }
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
int fd; int fd;
pid_t pid; pid_t pid;
if (crash_reporter::GetHandlerSocket(&fd, &pid)) { if (crash_reporter::GetHandlerSocket(&fd, &pid)) {
@@ -215,7 +215,7 @@ void HeadlessContentBrowserClient::AppendExtraCommandLineSwitches(
crash_reporter::switches::kCrashpadHandlerPid, crash_reporter::switches::kCrashpadHandlerPid,
base::NumberToString(pid)); base::NumberToString(pid));
} }
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// If we're spawning a renderer, then override the language switch. // If we're spawning a renderer, then override the language switch.
std::string process_type = std::string process_type =
@@ -264,7 +264,7 @@ void HeadlessContentBrowserClient::AppendExtraCommandLineSwitches(
process_type, child_process_id); process_type, child_process_id);
} }
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Processes may only query perf_event_open with the BPF sandbox disabled. // Processes may only query perf_event_open with the BPF sandbox disabled.
if (old_command_line.HasSwitch(::switches::kEnableThreadInstructionCount) && if (old_command_line.HasSwitch(::switches::kEnableThreadInstructionCount) &&
old_command_line.HasSwitch(sandbox::policy::switches::kNoSandbox)) { old_command_line.HasSwitch(sandbox::policy::switches::kNoSandbox)) {
@@ -361,7 +361,7 @@ bool HeadlessContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
device::GeolocationManager* device::GeolocationManager*
HeadlessContentBrowserClient::GetGeolocationManager() { HeadlessContentBrowserClient::GetGeolocationManager() {
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
return browser_->browser_main_parts()->GetGeolocationManager(); return browser_->browser_main_parts()->GetGeolocationManager();
#else #else
return nullptr; return nullptr;

@@ -47,7 +47,7 @@ class HeadlessContentBrowserClient : public content::ContentBrowserClient {
override; override;
content::GeneratedCodeCacheSettings GetGeneratedCodeCacheSettings( content::GeneratedCodeCacheSettings GetGeneratedCodeCacheSettings(
content::BrowserContext* context) override; content::BrowserContext* context) override;
#if defined(OS_POSIX) && !defined(OS_MAC) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
void GetAdditionalMappedFilesForChildProcess( void GetAdditionalMappedFilesForChildProcess(
const base::CommandLine& command_line, const base::CommandLine& command_line,
int child_process_id, int child_process_id,

@@ -10,6 +10,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_agent_host.h"
@@ -81,7 +82,7 @@ class TCPEndpointServerSocketFactory : public content::DevToolsSocketFactory {
net::HostPortPair endpoint_; net::HostPortPair endpoint_;
}; };
#if defined(OS_POSIX) #if BUILDFLAG(IS_POSIX)
class TCPAdoptServerSocketFactory : public content::DevToolsSocketFactory { class TCPAdoptServerSocketFactory : public content::DevToolsSocketFactory {
public: public:
// Construct a factory to use an already-open, already-listening socket. // Construct a factory to use an already-open, already-listening socket.
@@ -112,7 +113,7 @@ class TCPAdoptServerSocketFactory : public content::DevToolsSocketFactory {
size_t socket_fd_; size_t socket_fd_;
}; };
#else // defined(OS_POSIX) #else // BUILDFLAG(IS_POSIX)
// Placeholder class to use when a socket_fd is passed in on non-Posix. // Placeholder class to use when a socket_fd is passed in on non-Posix.
class DummyTCPServerSocketFactory : public content::DevToolsSocketFactory { class DummyTCPServerSocketFactory : public content::DevToolsSocketFactory {
@@ -133,7 +134,7 @@ class DummyTCPServerSocketFactory : public content::DevToolsSocketFactory {
return nullptr; return nullptr;
} }
}; };
#endif // defined(OS_POSIX) #endif // BUILDFLAG(IS_POSIX)
void PostTaskToCloseBrowser(base::WeakPtr<HeadlessBrowserImpl> browser) { void PostTaskToCloseBrowser(base::WeakPtr<HeadlessBrowserImpl> browser) {
content::GetUIThreadTaskRunner({})->PostTask( content::GetUIThreadTaskRunner({})->PostTask(

@@ -65,11 +65,11 @@ void SetCryptKeyOnce(const base::FilePath& user_data_path) {
return; return;
done_once = true; done_once = true;
#if (defined(OS_WIN) || defined(OS_LINUX)) && defined(HEADLESS_USE_PREFS) #if (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)) && defined(HEADLESS_USE_PREFS)
// The OSCrypt keys are process bound, so if network service is out of // The OSCrypt keys are process bound, so if network service is out of
// process, send it the required key if it is available. // process, send it the required key if it is available.
if (content::IsOutOfProcessNetworkService() if (content::IsOutOfProcessNetworkService()
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
&& OSCrypt::IsEncryptionAvailable() && OSCrypt::IsEncryptionAvailable()
#endif #endif
) { ) {
@@ -204,7 +204,7 @@ HeadlessRequestContextManager::HeadlessRequestContextManager(
base::FilePath user_data_path) base::FilePath user_data_path)
: :
// On Windows, Cookie encryption requires access to local_state prefs. // On Windows, Cookie encryption requires access to local_state prefs.
#if defined(OS_WIN) && !defined(HEADLESS_USE_PREFS) #if BUILDFLAG(IS_WIN) && !defined(HEADLESS_USE_PREFS)
cookie_encryption_enabled_(false), cookie_encryption_enabled_(false),
#else #else
cookie_encryption_enabled_( cookie_encryption_enabled_(

@@ -57,12 +57,12 @@ namespace headless {
namespace { namespace {
void UpdatePrefsFromSystemSettings(blink::RendererPreferences* prefs) { void UpdatePrefsFromSystemSettings(blink::RendererPreferences* prefs) {
#if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || defined(OS_WIN) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_WIN)
content::UpdateFontRendererPreferencesFromSystemSettings(prefs); content::UpdateFontRendererPreferencesFromSystemSettings(prefs);
#endif #endif
// The values were copied from chrome/browser/renderer_preferences_util.cc. // The values were copied from chrome/browser/renderer_preferences_util.cc.
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
prefs->focus_ring_color = SkColorSetRGB(0x00, 0x5F, 0xCC); prefs->focus_ring_color = SkColorSetRGB(0x00, 0x5F, 0xCC);
#else #else
prefs->focus_ring_color = SkColorSetRGB(0x10, 0x10, 0x10); prefs->focus_ring_color = SkColorSetRGB(0x10, 0x10, 0x10);

@@ -23,16 +23,16 @@
#include "headless/lib/browser/policy/headless_mode_policy.h" #include "headless/lib/browser/policy/headless_mode_policy.h"
#include "headless/lib/browser/policy/headless_policies.h" #include "headless/lib/browser/policy/headless_policies.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "base/win/registry.h" #include "base/win/registry.h"
#include "components/policy/core/common/policy_loader_win.h" #include "components/policy/core/common/policy_loader_win.h"
#elif defined(OS_MAC) #elif BUILDFLAG(IS_MAC)
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/policy/core/common/policy_loader_mac.h" #include "components/policy/core/common/policy_loader_mac.h"
#include "components/policy/core/common/preferences_mac.h" #include "components/policy/core/common/preferences_mac.h"
#elif defined(OS_POSIX) && !defined(OS_ANDROID) #elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
#include "components/policy/core/common/config_dir_policy_loader.h" // nogncheck http://crbug.com/1227148 #include "components/policy/core/common/config_dir_policy_loader.h" // nogncheck http://crbug.com/1227148
#endif #endif
@@ -119,14 +119,14 @@ HeadlessBrowserPolicyConnector::CreatePolicyProviders() {
std::unique_ptr<ConfigurationPolicyProvider> std::unique_ptr<ConfigurationPolicyProvider>
HeadlessBrowserPolicyConnector::CreatePlatformProvider() { HeadlessBrowserPolicyConnector::CreatePlatformProvider() {
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
std::unique_ptr<AsyncPolicyLoader> loader(PolicyLoaderWin::Create( std::unique_ptr<AsyncPolicyLoader> loader(PolicyLoaderWin::Create(
base::ThreadPool::CreateSequencedTaskRunner( base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT}), {base::MayBlock(), base::TaskPriority::BEST_EFFORT}),
&platform_management_service_, kRegistryChromePolicyKey)); &platform_management_service_, kRegistryChromePolicyKey));
return std::make_unique<AsyncPolicyProvider>(GetSchemaRegistry(), return std::make_unique<AsyncPolicyProvider>(GetSchemaRegistry(),
std::move(loader)); std::move(loader));
#elif defined(OS_MAC) #elif BUILDFLAG(IS_MAC)
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Explicitly watch the "com.google.Chrome" bundle ID, no matter what this // Explicitly watch the "com.google.Chrome" bundle ID, no matter what this
// app's bundle ID actually is. All channels of Chrome should obey the same // app's bundle ID actually is. All channels of Chrome should obey the same
@@ -143,7 +143,7 @@ HeadlessBrowserPolicyConnector::CreatePlatformProvider() {
new MacPreferences(), bundle_id); new MacPreferences(), bundle_id);
return std::make_unique<AsyncPolicyProvider>(GetSchemaRegistry(), return std::make_unique<AsyncPolicyProvider>(GetSchemaRegistry(),
std::move(loader)); std::move(loader));
#elif defined(OS_POSIX) #elif BUILDFLAG(IS_POSIX)
// The following should match chrome::DIR_POLICY_FILES definition in // The following should match chrome::DIR_POLICY_FILES definition in
// chrome/common/chrome_paths.cc // chrome/common/chrome_paths.cc
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)

@@ -34,7 +34,7 @@ Response TargetHandler::CreateTarget(const std::string& url,
Maybe<bool> new_window, Maybe<bool> new_window,
Maybe<bool> background, Maybe<bool> background,
std::string* out_target_id) { std::string* out_target_id) {
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
if (enable_begin_frame_control.fromMaybe(false)) { if (enable_begin_frame_control.fromMaybe(false)) {
return Response::ServerError( return Response::ServerError(
"BeginFrameControl is not supported on MacOS yet"); "BeginFrameControl is not supported on MacOS yet");

@@ -47,15 +47,15 @@
#include "headless/embedded_resource_pak.h" #include "headless/embedded_resource_pak.h"
#endif #endif
#if defined(OS_MAC) || defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crashpad.h" #include "components/crash/core/app/crashpad.h"
#endif // defined(OS_MAC) || defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crash_switches.h" #include "components/crash/core/app/crash_switches.h"
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if defined(OS_POSIX) #if BUILDFLAG(IS_POSIX)
#include <signal.h> #include <signal.h>
#endif #endif
@@ -77,7 +77,7 @@ const int kTraceEventBrowserProcessSortIndex = -6;
HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr;
#if !defined(OS_FUCHSIA) #if !BUILDFLAG(IS_FUCHSIA)
base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client = base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
#endif #endif
@@ -120,7 +120,7 @@ void InitializeResourceBundle(const base::CommandLine& command_line) {
base::FilePath chrome_200_pak = base::FilePath chrome_200_pak =
resource_dir.Append(FILE_PATH_LITERAL("chrome_200_percent.pak")); resource_dir.Append(FILE_PATH_LITERAL("chrome_200_percent.pak"));
#if defined(OS_MAC) && !defined(COMPONENT_BUILD) #if BUILDFLAG(IS_MAC) && !defined(COMPONENT_BUILD)
// In non component builds, check if fall back in Resources/ folder is // In non component builds, check if fall back in Resources/ folder is
// available. // available.
if (!base::PathExists(resources_pak)) { if (!base::PathExists(resources_pak)) {
@@ -210,7 +210,7 @@ bool HeadlessContentMainDelegate::BasicStartupComplete(int* exit_code) {
// in content/public/common/content_switch_dependent_feature_overrides.cc // in content/public/common/content_switch_dependent_feature_overrides.cc
command_line->AppendSwitch(::blink::switches::kAllowPreCommitInput); command_line->AppendSwitch(::blink::switches::kAllowPreCommitInput);
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
command_line->AppendSwitch( command_line->AppendSwitch(
::switches::kDisableGpuProcessForDX12InfoCollection); ::switches::kDisableGpuProcessForDX12InfoCollection);
#endif #endif
@@ -223,14 +223,14 @@ void HeadlessContentMainDelegate::InitLogging(
const base::CommandLine& command_line) { const base::CommandLine& command_line) {
const std::string process_type = const std::string process_type =
command_line.GetSwitchValueASCII(::switches::kProcessType); command_line.GetSwitchValueASCII(::switches::kProcessType);
#if !defined(OS_WIN) #if !BUILDFLAG(IS_WIN)
if (!command_line.HasSwitch(::switches::kEnableLogging)) if (!command_line.HasSwitch(::switches::kEnableLogging))
return; return;
#else #else
// Child processes in Windows are not able to initialize logging. // Child processes in Windows are not able to initialize logging.
if (!process_type.empty()) if (!process_type.empty())
return; return;
#endif // !defined(OS_WIN) #endif // !BUILDFLAG(IS_WIN)
logging::LoggingDestination log_mode; logging::LoggingDestination log_mode;
base::FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log")); base::FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log"));
@@ -276,7 +276,7 @@ void HeadlessContentMainDelegate::InitLogging(
// Otherwise we log to where the executable is. // Otherwise we log to where the executable is.
if (log_path.empty()) { if (log_path.empty()) {
#if defined(OS_FUCHSIA) #if BUILDFLAG(IS_FUCHSIA)
// TODO(crbug.com/1262330): Use the same solution as used for LOG_DIR. // TODO(crbug.com/1262330): Use the same solution as used for LOG_DIR.
// Use -1 to allow this to compile. // Use -1 to allow this to compile.
if (base::PathService::Get(-1, &log_path)) { if (base::PathService::Get(-1, &log_path)) {
@@ -313,7 +313,7 @@ void HeadlessContentMainDelegate::InitCrashReporter(
if (!options()->enable_crash_reporter) if (!options()->enable_crash_reporter)
return; return;
#if defined(OS_FUCHSIA) #if BUILDFLAG(IS_FUCHSIA)
// TODO(crbug.com/1226159): Implement this when crash reporting is available // TODO(crbug.com/1226159): Implement this when crash reporting is available
// for Fuchsia. // for Fuchsia.
NOTIMPLEMENTED(); NOTIMPLEMENTED();
@@ -325,13 +325,13 @@ void HeadlessContentMainDelegate::InitCrashReporter(
crash_reporter::InitializeCrashKeys(); crash_reporter::InitializeCrashKeys();
crash_keys::SetSwitchesFromCommandLine(command_line, nullptr); crash_keys::SetSwitchesFromCommandLine(command_line, nullptr);
#if !defined(OS_WIN) #if !BUILDFLAG(IS_WIN)
const std::string process_type = const std::string process_type =
command_line.GetSwitchValueASCII(::switches::kProcessType); command_line.GetSwitchValueASCII(::switches::kProcessType);
if (process_type != switches::kZygoteProcess) if (process_type != switches::kZygoteProcess)
crash_reporter::InitializeCrashpad(process_type.empty(), process_type); crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
#endif // !defined(OS_WIN) #endif // !BUILDFLAG(IS_WIN)
#endif // defined(OS_FUCHSIA) #endif // BUILDFLAG(IS_FUCHSIA)
// Mark any bug reports from headless mode as such. // Mark any bug reports from headless mode as such.
static crash_reporter::CrashKeyString<32> headless_key(kHeadlessCrashKey); static crash_reporter::CrashKeyString<32> headless_key(kHeadlessCrashKey);
@@ -341,14 +341,14 @@ void HeadlessContentMainDelegate::InitCrashReporter(
void HeadlessContentMainDelegate::PreSandboxStartup() { void HeadlessContentMainDelegate::PreSandboxStartup() {
const base::CommandLine& command_line( const base::CommandLine& command_line(
*base::CommandLine::ForCurrentProcess()); *base::CommandLine::ForCurrentProcess());
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// Windows always needs to initialize logging, otherwise you get a renderer // Windows always needs to initialize logging, otherwise you get a renderer
// crash. // crash.
InitLogging(command_line); InitLogging(command_line);
#else #else
if (command_line.HasSwitch(::switches::kEnableLogging)) if (command_line.HasSwitch(::switches::kEnableLogging))
InitLogging(command_line); InitLogging(command_line);
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
InitCrashReporter(command_line); InitCrashReporter(command_line);
@@ -387,7 +387,7 @@ HeadlessContentMainDelegate::RunProcess(
return 0; return 0;
} }
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void SIGTERMProfilingShutdown(int signal) { void SIGTERMProfilingShutdown(int signal) {
content::Profiling::Stop(); content::Profiling::Stop();
struct sigaction sigact; struct sigaction sigact;
@@ -419,7 +419,7 @@ void HeadlessContentMainDelegate::ZygoteForked() {
crash_reporter::InitializeCrashpad(false, process_type); crash_reporter::InitializeCrashpad(false, process_type);
} }
} }
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS) #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// static // static
HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() { HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() {

@@ -46,7 +46,7 @@ class HEADLESS_EXPORT HeadlessContentMainDelegate
absl::variant<int, content::MainFunctionParams> RunProcess( absl::variant<int, content::MainFunctionParams> RunProcess(
const std::string& process_type, const std::string& process_type,
content::MainFunctionParams main_function_params) override; content::MainFunctionParams main_function_params) override;
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
void PreBrowserMain() override; void PreBrowserMain() override;
#endif #endif
content::ContentClient* CreateContentClient() override; content::ContentClient* CreateContentClient() override;
@@ -58,7 +58,7 @@ class HEADLESS_EXPORT HeadlessContentMainDelegate
HeadlessBrowserImpl* browser() const { return browser_.get(); } HeadlessBrowserImpl* browser() const { return browser_.get(); }
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void ZygoteForked() override; void ZygoteForked() override;
#endif #endif

@@ -19,7 +19,7 @@ namespace headless {
namespace { namespace {
#if defined(OS_POSIX) && !defined(OS_MAC) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
constexpr char kChromeHeadlessProductName[] = "Chrome_Headless"; constexpr char kChromeHeadlessProductName[] = "Chrome_Headless";
@@ -30,7 +30,7 @@ constexpr char kChromeHeadlessProductName[] = "Chrome_Headless";
HeadlessCrashReporterClient::HeadlessCrashReporterClient() = default; HeadlessCrashReporterClient::HeadlessCrashReporterClient() = default;
HeadlessCrashReporterClient::~HeadlessCrashReporterClient() = default; HeadlessCrashReporterClient::~HeadlessCrashReporterClient() = default;
#if defined(OS_POSIX) && !defined(OS_MAC) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
void HeadlessCrashReporterClient::GetProductNameAndVersion( void HeadlessCrashReporterClient::GetProductNameAndVersion(
std::string* product_name, std::string* product_name,
std::string* version, std::string* version,
@@ -39,10 +39,10 @@ void HeadlessCrashReporterClient::GetProductNameAndVersion(
*version = PRODUCT_VERSION; *version = PRODUCT_VERSION;
*channel = ""; *channel = "";
} }
#endif // defined(OS_POSIX) && !defined(OS_MAC) #endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
bool HeadlessCrashReporterClient::GetCrashDumpLocation( bool HeadlessCrashReporterClient::GetCrashDumpLocation(
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
std::wstring* crash_dir std::wstring* crash_dir
#else #else
base::FilePath* crash_dir base::FilePath* crash_dir
@@ -57,7 +57,7 @@ bool HeadlessCrashReporterClient::GetCrashDumpLocation(
if (crash_dumps_dir_.empty()) { if (crash_dumps_dir_.empty()) {
crash_directory = crash_directory.Append(FILE_PATH_LITERAL("Crashpad")); crash_directory = crash_directory.Append(FILE_PATH_LITERAL("Crashpad"));
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
*crash_dir = crash_directory.value(); *crash_dir = crash_directory.value();
#else #else
*crash_dir = std::move(crash_directory); *crash_dir = std::move(crash_directory);

@@ -28,13 +28,13 @@ class HeadlessCrashReporterClient : public crash_reporter::CrashReporterClient {
} }
const base::FilePath& crash_dumps_dir() const { return crash_dumps_dir_; } const base::FilePath& crash_dumps_dir() const { return crash_dumps_dir_; }
#if defined(OS_POSIX) && !defined(OS_MAC) #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
void GetProductNameAndVersion(std::string* product_name, void GetProductNameAndVersion(std::string* product_name,
std::string* version, std::string* version,
std::string* channel) override; std::string* channel) override;
#endif // defined(OS_POSIX) && !defined(OS_MAC) #endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
bool GetCrashDumpLocation(std::wstring* crash_dir) override; bool GetCrashDumpLocation(std::wstring* crash_dir) override;
#else #else
bool GetCrashDumpLocation(base::FilePath* crash_dir) override; bool GetCrashDumpLocation(base::FilePath* crash_dir) override;

@@ -11,7 +11,7 @@
#include "headless/public/version.h" #include "headless/public/version.h"
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/sandbox_types.h"
#endif #endif
@@ -42,7 +42,7 @@ Options::Options(int argc, const char** argv)
user_agent(content::BuildUserAgentFromProduct(product_name_and_version)), user_agent(content::BuildUserAgentFromProduct(product_name_and_version)),
window_size(kDefaultWindowSize), window_size(kDefaultWindowSize),
font_render_hinting(kDefaultFontRenderHinting) { font_render_hinting(kDefaultFontRenderHinting) {
#if defined(OS_LINUX) || defined(OS_WIN) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
gl_implementation = gl::kGLImplementationANGLEName; gl_implementation = gl::kGLImplementationANGLEName;
angle_implementation = gl::kANGLEImplementationSwiftShaderForWebGLName; angle_implementation = gl::kANGLEImplementationSwiftShaderForWebGLName;
#endif #endif
@@ -136,7 +136,7 @@ Builder& Builder::SetAppendCommandLineFlagsCallback(
return *this; return *this;
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
Builder& Builder::SetInstance(HINSTANCE hinstance) { Builder& Builder::SetInstance(HINSTANCE hinstance) {
options_.instance = hinstance; options_.instance = hinstance;
return *this; return *this;
@@ -146,7 +146,7 @@ Builder& Builder::SetSandboxInfo(sandbox::SandboxInterfaceInfo* info) {
options_.sandbox_info = info; options_.sandbox_info = info;
return *this; return *this;
} }
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
Builder& Builder::SetUserDataDir(const base::FilePath& dir) { Builder& Builder::SetUserDataDir(const base::FilePath& dir) {
options_.user_data_dir = dir; options_.user_data_dir = dir;

@@ -24,7 +24,7 @@
#include "ui/gfx/font_render_params.h" #include "ui/gfx/font_render_params.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/sandbox_types.h"
#endif #endif
@@ -116,7 +116,7 @@ struct HEADLESS_EXPORT HeadlessBrowser::Options {
int argc; int argc;
raw_ptr<const char*> argv; raw_ptr<const char*> argv;
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// Set hardware instance if available, otherwise it defaults to 0. // Set hardware instance if available, otherwise it defaults to 0.
HINSTANCE instance = 0; HINSTANCE instance = 0;
@@ -249,7 +249,7 @@ class HEADLESS_EXPORT HeadlessBrowser::Options::Builder {
Builder& SetANGLEImplementation(const std::string& implementation); Builder& SetANGLEImplementation(const std::string& implementation);
Builder& SetAppendCommandLineFlagsCallback( Builder& SetAppendCommandLineFlagsCallback(
const Options::AppendCommandLineFlagsCallback& callback); const Options::AppendCommandLineFlagsCallback& callback);
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
Builder& SetInstance(HINSTANCE hinstance); Builder& SetInstance(HINSTANCE hinstance);
Builder& SetSandboxInfo(sandbox::SandboxInterfaceInfo* info); Builder& SetSandboxInfo(sandbox::SandboxInterfaceInfo* info);
#endif #endif
@@ -278,7 +278,7 @@ class HEADLESS_EXPORT HeadlessBrowser::Options::Builder {
Options options_; Options options_;
}; };
#if !defined(OS_WIN) #if !BUILDFLAG(IS_WIN)
// The headless browser may need to create child processes (e.g., a renderer // The headless browser may need to create child processes (e.g., a renderer
// which runs web content). This is done by re-executing the parent process as // which runs web content). This is done by re-executing the parent process as
// a zygote[1] and forking each child process from that zygote. // a zygote[1] and forking each child process from that zygote.
@@ -307,7 +307,7 @@ void RunChildProcessIfNeeded(int argc, const char** argv);
// the child process. // the child process.
void RunChildProcessIfNeeded(HINSTANCE instance, void RunChildProcessIfNeeded(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info); sandbox::SandboxInterfaceInfo* sandbox_info);
#endif // !defined(OS_WIN) #endif // !BUILDFLAG(IS_WIN)
// Main entry point for running the headless browser. This function constructs // Main entry point for running the headless browser. This function constructs
// the headless browser instance, passing it to the given // the headless browser instance, passing it to the given

@@ -5,9 +5,10 @@
#ifndef HEADLESS_PUBLIC_HEADLESS_SHELL_H_ #ifndef HEADLESS_PUBLIC_HEADLESS_SHELL_H_
#define HEADLESS_PUBLIC_HEADLESS_SHELL_H_ #define HEADLESS_PUBLIC_HEADLESS_SHELL_H_
#include "build/build_config.h"
#include "content/public/app/content_main.h" #include "content/public/app/content_main.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "sandbox/win/src/sandbox_types.h" #include "sandbox/win/src/sandbox_types.h"
#endif #endif
@@ -20,12 +21,12 @@ int HeadlessShellMain(const content::ContentMainParams& params);
// Start the Headless Shell application. Intended to be called early in main(). // Start the Headless Shell application. Intended to be called early in main().
// Returns the exit code for the process. // Returns the exit code for the process.
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
int HeadlessShellMain(HINSTANCE instance, int HeadlessShellMain(HINSTANCE instance,
sandbox::SandboxInterfaceInfo* sandbox_info); sandbox::SandboxInterfaceInfo* sandbox_info);
#else #else
int HeadlessShellMain(int argc, const char** argv); int HeadlessShellMain(int argc, const char** argv);
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
} // namespace headless } // namespace headless
#endif // HEADLESS_PUBLIC_HEADLESS_SHELL_H_ #endif // HEADLESS_PUBLIC_HEADLESS_SHELL_H_

@@ -52,7 +52,7 @@
#include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#if !defined(OS_FUCHSIA) #if !BUILDFLAG(IS_FUCHSIA)
#include "third_party/crashpad/crashpad/client/crash_report_database.h" // nogncheck #include "third_party/crashpad/crashpad/client/crash_report_database.h" // nogncheck
#endif #endif
@@ -223,7 +223,7 @@ class HeadlessBrowserTestWithProxy : public HeadlessBrowserTest {
net::EmbeddedTestServer proxy_server_; net::EmbeddedTestServer proxy_server_;
}; };
#if defined(OS_MAC) && defined(ADDRESS_SANITIZER) #if BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER)
// TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN. // TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN.
#define MAYBE_SetProxyConfig DISABLED_SetProxyConfig #define MAYBE_SetProxyConfig DISABLED_SetProxyConfig
#else #else
@@ -300,7 +300,7 @@ IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, DefaultSizes) {
HeadlessBrowser::Options::Builder builder; HeadlessBrowser::Options::Builder builder;
const HeadlessBrowser::Options kDefaultOptions = builder.Build(); const HeadlessBrowser::Options kDefaultOptions = builder.Build();
#if !defined(OS_MAC) #if !BUILDFLAG(IS_MAC)
// On Mac headless does not override the screen dimensions, so they are // On Mac headless does not override the screen dimensions, so they are
// left with the actual screen values. // left with the actual screen values.
EXPECT_EQ(kDefaultOptions.window_size.width(), EXPECT_EQ(kDefaultOptions.window_size.width(),
@@ -313,7 +313,7 @@ IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, DefaultSizes) {
->GetResult() ->GetResult()
->GetValue() ->GetValue()
->GetInt()); ->GetInt());
#endif // !defined(OS_MAC) #endif // !BUILDFLAG(IS_MAC)
EXPECT_EQ(kDefaultOptions.window_size.width(), EXPECT_EQ(kDefaultOptions.window_size.width(),
EvaluateScript(web_contents, "window.innerWidth") EvaluateScript(web_contents, "window.innerWidth")
->GetResult() ->GetResult()
@@ -371,7 +371,7 @@ class CookieSetter {
// TODO(skyostil): This test currently relies on being able to run a shell // TODO(skyostil): This test currently relies on being able to run a shell
// script. // script.
#if defined(OS_POSIX) #if BUILDFLAG(IS_POSIX)
class HeadlessBrowserRendererCommandPrefixTest : public HeadlessBrowserTest { class HeadlessBrowserRendererCommandPrefixTest : public HeadlessBrowserTest {
public: public:
const base::FilePath& launcher_stamp() const { return launcher_stamp_; } const base::FilePath& launcher_stamp() const { return launcher_stamp_; }
@@ -386,11 +386,11 @@ class HeadlessBrowserRendererCommandPrefixTest : public HeadlessBrowserTest {
launcher_stamp_.value().c_str()); launcher_stamp_.value().c_str());
fprintf(launcher_file.get(), "exec $@\n"); fprintf(launcher_file.get(), "exec $@\n");
launcher_file.reset(); launcher_file.reset();
#if !defined(OS_FUCHSIA) #if !BUILDFLAG(IS_FUCHSIA)
base::SetPosixFilePermissions(launcher_script_, base::SetPosixFilePermissions(launcher_script_,
base::FILE_PERMISSION_READ_BY_USER | base::FILE_PERMISSION_READ_BY_USER |
base::FILE_PERMISSION_EXECUTE_BY_USER); base::FILE_PERMISSION_EXECUTE_BY_USER);
#endif // !defined(OS_FUCHSIA) #endif // !BUILDFLAG(IS_FUCHSIA)
HeadlessBrowserTest::SetUp(); HeadlessBrowserTest::SetUp();
} }
@@ -431,7 +431,7 @@ IN_PROC_BROWSER_TEST_F(HeadlessBrowserRendererCommandPrefixTest, Prefix) {
EXPECT_TRUE(base::ReadFileToString(launcher_stamp(), &stamp)); EXPECT_TRUE(base::ReadFileToString(launcher_stamp(), &stamp));
EXPECT_GE(stamp.find("--type=renderer"), 0u); EXPECT_GE(stamp.find("--type=renderer"), 0u);
} }
#endif // defined(OS_POSIX) #endif // BUILDFLAG(IS_POSIX)
class CrashReporterTest : public HeadlessBrowserTest, class CrashReporterTest : public HeadlessBrowserTest,
public HeadlessWebContents::Observer, public HeadlessWebContents::Observer,
@@ -473,7 +473,7 @@ class CrashReporterTest : public HeadlessBrowserTest,
base::FilePath crash_dumps_dir_; base::FilePath crash_dumps_dir_;
}; };
#if !defined(OS_FUCHSIA) && !defined(OS_WIN) #if !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(CrashReporterTest, GenerateMinidump) { IN_PROC_BROWSER_TEST_F(CrashReporterTest, GenerateMinidump) {
content::ScopedAllowRendererCrashes scoped_allow_renderer_crashes; content::ScopedAllowRendererCrashes scoped_allow_renderer_crashes;
@@ -513,7 +513,7 @@ IN_PROC_BROWSER_TEST_F(CrashReporterTest, GenerateMinidump) {
browser_context_->Close(); browser_context_->Close();
browser_context_ = nullptr; browser_context_ = nullptr;
} }
#endif // !defined(OS_FUCHSIA) && !defined(OS_WIN) #endif // !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, PermissionManagerAlwaysASK) { IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, PermissionManagerAlwaysASK) {
GURL url("https://example.com"); GURL url("https://example.com");
@@ -599,12 +599,12 @@ class TraceHelper : public tracing::ExperimentalObserver {
} // namespace } // namespace
// Flaky, http://crbug.com/1269261. // Flaky, http://crbug.com/1269261.
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#define MAYBE_TraceUsingBrowserDevToolsTarget \ #define MAYBE_TraceUsingBrowserDevToolsTarget \
DISABLED_TraceUsingBrowserDevToolsTarget DISABLED_TraceUsingBrowserDevToolsTarget
#else #else
#define MAYBE_TraceUsingBrowserDevToolsTarget TraceUsingBrowserDevToolsTarget #define MAYBE_TraceUsingBrowserDevToolsTarget TraceUsingBrowserDevToolsTarget
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest,
MAYBE_TraceUsingBrowserDevToolsTarget) { MAYBE_TraceUsingBrowserDevToolsTarget) {
HeadlessDevToolsTarget* target = browser()->GetDevToolsTarget(); HeadlessDevToolsTarget* target = browser()->GetDevToolsTarget();

@@ -34,7 +34,7 @@
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
#include "url/gurl.h" #include "url/gurl.h"
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
#include "services/device/public/cpp/test/fake_geolocation_manager.h" #include "services/device/public/cpp/test/fake_geolocation_manager.h"
#endif #endif
@@ -137,14 +137,14 @@ void LoadObserver::OnResponseReceived(
} }
HeadlessBrowserTest::HeadlessBrowserTest() { HeadlessBrowserTest::HeadlessBrowserTest() {
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
// On Mac the source root is not set properly. We override it by assuming // On Mac the source root is not set properly. We override it by assuming
// that is two directories up from the execution test file. // that is two directories up from the execution test file.
base::FilePath dir_exe_path; base::FilePath dir_exe_path;
CHECK(base::PathService::Get(base::DIR_EXE, &dir_exe_path)); CHECK(base::PathService::Get(base::DIR_EXE, &dir_exe_path));
dir_exe_path = dir_exe_path.Append("../../"); dir_exe_path = dir_exe_path.Append("../../");
CHECK(base::PathService::Override(base::DIR_SOURCE_ROOT, dir_exe_path)); CHECK(base::PathService::Override(base::DIR_SOURCE_ROOT, dir_exe_path));
#endif // defined(OS_MAC) #endif // BUILDFLAG(IS_MAC)
base::FilePath headless_test_data(FILE_PATH_LITERAL("headless/test/data")); base::FilePath headless_test_data(FILE_PATH_LITERAL("headless/test/data"));
CreateTestServer(headless_test_data); CreateTestServer(headless_test_data);
} }
@@ -194,7 +194,7 @@ void HeadlessBrowserTest::PostRunTestOnMainThread() {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
void HeadlessBrowserTest::CreatedBrowserMainParts( void HeadlessBrowserTest::CreatedBrowserMainParts(
content::BrowserMainParts* parts) { content::BrowserMainParts* parts) {
auto fake_geolocation_manager = auto fake_geolocation_manager =
@@ -273,7 +273,7 @@ HeadlessAsyncDevTooledBrowserTest::~HeadlessAsyncDevTooledBrowserTest() =
void HeadlessAsyncDevTooledBrowserTest::DevToolsTargetReady() { void HeadlessAsyncDevTooledBrowserTest::DevToolsTargetReady() {
EXPECT_TRUE(web_contents_->GetDevToolsTarget()); EXPECT_TRUE(web_contents_->GetDevToolsTarget());
web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get()); web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get());
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
devtools_client_->GetEmulation()->SetDeviceMetricsOverride( devtools_client_->GetEmulation()->SetDeviceMetricsOverride(
emulation::SetDeviceMetricsOverrideParams::Builder() emulation::SetDeviceMetricsOverrideParams::Builder()
.SetWidth(0) .SetWidth(0)

@@ -72,7 +72,7 @@ class HeadlessBrowserTest : public content::BrowserTestBase {
void SetUp() override; void SetUp() override;
void PreRunTestOnMainThread() override; void PreRunTestOnMainThread() override;
void PostRunTestOnMainThread() override; void PostRunTestOnMainThread() override;
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
void CreatedBrowserMainParts(content::BrowserMainParts* parts) override; void CreatedBrowserMainParts(content::BrowserMainParts* parts) override;
#endif #endif

@@ -48,8 +48,8 @@ class HeadlessCompositorBrowserTest : public HeadlessProtocolBrowserTest {
// chromium/src/headless/lib/browser/protocol/target_handler.cc? // chromium/src/headless/lib/browser/protocol/target_handler.cc?
// rcl=5811aa08e60ba5ac7622f029163213cfbdb682f7&l=32 // rcl=5811aa08e60ba5ac7622f029163213cfbdb682f7&l=32
// TODO(crbug.com/1020046): Suite is flaky on TSan Linux. // TODO(crbug.com/1020046): Suite is flaky on TSan Linux.
#if defined(OS_MAC) || \ #if BUILDFLAG(IS_MAC) || ((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && \
((defined(OS_LINUX) || defined(OS_CHROMEOS)) && defined(THREAD_SANITIZER)) defined(THREAD_SANITIZER))
#define HEADLESS_COMPOSITOR_TEST(TEST_NAME, SCRIPT_NAME) \ #define HEADLESS_COMPOSITOR_TEST(TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_F(HeadlessCompositorBrowserTest, \ IN_PROC_BROWSER_TEST_F(HeadlessCompositorBrowserTest, \
DISABLED_##TEST_NAME) { \ DISABLED_##TEST_NAME) { \
@@ -72,8 +72,8 @@ HEADLESS_COMPOSITOR_TEST(CompositorImageAnimation,
"emulation/compositor-image-animation-test.js") "emulation/compositor-image-animation-test.js")
// Flaky on all platforms. TODO(crbug.com/986027): Re-enable. // Flaky on all platforms. TODO(crbug.com/986027): Re-enable.
#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) || \ #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
defined(OS_FUCHSIA) BUILDFLAG(IS_FUCHSIA)
#define MAYBE_CompositorCssAnimation DISABLED_CompositorCssAnimation #define MAYBE_CompositorCssAnimation DISABLED_CompositorCssAnimation
#else #else
#define MAYBE_CompositorCssAnimation CompositorCssAnimation #define MAYBE_CompositorCssAnimation CompositorCssAnimation

@@ -140,10 +140,10 @@ class HeadlessDevToolsClientWindowManagementTest
std::unique_ptr<browser::GetWindowBoundsResult> result) { std::unique_ptr<browser::GetWindowBoundsResult> result) {
const browser::Bounds* actual_bounds = result->GetBounds(); const browser::Bounds* actual_bounds = result->GetBounds();
// Mac does not support repositioning, as we don't show any actual window. // Mac does not support repositioning, as we don't show any actual window.
#if !defined(OS_MAC) #if !BUILDFLAG(IS_MAC)
EXPECT_EQ(bounds.x(), actual_bounds->GetLeft()); EXPECT_EQ(bounds.x(), actual_bounds->GetLeft());
EXPECT_EQ(bounds.y(), actual_bounds->GetTop()); EXPECT_EQ(bounds.y(), actual_bounds->GetTop());
#endif // !defined(OS_MAC) #endif // !BUILDFLAG(IS_MAC)
EXPECT_EQ(bounds.width(), actual_bounds->GetWidth()); EXPECT_EQ(bounds.width(), actual_bounds->GetWidth());
EXPECT_EQ(bounds.height(), actual_bounds->GetHeight()); EXPECT_EQ(bounds.height(), actual_bounds->GetHeight());
EXPECT_EQ(state, actual_bounds->GetWindowState()); EXPECT_EQ(state, actual_bounds->GetWindowState());
@@ -175,7 +175,7 @@ class HeadlessDevToolsClientChangeWindowBoundsTest
} }
}; };
#if defined(OS_MAC) && defined(ADDRESS_SANITIZER) #if BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER)
// TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN. // TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN.
DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_F( DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_F(
HeadlessDevToolsClientChangeWindowBoundsTest); HeadlessDevToolsClientChangeWindowBoundsTest);
@@ -506,12 +506,12 @@ class HeadlessCrashObserverTest : public HeadlessAsyncDevTooledBrowserTest,
// Make sure we don't fail because the renderer crashed! // Make sure we don't fail because the renderer crashed!
void RenderProcessExited(base::TerminationStatus status, void RenderProcessExited(base::TerminationStatus status,
int exit_code) override { int exit_code) override {
#if defined(OS_WIN) && defined(ADDRESS_SANITIZER) #if BUILDFLAG(IS_WIN) && defined(ADDRESS_SANITIZER)
// TODO(crbug.com/845011): Make ASan not interfere and expect a crash. // TODO(crbug.com/845011): Make ASan not interfere and expect a crash.
// ASan's normal error exit code is 1, which base categorizes as the process // ASan's normal error exit code is 1, which base categorizes as the process
// being killed. // being killed.
EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status); EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_WAS_KILLED, status);
#elif defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) #elif BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_CRASHED, status); EXPECT_EQ(base::TERMINATION_STATUS_PROCESS_CRASHED, status);
#else #else
EXPECT_EQ(base::TERMINATION_STATUS_ABNORMAL_TERMINATION, status); EXPECT_EQ(base::TERMINATION_STATUS_ABNORMAL_TERMINATION, status);
@@ -894,7 +894,7 @@ class DomTreeExtractionBrowserTest : public HeadlessAsyncDevTooledBrowserTest,
dom_nodes_result += result_json; dom_nodes_result += result_json;
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
ASSERT_TRUE(base::RemoveChars(dom_nodes_result, "\r", &dom_nodes_result)); ASSERT_TRUE(base::RemoveChars(dom_nodes_result, "\r", &dom_nodes_result));
#endif #endif
@@ -917,7 +917,7 @@ class DomTreeExtractionBrowserTest : public HeadlessAsyncDevTooledBrowserTest,
computed_styles_result += result_json; computed_styles_result += result_json;
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
ASSERT_TRUE(base::RemoveChars(computed_styles_result, "\r", ASSERT_TRUE(base::RemoveChars(computed_styles_result, "\r",
&computed_styles_result)); &computed_styles_result));
#endif #endif
@@ -1120,7 +1120,7 @@ class DevtoolsInterceptionWithAuthProxyTest
std::set<std::string> files_loaded_; std::set<std::string> files_loaded_;
}; };
#if defined(OS_MAC) && defined(ADDRESS_SANITIZER) #if BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER)
// TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN. // TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN.
DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_F(DevtoolsInterceptionWithAuthProxyTest); DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_F(DevtoolsInterceptionWithAuthProxyTest);
#else #else

@@ -29,7 +29,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if !defined(OS_WIN) #if !BUILDFLAG(IS_WIN)
#include <unistd.h> #include <unistd.h>
#endif #endif
@@ -119,7 +119,7 @@ namespace {
class CaptureStdErr { class CaptureStdErr {
public: public:
CaptureStdErr() { CaptureStdErr() {
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
CHECK_EQ(_pipe(pipes_, 4096, O_BINARY), 0); CHECK_EQ(_pipe(pipes_, 4096, O_BINARY), 0);
#else #else
CHECK_EQ(pipe(pipes_), 0); CHECK_EQ(pipe(pipes_), 0);
@@ -224,7 +224,7 @@ INSTANTIATE_TEST_CASE_P(HeadlessBrowserTestWithRemoteDebuggingAllowedPolicy,
// Remote debugging with ephemeral port is not working on Fuchsia, see // Remote debugging with ephemeral port is not working on Fuchsia, see
// crbug.com/1209251. // crbug.com/1209251.
#if defined(OS_FUCHSIA) #if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_RemoteDebuggingDisallowed DISABLED_RemoteDebuggingDisallowed #define MAYBE_RemoteDebuggingDisallowed DISABLED_RemoteDebuggingDisallowed
#else #else
#define MAYBE_RemoteDebuggingDisallowed RemoteDebuggingDisallowed #define MAYBE_RemoteDebuggingDisallowed RemoteDebuggingDisallowed

@@ -177,7 +177,7 @@ void HeadlessProtocolBrowserTest::FinishTest() {
} }
// TODO(crbug.com/1086872): The whole test suite is flaky on Mac ASAN. // TODO(crbug.com/1086872): The whole test suite is flaky on Mac ASAN.
#if (defined(OS_MAC) && defined(ADDRESS_SANITIZER)) #if (BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER))
#define HEADLESS_PROTOCOL_TEST(TEST_NAME, SCRIPT_NAME) \ #define HEADLESS_PROTOCOL_TEST(TEST_NAME, SCRIPT_NAME) \
IN_PROC_BROWSER_TEST_F(HeadlessProtocolBrowserTest, DISABLED_##TEST_NAME) { \ IN_PROC_BROWSER_TEST_F(HeadlessProtocolBrowserTest, DISABLED_##TEST_NAME) { \
test_folder_ = "/protocol/"; \ test_folder_ = "/protocol/"; \
@@ -199,8 +199,8 @@ HEADLESS_PROTOCOL_TEST(VirtualTimeInterrupt,
"emulation/virtual-time-interrupt.js") "emulation/virtual-time-interrupt.js")
// Flaky on Linux, Mac & Win. TODO(crbug.com/930717): Re-enable. // Flaky on Linux, Mac & Win. TODO(crbug.com/930717): Re-enable.
#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_MAC) || \ #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) || \
defined(OS_WIN) || defined(OS_FUCHSIA) BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA)
#define MAYBE_VirtualTimeCrossProcessNavigation \ #define MAYBE_VirtualTimeCrossProcessNavigation \
DISABLED_VirtualTimeCrossProcessNavigation DISABLED_VirtualTimeCrossProcessNavigation
#else #else
@@ -235,7 +235,7 @@ HEADLESS_PROTOCOL_TEST(VirtualTimeHistoryNavigationSameDoc,
"emulation/virtual-time-history-navigation-same-doc.js") "emulation/virtual-time-history-navigation-same-doc.js")
// Flaky on Mac. TODO(crbug.com/1164173): Re-enable. // Flaky on Mac. TODO(crbug.com/1164173): Re-enable.
#if defined(OS_MAC) #if BUILDFLAG(IS_MAC)
#define MAYBE_VirtualTimeFetchKeepalive DISABLED_VirtualTimeFetchKeepalive #define MAYBE_VirtualTimeFetchKeepalive DISABLED_VirtualTimeFetchKeepalive
#else #else
#define MAYBE_VirtualTimeFetchKeepalive VirtualTimeFetchKeepalive #define MAYBE_VirtualTimeFetchKeepalive VirtualTimeFetchKeepalive
@@ -250,7 +250,7 @@ HEADLESS_PROTOCOL_TEST(VirtualTimePausesDocumentLoading,
HEADLESS_PROTOCOL_TEST(PageBeforeUnload, "page/page-before-unload.js") HEADLESS_PROTOCOL_TEST(PageBeforeUnload, "page/page-before-unload.js")
// http://crbug.com/633321 // http://crbug.com/633321
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
#define MAYBE_VirtualTimeTimerOrder DISABLED_VirtualTimeTimerOrder #define MAYBE_VirtualTimeTimerOrder DISABLED_VirtualTimeTimerOrder
#define MAYBE_VirtualTimeTimerSuspend DISABLED_VirtualTimeTimerSuspend #define MAYBE_VirtualTimeTimerSuspend DISABLED_VirtualTimeTimerSuspend
#else #else
@@ -269,7 +269,7 @@ HEADLESS_PROTOCOL_TEST(Geolocation, "emulation/geolocation-crash.js")
HEADLESS_PROTOCOL_TEST(DragStarted, "input/dragIntercepted.js") HEADLESS_PROTOCOL_TEST(DragStarted, "input/dragIntercepted.js")
// https://crbug.com/1204620 // https://crbug.com/1204620
#if defined(OS_LINUX) || defined(OS_MAC) || defined(OS_WIN) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
#define MAYBE_InputClipboardOps DISABLED_InputClipboardOps #define MAYBE_InputClipboardOps DISABLED_InputClipboardOps
#else #else
#define MAYBE_InputClipboardOps InputClipboardOps #define MAYBE_InputClipboardOps InputClipboardOps

@@ -17,9 +17,9 @@
#include "headless/lib/utility/headless_content_utility_client.h" #include "headless/lib/utility/headless_content_utility_client.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "base/win/win_util.h" #include "base/win/win_util.h"
#endif // defined(OS_WIN) #endif // BUILDFLAG(IS_WIN)
namespace headless { namespace headless {
namespace { namespace {
@@ -76,7 +76,7 @@ int main(int argc, char** argv) {
if (parallel_jobs == 0U) if (parallel_jobs == 0U)
return 1; return 1;
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// Load and pin user32.dll to avoid having to load it once tests start while // Load and pin user32.dll to avoid having to load it once tests start while
// on the main thread loop where blocking calls are disallowed. // on the main thread loop where blocking calls are disallowed.
base::win::PinUser32(); base::win::PinUser32();

@@ -113,14 +113,14 @@ IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, WindowOpen) {
EXPECT_NE(parent->window_tree_host(), child->window_tree_host()); EXPECT_NE(parent->window_tree_host(), child->window_tree_host());
gfx::Rect expected_bounds(0, 0, 200, 100); gfx::Rect expected_bounds(0, 0, 200, 100);
#if !defined(OS_MAC) #if !BUILDFLAG(IS_MAC)
EXPECT_EQ(expected_bounds, child->web_contents()->GetViewBounds()); EXPECT_EQ(expected_bounds, child->web_contents()->GetViewBounds());
EXPECT_EQ(expected_bounds, child->web_contents()->GetContainerBounds()); EXPECT_EQ(expected_bounds, child->web_contents()->GetContainerBounds());
#else // !defined(OS_MAC) #else // !BUILDFLAG(IS_MAC)
// Mac does not support GetViewBounds() and view positions are random. // Mac does not support GetViewBounds() and view positions are random.
EXPECT_EQ(expected_bounds.size(), EXPECT_EQ(expected_bounds.size(),
child->web_contents()->GetContainerBounds().size()); child->web_contents()->GetContainerBounds().size());
#endif // !defined(OS_MAC) #endif // !BUILDFLAG(IS_MAC)
} }
IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest,
@@ -260,7 +260,7 @@ class HeadlessWebContentsScreenshotWindowPositionTest
} }
}; };
#if defined(OS_MAC) && defined(ADDRESS_SANITIZER) #if BUILDFLAG(IS_MAC) && defined(ADDRESS_SANITIZER)
// TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN. // TODO(crbug.com/1086872): Disabled due to flakiness on Mac ASAN.
DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_P( DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_P(
HeadlessWebContentsScreenshotWindowPositionTest); HeadlessWebContentsScreenshotWindowPositionTest);
@@ -727,7 +727,7 @@ IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, BrowserOpenInTab) {
} }
// BeginFrameControl is not supported on MacOS. // BeginFrameControl is not supported on MacOS.
#if !defined(OS_MAC) #if !BUILDFLAG(IS_MAC)
class HeadlessWebContentsBeginFrameControlTest class HeadlessWebContentsBeginFrameControlTest
: public HeadlessBrowserTest, : public HeadlessBrowserTest,
@@ -1043,7 +1043,7 @@ class HeadlessWebContentsBeginFrameControlViewportTest
HEADLESS_ASYNC_DEVTOOLED_TEST_F( HEADLESS_ASYNC_DEVTOOLED_TEST_F(
HeadlessWebContentsBeginFrameControlViewportTest); HeadlessWebContentsBeginFrameControlViewportTest);
#endif // !defined(OS_MAC) #endif // !BUILDFLAG(IS_MAC)
class CookiesEnabled : public HeadlessAsyncDevTooledBrowserTest, class CookiesEnabled : public HeadlessAsyncDevTooledBrowserTest,
page::Observer { page::Observer {