summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 05:52:20 +0000
committertapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 05:53:42 +0000
commit1f0ece91df08a1e162fd8a94bf819233b6d87eb2 (patch)
treef71dc606bc51eeefee449784d17eaa41daa1ddc8
parent59835a5d6d88b30a7cf6dee19ea2b9d03337c903 (diff)
downloadchromium_src-1f0ece91df08a1e162fd8a94bf819233b6d87eb2.zip
chromium_src-1f0ece91df08a1e162fd8a94bf819233b6d87eb2.tar.gz
chromium_src-1f0ece91df08a1e162fd8a94bf819233b6d87eb2.tar.bz2
Fix events_test_support layering violation, missing dependencies
EventGenerator currently depends on a backreference for the EventGeneratorDelegate factory function, which it can get away with in gyp because events_test_support is statically linked. This CL solves the layering violation by requiring TestHelper and TestBase classes that require the event generator to initialize a default delegate, similar to how ViewsDelegate solves a similar layering problem. It was tested by temporarily making events_test_support a component library, which exposed some missing dependencies. With this, events_unittests links properly with GN, with sources matching gyp. BUG=399106 R=brettw@chromium.org,sadrul@chromium.org,oshima@chromium.org TBR=sky@chromium.org Review URL: https://codereview.chromium.org/429803005 Cr-Commit-Position: refs/heads/master@{#288663} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288663 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/test/ash_test_helper.cc2
-rw-r--r--athena/test/athena_test_base.cc2
-rw-r--r--content/public/test/browser_test_base.cc6
-rw-r--r--ui/aura/test/aura_test_helper.cc2
-rw-r--r--ui/aura/test/event_generator_delegate_aura.cc46
-rw-r--r--ui/aura/test/event_generator_delegate_aura.h2
-rw-r--r--ui/events/BUILD.gn13
-rw-r--r--ui/events/events.gyp27
-rw-r--r--ui/events/test/event_generator.cc58
-rw-r--r--ui/events/test/event_generator.h21
-rw-r--r--ui/ui_unittests.gyp2
-rw-r--r--ui/views/test/event_generator_delegate_mac.h16
-rw-r--r--ui/views/test/event_generator_delegate_mac.mm59
-rw-r--r--ui/views/test/views_test_helper_mac.mm2
-rw-r--r--ui/views/views.gyp1
-rw-r--r--ui/wm/BUILD.gn2
-rw-r--r--ui/wm/wm.gyp2
17 files changed, 187 insertions, 76 deletions
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index ceb2910..b9f8ece 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -19,6 +19,7 @@
#include "ui/aura/env.h"
#include "ui/aura/input_state_lookup.h"
#include "ui/aura/test/env_test_helper.h"
+#include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/base/ime/input_method_initializer.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/context_factories_for_test.h"
@@ -51,6 +52,7 @@ AshTestHelper::AshTestHelper(base::MessageLoopForUI* message_loop)
#if defined(USE_X11)
aura::test::SetUseOverrideRedirectWindowByDefault(true);
#endif
+ aura::test::InitializeAuraEventGeneratorDelegate();
}
AshTestHelper::~AshTestHelper() {
diff --git a/athena/test/athena_test_base.cc b/athena/test/athena_test_base.cc
index a8ee6d3..8ddc437 100644
--- a/athena/test/athena_test_base.cc
+++ b/athena/test/athena_test_base.cc
@@ -5,6 +5,7 @@
#include "athena/test/athena_test_base.h"
#include "athena/test/athena_test_helper.h"
+#include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/compositor/test/context_factories_for_test.h"
#if defined(USE_X11)
@@ -38,6 +39,7 @@ void AthenaTestBase::SetUp() {
#if defined(USE_X11)
aura::test::SetUseOverrideRedirectWindowByDefault(true);
#endif
+ aura::test::InitializeAuraEventGeneratorDelegate();
helper_->SetUp(context_factory);
}
diff --git a/content/public/test/browser_test_base.cc b/content/public/test/browser_test_base.cc
index 3493242..e31d937 100644
--- a/content/public/test/browser_test_base.cc
+++ b/content/public/test/browser_test_base.cc
@@ -42,6 +42,7 @@
#if defined(USE_AURA)
#include "content/browser/compositor/image_transport_factory.h"
+#include "ui/aura/test/event_generator_delegate_aura.h"
#if defined(USE_X11)
#include "ui/aura/window_tree_host_x11.h"
#endif
@@ -132,9 +133,12 @@ BrowserTestBase::BrowserTestBase()
base::mac::SetOverrideAmIBundled(true);
#endif
-#if defined(USE_AURA) && defined(USE_X11)
+#if defined(USE_AURA)
+#if defined(USE_X11)
aura::test::SetUseOverrideRedirectWindowByDefault(true);
#endif
+ aura::test::InitializeAuraEventGeneratorDelegate();
+#endif
#if defined(OS_POSIX)
handle_sigterm_ = true;
diff --git a/ui/aura/test/aura_test_helper.cc b/ui/aura/test/aura_test_helper.cc
index 7beca60..836cf03 100644
--- a/ui/aura/test/aura_test_helper.cc
+++ b/ui/aura/test/aura_test_helper.cc
@@ -12,6 +12,7 @@
#include "ui/aura/env.h"
#include "ui/aura/input_state_lookup.h"
#include "ui/aura/test/env_test_helper.h"
+#include "ui/aura/test/event_generator_delegate_aura.h"
#include "ui/aura/test/test_focus_client.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_window_tree_client.h"
@@ -43,6 +44,7 @@ AuraTestHelper::AuraTestHelper(base::MessageLoopForUI* message_loop)
#if defined(USE_X11)
test::SetUseOverrideRedirectWindowByDefault(true);
#endif
+ InitializeAuraEventGeneratorDelegate();
}
AuraTestHelper::~AuraTestHelper() {
diff --git a/ui/aura/test/event_generator_delegate_aura.cc b/ui/aura/test/event_generator_delegate_aura.cc
index a32ab5b..a4041a3 100644
--- a/ui/aura/test/event_generator_delegate_aura.cc
+++ b/ui/aura/test/event_generator_delegate_aura.cc
@@ -4,6 +4,7 @@
#include "ui/aura/test/event_generator_delegate_aura.h"
+#include "base/memory/singleton.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
@@ -14,11 +15,18 @@ namespace {
class DefaultEventGeneratorDelegate : public EventGeneratorDelegateAura {
public:
- explicit DefaultEventGeneratorDelegate(Window* root_window)
- : root_window_(root_window) {}
- virtual ~DefaultEventGeneratorDelegate() {}
+ static DefaultEventGeneratorDelegate* GetInstance() {
+ return Singleton<DefaultEventGeneratorDelegate>::get();
+ }
+
+ // EventGeneratorDelegate:
+ virtual void SetContext(ui::test::EventGenerator* owner,
+ gfx::NativeWindow root_window,
+ gfx::NativeWindow window) OVERRIDE {
+ root_window_ = root_window;
+ }
- // EventGeneratorDelegateAura overrides:
+ // EventGeneratorDelegateAura:
virtual WindowTreeHost* GetHostAt(const gfx::Point& point) const OVERRIDE {
return root_window_->GetHost();
}
@@ -29,6 +37,18 @@ class DefaultEventGeneratorDelegate : public EventGeneratorDelegateAura {
}
private:
+ friend struct DefaultSingletonTraits<DefaultEventGeneratorDelegate>;
+
+ DefaultEventGeneratorDelegate() : root_window_(NULL) {
+ DCHECK(!ui::test::EventGenerator::default_delegate);
+ ui::test::EventGenerator::default_delegate = this;
+ }
+
+ virtual ~DefaultEventGeneratorDelegate() {
+ DCHECK_EQ(this, ui::test::EventGenerator::default_delegate);
+ ui::test::EventGenerator::default_delegate = NULL;
+ }
+
Window* root_window_;
DISALLOW_COPY_AND_ASSIGN(DefaultEventGeneratorDelegate);
@@ -40,6 +60,10 @@ const Window* WindowFromTarget(const ui::EventTarget* event_target) {
} // namespace
+void InitializeAuraEventGeneratorDelegate() {
+ DefaultEventGeneratorDelegate::GetInstance();
+}
+
EventGeneratorDelegateAura::EventGeneratorDelegateAura() {
}
@@ -102,17 +126,3 @@ void EventGeneratorDelegateAura::ConvertPointFromHost(
} // namespace test
} // namespace aura
-
-namespace ui {
-namespace test {
-
-// static
-EventGeneratorDelegate* EventGenerator::CreateDefaultPlatformDelegate(
- EventGenerator* owner,
- gfx::NativeWindow root_window,
- gfx::NativeWindow window) {
- return new aura::test::DefaultEventGeneratorDelegate(root_window);
-}
-
-} // namespace test
-} // namespace ui
diff --git a/ui/aura/test/event_generator_delegate_aura.h b/ui/aura/test/event_generator_delegate_aura.h
index 5850789..5d37538 100644
--- a/ui/aura/test/event_generator_delegate_aura.h
+++ b/ui/aura/test/event_generator_delegate_aura.h
@@ -17,6 +17,8 @@ class ScreenPositionClient;
namespace test {
+void InitializeAuraEventGeneratorDelegate();
+
// Implementation of ui::test::EventGeneratorDelegate for Aura.
class EventGeneratorDelegateAura : public ui::test::EventGeneratorDelegate {
public:
diff --git a/ui/events/BUILD.gn b/ui/events/BUILD.gn
index 4de4301..7a868b1 100644
--- a/ui/events/BUILD.gn
+++ b/ui/events/BUILD.gn
@@ -218,6 +218,8 @@ source_set("test_support") {
sources = [
"test/cocoa_test_event_utils.h",
"test/cocoa_test_event_utils.mm",
+ "test/event_generator.cc",
+ "test/event_generator.h",
"test/events_test_utils.cc",
"test/events_test_utils.h",
"test/events_test_utils_x11.cc",
@@ -235,9 +237,12 @@ source_set("test_support") {
]
deps = [
+ "//base",
"//skia",
+ "//ui/gfx/geometry",
":events_base",
":events",
+ ":gesture_detection",
]
if (is_ios) {
@@ -247,9 +252,7 @@ source_set("test_support") {
]
}
- if (use_x11) {
- configs += [ "//build/config/linux:x11" ]
- } else {
+ if (!use_x11) {
sources -= [
"test/events_test_utils_x11.cc",
"test/events_test_utils_x11.h",
@@ -278,7 +281,9 @@ test("events_unittests") {
"x/events_x_unittest.cc",
]
- if (!use_x11) {
+ if (use_x11) {
+ configs += [ "//build/config/linux:x11" ]
+ } else {
sources -= [
"x/events_x_unittest.cc",
]
diff --git a/ui/events/events.gyp b/ui/events/events.gyp
index ceeddfb..cb4c0ca 100644
--- a/ui/events/events.gyp
+++ b/ui/events/events.gyp
@@ -149,6 +149,11 @@
'linux/text_edit_key_bindings_delegate_auralinux.h',
],
'conditions': [
+ ['use_x11==1', {
+ 'dependencies': [
+ '../../build/linux/system.gyp:x11',
+ ],
+ }],
['use_aura==0', {
'sources!': [
'gestures/gesture_point.cc',
@@ -245,9 +250,12 @@
'target_name': 'events_test_support',
'type': 'static_library',
'dependencies': [
+ '<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/skia/skia.gyp:skia',
+ '../gfx/gfx.gyp:gfx_geometry',
'events',
'events_base',
+ 'gesture_detection',
'platform/events_platform.gyp:events_platform',
],
'sources': [
@@ -272,23 +280,10 @@
'test/test_event_target.h',
],
'conditions': [
- ['use_x11==1', {
- 'dependencies': [
- '../../build/linux/system.gyp:x11',
- '../gfx/x/gfx_x11.gyp:gfx_x11',
- ],
- }],
['OS=="ios"', {
# The cocoa files don't apply to iOS.
'sources/': [['exclude', 'cocoa']],
}],
- ['OS == "android"', {
- 'sources!': [
- # Event generator not yet ported to Android.
- 'test/event_generator.cc',
- 'test/event_generator.h',
- ],
- }],
],
},
{
@@ -335,6 +330,12 @@
'x/events_x_unittest.cc',
],
'conditions': [
+ ['use_x11==1', {
+ 'dependencies': [
+ '../../build/linux/system.gyp:x11',
+ '../gfx/x/gfx_x11.gyp:gfx_x11',
+ ],
+ }],
['use_ozone==1', {
'sources': [
'ozone/evdev/key_event_converter_evdev_unittest.cc',
diff --git a/ui/events/test/event_generator.cc b/ui/events/test/event_generator.cc
index b4772e5..b17c801 100644
--- a/ui/events/test/event_generator.cc
+++ b/ui/events/test/event_generator.cc
@@ -58,44 +58,46 @@ const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON;
} // namespace
+EventGeneratorDelegate* EventGenerator::default_delegate = NULL;
+
EventGenerator::EventGenerator(gfx::NativeWindow root_window)
- : delegate_(CreateDefaultPlatformDelegate(this, root_window, NULL)),
- current_target_(delegate_->GetTargetAt(current_location_)),
+ : current_target_(NULL),
flags_(0),
grab_(false),
async_(false),
tick_clock_(new base::DefaultTickClock()) {
+ Init(root_window, NULL);
}
EventGenerator::EventGenerator(gfx::NativeWindow root_window,
const gfx::Point& point)
- : delegate_(CreateDefaultPlatformDelegate(this, root_window, NULL)),
- current_location_(point),
- current_target_(delegate_->GetTargetAt(current_location_)),
+ : current_location_(point),
+ current_target_(NULL),
flags_(0),
grab_(false),
async_(false),
tick_clock_(new base::DefaultTickClock()) {
+ Init(root_window, NULL);
}
EventGenerator::EventGenerator(gfx::NativeWindow root_window,
gfx::NativeWindow window)
- : delegate_(CreateDefaultPlatformDelegate(this, root_window, window)),
- current_location_(delegate_->CenterOfWindow(window)),
- current_target_(delegate_->GetTargetAt(current_location_)),
+ : current_target_(NULL),
flags_(0),
grab_(false),
async_(false),
tick_clock_(new base::DefaultTickClock()) {
+ Init(root_window, window);
}
EventGenerator::EventGenerator(EventGeneratorDelegate* delegate)
: delegate_(delegate),
- current_target_(delegate_->GetTargetAt(current_location_)),
+ current_target_(NULL),
flags_(0),
grab_(false),
async_(false),
tick_clock_(new base::DefaultTickClock()) {
+ Init(NULL, NULL);
}
EventGenerator::~EventGenerator() {
@@ -103,6 +105,7 @@ EventGenerator::~EventGenerator() {
i != pending_events_.end(); ++i)
delete *i;
pending_events_.clear();
+ delegate()->SetContext(NULL, NULL, NULL);
}
void EventGenerator::PressLeftButton() {
@@ -142,7 +145,7 @@ void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) {
void EventGenerator::SendMouseExit() {
gfx::Point exit_location(current_location_);
- delegate_->ConvertPointToTarget(current_target_, &exit_location);
+ delegate()->ConvertPointToTarget(current_target_, &exit_location);
ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location,
flags_, 0);
Dispatch(&mouseev);
@@ -155,7 +158,7 @@ void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) {
Dispatch(&mouseev);
current_location_ = point_in_host;
- delegate_->ConvertPointFromHost(current_target_, &current_location_);
+ delegate()->ConvertPointFromHost(current_target_, &current_location_);
}
void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
@@ -171,7 +174,7 @@ void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step);
if (!grab_)
UpdateCurrentDispatcher(move_point);
- delegate_->ConvertPointToTarget(current_target_, &move_point);
+ delegate()->ConvertPointToTarget(current_target_, &move_point);
ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0);
Dispatch(&mouseev);
}
@@ -181,7 +184,7 @@ void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
void EventGenerator::MoveMouseRelativeTo(const EventTarget* window,
const gfx::Point& point_in_parent) {
gfx::Point point(point_in_parent);
- delegate_->ConvertPointFromTarget(window, &point);
+ delegate()->ConvertPointFromTarget(window, &point);
MoveMouseTo(point);
}
@@ -494,6 +497,14 @@ base::TimeDelta EventGenerator::Now() {
tick_clock_->NowTicks().ToInternalValue());
}
+void EventGenerator::Init(gfx::NativeWindow root_window,
+ gfx::NativeWindow window_context) {
+ delegate()->SetContext(this, root_window, window_context);
+ if (window_context)
+ current_location_ = delegate()->CenterOfWindow(window_context);
+ current_target_ = delegate()->GetTargetAt(current_location_);
+}
+
void EventGenerator::DispatchKeyEvent(bool is_press,
ui::KeyboardCode key_code,
int flags) {
@@ -526,7 +537,7 @@ void EventGenerator::DispatchKeyEvent(bool is_press,
}
void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) {
- current_target_ = delegate_->GetTargetAt(point);
+ current_target_ = delegate()->GetTargetAt(point);
}
void EventGenerator::PressButton(int flag) {
@@ -553,12 +564,12 @@ void EventGenerator::ReleaseButton(int flag) {
gfx::Point EventGenerator::GetLocationInCurrentRoot() const {
gfx::Point p(current_location_);
- delegate_->ConvertPointToTarget(current_target_, &p);
+ delegate()->ConvertPointToTarget(current_target_, &p);
return p;
}
gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const {
- return delegate_->CenterOfTarget(window);
+ return delegate()->CenterOfTarget(window);
}
void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
@@ -585,7 +596,7 @@ void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
}
pending_events_.push_back(pending_event);
} else {
- ui::EventSource* event_source = delegate_->GetEventSource(current_target_);
+ ui::EventSource* event_source = delegate()->GetEventSource(current_target_);
ui::EventSourceTestApi event_source_test(event_source);
ui::EventDispatchDetails details =
event_source_test.SendEventToProcessor(event);
@@ -607,5 +618,18 @@ void EventGenerator::DispatchNextPendingEvent() {
}
}
+const EventGeneratorDelegate* EventGenerator::delegate() const {
+ if (delegate_)
+ return delegate_.get();
+
+ DCHECK(default_delegate);
+ return default_delegate;
+}
+
+EventGeneratorDelegate* EventGenerator::delegate() {
+ return const_cast<EventGeneratorDelegate*>(
+ const_cast<const EventGenerator*>(this)->delegate());
+}
+
} // namespace test
} // namespace ui
diff --git a/ui/events/test/event_generator.h b/ui/events/test/event_generator.h
index 67360c4..bc243b9 100644
--- a/ui/events/test/event_generator.h
+++ b/ui/events/test/event_generator.h
@@ -36,12 +36,20 @@ namespace test {
typedef base::Callback<void(EventType, const gfx::Vector2dF&)>
ScrollStepCallback;
+class EventGenerator;
+
// A delegate interface for EventGenerator to abstract platform-specific event
// targeting and coordinate conversion.
class EventGeneratorDelegate {
public:
virtual ~EventGeneratorDelegate() {}
+ // Set the context of the delegate, whilst it is being used by an active
+ // EventGenerator.
+ virtual void SetContext(EventGenerator* owner,
+ gfx::NativeWindow root_window,
+ gfx::NativeWindow window) {}
+
// The ui::EventTarget at the given |location|.
virtual EventTarget* GetTargetAt(const gfx::Point& location) = 0;
@@ -335,12 +343,12 @@ class EventGenerator {
// Get the current time from the tick clock.
base::TimeDelta Now();
+ // Default delegate set by a platform-specific GeneratorDelegate singleton.
+ static EventGeneratorDelegate* default_delegate;
+
private:
- // Implemented per-platform to create the default EventGeneratorDelegate.
- static EventGeneratorDelegate* CreateDefaultPlatformDelegate(
- EventGenerator* owner,
- gfx::NativeWindow root_window,
- gfx::NativeWindow window);
+ // Set up the test context using the delegate.
+ void Init(gfx::NativeWindow root_window, gfx::NativeWindow window_context);
// Dispatch a key event to the WindowEventDispatcher.
void DispatchKeyEvent(bool is_press, KeyboardCode key_code, int flags);
@@ -355,6 +363,9 @@ class EventGenerator {
void DispatchNextPendingEvent();
void DoDispatchEvent(Event* event, bool async);
+ const EventGeneratorDelegate* delegate() const;
+ EventGeneratorDelegate* delegate();
+
scoped_ptr<EventGeneratorDelegate> delegate_;
gfx::Point current_location_;
EventTarget* current_target_;
diff --git a/ui/ui_unittests.gyp b/ui/ui_unittests.gyp
index ff09911..938b4d6 100644
--- a/ui/ui_unittests.gyp
+++ b/ui/ui_unittests.gyp
@@ -160,8 +160,10 @@
}],
['use_x11==1', {
'dependencies': [
+ '../build/linux/system.gyp:x11',
'../tools/xdisplaycheck/xdisplaycheck.gyp:xdisplaycheck',
'events/platform/x11/x11_events_platform.gyp:x11_events_platform',
+ 'gfx/x/gfx_x11.gyp:gfx_x11',
],
}],
['OS!="win" or use_aura==0', {
diff --git a/ui/views/test/event_generator_delegate_mac.h b/ui/views/test/event_generator_delegate_mac.h
new file mode 100644
index 0000000..86239ba
--- /dev/null
+++ b/ui/views/test/event_generator_delegate_mac.h
@@ -0,0 +1,16 @@
+// 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_VIEWS_TEST_EVENT_GENERATOR_DELEGATE_MAC_H_
+#define UI_VIEWS_TEST_EVENT_GENERATOR_DELEGATE_MAC_H_
+
+namespace views {
+namespace test {
+
+void InitializeMacEventGeneratorDelegate();
+
+} // namespace test
+} // namespace views
+
+#endif // UI_VIEWS_TEST_EVENT_GENERATOR_DELEGATE_MAC_H_
diff --git a/ui/views/test/event_generator_delegate_mac.mm b/ui/views/test/event_generator_delegate_mac.mm
index 69fd88f..d0e351a 100644
--- a/ui/views/test/event_generator_delegate_mac.mm
+++ b/ui/views/test/event_generator_delegate_mac.mm
@@ -4,6 +4,7 @@
#import <Cocoa/Cocoa.h>
+#include "base/memory/singleton.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_target.h"
#include "ui/events/event_target_iterator.h"
@@ -237,8 +238,9 @@ class EventGeneratorDelegateMac : public ui::EventTarget,
public ui::EventTargeter,
public ui::test::EventGeneratorDelegate {
public:
- EventGeneratorDelegateMac(ui::test::EventGenerator* owner, NSWindow* window);
- virtual ~EventGeneratorDelegateMac() {}
+ static EventGeneratorDelegateMac* GetInstance() {
+ return Singleton<EventGeneratorDelegateMac>::get();
+ }
// Overridden from ui::EventTarget:
virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE { return true; }
@@ -263,6 +265,9 @@ class EventGeneratorDelegateMac : public ui::EventTarget,
}
// Overridden from ui::test::EventGeneratorDelegate:
+ virtual void SetContext(ui::test::EventGenerator* owner,
+ gfx::NativeWindow root_window,
+ gfx::NativeWindow window) OVERRIDE;
virtual ui::EventTarget* GetTargetAt(const gfx::Point& location) OVERRIDE {
return this;
}
@@ -281,20 +286,28 @@ class EventGeneratorDelegateMac : public ui::EventTarget,
gfx::Point* point) const OVERRIDE {}
private:
+ friend struct DefaultSingletonTraits<EventGeneratorDelegateMac>;
+
+ EventGeneratorDelegateMac();
+ virtual ~EventGeneratorDelegateMac();
+
ui::test::EventGenerator* owner_;
NSWindow* window_;
- ScopedClassSwizzler swizzle_pressed_;
+ scoped_ptr<ScopedClassSwizzler> swizzle_pressed_;
DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateMac);
};
-EventGeneratorDelegateMac::EventGeneratorDelegateMac(
- ui::test::EventGenerator* owner, NSWindow* window)
- : owner_(owner),
- window_(window),
- swizzle_pressed_([NSEvent class],
- [NSEventDonor class],
- @selector(pressedMouseButtons)) {
+EventGeneratorDelegateMac::EventGeneratorDelegateMac()
+ : owner_(NULL),
+ window_(NULL) {
+ DCHECK(!ui::test::EventGenerator::default_delegate);
+ ui::test::EventGenerator::default_delegate = this;
+}
+
+EventGeneratorDelegateMac::~EventGeneratorDelegateMac() {
+ DCHECK_EQ(this, ui::test::EventGenerator::default_delegate);
+ ui::test::EventGenerator::default_delegate = NULL;
}
scoped_ptr<ui::EventTargetIterator>
@@ -312,6 +325,20 @@ void EventGeneratorDelegateMac::OnMouseEvent(ui::MouseEvent* event) {
event->changed_button_flags());
}
+void EventGeneratorDelegateMac::SetContext(ui::test::EventGenerator* owner,
+ gfx::NativeWindow root_window,
+ gfx::NativeWindow window) {
+ swizzle_pressed_.reset();
+ owner_ = owner;
+ window_ = window;
+ if (owner_) {
+ swizzle_pressed_.reset(new ScopedClassSwizzler(
+ [NSEvent class],
+ [NSEventDonor class],
+ @selector(pressedMouseButtons)));
+ }
+}
+
gfx::Point EventGeneratorDelegateMac::CenterOfTarget(
const ui::EventTarget* target) const {
DCHECK_EQ(target, this);
@@ -326,16 +353,12 @@ gfx::Point EventGeneratorDelegateMac::CenterOfWindow(
} // namespace
-namespace ui {
+namespace views {
namespace test {
-// static
-EventGeneratorDelegate* EventGenerator::CreateDefaultPlatformDelegate(
- EventGenerator* owner,
- gfx::NativeWindow root_window,
- gfx::NativeWindow window) {
- return new EventGeneratorDelegateMac(owner, window);
+void InitializeMacEventGeneratorDelegate() {
+ EventGeneratorDelegateMac::GetInstance();
}
} // namespace test
-} // namespace ui
+} // namespace views
diff --git a/ui/views/test/views_test_helper_mac.mm b/ui/views/test/views_test_helper_mac.mm
index b0eb85a..a50f4aa 100644
--- a/ui/views/test/views_test_helper_mac.mm
+++ b/ui/views/test/views_test_helper_mac.mm
@@ -5,6 +5,7 @@
#include "ui/views/test/views_test_helper_mac.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
+#include "ui/views/test/event_generator_delegate_mac.h"
namespace views {
@@ -17,6 +18,7 @@ ViewsTestHelper* ViewsTestHelper::Create(base::MessageLoopForUI* message_loop,
ViewsTestHelperMac::ViewsTestHelperMac()
: zero_duration_mode_(new ui::ScopedAnimationDurationScaleMode(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)) {
+ test::InitializeMacEventGeneratorDelegate();
}
ViewsTestHelperMac::~ViewsTestHelperMac() {
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 4376618..9d1bf02 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -448,6 +448,7 @@
'test/desktop_test_views_delegate.h',
'test/desktop_test_views_delegate_aura.cc',
'test/desktop_test_views_delegate_mac.mm',
+ 'test/event_generator_delegate_mac.h',
'test/event_generator_delegate_mac.mm',
'test/focus_manager_test.h',
'test/focus_manager_test.cc',
diff --git a/ui/wm/BUILD.gn b/ui/wm/BUILD.gn
index 23b7792..def5803 100644
--- a/ui/wm/BUILD.gn
+++ b/ui/wm/BUILD.gn
@@ -80,6 +80,7 @@ component("wm") {
"//ui/compositor",
"//ui/events",
"//ui/events:events_base",
+ "//ui/events/platform",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/resources",
@@ -135,6 +136,7 @@ test("wm_unittests") {
"//ui/compositor",
"//ui/events",
"//ui/events:events_base",
+ "//ui/events/platform",
"//ui/gfx",
"//ui/gfx/geometry",
]
diff --git a/ui/wm/wm.gyp b/ui/wm/wm.gyp
index cfdc937..b743f76 100644
--- a/ui/wm/wm.gyp
+++ b/ui/wm/wm.gyp
@@ -18,6 +18,7 @@
'../compositor/compositor.gyp:compositor',
'../events/events.gyp:events',
'../events/events.gyp:events_base',
+ '../events/platform/events_platform.gyp:events_platform',
'../gfx/gfx.gyp:gfx_geometry',
'../gfx/gfx.gyp:gfx',
'../resources/ui_resources.gyp:ui_resources',
@@ -125,6 +126,7 @@
'../compositor/compositor.gyp:compositor',
'../events/events.gyp:events',
'../events/events.gyp:events_base',
+ '../events/platform/events_platform.gyp:events_platform',
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
'wm',