1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45

ash / wm / overview / overview_animation_state_waiter.h [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WM_OVERVIEW_OVERVIEW_ANIMATION_STATE_WAITER_H_
#define ASH_WM_OVERVIEW_OVERVIEW_ANIMATION_STATE_WAITER_H_

#include "ash/ash_export.h"
#include "ash/public/cpp/overview_test_api.h"
#include "ash/wm/overview/overview_observer.h"
#include "base/functional/callback.h"

namespace ash {

// Wait until an overview animation completes. This self destruct
// after executing the callback. Used by testing APIs.
class ASH_EXPORT OverviewAnimationStateWaiter : public OverviewObserver {
 public:
  // Type of the callback. It receives true when the overview animation finishes
  // properly.
  using DoneCallback = base::OnceCallback<void(bool)>;

  OverviewAnimationStateWaiter(OverviewAnimationState expected_state,
                               DoneCallback callback);
  OverviewAnimationStateWaiter(const OverviewAnimationStateWaiter&) = delete;
  OverviewAnimationStateWaiter& operator=(const OverviewAnimationStateWaiter&) =
      delete;
  ~OverviewAnimationStateWaiter() override;

  // Cancels the ongoing observation of the overview animation and invokes
  // |callback_| with false. This also destructs itself.
  void Cancel();

 private:
  // OverviewObserver:
  void OnOverviewModeStartingAnimationComplete(bool canceled) override;
  void OnOverviewModeEndingAnimationComplete(bool canceled) override;

  OverviewAnimationState expected_state_;
  DoneCallback callback_;
};

}  // namespace ash

#endif  // ASH_WM_OVERVIEW_OVERVIEW_ANIMATION_STATE_WAITER_H_