run_all_unittests.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/files/file.h"
  6. #include "base/path_service.h"
  7. #include "base/test/launcher/unit_test_launcher.h"
  8. #include "base/test/test_suite.h"
  9. #include "build/build_config.h"
  10. #include "mojo/core/embedder/embedder.h"
  11. #include "ui/base/resource/resource_bundle.h"
  12. #include "ui/base/resource/resource_scale_factor.h"
  13. #include "ui/base/ui_base_paths.h"
  14. namespace {
  15. class DeviceTestSuite : public base::TestSuite {
  16. public:
  17. DeviceTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
  18. DeviceTestSuite(const DeviceTestSuite&) = delete;
  19. DeviceTestSuite& operator=(const DeviceTestSuite&) = delete;
  20. ~DeviceTestSuite() override = default;
  21. protected:
  22. void Initialize() override {
  23. base::TestSuite::Initialize();
  24. #if !BUILDFLAG(IS_IOS)
  25. ui::RegisterPathProvider();
  26. base::FilePath ui_test_pak_path;
  27. ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
  28. ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
  29. base::FilePath path;
  30. #if BUILDFLAG(IS_ANDROID)
  31. ASSERT_TRUE(base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path));
  32. #else
  33. ASSERT_TRUE(base::PathService::Get(base::DIR_ASSETS, &path));
  34. #endif // BUILDFLAG(IS_ANDROID)
  35. base::FilePath bluetooth_test_strings =
  36. path.Append(FILE_PATH_LITERAL("bluetooth_test_strings.pak"));
  37. ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
  38. bluetooth_test_strings, ui::kScaleFactorNone);
  39. #endif // !BUILDFLAG(IS_IOS)
  40. }
  41. void Shutdown() override {
  42. #if !BUILDFLAG(IS_IOS)
  43. ui::ResourceBundle::CleanupSharedInstance();
  44. #endif
  45. base::TestSuite::Shutdown();
  46. }
  47. };
  48. } // namespace
  49. int main(int argc, char** argv) {
  50. DeviceTestSuite test_suite(argc, argv);
  51. mojo::core::Init();
  52. return base::LaunchUnitTests(
  53. argc, argv,
  54. base::BindOnce(&DeviceTestSuite::Run, base::Unretained(&test_suite)));
  55. }