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

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

Issue 404203003: Distinguish between keystroke and character events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsCharFromNative() for Mac build Created 6 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
« no previous file with comments | « ui/events/event.cc ('k') | ui/events/event_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"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 ASSERT_EQ(1u, root()->child_count()); 246 ASSERT_EQ(1u, root()->child_count());
247 ASSERT_EQ(1u, root()->child_at(0)->child_count()); 247 ASSERT_EQ(1u, root()->child_at(0)->child_count());
248 ASSERT_EQ(0u, root()->child_at(0)->child_at(0)->child_count()); 248 ASSERT_EQ(0u, root()->child_at(0)->child_at(0)->child_count());
249 249
250 TestEventTarget* child_r = root()->child_at(0); 250 TestEventTarget* child_r = root()->child_at(0);
251 TestEventTarget* grandchild_r = child_r->child_at(0); 251 TestEventTarget* grandchild_r = child_r->child_at(0);
252 252
253 // When the root has a BubblingEventTargeter installed, events targeted 253 // When the root has a BubblingEventTargeter installed, events targeted
254 // at the grandchild target should be dispatched to all three targets. 254 // at the grandchild target should be dispatched to all three targets.
255 KeyEvent key_event(ET_KEY_PRESSED, VKEY_ESCAPE, 0, false); 255 KeyEvent key_event(ET_KEY_PRESSED, VKEY_ESCAPE, EF_NONE);
256 DispatchEvent(&key_event); 256 DispatchEvent(&key_event);
257 EXPECT_TRUE(root()->DidReceiveEvent(ET_KEY_PRESSED)); 257 EXPECT_TRUE(root()->DidReceiveEvent(ET_KEY_PRESSED));
258 EXPECT_TRUE(child_r->DidReceiveEvent(ET_KEY_PRESSED)); 258 EXPECT_TRUE(child_r->DidReceiveEvent(ET_KEY_PRESSED));
259 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED)); 259 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED));
260 root()->ResetReceivedEvents(); 260 root()->ResetReceivedEvents();
261 child_r->ResetReceivedEvents(); 261 child_r->ResetReceivedEvents();
262 grandchild_r->ResetReceivedEvents(); 262 grandchild_r->ResetReceivedEvents();
263 263
264 // Add a pre-target handler on the child of the root that will mark the event 264 // Add a pre-target handler on the child of the root that will mark the event
265 // as handled. No targets in the hierarchy should receive the event. 265 // as handled. No targets in the hierarchy should receive the event.
266 TestEventHandler handler; 266 TestEventHandler handler;
267 child_r->AddPreTargetHandler(&handler); 267 child_r->AddPreTargetHandler(&handler);
268 key_event = KeyEvent(ET_KEY_PRESSED, VKEY_ESCAPE, 0, false); 268 key_event = KeyEvent(ET_KEY_PRESSED, VKEY_ESCAPE, EF_NONE);
269 DispatchEvent(&key_event); 269 DispatchEvent(&key_event);
270 EXPECT_FALSE(root()->DidReceiveEvent(ET_KEY_PRESSED)); 270 EXPECT_FALSE(root()->DidReceiveEvent(ET_KEY_PRESSED));
271 EXPECT_FALSE(child_r->DidReceiveEvent(ET_KEY_PRESSED)); 271 EXPECT_FALSE(child_r->DidReceiveEvent(ET_KEY_PRESSED));
272 EXPECT_FALSE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED)); 272 EXPECT_FALSE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED));
273 EXPECT_EQ(1, handler.num_key_events()); 273 EXPECT_EQ(1, handler.num_key_events());
274 handler.Reset(); 274 handler.Reset();
275 275
276 // Add a post-target handler on the child of the root that will mark the event 276 // Add a post-target handler on the child of the root that will mark the event
277 // as handled. Only the grandchild (the initial target) should receive the 277 // as handled. Only the grandchild (the initial target) should receive the
278 // event. 278 // event.
279 child_r->RemovePreTargetHandler(&handler); 279 child_r->RemovePreTargetHandler(&handler);
280 child_r->AddPostTargetHandler(&handler); 280 child_r->AddPostTargetHandler(&handler);
281 key_event = KeyEvent(ET_KEY_PRESSED, VKEY_ESCAPE, 0, false); 281 key_event = KeyEvent(ET_KEY_PRESSED, VKEY_ESCAPE, EF_NONE);
282 DispatchEvent(&key_event); 282 DispatchEvent(&key_event);
283 EXPECT_FALSE(root()->DidReceiveEvent(ET_KEY_PRESSED)); 283 EXPECT_FALSE(root()->DidReceiveEvent(ET_KEY_PRESSED));
284 EXPECT_FALSE(child_r->DidReceiveEvent(ET_KEY_PRESSED)); 284 EXPECT_FALSE(child_r->DidReceiveEvent(ET_KEY_PRESSED));
285 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED)); 285 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED));
286 EXPECT_EQ(1, handler.num_key_events()); 286 EXPECT_EQ(1, handler.num_key_events());
287 handler.Reset(); 287 handler.Reset();
288 grandchild_r->ResetReceivedEvents(); 288 grandchild_r->ResetReceivedEvents();
289 child_r->RemovePostTargetHandler(&handler); 289 child_r->RemovePostTargetHandler(&handler);
290 290
291 // Mark the event as handled when it reaches the EP_TARGET phase of 291 // Mark the event as handled when it reaches the EP_TARGET phase of
292 // dispatch at the child of the root. The child and grandchild 292 // dispatch at the child of the root. The child and grandchild
293 // targets should both receive the event, but the root should not. 293 // targets should both receive the event, but the root should not.
294 child_r->set_mark_events_as_handled(true); 294 child_r->set_mark_events_as_handled(true);
295 key_event = KeyEvent(ET_KEY_PRESSED, VKEY_ESCAPE, 0, false); 295 key_event = KeyEvent(ET_KEY_PRESSED, VKEY_ESCAPE, EF_NONE);
296 DispatchEvent(&key_event); 296 DispatchEvent(&key_event);
297 EXPECT_FALSE(root()->DidReceiveEvent(ET_KEY_PRESSED)); 297 EXPECT_FALSE(root()->DidReceiveEvent(ET_KEY_PRESSED));
298 EXPECT_TRUE(child_r->DidReceiveEvent(ET_KEY_PRESSED)); 298 EXPECT_TRUE(child_r->DidReceiveEvent(ET_KEY_PRESSED));
299 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED)); 299 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_KEY_PRESSED));
300 root()->ResetReceivedEvents(); 300 root()->ResetReceivedEvents();
301 child_r->ResetReceivedEvents(); 301 child_r->ResetReceivedEvents();
302 grandchild_r->ResetReceivedEvents(); 302 grandchild_r->ResetReceivedEvents();
303 child_r->set_mark_events_as_handled(false); 303 child_r->set_mark_events_as_handled(false);
304 } 304 }
305 305
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 DispatchEvent(&mouse); 365 DispatchEvent(&mouse);
366 366
367 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", 367 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC",
368 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; 368 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" };
369 EXPECT_EQ(std::vector<std::string>( 369 EXPECT_EQ(std::vector<std::string>(
370 expected, expected + arraysize(expected)), recorder); 370 expected, expected + arraysize(expected)), recorder);
371 } 371 }
372 372
373 } // namespace test 373 } // namespace test
374 } // namespace ui 374 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event.cc ('k') | ui/events/event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698