views_test_suite.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (c) 2012 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 "ui/views/views_test_suite.h"
  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 "gpu/ipc/service/image_transport_surface.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. #include "ui/base/resource/resource_bundle.h"
  14. #include "ui/base/ui_base_paths.h"
  15. #include "ui/gl/test/gl_surface_test_support.h"
  16. #if defined(USE_AURA)
  17. #include <memory>
  18. #include "ui/aura/env.h"
  19. #endif
  20. #if BUILDFLAG(IS_CHROMEOS_ASH)
  21. #include "base/command_line.h"
  22. #include "ui/gl/gl_switches.h"
  23. #endif
  24. namespace views {
  25. ViewsTestSuite::ViewsTestSuite(int argc, char** argv)
  26. : base::TestSuite(argc, argv), argc_(argc), argv_(argv) {}
  27. ViewsTestSuite::~ViewsTestSuite() = default;
  28. int ViewsTestSuite::RunTests() {
  29. return base::LaunchUnitTests(
  30. argc_, argv_,
  31. base::BindOnce(&ViewsTestSuite::Run, base::Unretained(this)));
  32. }
  33. int ViewsTestSuite::RunTestsSerially() {
  34. return base::LaunchUnitTestsSerially(
  35. argc_, argv_,
  36. base::BindOnce(&ViewsTestSuite::Run, base::Unretained(this)));
  37. }
  38. void ViewsTestSuite::Initialize() {
  39. base::TestSuite::Initialize();
  40. #if BUILDFLAG(IS_CHROMEOS_ASH) && defined(MEMORY_SANITIZER)
  41. // Force software-gl. This is necessary for mus tests to avoid an msan warning
  42. // in gl init.
  43. base::CommandLine::ForCurrentProcess()->AppendSwitch(
  44. switches::kOverrideUseSoftwareGLForTests);
  45. #endif
  46. gl::GLSurfaceTestSupport::InitializeOneOff();
  47. ui::RegisterPathProvider();
  48. base::FilePath ui_test_pak_path;
  49. ASSERT_TRUE(base::PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
  50. ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
  51. #if defined(USE_AURA)
  52. InitializeEnv();
  53. #endif
  54. }
  55. void ViewsTestSuite::Shutdown() {
  56. #if defined(USE_AURA)
  57. DestroyEnv();
  58. #endif
  59. ui::ResourceBundle::CleanupSharedInstance();
  60. base::TestSuite::Shutdown();
  61. }
  62. #if defined(USE_AURA)
  63. void ViewsTestSuite::InitializeEnv() {
  64. env_ = aura::Env::CreateInstance();
  65. }
  66. void ViewsTestSuite::DestroyEnv() {
  67. env_.reset();
  68. }
  69. #endif
  70. } // namespace views