summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-07 22:40:52 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-07 22:40:52 +0000
commit1ece3e2bfb09e4c57cebd9ccd7127bc7874b3620 (patch)
treebfc349a1c15eb1f4621f9d1de0e6912f138c1d34
parent064128c1d8c7a3fb1d4ceaae996891130f2cf171 (diff)
downloadchromium_src-1ece3e2bfb09e4c57cebd9ccd7127bc7874b3620.zip
chromium_src-1ece3e2bfb09e4c57cebd9ccd7127bc7874b3620.tar.gz
chromium_src-1ece3e2bfb09e4c57cebd9ccd7127bc7874b3620.tar.bz2
events/test: Add PlatformEventWaiter.
Add a generic PlatformEventWaiter that can trigger a callback when an expected event is received from the event-source. Use this in ui-tests. BUG=354062 R=oshima@chromium.org Review URL: https://codereview.chromium.org/224963015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262229 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/test/ui_controls_factory_aurax11.cc38
-rw-r--r--ui/events/events.gyp2
-rw-r--r--ui/events/test/platform_event_waiter.cc41
-rw-r--r--ui/events/test/platform_event_waiter.h37
-rw-r--r--ui/views/test/ui_controls_factory_desktop_aurax11.cc38
5 files changed, 86 insertions, 70 deletions
diff --git a/ui/aura/test/ui_controls_factory_aurax11.cc b/ui/aura/test/ui_controls_factory_aurax11.cc
index da8dff4..1bfe106 100644
--- a/ui/aura/test/ui_controls_factory_aurax11.cc
+++ b/ui/aura/test/ui_controls_factory_aurax11.cc
@@ -5,6 +5,7 @@
#include <X11/keysym.h>
#include <X11/Xlib.h>
+#include "base/bind.h"
#include "base/logging.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
@@ -15,6 +16,7 @@
#include "ui/base/x/x11_util.h"
#include "ui/compositor/dip_util.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
+#include "ui/events/test/platform_event_waiter.h"
namespace aura {
namespace test {
@@ -31,40 +33,6 @@ using ui_controls::UP;
// Mask of the buttons currently down.
unsigned button_down_mask = 0;
-// Event waiter executes the specified closure|when a matching event
-// is found.
-// TODO(oshima): Move this to base.
-class EventWaiter : public base::MessageLoopForUI::Observer {
- public:
- typedef bool (*EventWaiterMatcher)(const base::NativeEvent& event);
-
- EventWaiter(const base::Closure& closure, EventWaiterMatcher matcher)
- : closure_(closure),
- matcher_(matcher) {
- base::MessageLoopForUI::current()->AddObserver(this);
- }
-
- virtual ~EventWaiter() {
- base::MessageLoopForUI::current()->RemoveObserver(this);
- }
-
- // MessageLoop::Observer implementation:
- virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE {
- if ((*matcher_)(event)) {
- base::MessageLoop::current()->PostTask(FROM_HERE, closure_);
- delete this;
- }
- }
-
- virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE {
- }
-
- private:
- base::Closure closure_;
- EventWaiterMatcher matcher_;
- DISALLOW_COPY_AND_ASSIGN(EventWaiter);
-};
-
// Returns atom that indidates that the XEvent is marker event.
Atom MarkerEventAtom() {
return XInternAtom(gfx::GetXDisplay(), "marker_event", False);
@@ -227,7 +195,7 @@ class UIControlsX11 : public UIControlsAura {
}
marker_event->xclient.message_type = MarkerEventAtom();
host_->PostNativeEvent(marker_event);
- new EventWaiter(closure, &Matcher);
+ ui::PlatformEventWaiter::Create(closure, base::Bind(&Matcher));
}
private:
void SetKeycodeAndSendThenMask(XEvent* xevent,
diff --git a/ui/events/events.gyp b/ui/events/events.gyp
index 93d09d2..52fd155 100644
--- a/ui/events/events.gyp
+++ b/ui/events/events.gyp
@@ -267,6 +267,8 @@
'test/events_test_utils.h',
'test/events_test_utils_x11.cc',
'test/events_test_utils_x11.h',
+ 'test/platform_event_waiter.cc',
+ 'test/platform_event_waiter.h',
'test/test_event_handler.cc',
'test/test_event_handler.h',
'test/test_event_processor.cc',
diff --git a/ui/events/test/platform_event_waiter.cc b/ui/events/test/platform_event_waiter.cc
new file mode 100644
index 0000000..e024da5
--- /dev/null
+++ b/ui/events/test/platform_event_waiter.cc
@@ -0,0 +1,41 @@
+// 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.
+
+#include "ui/events/test/platform_event_waiter.h"
+
+#include "base/message_loop/message_loop.h"
+#include "ui/events/platform/platform_event_source.h"
+
+namespace ui {
+
+PlatformEventWaiter::PlatformEventWaiter(
+ const base::Closure& success_callback,
+ const PlatformEventMatcher& event_matcher)
+ : success_callback_(success_callback),
+ event_matcher_(event_matcher) {
+ PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
+}
+
+PlatformEventWaiter::~PlatformEventWaiter() {
+ PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
+}
+
+void PlatformEventWaiter::WillProcessEvent(const PlatformEvent& event) {
+ if (event_matcher_.Run(event)) {
+ base::MessageLoop::current()->PostTask(FROM_HERE, success_callback_);
+ delete this;
+ }
+}
+
+void PlatformEventWaiter::DidProcessEvent(const PlatformEvent& event) {
+}
+
+// static
+PlatformEventWaiter* PlatformEventWaiter::Create(
+ const base::Closure& success_callback,
+ const PlatformEventMatcher& event_matcher) {
+ return new PlatformEventWaiter(success_callback, event_matcher);
+}
+
+} // namespace ui
diff --git a/ui/events/test/platform_event_waiter.h b/ui/events/test/platform_event_waiter.h
new file mode 100644
index 0000000..259662c
--- /dev/null
+++ b/ui/events/test/platform_event_waiter.h
@@ -0,0 +1,37 @@
+// 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_EVENTS_TEST_PLATFORM_EVENT_WAITER_H_
+#define UI_EVENTS_TEST_PLATFORM_EVENT_WAITER_H_
+
+#include "base/callback.h"
+#include "ui/events/platform/platform_event_observer.h"
+
+namespace ui {
+
+class PlatformEventWaiter : public PlatformEventObserver {
+ public:
+ typedef base::Callback<bool(const PlatformEvent&)> PlatformEventMatcher;
+
+ static PlatformEventWaiter* Create(const base::Closure& success_callback,
+ const PlatformEventMatcher& event_matcher);
+
+ private:
+ PlatformEventWaiter(const base::Closure& success_callback,
+ const PlatformEventMatcher& event_matcher);
+ virtual ~PlatformEventWaiter();
+
+ // PlatformEventObserver:
+ virtual void WillProcessEvent(const PlatformEvent& event) OVERRIDE;
+ virtual void DidProcessEvent(const PlatformEvent& event) OVERRIDE;
+
+ base::Closure success_callback_;
+ PlatformEventMatcher event_matcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(PlatformEventWaiter);
+};
+
+} // namespace ui
+
+#endif // UI_EVENTS_TEST_PLATFORM_EVENT_WAITER_H_
diff --git a/ui/views/test/ui_controls_factory_desktop_aurax11.cc b/ui/views/test/ui_controls_factory_desktop_aurax11.cc
index 416169d..a846799 100644
--- a/ui/views/test/ui_controls_factory_desktop_aurax11.cc
+++ b/ui/views/test/ui_controls_factory_desktop_aurax11.cc
@@ -10,6 +10,7 @@
#undef RootWindow
#endif
+#include "base/bind.h"
#include "base/logging.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
@@ -19,6 +20,7 @@
#include "ui/base/x/x11_util.h"
#include "ui/compositor/dip_util.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
+#include "ui/events/test/platform_event_waiter.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
namespace views {
@@ -36,40 +38,6 @@ using ui_controls::UP;
// Mask of the buttons currently down.
unsigned button_down_mask = 0;
-// Event waiter executes the specified closure|when a matching event
-// is found.
-// TODO(oshima): Move this to base.
-class EventWaiter : public base::MessageLoopForUI::Observer {
- public:
- typedef bool (*EventWaiterMatcher)(const base::NativeEvent& event);
-
- EventWaiter(const base::Closure& closure, EventWaiterMatcher matcher)
- : closure_(closure),
- matcher_(matcher) {
- base::MessageLoopForUI::current()->AddObserver(this);
- }
-
- virtual ~EventWaiter() {
- base::MessageLoopForUI::current()->RemoveObserver(this);
- }
-
- // MessageLoop::Observer implementation:
- virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE {
- if ((*matcher_)(event)) {
- base::MessageLoop::current()->PostTask(FROM_HERE, closure_);
- delete this;
- }
- }
-
- virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE {
- }
-
- private:
- base::Closure closure_;
- EventWaiterMatcher matcher_;
- DISALLOW_COPY_AND_ASSIGN(EventWaiter);
-};
-
// Returns atom that indidates that the XEvent is marker event.
Atom MarkerEventAtom() {
return XInternAtom(gfx::GetXDisplay(), "marker_event", False);
@@ -258,7 +226,7 @@ class UIControlsDesktopX11 : public UIControlsAura {
}
marker_event->xclient.message_type = MarkerEventAtom();
XSendEvent(x_display_, x_window_, False, 0, marker_event);
- new EventWaiter(closure, &Matcher);
+ ui::PlatformEventWaiter::Create(closure, base::Bind(&Matcher));
}
private:
aura::Window* RootWindowForPoint(const gfx::Point& point) {