Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(678)

Unified Diff: ui/base/test/event_generator_base.h

Issue 322893005: MacViews: Add WidgetEventGenerator to abstract platform-specific event generation for tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase at r282511 Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/test/event_generator_base.h
diff --git a/ui/base/test/event_generator_base.h b/ui/base/test/event_generator_base.h
new file mode 100644
index 0000000000000000000000000000000000000000..e261a5c8aabc639309a8042fcd110642999ec903
--- /dev/null
+++ b/ui/base/test/event_generator_base.h
@@ -0,0 +1,105 @@
+// Copyright 2014 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 UI_BASE_TEST_EVENT_GENERATOR_BASE_H_
Ben Goodger (Google) 2014/07/11 18:26:50 I think this should go into ui/events/test rather
tapted 2014/07/14 11:37:47 Done.
+#define UI_BASE_TEST_EVENT_GENERATOR_BASE_H_
+
+#include "base/macros.h"
+#include "ui/events/event_constants.h"
+#include "ui/gfx/geometry/point.h"
+
+namespace ui {
+namespace test {
+
+// Common base class for generating and dispatching platform-specific events.
+// Unlike |ui_controls|, events are dispatched directly to the EventProcessor.
+// MessageLoops are not used, and this interface is not suited to tests that
+// require a RunLoop.
+class EventGeneratorBase {
+ public:
+ explicit EventGeneratorBase(const gfx::Point& initial_location);
+ virtual ~EventGeneratorBase();
+
+ // Explicitly sets the location used by mouse/touch events. This is set by the
+ // various methods that take a location but can be manipulated directly,
+ // typically for touch.
+ void set_current_location(const gfx::Point& location) {
+ current_location_ = location;
+ }
+ const gfx::Point& current_location() const { return current_location_; }
+
+ // Resets the event flags bitmask.
+ void set_flags(int flags) { flags_ = flags; }
+ int flags() const { return flags_; }
+
+ bool grab() const { return grab_; }
+
+ // Generates a left button press event.
+ void PressLeftButton();
+
+ // Generates a left button release event.
+ void ReleaseLeftButton();
+
+ // Generates events to click (press, release) left button.
+ void ClickLeftButton();
+
+ // Generates a double click event using the left button.
+ void DoubleClickLeftButton();
+
+ // Generates a right button press event.
+ void PressRightButton();
+
+ // Generates a right button release event.
+ void ReleaseRightButton();
+
+ // Generates events to move mouse to be the given |point| in screen
+ // coordinates.
+ void MoveMouseTo(const gfx::Point& point_in_screen, int count) {
+ DoMoveMouseTo(point_in_screen, count);
+ }
+ void MoveMouseTo(const gfx::Point& point_in_screen) {
+ MoveMouseTo(point_in_screen, 1);
+ }
+ void MoveMouseTo(int x, int y) {
+ MoveMouseTo(gfx::Point(x, y));
+ }
+
+ // Generates events to drag mouse to given |point|.
+ void DragMouseTo(const gfx::Point& point);
+
+ void DragMouseTo(int x, int y) {
+ DragMouseTo(gfx::Point(x, y));
+ }
+
+ void DragMouseBy(int dx, int dy) {
+ DragMouseTo(current_location_ + gfx::Vector2d(dx, dy));
+ }
+
+ protected:
+ virtual gfx::Point GetLocationInCurrentRoot() const = 0;
+ virtual void DoMoveMouseTo(const gfx::Point& point_in_screen, int count) = 0;
+ virtual void DispatchMouseEvent(EventType type,
+ const gfx::Point& location_in_root,
+ int flags,
+ int changed_button_flags) = 0;
+
+ void PressButton(int flag);
+ void ReleaseButton(int flag);
+
+ private:
+ gfx::Point current_location_;
+
+ // Current ui::EventFlag state.
+ int flags_;
+
+ // Whether the event dispatcher should receive mousemove updates.
+ bool grab_;
+
+ DISALLOW_COPY_AND_ASSIGN(EventGeneratorBase);
+};
+
+} // namespace test
+} // namespace ui
+
+#endif // UI_BASE_TEST_EVENT_GENERATOR_BASE_H_

Powered by Google App Engine
This is Rietveld 408576698