#include "content/browser/utility_process_host.h"
#include <string_view>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/memory/writable_shared_memory_region.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "content/browser/child_process_launcher.h"
#include "content/public/browser/browser_child_process_observer.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/child_process_termination_info.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/zygote/zygote_buildflags.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_service.mojom.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/remote.h"
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include <sys/wait.h>
#endif
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "sandbox/win/src/sandbox_types.h"
#endif
#if BUILDFLAG(USE_ZYGOTE)
#include "content/common/zygote/zygote_handle_impl_linux.h"
#include "content/public/common/zygote/zygote_handle.h"
#endif
namespace content {
namespace {
const char kTestProcessName[] = …;
constexpr std::string_view kTestMessage{ … };
}
class UtilityProcessHostBrowserTest : public BrowserChildProcessObserver,
public ContentBrowserTest { … };
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest, LaunchProcess) { … }
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_FileDescriptorStore …
#else
#define MAYBE_FileDescriptorStore …
#endif
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest,
MAYBE_FileDescriptorStore) { … }
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && BUILDFLAG(USE_ZYGOTE)
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest,
FileDescriptorStoreWithUnsandboxedZygote) { … }
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest,
FileDescriptorStoreWithGenericZygote) { … }
#endif
#if !(BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_ARM64))
#if (BUILDFLAG(IS_LINUX) && defined(ARCH_CPU_X86_64)) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_LaunchProcessAndCrash …
#else
#define MAYBE_LaunchProcessAndCrash …
#endif
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest,
MAYBE_LaunchProcessAndCrash) { … }
#endif
#if !BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_MAC)
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest, FailToLaunchProcess) {
SetExpectFailLaunch();
RunUtilityProcess(
base::BindOnce(&UtilityProcessHostBrowserTest::RunBasicPingPongTest,
base::Unretained(this)));
}
#endif
#if BUILDFLAG(IS_WIN)
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest, LaunchElevatedProcess) {
SetElevated();
RunUtilityProcess(
mojo::core::IsMojoIpczEnabled()
? base::BindOnce(
&UtilityProcessHostBrowserTest::RunSharedMemoryHandleTest,
base::Unretained(this))
: base::BindOnce(&UtilityProcessHostBrowserTest::RunBasicPingPongTest,
base::Unretained(this)));
}
IN_PROC_BROWSER_TEST_F(UtilityProcessHostBrowserTest,
DISABLED_LaunchElevatedProcessAndCrash) {
SetElevated();
RunUtilityProcess(
base::BindOnce(&UtilityProcessHostBrowserTest::RunCrashImmediatelyTest,
base::Unretained(this)));
}
#endif
}