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

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

Issue 1260453006: ui: events: Add a class to hold common touch and stylus properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address build problems, add accessor and unit tests. Created 5 years, 4 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
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_target_iterator.h" 9 #include "ui/events/event_target_iterator.h"
10 #include "ui/events/event_targeter.h" 10 #include "ui/events/event_targeter.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest); 57 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest);
58 }; 58 };
59 59
60 TEST_F(EventProcessorTest, Basic) { 60 TEST_F(EventProcessorTest, Basic) {
61 scoped_ptr<TestEventTarget> child(new TestEventTarget()); 61 scoped_ptr<TestEventTarget> child(new TestEventTarget());
62 child->SetEventTargeter( 62 child->SetEventTargeter(
63 make_scoped_ptr(new TestEventTargeter(child.get(), false))); 63 make_scoped_ptr(new TestEventTargeter(child.get(), false)));
64 SetTarget(child.get()); 64 SetTarget(child.get());
65 root()->AddChild(child.Pass()); 65 root()->AddChild(child.Pass());
66 66
67 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), 67 MouseEvent mouse(
68 EventTimeForNow(), EF_NONE, EF_NONE); 68 ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), EventTimeForNow(),
69 EF_NONE, EF_NONE,
70 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
69 DispatchEvent(&mouse); 71 DispatchEvent(&mouse);
70 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 72 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
71 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); 73 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
72 74
73 SetTarget(root()); 75 SetTarget(root());
74 root()->RemoveChild(root()->child_at(0)); 76 root()->RemoveChild(root()->child_at(0));
75 DispatchEvent(&mouse); 77 DispatchEvent(&mouse);
76 EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); 78 EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
77 } 79 }
78 80
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 139
138 // Indicate that an event which is dispatched to the child target owned by the 140 // Indicate that an event which is dispatched to the child target owned by the
139 // first event processor should be handled by |target_handler| instead. 141 // first event processor should be handled by |target_handler| instead.
140 scoped_ptr<TestEventHandler> target_handler( 142 scoped_ptr<TestEventHandler> target_handler(
141 new ReDispatchEventHandler(second_processor.get(), root()->child_at(0))); 143 new ReDispatchEventHandler(second_processor.get(), root()->child_at(0)));
142 root()->child_at(0)->set_target_handler(target_handler.get()); 144 root()->child_at(0)->set_target_handler(target_handler.get());
143 145
144 // Dispatch a mouse event to the tree of event targets owned by the first 146 // Dispatch a mouse event to the tree of event targets owned by the first
145 // event processor, checking in ReDispatchEventHandler that the phase and 147 // event processor, checking in ReDispatchEventHandler that the phase and
146 // target information of the event is correct. 148 // target information of the event is correct.
147 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), 149 MouseEvent mouse(
148 EventTimeForNow(), EF_NONE, EF_NONE); 150 ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), EventTimeForNow(),
151 EF_NONE, EF_NONE,
152 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
149 DispatchEvent(&mouse); 153 DispatchEvent(&mouse);
150 154
151 // Verify also that |mouse| was seen by the child nodes contained in both 155 // Verify also that |mouse| was seen by the child nodes contained in both
152 // event processors and that the event was not handled. 156 // event processors and that the event was not handled.
153 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 157 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
154 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 158 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
155 EXPECT_FALSE(mouse.handled()); 159 EXPECT_FALSE(mouse.handled());
156 second_root->child_at(0)->ResetReceivedEvents(); 160 second_root->child_at(0)->ResetReceivedEvents();
157 root()->child_at(0)->ResetReceivedEvents(); 161 root()->child_at(0)->ResetReceivedEvents();
158 162
159 // Indicate that the child of the second root should handle events, and 163 // Indicate that the child of the second root should handle events, and
160 // dispatch another mouse event to verify that it is marked as handled. 164 // dispatch another mouse event to verify that it is marked as handled.
161 second_root->child_at(0)->set_mark_events_as_handled(true); 165 second_root->child_at(0)->set_mark_events_as_handled(true);
162 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), 166 MouseEvent mouse2(
163 EventTimeForNow(), EF_NONE, EF_NONE); 167 ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), EventTimeForNow(),
168 EF_NONE, EF_NONE,
169 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
164 DispatchEvent(&mouse2); 170 DispatchEvent(&mouse2);
165 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 171 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
166 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 172 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
167 EXPECT_TRUE(mouse2.handled()); 173 EXPECT_TRUE(mouse2.handled());
168 } 174 }
169 175
170 // Verifies that OnEventProcessingFinished() is called when an event 176 // Verifies that OnEventProcessingFinished() is called when an event
171 // has been handled. 177 // has been handled.
172 TEST_F(EventProcessorTest, OnEventProcessingFinished) { 178 TEST_F(EventProcessorTest, OnEventProcessingFinished) {
173 scoped_ptr<TestEventTarget> child(new TestEventTarget()); 179 scoped_ptr<TestEventTarget> child(new TestEventTarget());
174 child->set_mark_events_as_handled(true); 180 child->set_mark_events_as_handled(true);
175 SetTarget(child.get()); 181 SetTarget(child.get());
176 root()->AddChild(child.Pass()); 182 root()->AddChild(child.Pass());
177 183
178 // Dispatch a mouse event. We expect the event to be seen by the target, 184 // Dispatch a mouse event. We expect the event to be seen by the target,
179 // handled, and we expect OnEventProcessingFinished() to be invoked once. 185 // handled, and we expect OnEventProcessingFinished() to be invoked once.
180 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), 186 MouseEvent mouse(
181 EventTimeForNow(), EF_NONE, EF_NONE); 187 ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), EventTimeForNow(),
188 EF_NONE, EF_NONE,
189 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
182 DispatchEvent(&mouse); 190 DispatchEvent(&mouse);
183 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 191 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
184 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); 192 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
185 EXPECT_TRUE(mouse.handled()); 193 EXPECT_TRUE(mouse.handled());
186 EXPECT_EQ(1, processor()->num_times_processing_finished()); 194 EXPECT_EQ(1, processor()->num_times_processing_finished());
187 } 195 }
188 196
189 // Verifies that OnEventProcessingStarted() has been called when starting to 197 // Verifies that OnEventProcessingStarted() has been called when starting to
190 // process an event, and that processing does not take place if 198 // process an event, and that processing does not take place if
191 // OnEventProcessingStarted() marks the event as handled. Also verifies that 199 // OnEventProcessingStarted() marks the event as handled. Also verifies that
192 // OnEventProcessingFinished() is also called in either case. 200 // OnEventProcessingFinished() is also called in either case.
193 TEST_F(EventProcessorTest, OnEventProcessingStarted) { 201 TEST_F(EventProcessorTest, OnEventProcessingStarted) {
194 scoped_ptr<TestEventTarget> child(new TestEventTarget()); 202 scoped_ptr<TestEventTarget> child(new TestEventTarget());
195 SetTarget(child.get()); 203 SetTarget(child.get());
196 root()->AddChild(child.Pass()); 204 root()->AddChild(child.Pass());
197 205
198 // Dispatch a mouse event. We expect the event to be seen by the target, 206 // Dispatch a mouse event. We expect the event to be seen by the target,
199 // OnEventProcessingStarted() should be called once, and 207 // OnEventProcessingStarted() should be called once, and
200 // OnEventProcessingFinished() should be called once. The event should 208 // OnEventProcessingFinished() should be called once. The event should
201 // remain unhandled. 209 // remain unhandled.
202 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), 210 MouseEvent mouse(
203 EventTimeForNow(), EF_NONE, EF_NONE); 211 ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), EventTimeForNow(),
212 EF_NONE, EF_NONE,
213 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
204 DispatchEvent(&mouse); 214 DispatchEvent(&mouse);
205 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 215 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
206 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); 216 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
207 EXPECT_FALSE(mouse.handled()); 217 EXPECT_FALSE(mouse.handled());
208 EXPECT_EQ(1, processor()->num_times_processing_started()); 218 EXPECT_EQ(1, processor()->num_times_processing_started());
209 EXPECT_EQ(1, processor()->num_times_processing_finished()); 219 EXPECT_EQ(1, processor()->num_times_processing_finished());
210 processor()->Reset(); 220 processor()->Reset();
211 root()->ResetReceivedEvents(); 221 root()->ResetReceivedEvents();
212 root()->child_at(0)->ResetReceivedEvents(); 222 root()->child_at(0)->ResetReceivedEvents();
213 223
214 // Dispatch another mouse event, but with OnEventProcessingStarted() marking 224 // Dispatch another mouse event, but with OnEventProcessingStarted() marking
215 // the event as handled to prevent processing. We expect the event to not be 225 // the event as handled to prevent processing. We expect the event to not be
216 // seen by the target this time, but OnEventProcessingStarted() and 226 // seen by the target this time, but OnEventProcessingStarted() and
217 // OnEventProcessingFinished() should both still be called once. 227 // OnEventProcessingFinished() should both still be called once.
218 processor()->set_should_processing_occur(false); 228 processor()->set_should_processing_occur(false);
219 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), 229 MouseEvent mouse2(
220 EventTimeForNow(), EF_NONE, EF_NONE); 230 ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), EventTimeForNow(),
231 EF_NONE, EF_NONE,
232 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
221 DispatchEvent(&mouse2); 233 DispatchEvent(&mouse2);
222 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); 234 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED));
223 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); 235 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED));
224 EXPECT_TRUE(mouse2.handled()); 236 EXPECT_TRUE(mouse2.handled());
225 EXPECT_EQ(1, processor()->num_times_processing_started()); 237 EXPECT_EQ(1, processor()->num_times_processing_started());
226 EXPECT_EQ(1, processor()->num_times_processing_finished()); 238 EXPECT_EQ(1, processor()->num_times_processing_finished());
227 } 239 }
228 240
229 // Tests that unhandled events are correctly dispatched to the next-best 241 // Tests that unhandled events are correctly dispatched to the next-best
230 // target as decided by the TestEventTargeter. 242 // target as decided by the TestEventTargeter.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 TestEventHandler post_child; 362 TestEventHandler post_child;
351 post_child.set_handler_name("PostC"); 363 post_child.set_handler_name("PostC");
352 post_child.set_recorder(&recorder); 364 post_child.set_recorder(&recorder);
353 child_r->AddPostTargetHandler(&post_child); 365 child_r->AddPostTargetHandler(&post_child);
354 366
355 TestEventHandler post_grandchild; 367 TestEventHandler post_grandchild;
356 post_grandchild.set_handler_name("PostG"); 368 post_grandchild.set_handler_name("PostG");
357 post_grandchild.set_recorder(&recorder); 369 post_grandchild.set_recorder(&recorder);
358 grandchild_r->AddPostTargetHandler(&post_grandchild); 370 grandchild_r->AddPostTargetHandler(&post_grandchild);
359 371
360 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), 372 MouseEvent mouse(
361 EventTimeForNow(), EF_NONE, EF_NONE); 373 ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), EventTimeForNow(),
374 EF_NONE, EF_NONE,
375 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
362 DispatchEvent(&mouse); 376 DispatchEvent(&mouse);
363 377
364 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", 378 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC",
365 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; 379 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" };
366 EXPECT_EQ(std::vector<std::string>( 380 EXPECT_EQ(std::vector<std::string>(
367 expected, expected + arraysize(expected)), recorder); 381 expected, expected + arraysize(expected)), recorder);
368 } 382 }
369 383
370 } // namespace test 384 } // namespace test
371 } // namespace ui 385 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698