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

Unified Diff: ui/events/event_processor_unittest.cc

Issue 98353008: events: Update EventTargeter to operate on the EventTarget that owns the targeter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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
« no previous file with comments | « no previous file | ui/events/event_targeter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/event_processor_unittest.cc
diff --git a/ui/events/event_processor_unittest.cc b/ui/events/event_processor_unittest.cc
index 6d8edf5a7b4fc30c738f962c8f2617105b1dea50..15118194046216fc5587acab64b25bca7d3dad52 100644
--- a/ui/events/event_processor_unittest.cc
+++ b/ui/events/event_processor_unittest.cc
@@ -142,9 +142,11 @@ TEST_F(EventProcessorTest, Bounds) {
// Now install a targeter on the parent that looks at the bounds and makes
// sure the event reaches the target only if the location of the event within
// the bounds of the target.
+ MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(1, 1), gfx::Point(1, 1), EF_NONE,
+ EF_NONE);
parent_r->SetEventTargeter(scoped_ptr<EventTargeter>(
new BoundsEventTargeter<BoundsTestTarget>()));
- DispatchEvent(&mouse);
+ DispatchEvent(&mouse2);
EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
EXPECT_TRUE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED));
EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED));
@@ -160,5 +162,42 @@ TEST_F(EventProcessorTest, Bounds) {
EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED));
}
+class IgnoreEventTargeter : public EventTargeter {
+ public:
+ IgnoreEventTargeter() {}
+ virtual ~IgnoreEventTargeter() {}
+
+ private:
+ // EventTargeter:
+ virtual bool SubtreeShouldBeExploredForEvent(
+ EventTarget* target, const LocatedEvent& event) OVERRIDE {
+ return false;
+ }
+};
+
+// Verifies that the EventTargeter installed on an EventTarget can dictate
+// whether the target itself can process an event.
+TEST_F(EventProcessorTest, TargeterChecksOwningEventTarget) {
+ scoped_ptr<TestEventTarget> child(new TestEventTarget());
+ root()->AddChild(child.Pass());
+
+ MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10),
+ EF_NONE, EF_NONE);
+ DispatchEvent(&mouse);
+ EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
+ EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
+ root()->child_at(0)->ResetReceivedEvents();
+
+ // Install an even handler on |child| which always prevents the target from
+ // receiving event.
+ root()->child_at(0)->SetEventTargeter(
+ scoped_ptr<EventTargeter>(new IgnoreEventTargeter()));
+ MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10),
+ EF_NONE, EF_NONE);
+ DispatchEvent(&mouse2);
+ EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
+ EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
+}
+
} // namespace test
} // namespace ui
« no previous file with comments | « no previous file | ui/events/event_targeter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698