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

Side by Side Diff: ui/events/event_processor_unittest.cc

Issue 988693005: Chromium roll (https://codereview.chromium.org/976353002) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fixed bad android build patch Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « ui/events/event_dispatcher_unittest.cc ('k') | ui/events/event_rewriter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/event_targeter.h" 9 #include "ui/events/event_targeter.h"
10 #include "ui/events/test/events_test_utils.h" 10 #include "ui/events/test/events_test_utils.h"
11 #include "ui/events/test/test_event_handler.h" 11 #include "ui/events/test/test_event_handler.h"
12 #include "ui/events/test/test_event_processor.h" 12 #include "ui/events/test/test_event_processor.h"
13 #include "ui/events/test/test_event_target.h" 13 #include "ui/events/test/test_event_target.h"
14 14
15 typedef std::vector<std::string> HandlerSequenceRecorder; 15 typedef std::vector<std::string> HandlerSequenceRecorder;
16 16
17 namespace ui { 17 namespace ui {
18 namespace test { 18 namespace test {
19 19
20 class EventProcessorTest : public testing::Test { 20 class EventProcessorTest : public testing::Test {
21 public: 21 public:
22 EventProcessorTest() {} 22 EventProcessorTest() {}
23 virtual ~EventProcessorTest() {} 23 ~EventProcessorTest() override {}
24 24
25 // testing::Test: 25 // testing::Test:
26 virtual void SetUp() override { 26 void SetUp() override {
27 processor_.SetRoot(scoped_ptr<EventTarget>(new TestEventTarget())); 27 processor_.SetRoot(scoped_ptr<EventTarget>(new TestEventTarget()));
28 processor_.Reset(); 28 processor_.Reset();
29 root()->SetEventTargeter(make_scoped_ptr(new EventTargeter())); 29 root()->SetEventTargeter(make_scoped_ptr(new EventTargeter()));
30 } 30 }
31 31
32 TestEventTarget* root() { 32 TestEventTarget* root() {
33 return static_cast<TestEventTarget*>(processor_.GetRootTarget()); 33 return static_cast<TestEventTarget*>(processor_.GetRootTarget());
34 } 34 }
35 35
36 TestEventProcessor* processor() { 36 TestEventProcessor* processor() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 virtual bool SubtreeShouldBeExploredForEvent( 71 virtual bool SubtreeShouldBeExploredForEvent(
72 EventTarget* target, const LocatedEvent& event) override { 72 EventTarget* target, const LocatedEvent& event) override {
73 T* t = static_cast<T*>(target); 73 T* t = static_cast<T*>(target);
74 return (t->bounds().Contains(event.location())); 74 return (t->bounds().Contains(event.location()));
75 } 75 }
76 }; 76 };
77 77
78 class BoundsTestTarget : public TestEventTarget { 78 class BoundsTestTarget : public TestEventTarget {
79 public: 79 public:
80 BoundsTestTarget() {} 80 BoundsTestTarget() {}
81 virtual ~BoundsTestTarget() {} 81 ~BoundsTestTarget() override {}
82 82
83 void set_bounds(gfx::Rect rect) { bounds_ = rect; } 83 void set_bounds(gfx::Rect rect) { bounds_ = rect; }
84 gfx::Rect bounds() const { return bounds_; } 84 gfx::Rect bounds() const { return bounds_; }
85 85
86 static void ConvertPointToTarget(BoundsTestTarget* source, 86 static void ConvertPointToTarget(BoundsTestTarget* source,
87 BoundsTestTarget* target, 87 BoundsTestTarget* target,
88 gfx::Point* location) { 88 gfx::Point* location) {
89 gfx::Vector2d vector; 89 gfx::Vector2d vector;
90 if (source->Contains(target)) { 90 if (source->Contains(target)) {
91 for (; target && target != source; 91 for (; target && target != source;
92 target = static_cast<BoundsTestTarget*>(target->parent())) { 92 target = static_cast<BoundsTestTarget*>(target->parent())) {
93 vector += target->bounds().OffsetFromOrigin(); 93 vector += target->bounds().OffsetFromOrigin();
94 } 94 }
95 *location -= vector; 95 *location -= vector;
96 } else if (target->Contains(source)) { 96 } else if (target->Contains(source)) {
97 for (; source && source != target; 97 for (; source && source != target;
98 source = static_cast<BoundsTestTarget*>(source->parent())) { 98 source = static_cast<BoundsTestTarget*>(source->parent())) {
99 vector += source->bounds().OffsetFromOrigin(); 99 vector += source->bounds().OffsetFromOrigin();
100 } 100 }
101 *location += vector; 101 *location += vector;
102 } else { 102 } else {
103 NOTREACHED(); 103 NOTREACHED();
104 } 104 }
105 } 105 }
106 106
107 private: 107 private:
108 // EventTarget: 108 // EventTarget:
109 virtual void ConvertEventToTarget(EventTarget* target, 109 void ConvertEventToTarget(EventTarget* target,
110 LocatedEvent* event) override { 110 LocatedEvent* event) override {
111 event->ConvertLocationToTarget(this, 111 event->ConvertLocationToTarget(this,
112 static_cast<BoundsTestTarget*>(target)); 112 static_cast<BoundsTestTarget*>(target));
113 } 113 }
114 114
115 gfx::Rect bounds_; 115 gfx::Rect bounds_;
116 116
117 DISALLOW_COPY_AND_ASSIGN(BoundsTestTarget); 117 DISALLOW_COPY_AND_ASSIGN(BoundsTestTarget);
118 }; 118 };
119 119
120 TEST_F(EventProcessorTest, Bounds) { 120 TEST_F(EventProcessorTest, Bounds) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 175
176 // ReDispatchEventHandler is used to receive mouse events and forward them 176 // ReDispatchEventHandler is used to receive mouse events and forward them
177 // to a specified EventProcessor. Verifies that the event has the correct 177 // to a specified EventProcessor. Verifies that the event has the correct
178 // target and phase both before and after the nested event processing. Also 178 // target and phase both before and after the nested event processing. Also
179 // verifies that the location of the event remains the same after it has 179 // verifies that the location of the event remains the same after it has
180 // been processed by the second EventProcessor. 180 // been processed by the second EventProcessor.
181 class ReDispatchEventHandler : public TestEventHandler { 181 class ReDispatchEventHandler : public TestEventHandler {
182 public: 182 public:
183 ReDispatchEventHandler(EventProcessor* processor, EventTarget* target) 183 ReDispatchEventHandler(EventProcessor* processor, EventTarget* target)
184 : processor_(processor), expected_target_(target) {} 184 : processor_(processor), expected_target_(target) {}
185 virtual ~ReDispatchEventHandler() {} 185 ~ReDispatchEventHandler() override {}
186 186
187 // TestEventHandler: 187 // TestEventHandler:
188 virtual void OnMouseEvent(MouseEvent* event) override { 188 void OnMouseEvent(MouseEvent* event) override {
189 TestEventHandler::OnMouseEvent(event); 189 TestEventHandler::OnMouseEvent(event);
190 190
191 EXPECT_EQ(expected_target_, event->target()); 191 EXPECT_EQ(expected_target_, event->target());
192 EXPECT_EQ(EP_TARGET, event->phase()); 192 EXPECT_EQ(EP_TARGET, event->phase());
193 193
194 gfx::Point location(event->location()); 194 gfx::Point location(event->location());
195 EventDispatchDetails details = processor_->OnEventFromSource(event); 195 EventDispatchDetails details = processor_->OnEventFromSource(event);
196 EXPECT_FALSE(details.dispatcher_destroyed); 196 EXPECT_FALSE(details.dispatcher_destroyed);
197 EXPECT_FALSE(details.target_destroyed); 197 EXPECT_FALSE(details.target_destroyed);
198 198
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 315 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
316 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); 316 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
317 EXPECT_TRUE(mouse2.handled()); 317 EXPECT_TRUE(mouse2.handled());
318 EXPECT_EQ(1, processor()->num_times_processing_started()); 318 EXPECT_EQ(1, processor()->num_times_processing_started());
319 EXPECT_EQ(1, processor()->num_times_processing_finished()); 319 EXPECT_EQ(1, processor()->num_times_processing_finished());
320 } 320 }
321 321
322 class IgnoreEventTargeter : public EventTargeter { 322 class IgnoreEventTargeter : public EventTargeter {
323 public: 323 public:
324 IgnoreEventTargeter() {} 324 IgnoreEventTargeter() {}
325 virtual ~IgnoreEventTargeter() {} 325 ~IgnoreEventTargeter() override {}
326 326
327 private: 327 private:
328 // EventTargeter: 328 // EventTargeter:
329 virtual bool SubtreeShouldBeExploredForEvent( 329 bool SubtreeShouldBeExploredForEvent(
330 EventTarget* target, const LocatedEvent& event) override { 330 EventTarget* target, const LocatedEvent& event) override {
331 return false; 331 return false;
332 } 332 }
333 }; 333 };
334 334
335 // Verifies that the EventTargeter installed on an EventTarget can dictate 335 // Verifies that the EventTargeter installed on an EventTarget can dictate
336 // whether the target itself can process an event. 336 // whether the target itself can process an event.
337 TEST_F(EventProcessorTest, TargeterChecksOwningEventTarget) { 337 TEST_F(EventProcessorTest, TargeterChecksOwningEventTarget) {
338 scoped_ptr<TestEventTarget> child(new TestEventTarget()); 338 scoped_ptr<TestEventTarget> child(new TestEventTarget());
339 root()->AddChild(child.Pass()); 339 root()->AddChild(child.Pass());
(...skipping 17 matching lines...) Expand all
357 } 357 }
358 358
359 // An EventTargeter which is used to allow a bubbling behaviour in event 359 // An EventTargeter which is used to allow a bubbling behaviour in event
360 // dispatch: if an event is not handled after being dispatched to its 360 // dispatch: if an event is not handled after being dispatched to its
361 // initial target, the event is dispatched to the next-best target as 361 // initial target, the event is dispatched to the next-best target as
362 // specified by FindNextBestTarget(). 362 // specified by FindNextBestTarget().
363 class BubblingEventTargeter : public EventTargeter { 363 class BubblingEventTargeter : public EventTargeter {
364 public: 364 public:
365 explicit BubblingEventTargeter(TestEventTarget* initial_target) 365 explicit BubblingEventTargeter(TestEventTarget* initial_target)
366 : initial_target_(initial_target) {} 366 : initial_target_(initial_target) {}
367 virtual ~BubblingEventTargeter() {} 367 ~BubblingEventTargeter() override {}
368 368
369 private: 369 private:
370 // EventTargeter: 370 // EventTargeter:
371 virtual EventTarget* FindTargetForEvent(EventTarget* root, 371 EventTarget* FindTargetForEvent(EventTarget* root,
372 Event* event) override { 372 Event* event) override {
373 return initial_target_; 373 return initial_target_;
374 } 374 }
375 375
376 virtual EventTarget* FindNextBestTarget(EventTarget* previous_target, 376 EventTarget* FindNextBestTarget(EventTarget* previous_target,
377 Event* event) override { 377 Event* event) override {
378 return previous_target->GetParentTarget(); 378 return previous_target->GetParentTarget();
379 } 379 }
380 380
381 TestEventTarget* initial_target_; 381 TestEventTarget* initial_target_;
382 382
383 DISALLOW_COPY_AND_ASSIGN(BubblingEventTargeter); 383 DISALLOW_COPY_AND_ASSIGN(BubblingEventTargeter);
384 }; 384 };
385 385
386 // Tests that unhandled events are correctly dispatched to the next-best 386 // Tests that unhandled events are correctly dispatched to the next-best
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 DispatchEvent(&mouse); 516 DispatchEvent(&mouse);
517 517
518 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", 518 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC",
519 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; 519 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" };
520 EXPECT_EQ(std::vector<std::string>( 520 EXPECT_EQ(std::vector<std::string>(
521 expected, expected + arraysize(expected)), recorder); 521 expected, expected + arraysize(expected)), recorder);
522 } 522 }
523 523
524 } // namespace test 524 } // namespace test
525 } // namespace ui 525 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event_dispatcher_unittest.cc ('k') | ui/events/event_rewriter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698