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
ash / events / test_event_capturer.h [blame]
// Copyright 2024 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_EVENTS_TEST_EVENT_CAPTURER_H_
#define ASH_EVENTS_TEST_EVENT_CAPTURER_H_
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
namespace ash {
// Used to capture and inspect events in ash_unittests. By default it captures
// all KeyEvents, MouseEvents, and TouchEvents.
// EventType::kMouseMoved, EventType::kMouseEntered and EventType::kMouseExited
// can be optionally filtered out to make the stored events less noisy.
class TestEventCapturer : public ui::EventHandler {
public:
TestEventCapturer();
TestEventCapturer(const TestEventCapturer&) = delete;
TestEventCapturer& operator=(const TestEventCapturer&) = delete;
~TestEventCapturer() override;
void ClearEvents();
// ui::EventHandler:
void OnKeyEvent(ui::KeyEvent* event) override;
void OnMouseEvent(ui::MouseEvent* event) override;
void OnTouchEvent(ui::TouchEvent* event) override;
std::string_view GetLogContext() const override;
ui::KeyEvent* LastKeyEvent();
ui::MouseEvent* LastMouseEvent();
ui::TouchEvent* LastTouchEvent();
void set_capture_mouse_move(bool value) { capture_mouse_move_ = value; }
void set_capture_mouse_enter_exit(bool value) {
capture_mouse_enter_exit_ = value;
}
const std::vector<ui::KeyEvent>& key_events() const { return key_events_; }
const std::vector<ui::MouseEvent>& mouse_events() const {
return mouse_events_;
}
const std::vector<ui::TouchEvent>& touch_events() const {
return touch_events_;
}
const std::vector<ui::MouseWheelEvent>& captured_mouse_wheel_events() const {
return wheel_events_;
}
private:
bool capture_mouse_move_ = true;
bool capture_mouse_enter_exit_ = true;
std::vector<ui::KeyEvent> key_events_;
std::vector<ui::MouseEvent> mouse_events_;
std::vector<ui::TouchEvent> touch_events_;
std::vector<ui::MouseWheelEvent> wheel_events_;
};
} // namespace ash
#endif // ASH_EVENTS_TEST_EVENT_CAPTURER_H_