status_area_widget_test_helper.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "ash/system/status_area_widget_test_helper.h"
  5. #include "ash/root_window_controller.h"
  6. #include "ash/session/session_controller_impl.h"
  7. #include "ash/shell.h"
  8. #include "ash/system/status_area_widget.h"
  9. #include "base/run_loop.h"
  10. #include "ui/compositor/layer_animation_observer.h"
  11. #include "ui/compositor/layer_animator.h"
  12. namespace ash {
  13. // An observer that quits a run loop when the animation finishes.
  14. class AnimationEndObserver : public ui::LayerAnimationObserver {
  15. public:
  16. explicit AnimationEndObserver(ui::LayerAnimator* animator)
  17. : animator_(animator) {
  18. animator_->AddObserver(this);
  19. }
  20. ~AnimationEndObserver() override { animator_->RemoveObserver(this); }
  21. void WaitForAnimationEnd() {
  22. if (!animator_->is_animating())
  23. return;
  24. // This will return immediately if |Quit| was already called.
  25. run_loop_.Run();
  26. }
  27. // ui::LayerAnimationObserver:
  28. void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override {
  29. run_loop_.Quit();
  30. }
  31. void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override {}
  32. void OnLayerAnimationScheduled(
  33. ui::LayerAnimationSequence* sequence) override {}
  34. private:
  35. ui::LayerAnimator* animator_;
  36. base::RunLoop run_loop_;
  37. };
  38. LoginStatus StatusAreaWidgetTestHelper::GetUserLoginStatus() {
  39. return Shell::Get()->session_controller()->login_status();
  40. }
  41. StatusAreaWidget* StatusAreaWidgetTestHelper::GetStatusAreaWidget() {
  42. return Shell::GetPrimaryRootWindowController()->GetStatusAreaWidget();
  43. }
  44. StatusAreaWidget* StatusAreaWidgetTestHelper::GetSecondaryStatusAreaWidget() {
  45. RootWindowController* primary_controller =
  46. Shell::GetPrimaryRootWindowController();
  47. Shell::RootWindowControllerList controllers =
  48. Shell::GetAllRootWindowControllers();
  49. for (size_t i = 0; i < controllers.size(); ++i) {
  50. if (controllers[i] != primary_controller)
  51. return controllers[i]->GetStatusAreaWidget();
  52. }
  53. return nullptr;
  54. }
  55. void StatusAreaWidgetTestHelper::WaitForAnimationEnd(
  56. StatusAreaWidget* status_area_widget) {
  57. AnimationEndObserver observer(status_area_widget->GetLayer()->GetAnimator());
  58. observer.WaitForAnimationEnd();
  59. status_area_widget->GetLayer()->GetAnimator()->StopAnimating();
  60. }
  61. void StatusAreaWidgetTestHelper::WaitForLayerAnimationEnd(ui::Layer* layer) {
  62. AnimationEndObserver observer(layer->GetAnimator());
  63. observer.WaitForAnimationEnd();
  64. }
  65. } // namespace ash