1 // Copyright 2013 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.
5 #ifndef UI_EVENTS_TEST_TEST_EVENT_TARGET_H_
6 #define UI_EVENTS_TEST_TEST_EVENT_TARGET_H_
12 #include "base/memory/scoped_vector.h"
13 #include "ui/events/event_target.h"
15 typedef std::vector
<std::string
> HandlerSequenceRecorder
;
24 class TestEventTarget
: public EventTarget
{
27 ~TestEventTarget() override
;
29 void AddChild(scoped_ptr
<TestEventTarget
> child
);
30 scoped_ptr
<TestEventTarget
> RemoveChild(TestEventTarget
* child
);
32 TestEventTarget
* parent() { return parent_
; }
34 void set_mark_events_as_handled(bool handle
) {
35 mark_events_as_handled_
= handle
;
38 TestEventTarget
* child_at(int index
) { return children_
[index
]; }
39 size_t child_count() const { return children_
.size(); }
41 void SetEventTargeter(scoped_ptr
<EventTargeter
> targeter
);
43 bool DidReceiveEvent(ui::EventType type
) const;
44 void ResetReceivedEvents();
46 void set_recorder(HandlerSequenceRecorder
* recorder
) {
49 void set_target_name(const std::string
& target_name
) {
50 target_name_
= target_name
;
54 bool Contains(TestEventTarget
* target
) const;
57 bool CanAcceptEvent(const ui::Event
& event
) override
;
58 EventTarget
* GetParentTarget() override
;
59 scoped_ptr
<EventTargetIterator
> GetChildIterator() const override
;
60 EventTargeter
* GetEventTargeter() override
;
63 void OnEvent(Event
* event
) override
;
66 void set_parent(TestEventTarget
* parent
) { parent_
= parent
; }
68 TestEventTarget
* parent_
;
69 ScopedVector
<TestEventTarget
> children_
;
70 scoped_ptr
<EventTargeter
> targeter_
;
71 bool mark_events_as_handled_
;
73 std::set
<ui::EventType
> received_
;
75 HandlerSequenceRecorder
* recorder_
;
76 std::string target_name_
;
78 DISALLOW_COPY_AND_ASSIGN(TestEventTarget
);
84 #endif // UI_EVENTS_TEST_TEST_EVENT_TARGET_H_