run_all_unittests.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2014 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/compiler_specific.h"
  6. #include "base/path_service.h"
  7. #include "base/test/launcher/unit_test_launcher.h"
  8. #include "base/test/test_discardable_memory_allocator.h"
  9. #include "base/test/test_suite.h"
  10. #include "build/build_config.h"
  11. #include "testing/gtest/include/gtest/gtest.h"
  12. #include "ui/base/resource/resource_bundle.h"
  13. #include "ui/base/ui_base_paths.h"
  14. #include "ui/gfx/font_util.h"
  15. #if BUILDFLAG(IS_MAC)
  16. #include "base/test/mock_chrome_application_mac.h"
  17. #endif
  18. #if !BUILDFLAG(IS_IOS)
  19. #include "mojo/core/embedder/embedder.h" // nogncheck
  20. #endif
  21. #if BUILDFLAG(IS_FUCHSIA)
  22. #include "skia/ext/test_fonts.h" // nogncheck
  23. #endif
  24. namespace {
  25. class GfxTestSuite : public base::TestSuite {
  26. public:
  27. GfxTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {
  28. }
  29. GfxTestSuite(const GfxTestSuite&) = delete;
  30. GfxTestSuite& operator=(const GfxTestSuite&) = delete;
  31. protected:
  32. void Initialize() override {
  33. base::TestSuite::Initialize();
  34. #if BUILDFLAG(IS_MAC)
  35. mock_cr_app::RegisterMockCrApp();
  36. #endif
  37. ui::RegisterPathProvider();
  38. base::FilePath ui_test_pak_path;
  39. ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
  40. ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
  41. #if BUILDFLAG(IS_ANDROID)
  42. // Android needs a discardable memory allocator when loading fallback fonts.
  43. base::DiscardableMemoryAllocator::SetInstance(
  44. &discardable_memory_allocator);
  45. #endif
  46. #if BUILDFLAG(IS_FUCHSIA)
  47. skia::InitializeSkFontMgrForTest();
  48. #endif
  49. gfx::InitializeFonts();
  50. }
  51. void Shutdown() override {
  52. ui::ResourceBundle::CleanupSharedInstance();
  53. base::TestSuite::Shutdown();
  54. }
  55. private:
  56. base::TestDiscardableMemoryAllocator discardable_memory_allocator;
  57. };
  58. } // namespace
  59. int main(int argc, char** argv) {
  60. GfxTestSuite test_suite(argc, argv);
  61. #if !BUILDFLAG(IS_IOS)
  62. mojo::core::Init();
  63. #endif
  64. return base::LaunchUnitTests(
  65. argc, argv,
  66. base::BindOnce(&GfxTestSuite::Run, base::Unretained(&test_suite)));
  67. }