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

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

Issue 683553002: Standardize usage of virtual/override/final specifiers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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, LocatedEvent* event) override {
110 LocatedEvent* event) override {
111 event->ConvertLocationToTarget(this, 110 event->ConvertLocationToTarget(this,
112 static_cast<BoundsTestTarget*>(target)); 111 static_cast<BoundsTestTarget*>(target));
113 } 112 }
114 113
115 gfx::Rect bounds_; 114 gfx::Rect bounds_;
116 115
117 DISALLOW_COPY_AND_ASSIGN(BoundsTestTarget); 116 DISALLOW_COPY_AND_ASSIGN(BoundsTestTarget);
118 }; 117 };
119 118
120 TEST_F(EventProcessorTest, Bounds) { 119 TEST_F(EventProcessorTest, Bounds) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 174
176 // ReDispatchEventHandler is used to receive mouse events and forward them 175 // ReDispatchEventHandler is used to receive mouse events and forward them
177 // to a specified EventProcessor. Verifies that the event has the correct 176 // to a specified EventProcessor. Verifies that the event has the correct
178 // target and phase both before and after the nested event processing. Also 177 // 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 178 // verifies that the location of the event remains the same after it has
180 // been processed by the second EventProcessor. 179 // been processed by the second EventProcessor.
181 class ReDispatchEventHandler : public TestEventHandler { 180 class ReDispatchEventHandler : public TestEventHandler {
182 public: 181 public:
183 ReDispatchEventHandler(EventProcessor* processor, EventTarget* target) 182 ReDispatchEventHandler(EventProcessor* processor, EventTarget* target)
184 : processor_(processor), expected_target_(target) {} 183 : processor_(processor), expected_target_(target) {}
185 virtual ~ReDispatchEventHandler() {} 184 ~ReDispatchEventHandler() override {}
186 185
187 // TestEventHandler: 186 // TestEventHandler:
188 virtual void OnMouseEvent(MouseEvent* event) override { 187 void OnMouseEvent(MouseEvent* event) override {
189 TestEventHandler::OnMouseEvent(event); 188 TestEventHandler::OnMouseEvent(event);
190 189
191 EXPECT_EQ(expected_target_, event->target()); 190 EXPECT_EQ(expected_target_, event->target());
192 EXPECT_EQ(EP_TARGET, event->phase()); 191 EXPECT_EQ(EP_TARGET, event->phase());
193 192
194 gfx::Point location(event->location()); 193 gfx::Point location(event->location());
195 EventDispatchDetails details = processor_->OnEventFromSource(event); 194 EventDispatchDetails details = processor_->OnEventFromSource(event);
196 EXPECT_FALSE(details.dispatcher_destroyed); 195 EXPECT_FALSE(details.dispatcher_destroyed);
197 EXPECT_FALSE(details.target_destroyed); 196 EXPECT_FALSE(details.target_destroyed);
198 197
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 314 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
316 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); 315 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
317 EXPECT_TRUE(mouse2.handled()); 316 EXPECT_TRUE(mouse2.handled());
318 EXPECT_EQ(1, processor()->num_times_processing_started()); 317 EXPECT_EQ(1, processor()->num_times_processing_started());
319 EXPECT_EQ(1, processor()->num_times_processing_finished()); 318 EXPECT_EQ(1, processor()->num_times_processing_finished());
320 } 319 }
321 320
322 class IgnoreEventTargeter : public EventTargeter { 321 class IgnoreEventTargeter : public EventTargeter {
323 public: 322 public:
324 IgnoreEventTargeter() {} 323 IgnoreEventTargeter() {}
325 virtual ~IgnoreEventTargeter() {} 324 ~IgnoreEventTargeter() override {}
326 325
327 private: 326 private:
328 // EventTargeter: 327 // EventTargeter:
329 virtual bool SubtreeShouldBeExploredForEvent( 328 bool SubtreeShouldBeExploredForEvent(EventTarget* target,
330 EventTarget* target, const LocatedEvent& event) override { 329 const LocatedEvent& event) override {
331 return false; 330 return false;
332 } 331 }
333 }; 332 };
334 333
335 // Verifies that the EventTargeter installed on an EventTarget can dictate 334 // Verifies that the EventTargeter installed on an EventTarget can dictate
336 // whether the target itself can process an event. 335 // whether the target itself can process an event.
337 TEST_F(EventProcessorTest, TargeterChecksOwningEventTarget) { 336 TEST_F(EventProcessorTest, TargeterChecksOwningEventTarget) {
338 scoped_ptr<TestEventTarget> child(new TestEventTarget()); 337 scoped_ptr<TestEventTarget> child(new TestEventTarget());
339 root()->AddChild(child.Pass()); 338 root()->AddChild(child.Pass());
340 339
(...skipping 16 matching lines...) Expand all
357 } 356 }
358 357
359 // An EventTargeter which is used to allow a bubbling behaviour in event 358 // 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 359 // 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 360 // initial target, the event is dispatched to the next-best target as
362 // specified by FindNextBestTarget(). 361 // specified by FindNextBestTarget().
363 class BubblingEventTargeter : public EventTargeter { 362 class BubblingEventTargeter : public EventTargeter {
364 public: 363 public:
365 explicit BubblingEventTargeter(TestEventTarget* initial_target) 364 explicit BubblingEventTargeter(TestEventTarget* initial_target)
366 : initial_target_(initial_target) {} 365 : initial_target_(initial_target) {}
367 virtual ~BubblingEventTargeter() {} 366 ~BubblingEventTargeter() override {}
368 367
369 private: 368 private:
370 // EventTargeter: 369 // EventTargeter:
371 virtual EventTarget* FindTargetForEvent(EventTarget* root, 370 EventTarget* FindTargetForEvent(EventTarget* root, Event* event) override {
372 Event* event) override {
373 return initial_target_; 371 return initial_target_;
374 } 372 }
375 373
376 virtual EventTarget* FindNextBestTarget(EventTarget* previous_target, 374 EventTarget* FindNextBestTarget(EventTarget* previous_target,
377 Event* event) override { 375 Event* event) override {
378 return previous_target->GetParentTarget(); 376 return previous_target->GetParentTarget();
379 } 377 }
380 378
381 TestEventTarget* initial_target_; 379 TestEventTarget* initial_target_;
382 380
383 DISALLOW_COPY_AND_ASSIGN(BubblingEventTargeter); 381 DISALLOW_COPY_AND_ASSIGN(BubblingEventTargeter);
384 }; 382 };
385 383
386 // Tests that unhandled events are correctly dispatched to the next-best 384 // Tests that unhandled events are correctly dispatched to the next-best
387 // target as decided by the BubblingEventTargeter. 385 // target as decided by the BubblingEventTargeter.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 DispatchEvent(&mouse); 514 DispatchEvent(&mouse);
517 515
518 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", 516 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC",
519 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; 517 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" };
520 EXPECT_EQ(std::vector<std::string>( 518 EXPECT_EQ(std::vector<std::string>(
521 expected, expected + arraysize(expected)), recorder); 519 expected, expected + arraysize(expected)), recorder);
522 } 520 }
523 521
524 } // namespace test 522 } // namespace test
525 } // namespace ui 523 } // 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