summaryrefslogtreecommitdiffstats
path: root/ash/test/test_activation_delegate.h
blob: 9c3ddbb8654d43ccb1014cbbf28291d4af6c6cd9 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_TEST_TEST_ACTIVATION_DELEGATE_H_
#define ASH_TEST_TEST_ACTIVATION_DELEGATE_H_

#include "base/compiler_specific.h"
#include "base/logging.h"
#include "ui/events/event_handler.h"
#include "ui/wm/public/activation_change_observer.h"
#include "ui/wm/public/activation_delegate.h"

namespace aura {
class Window;
}

namespace ash {
namespace test {

// A test ActivationDelegate that can be used to track activation changes for
// an aura::Window.
class TestActivationDelegate : public aura::client::ActivationDelegate,
                               public aura::client::ActivationChangeObserver {
 public:
  TestActivationDelegate();
  explicit TestActivationDelegate(bool activate);

  // Associates this delegate with a Window.
  void SetWindow(aura::Window* window);

  bool window_was_active() const { return window_was_active_; }
  void set_activate(bool v) { activate_ = v; }
  int activated_count() const { return activated_count_; }
  int lost_active_count() const { return lost_active_count_; }
  int should_activate_count() const { return should_activate_count_; }
  void Clear() {
    activated_count_ = lost_active_count_ = should_activate_count_ = 0;
    window_was_active_ = false;
  }

  // Overridden from aura::client::ActivationDelegate:
  bool ShouldActivate() const override;

 private:
  // Overridden from aura::client::ActivationChangeObserver:
  void OnWindowActivated(
      aura::client::ActivationChangeObserver::ActivationReason reason,
      aura::Window* gained_active,
      aura::Window* lost_active) override;

  aura::Window* window_;
  bool window_was_active_;
  bool activate_;
  int activated_count_;
  int lost_active_count_;
  mutable int should_activate_count_;

  DISALLOW_COPY_AND_ASSIGN(TestActivationDelegate);
};

}  // namespace test
}  // namespace ash

#endif  // ASH_TEST_TEST_ACTIVATION_DELEGATE_H_