run_all_unittests.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2018 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/bind.h"
  5. #include "base/files/file.h"
  6. #include "base/i18n/icu_util.h"
  7. #include "base/message_loop/message_pump_type.h"
  8. #include "base/path_service.h"
  9. #include "base/test/launcher/unit_test_launcher.h"
  10. #include "base/test/test_suite.h"
  11. #include "base/threading/thread.h"
  12. #include "build/build_config.h"
  13. #include "mojo/core/embedder/configuration.h"
  14. #include "mojo/core/embedder/embedder.h"
  15. #include "mojo/core/embedder/scoped_ipc_support.h"
  16. #include "ui/base/resource/resource_bundle.h"
  17. #include "ui/base/resource/resource_scale_factor.h"
  18. #include "ui/base/ui_base_paths.h"
  19. #if BUILDFLAG(IS_ANDROID)
  20. #include "base/android/jni_android.h"
  21. #endif
  22. namespace {
  23. class ServiceTestSuite : public base::TestSuite {
  24. public:
  25. ServiceTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
  26. ServiceTestSuite(const ServiceTestSuite&) = delete;
  27. ServiceTestSuite& operator=(const ServiceTestSuite&) = delete;
  28. ~ServiceTestSuite() override = default;
  29. protected:
  30. void Initialize() override {
  31. base::TestSuite::Initialize();
  32. #if !BUILDFLAG(IS_IOS)
  33. ui::RegisterPathProvider();
  34. base::FilePath ui_test_pak_path;
  35. ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
  36. ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
  37. base::FilePath path;
  38. #if BUILDFLAG(IS_ANDROID)
  39. ASSERT_TRUE(base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path));
  40. #else
  41. ASSERT_TRUE(base::PathService::Get(base::DIR_ASSETS, &path));
  42. #endif
  43. base::FilePath bluetooth_test_strings =
  44. path.Append(FILE_PATH_LITERAL("bluetooth_test_strings.pak"));
  45. ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
  46. bluetooth_test_strings, ui::kScaleFactorNone);
  47. #endif // !BUILDFLAG(IS_IOS)
  48. // base::TestSuite and ViewsInit both try to load icu. That's ok for tests.
  49. base::i18n::AllowMultipleInitializeCallsForTesting();
  50. }
  51. void Shutdown() override {
  52. #if !BUILDFLAG(IS_IOS)
  53. ui::ResourceBundle::CleanupSharedInstance();
  54. #endif
  55. base::TestSuite::Shutdown();
  56. }
  57. };
  58. } // namespace
  59. int main(int argc, char** argv) {
  60. ServiceTestSuite test_suite(argc, argv);
  61. mojo::core::Configuration mojo_config;
  62. mojo_config.is_broker_process = true;
  63. mojo::core::Init(mojo_config);
  64. base::Thread ipc_thread("IPC thread");
  65. ipc_thread.StartWithOptions(
  66. base::Thread::Options(base::MessagePumpType::IO, 0));
  67. mojo::core::ScopedIPCSupport ipc_support(
  68. ipc_thread.task_runner(),
  69. mojo::core::ScopedIPCSupport::ShutdownPolicy::CLEAN);
  70. return base::LaunchUnitTests(
  71. argc, argv,
  72. base::BindOnce(&ServiceTestSuite::Run, base::Unretained(&test_suite)));
  73. }