#include "chrome/test/base/chromeos/crosier/chromeos_test_launcher.h"
#include <string_view>
#include "base/profiler/thread_group_profiler.h"
#include "base/test/allow_check_is_test_for_testing.h"
#include "base/test/task_environment.h"
#include "base/types/pass_key.h"
#include "chrome/app/chrome_crash_reporter_client.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/common/profiler/chrome_thread_group_profiler_client.h"
#include "chrome/common/profiler/chrome_thread_profiler_client.h"
#include "chrome/common/profiler/main_thread_stack_sampling_profiler.h"
#include "chrome/test/base/chromeos/crosier/chromeos_test_suite.h"
#include "chrome/utility/chrome_content_utility_client.h"
#include "components/sampling_profiler/thread_profiler.h"
#include "content/public/test/network_service_test_helper.h"
#include "mojo/public/cpp/bindings/service_factory.h"
#include "services/test/echo/echo_service.h"
#include "ui/base/interaction/interactive_test_internal.h"
namespace {
auto RunEchoService(mojo::PendingReceiver<echo::mojom::EchoService> receiver) {
return std::make_unique<echo::EchoService>(std::move(receiver));
}
class BrowserTestChromeOSContentBrowserClient
: public ChromeContentBrowserClient {
public:
};
class BrowserTestChromeOSContentUtilityClient
: public ChromeContentUtilityClient {
public:
void RegisterIOThreadServices(mojo::ServiceFactory& services) override {
ChromeContentUtilityClient::RegisterIOThreadServices(services);
services.Add(RunEchoService);
}
};
}
int ChromeOSTestSuiteRunner::RunTestSuiteInternal(
ChromeOSTestSuite* test_suite) {
test_suite->DisableCheckForLeakedGlobals();
return test_suite->Run();
}
int ChromeOSTestSuiteRunner::RunTestSuite(int argc, char** argv) {
ChromeOSTestSuite test_suite(argc, argv);
return RunTestSuiteInternal(&test_suite);
}
ChromeOSTestLauncherDelegate::ChromeOSTestLauncherDelegate(
ChromeOSTestSuiteRunner* runner)
: runner_(runner) {
CHECK(runner);
ui::test::internal::InteractiveTestPrivate::
set_interactive_test_verbs_allowed(
base::PassKey<ChromeOSTestLauncherDelegate>());
}
ChromeOSTestLauncherDelegate::~ChromeOSTestLauncherDelegate() = default;
int ChromeOSTestLauncherDelegate::RunTestSuite(int argc, char** argv) {
return runner_->RunTestSuite(argc, argv);
}
content::ContentBrowserClient*
ChromeOSTestChromeMainDelegate::CreateContentBrowserClient() {
chrome_content_browser_client_ =
std::make_unique<BrowserTestChromeOSContentBrowserClient>();
return chrome_content_browser_client_.get();
}
content::ContentUtilityClient*
ChromeOSTestChromeMainDelegate::CreateContentUtilityClient() {
chrome_content_utility_client_ =
std::make_unique<BrowserTestChromeOSContentUtilityClient>();
return chrome_content_utility_client_.get();
}
void ChromeOSTestChromeMainDelegate::CreateThreadPool(std::string_view name) {
base::ThreadGroupProfiler::SetClient(
std::make_unique<ChromeThreadGroupProfilerClient>());
base::test::TaskEnvironment::CreateThreadPool();
sampling_profiler::ThreadProfiler::SetClient(
std::make_unique<ChromeThreadProfilerClient>());
sampling_profiler_ = std::make_unique<MainThreadStackSamplingProfiler>();
}
content::ContentMainDelegate*
ChromeOSTestLauncherDelegate::CreateContentMainDelegate() {
return new ChromeOSTestChromeMainDelegate();
}
void ChromeOSTestLauncherDelegate::PreSharding() {}
void ChromeOSTestLauncherDelegate::OnDoneRunningTests() {}
int LaunchChromeOSTests(content::TestLauncherDelegate* delegate,
int argc,
char** argv) {
base::test::AllowCheckIsTestForTesting();
ChromeCrashReporterClient::Create();
std::unique_ptr<content::NetworkServiceTestHelper>
network_service_test_helper = content::NetworkServiceTestHelper::Create();
return content::LaunchTests(
delegate,
1, argc, argv);
}