animation_throughput_reporter_test_base.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2020 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/compositor/test/animation_throughput_reporter_test_base.h"
  5. #include <memory>
  6. #include "base/run_loop.h"
  7. #include "base/test/task_environment.h"
  8. #include "build/chromeos_buildflags.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. #include "ui/compositor/test/test_context_factories.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. #if BUILDFLAG(IS_CHROMEOS_ASH)
  13. #include "base/threading/thread_task_runner_handle.h"
  14. #endif
  15. namespace ui {
  16. AnimationThroughputReporterTestBase::AnimationThroughputReporterTestBase() =
  17. default;
  18. AnimationThroughputReporterTestBase::~AnimationThroughputReporterTestBase() =
  19. default;
  20. void AnimationThroughputReporterTestBase::SetUp() {
  21. context_factories_ = std::make_unique<TestContextFactories>(false);
  22. const gfx::Rect bounds(100, 100);
  23. host_.reset(TestCompositorHost::Create(
  24. bounds, context_factories_->GetContextFactory()));
  25. host_->Show();
  26. compositor()->SetRootLayer(&root_);
  27. frame_generation_timer_.Start(
  28. FROM_HERE, base::Milliseconds(16), this,
  29. &AnimationThroughputReporterTestBase::GenerateOneFrame);
  30. }
  31. void AnimationThroughputReporterTestBase::TearDown() {
  32. frame_generation_timer_.Stop();
  33. host_.reset();
  34. context_factories_.reset();
  35. }
  36. void AnimationThroughputReporterTestBase::Advance(
  37. const base::TimeDelta& delta) {
  38. run_loop_ = std::make_unique<base::RunLoop>();
  39. base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
  40. FROM_HERE, run_loop_->QuitClosure(), delta);
  41. run_loop_->Run();
  42. }
  43. void AnimationThroughputReporterTestBase::QuitRunLoop() {
  44. run_loop_->Quit();
  45. }
  46. } // namespace ui