browsertests_main.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/command_line.h"
  5. #include "base/test/launcher/test_launcher.h"
  6. #include "build/build_config.h"
  7. #include "content/public/common/content_switches.h"
  8. #include "content/public/test/network_service_test_helper.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. #include "weblayer/test/test_launcher_delegate_impl.h"
  11. #include "weblayer/utility/content_utility_client_impl.h"
  12. #if BUILDFLAG(IS_WIN)
  13. #include "base/win/win_util.h"
  14. #endif // BUILDFLAG(IS_WIN)
  15. int main(int argc, char** argv) {
  16. base::CommandLine::Init(argc, argv);
  17. size_t parallel_jobs = base::NumParallelJobs(/*cores_per_job=*/1);
  18. if (parallel_jobs == 0U)
  19. return 1;
  20. #if BUILDFLAG(IS_WIN)
  21. // Load and pin user32.dll to avoid having to load it once tests start while
  22. // on the main thread loop where blocking calls are disallowed.
  23. base::win::PinUser32();
  24. #endif // BUILDFLAG(IS_WIN)
  25. // Set up a working test environment for the network service in case it's
  26. // used. Only create this object in the utility process, so that its members
  27. // don't interfere with other test objects in the browser process.
  28. std::unique_ptr<content::NetworkServiceTestHelper>
  29. network_service_test_helper;
  30. if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
  31. switches::kProcessType) == switches::kUtilityProcess) {
  32. network_service_test_helper =
  33. std::make_unique<content::NetworkServiceTestHelper>();
  34. weblayer::ContentUtilityClientImpl::
  35. SetNetworkBinderCreationCallbackForTests(base::BindRepeating(
  36. [](content::NetworkServiceTestHelper* helper,
  37. service_manager::BinderRegistry* registry) {
  38. helper->RegisterNetworkBinders(registry);
  39. },
  40. network_service_test_helper.get()));
  41. }
  42. weblayer::TestLauncherDelegateImpl launcher_delegate;
  43. return content::LaunchTests(&launcher_delegate, parallel_jobs, argc, argv);
  44. }