run_all_unittests.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <memory>
  5. #include "base/bind.h"
  6. #include "base/compiler_specific.h"
  7. #include "base/path_service.h"
  8. #include "base/test/launcher/unit_test_launcher.h"
  9. #include "base/test/test_suite.h"
  10. #include "build/chromeos_buildflags.h"
  11. #include "mojo/core/embedder/embedder.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. #include "ui/aura/env.h"
  14. #include "ui/base/resource/resource_bundle.h"
  15. #include "ui/base/ui_base_paths.h"
  16. #include "ui/gl/test/gl_surface_test_support.h"
  17. #if BUILDFLAG(IS_CHROMEOS_DEVICE)
  18. #error This test target only builds with linux-chromeos, not for real ChromeOS\
  19. devices. See comment in build/config/chromeos/args.gni.
  20. #endif
  21. namespace {
  22. class UIChromeOSTestSuite : public base::TestSuite {
  23. public:
  24. UIChromeOSTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
  25. UIChromeOSTestSuite(const UIChromeOSTestSuite&) = delete;
  26. UIChromeOSTestSuite& operator=(const UIChromeOSTestSuite&) = delete;
  27. ~UIChromeOSTestSuite() override {}
  28. protected:
  29. void Initialize() override {
  30. base::TestSuite::Initialize();
  31. gl::GLSurfaceTestSupport::InitializeOneOff();
  32. ui::RegisterPathProvider();
  33. base::FilePath ui_test_pak_path;
  34. ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
  35. ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
  36. env_ = aura::Env::CreateInstance();
  37. }
  38. void Shutdown() override {
  39. env_.reset();
  40. ui::ResourceBundle::CleanupSharedInstance();
  41. base::TestSuite::Shutdown();
  42. }
  43. private:
  44. std::unique_ptr<aura::Env> env_;
  45. };
  46. } // namespace
  47. int main(int argc, char** argv) {
  48. UIChromeOSTestSuite test_suite(argc, argv);
  49. mojo::core::Init();
  50. return base::LaunchUnitTests(
  51. argc, argv,
  52. base::BindOnce(&UIChromeOSTestSuite::Run, base::Unretained(&test_suite)));
  53. }