1 // Copyright (c) 2012 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 5 #ifndef UI_EVENTS_TEST_TEST_EVENT_HANDLER_H_ 6 #define UI_EVENTS_TEST_TEST_EVENT_HANDLER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "base/compiler_specific.h" 13 #include "ui/events/event_handler.h" 14 15 typedef std::vector<std::string> HandlerSequenceRecorder; 16 17 namespace ui { 18 namespace test { 19 20 // A simple EventHandler that keeps track of the number of key events that it's 21 // seen. 22 class TestEventHandler : public EventHandler { 23 public: 24 TestEventHandler(); 25 virtual ~TestEventHandler(); 26 num_key_events()27 int num_key_events() const { return num_key_events_; } num_mouse_events()28 int num_mouse_events() const { return num_mouse_events_; } num_scroll_events()29 int num_scroll_events() const { return num_scroll_events_; } num_touch_events()30 int num_touch_events() const { return num_touch_events_; } num_gesture_events()31 int num_gesture_events() const { return num_gesture_events_; } 32 33 void Reset(); 34 set_recorder(HandlerSequenceRecorder * recorder)35 void set_recorder(HandlerSequenceRecorder* recorder) { 36 recorder_ = recorder; 37 } set_handler_name(const std::string & handler_name)38 void set_handler_name(const std::string& handler_name) { 39 handler_name_ = handler_name; 40 } 41 42 // EventHandler overrides: 43 virtual void OnKeyEvent(KeyEvent* event) OVERRIDE; 44 virtual void OnMouseEvent(MouseEvent* event) OVERRIDE; 45 virtual void OnScrollEvent(ScrollEvent* event) OVERRIDE; 46 virtual void OnTouchEvent(TouchEvent* event) OVERRIDE; 47 virtual void OnGestureEvent(GestureEvent* event) OVERRIDE; 48 49 private: 50 // How many events have been received of each type? 51 int num_key_events_; 52 int num_mouse_events_; 53 int num_scroll_events_; 54 int num_touch_events_; 55 int num_gesture_events_; 56 57 HandlerSequenceRecorder* recorder_; 58 std::string handler_name_; 59 60 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 61 }; 62 63 } // namespace test 64 } // namespace ui 65 66 #endif // UI_EVENTS_TEST_TEST_EVENT_HANDLER_H_ 67