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

Side by Side Diff: trunk/src/ui/aura/root_window_unittest.cc

Issue 77203002: Revert 236048 "Rename RootWindowHost* to WindowTreeHost*" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/ui/aura/root_window_observer.h ('k') | trunk/src/ui/aura/test/event_generator.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/aura/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/client/event_client.h" 10 #include "ui/aura/client/event_client.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); 106 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight);
107 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( 107 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(
108 delegate1.get(), -1234, bounds1, root_window())); 108 delegate1.get(), -1234, bounds1, root_window()));
109 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( 109 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate(
110 delegate2.get(), -5678, bounds2, root_window())); 110 delegate2.get(), -5678, bounds2, root_window()));
111 111
112 // Send a mouse event to window1. 112 // Send a mouse event to window1.
113 gfx::Point point(101, 201); 113 gfx::Point point(101, 201);
114 ui::MouseEvent event1( 114 ui::MouseEvent event1(
115 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON); 115 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON);
116 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&event1); 116 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1);
117 117
118 // Event was tested for non-client area for the target window. 118 // Event was tested for non-client area for the target window.
119 EXPECT_EQ(1, delegate1->non_client_count()); 119 EXPECT_EQ(1, delegate1->non_client_count());
120 EXPECT_EQ(0, delegate2->non_client_count()); 120 EXPECT_EQ(0, delegate2->non_client_count());
121 // The non-client component test was in local coordinates. 121 // The non-client component test was in local coordinates.
122 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); 122 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location());
123 // Mouse event was received by target window. 123 // Mouse event was received by target window.
124 EXPECT_EQ(1, delegate1->mouse_event_count()); 124 EXPECT_EQ(1, delegate1->mouse_event_count());
125 EXPECT_EQ(0, delegate2->mouse_event_count()); 125 EXPECT_EQ(0, delegate2->mouse_event_count());
126 // Event was in local coordinates. 126 // Event was in local coordinates.
(...skipping 20 matching lines...) Expand all
147 147
148 gfx::Point location; 148 gfx::Point location;
149 scoped_ptr<ui::MouseEvent> event; 149 scoped_ptr<ui::MouseEvent> event;
150 150
151 // Press the left button. 151 // Press the left button.
152 event.reset(new ui::MouseEvent( 152 event.reset(new ui::MouseEvent(
153 ui::ET_MOUSE_PRESSED, 153 ui::ET_MOUSE_PRESSED,
154 location, 154 location,
155 location, 155 location,
156 ui::EF_LEFT_MOUSE_BUTTON)); 156 ui::EF_LEFT_MOUSE_BUTTON));
157 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 157 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
158 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 158 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
159 159
160 // Additionally press the right. 160 // Additionally press the right.
161 event.reset(new ui::MouseEvent( 161 event.reset(new ui::MouseEvent(
162 ui::ET_MOUSE_PRESSED, 162 ui::ET_MOUSE_PRESSED,
163 location, 163 location,
164 location, 164 location,
165 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)); 165 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON));
166 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 166 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
167 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 167 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
168 168
169 // Release the left button. 169 // Release the left button.
170 event.reset(new ui::MouseEvent( 170 event.reset(new ui::MouseEvent(
171 ui::ET_MOUSE_RELEASED, 171 ui::ET_MOUSE_RELEASED,
172 location, 172 location,
173 location, 173 location,
174 ui::EF_RIGHT_MOUSE_BUTTON)); 174 ui::EF_RIGHT_MOUSE_BUTTON));
175 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 175 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
176 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 176 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
177 177
178 // Release the right button. We should ignore the Shift-is-down flag. 178 // Release the right button. We should ignore the Shift-is-down flag.
179 event.reset(new ui::MouseEvent( 179 event.reset(new ui::MouseEvent(
180 ui::ET_MOUSE_RELEASED, 180 ui::ET_MOUSE_RELEASED,
181 location, 181 location,
182 location, 182 location,
183 ui::EF_SHIFT_DOWN)); 183 ui::EF_SHIFT_DOWN));
184 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 184 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
185 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 185 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
186 186
187 // Press the middle button. 187 // Press the middle button.
188 event.reset(new ui::MouseEvent( 188 event.reset(new ui::MouseEvent(
189 ui::ET_MOUSE_PRESSED, 189 ui::ET_MOUSE_PRESSED,
190 location, 190 location,
191 location, 191 location,
192 ui::EF_MIDDLE_MOUSE_BUTTON)); 192 ui::EF_MIDDLE_MOUSE_BUTTON));
193 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 193 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get());
194 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 194 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
195 } 195 }
196 196
197 TEST_F(RootWindowTest, TranslatedEvent) { 197 TEST_F(RootWindowTest, TranslatedEvent) {
198 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, 198 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1,
199 gfx::Rect(50, 50, 100, 100), root_window())); 199 gfx::Rect(50, 50, 100, 100), root_window()));
200 200
201 gfx::Point origin(100, 100); 201 gfx::Point origin(100, 100);
202 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0); 202 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0);
203 203
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // Prevent w3 from being deleted by the hierarchy since its delegate is owned 327 // Prevent w3 from being deleted by the hierarchy since its delegate is owned
328 // by this scope. 328 // by this scope.
329 w3->parent()->RemoveChild(w3.get()); 329 w3->parent()->RemoveChild(w3.get());
330 } 330 }
331 331
332 TEST_F(RootWindowTest, IgnoreUnknownKeys) { 332 TEST_F(RootWindowTest, IgnoreUnknownKeys) {
333 test::TestEventHandler* filter = new ConsumeKeyHandler; 333 test::TestEventHandler* filter = new ConsumeKeyHandler;
334 root_window()->SetEventFilter(filter); // passes ownership 334 root_window()->SetEventFilter(filter); // passes ownership
335 335
336 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); 336 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false);
337 EXPECT_FALSE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( 337 EXPECT_FALSE(dispatcher()->AsRootWindowHostDelegate()->OnHostKeyEvent(
338 &unknown_event)); 338 &unknown_event));
339 EXPECT_EQ(0, filter->num_key_events()); 339 EXPECT_EQ(0, filter->num_key_events());
340 340
341 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); 341 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
342 EXPECT_TRUE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( 342 EXPECT_TRUE(dispatcher()->AsRootWindowHostDelegate()->OnHostKeyEvent(
343 &known_event)); 343 &known_event));
344 EXPECT_EQ(1, filter->num_key_events()); 344 EXPECT_EQ(1, filter->num_key_events());
345 } 345 }
346 346
347 TEST_F(RootWindowTest, NoDelegateWindowReceivesKeyEvents) { 347 TEST_F(RootWindowTest, NoDelegateWindowReceivesKeyEvents) {
348 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); 348 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL));
349 w1->Show(); 349 w1->Show();
350 w1->Focus(); 350 w1->Focus();
351 351
352 test::TestEventHandler handler; 352 test::TestEventHandler handler;
353 w1->AddPreTargetHandler(&handler); 353 w1->AddPreTargetHandler(&handler);
354 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); 354 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
355 EXPECT_TRUE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( 355 EXPECT_TRUE(dispatcher()->AsRootWindowHostDelegate()->OnHostKeyEvent(
356 &key_press)); 356 &key_press));
357 EXPECT_EQ(1, handler.num_key_events()); 357 EXPECT_EQ(1, handler.num_key_events());
358 358
359 w1->RemovePreTargetHandler(&handler); 359 w1->RemovePreTargetHandler(&handler);
360 } 360 }
361 361
362 // Tests that touch-events that are beyond the bounds of the root-window do get 362 // Tests that touch-events that are beyond the bounds of the root-window do get
363 // propagated to the event filters correctly with the root as the target. 363 // propagated to the event filters correctly with the root as the target.
364 TEST_F(RootWindowTest, TouchEventsOutsideBounds) { 364 TEST_F(RootWindowTest, TouchEventsOutsideBounds) {
365 test::TestEventHandler* filter = new test::TestEventHandler; 365 test::TestEventHandler* filter = new test::TestEventHandler;
366 root_window()->SetEventFilter(filter); // passes ownership 366 root_window()->SetEventFilter(filter); // passes ownership
367 367
368 gfx::Point position = root_window()->bounds().origin(); 368 gfx::Point position = root_window()->bounds().origin();
369 position.Offset(-10, -10); 369 position.Offset(-10, -10);
370 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); 370 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta());
371 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); 371 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
372 EXPECT_EQ(1, filter->num_touch_events()); 372 EXPECT_EQ(1, filter->num_touch_events());
373 373
374 position = root_window()->bounds().origin(); 374 position = root_window()->bounds().origin();
375 position.Offset(root_window()->bounds().width() + 10, 375 position.Offset(root_window()->bounds().width() + 10,
376 root_window()->bounds().height() + 10); 376 root_window()->bounds().height() + 10);
377 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); 377 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta());
378 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release); 378 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
379 EXPECT_EQ(2, filter->num_touch_events()); 379 EXPECT_EQ(2, filter->num_touch_events());
380 } 380 }
381 381
382 // Tests that scroll events are dispatched correctly. 382 // Tests that scroll events are dispatched correctly.
383 TEST_F(RootWindowTest, ScrollEventDispatch) { 383 TEST_F(RootWindowTest, ScrollEventDispatch) {
384 base::TimeDelta now = ui::EventTimeForNow(); 384 base::TimeDelta now = ui::EventTimeForNow();
385 test::TestEventHandler* filter = new test::TestEventHandler; 385 test::TestEventHandler* filter = new test::TestEventHandler;
386 root_window()->SetEventFilter(filter); 386 root_window()->SetEventFilter(filter);
387 387
388 test::TestWindowDelegate delegate; 388 test::TestWindowDelegate delegate;
389 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); 389 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate));
390 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); 390 w1->SetBounds(gfx::Rect(20, 20, 40, 40));
391 391
392 // A scroll event on the root-window itself is dispatched. 392 // A scroll event on the root-window itself is dispatched.
393 ui::ScrollEvent scroll1(ui::ET_SCROLL, 393 ui::ScrollEvent scroll1(ui::ET_SCROLL,
394 gfx::Point(10, 10), 394 gfx::Point(10, 10),
395 now, 395 now,
396 0, 396 0,
397 0, -10, 397 0, -10,
398 0, -10, 398 0, -10,
399 2); 399 2);
400 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll1); 400 dispatcher()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll1);
401 EXPECT_EQ(1, filter->num_scroll_events()); 401 EXPECT_EQ(1, filter->num_scroll_events());
402 402
403 // Scroll event on a window should be dispatched properly. 403 // Scroll event on a window should be dispatched properly.
404 ui::ScrollEvent scroll2(ui::ET_SCROLL, 404 ui::ScrollEvent scroll2(ui::ET_SCROLL,
405 gfx::Point(25, 30), 405 gfx::Point(25, 30),
406 now, 406 now,
407 0, 407 0,
408 -10, 0, 408 -10, 0,
409 -10, 0, 409 -10, 0,
410 2); 410 2);
411 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll2); 411 dispatcher()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll2);
412 EXPECT_EQ(2, filter->num_scroll_events()); 412 EXPECT_EQ(2, filter->num_scroll_events());
413 } 413 }
414 414
415 namespace { 415 namespace {
416 416
417 // FilterFilter that tracks the types of events it's seen. 417 // FilterFilter that tracks the types of events it's seen.
418 class EventFilterRecorder : public ui::EventHandler { 418 class EventFilterRecorder : public ui::EventHandler {
419 public: 419 public:
420 typedef std::vector<ui::EventType> Events; 420 typedef std::vector<ui::EventType> Events;
421 typedef std::vector<gfx::Point> MouseEventLocations; 421 typedef std::vector<gfx::Point> MouseEventLocations;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 TEST_F(RootWindowTest, MouseMovesHeld) { 550 TEST_F(RootWindowTest, MouseMovesHeld) {
551 EventFilterRecorder* filter = new EventFilterRecorder; 551 EventFilterRecorder* filter = new EventFilterRecorder;
552 root_window()->SetEventFilter(filter); // passes ownership 552 root_window()->SetEventFilter(filter); // passes ownership
553 553
554 test::TestWindowDelegate delegate; 554 test::TestWindowDelegate delegate;
555 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 555 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
556 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 556 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
557 557
558 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), 558 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
559 gfx::Point(0, 0), 0); 559 gfx::Point(0, 0), 0);
560 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 560 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
561 &mouse_move_event); 561 &mouse_move_event);
562 // Discard MOUSE_ENTER. 562 // Discard MOUSE_ENTER.
563 filter->events().clear(); 563 filter->events().clear();
564 564
565 dispatcher()->HoldPointerMoves(); 565 dispatcher()->HoldPointerMoves();
566 566
567 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. 567 // Check that we don't immediately dispatch the MOUSE_DRAGGED event.
568 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), 568 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0),
569 gfx::Point(0, 0), 0); 569 gfx::Point(0, 0), 0);
570 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 570 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
571 &mouse_dragged_event); 571 &mouse_dragged_event);
572 EXPECT_TRUE(filter->events().empty()); 572 EXPECT_TRUE(filter->events().empty());
573 573
574 // Check that we do dispatch the held MOUSE_DRAGGED event before another type 574 // Check that we do dispatch the held MOUSE_DRAGGED event before another type
575 // of event. 575 // of event.
576 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 576 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
577 gfx::Point(0, 0), 0); 577 gfx::Point(0, 0), 0);
578 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 578 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
579 &mouse_pressed_event); 579 &mouse_pressed_event);
580 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 580 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
581 EventTypesToString(filter->events())); 581 EventTypesToString(filter->events()));
582 filter->events().clear(); 582 filter->events().clear();
583 583
584 // Check that we coalesce held MOUSE_DRAGGED events. 584 // Check that we coalesce held MOUSE_DRAGGED events.
585 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), 585 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1),
586 gfx::Point(1, 1), 0); 586 gfx::Point(1, 1), 0);
587 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 587 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
588 &mouse_dragged_event); 588 &mouse_dragged_event);
589 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 589 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
590 &mouse_dragged_event2); 590 &mouse_dragged_event2);
591 EXPECT_TRUE(filter->events().empty()); 591 EXPECT_TRUE(filter->events().empty());
592 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 592 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
593 &mouse_pressed_event); 593 &mouse_pressed_event);
594 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 594 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
595 EventTypesToString(filter->events())); 595 EventTypesToString(filter->events()));
596 filter->events().clear(); 596 filter->events().clear();
597 597
598 // Check that on ReleasePointerMoves, held events are not dispatched 598 // Check that on ReleasePointerMoves, held events are not dispatched
599 // immediately, but posted instead. 599 // immediately, but posted instead.
600 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 600 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
601 &mouse_dragged_event); 601 &mouse_dragged_event);
602 dispatcher()->ReleasePointerMoves(); 602 dispatcher()->ReleasePointerMoves();
603 EXPECT_TRUE(filter->events().empty()); 603 EXPECT_TRUE(filter->events().empty());
604 RunAllPendingInMessageLoop(); 604 RunAllPendingInMessageLoop();
605 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 605 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
606 filter->events().clear(); 606 filter->events().clear();
607 607
608 // However if another message comes in before the dispatch, 608 // However if another message comes in before the dispatch,
609 // the Check that on ReleasePointerMoves, held events are not dispatched 609 // the Check that on ReleasePointerMoves, held events are not dispatched
610 // immediately, but posted instead. 610 // immediately, but posted instead.
611 dispatcher()->HoldPointerMoves(); 611 dispatcher()->HoldPointerMoves();
612 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 612 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
613 &mouse_dragged_event); 613 &mouse_dragged_event);
614 dispatcher()->ReleasePointerMoves(); 614 dispatcher()->ReleasePointerMoves();
615 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 615 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
616 &mouse_pressed_event); 616 &mouse_pressed_event);
617 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 617 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
618 EventTypesToString(filter->events())); 618 EventTypesToString(filter->events()));
619 filter->events().clear(); 619 filter->events().clear();
620 RunAllPendingInMessageLoop(); 620 RunAllPendingInMessageLoop();
621 EXPECT_TRUE(filter->events().empty()); 621 EXPECT_TRUE(filter->events().empty());
622 622
623 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce 623 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce
624 // them. 624 // them.
625 dispatcher()->HoldPointerMoves(); 625 dispatcher()->HoldPointerMoves();
626 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 626 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
627 &mouse_dragged_event); 627 &mouse_dragged_event);
628 dispatcher()->ReleasePointerMoves(); 628 dispatcher()->ReleasePointerMoves();
629 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 629 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(
630 &mouse_dragged_event2); 630 &mouse_dragged_event2);
631 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 631 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
632 filter->events().clear(); 632 filter->events().clear();
633 RunAllPendingInMessageLoop(); 633 RunAllPendingInMessageLoop();
634 EXPECT_TRUE(filter->events().empty()); 634 EXPECT_TRUE(filter->events().empty());
635 } 635 }
636 636
637 TEST_F(RootWindowTest, TouchMovesHeld) { 637 TEST_F(RootWindowTest, TouchMovesHeld) {
638 EventFilterRecorder* filter = new EventFilterRecorder; 638 EventFilterRecorder* filter = new EventFilterRecorder;
639 root_window()->SetEventFilter(filter); // passes ownership 639 root_window()->SetEventFilter(filter); // passes ownership
640 640
641 test::TestWindowDelegate delegate; 641 test::TestWindowDelegate delegate;
642 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 642 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
643 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 643 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
644 644
645 // Starting the touch and throwing out the first few events, since the system 645 // Starting the touch and throwing out the first few events, since the system
646 // is going to generate synthetic mouse events that are not relevant to the 646 // is going to generate synthetic mouse events that are not relevant to the
647 // test. 647 // test.
648 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 648 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
649 0, base::TimeDelta()); 649 0, base::TimeDelta());
650 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 650 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(
651 &touch_pressed_event); 651 &touch_pressed_event);
652 RunAllPendingInMessageLoop(); 652 RunAllPendingInMessageLoop();
653 filter->events().clear(); 653 filter->events().clear();
654 654
655 dispatcher()->HoldPointerMoves(); 655 dispatcher()->HoldPointerMoves();
656 656
657 // Check that we don't immediately dispatch the TOUCH_MOVED event. 657 // Check that we don't immediately dispatch the TOUCH_MOVED event.
658 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, gfx::Point(0, 0), 658 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, gfx::Point(0, 0),
659 0, base::TimeDelta()); 659 0, base::TimeDelta());
660 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 660 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(
661 &touch_moved_event); 661 &touch_moved_event);
662 EXPECT_TRUE(filter->events().empty()); 662 EXPECT_TRUE(filter->events().empty());
663 663
664 // Check that on ReleasePointerMoves, held events are not dispatched 664 // Check that on ReleasePointerMoves, held events are not dispatched
665 // immediately, but posted instead. 665 // immediately, but posted instead.
666 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 666 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(
667 &touch_moved_event); 667 &touch_moved_event);
668 dispatcher()->ReleasePointerMoves(); 668 dispatcher()->ReleasePointerMoves();
669 EXPECT_TRUE(filter->events().empty()); 669 EXPECT_TRUE(filter->events().empty());
670 RunAllPendingInMessageLoop(); 670 RunAllPendingInMessageLoop();
671 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events())); 671 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events()));
672 filter->events().clear(); 672 filter->events().clear();
673 673
674 // If another touch event occurs then the held touch should be dispatched 674 // If another touch event occurs then the held touch should be dispatched
675 // immediately before it. 675 // immediately before it.
676 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 676 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0),
677 0, base::TimeDelta()); 677 0, base::TimeDelta());
678 filter->events().clear(); 678 filter->events().clear();
679 dispatcher()->HoldPointerMoves(); 679 dispatcher()->HoldPointerMoves();
680 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 680 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(
681 &touch_moved_event); 681 &touch_moved_event);
682 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 682 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(
683 &touch_released_event); 683 &touch_released_event);
684 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_END", 684 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_END",
685 EventTypesToString(filter->events())); 685 EventTypesToString(filter->events()));
686 filter->events().clear(); 686 filter->events().clear();
687 dispatcher()->ReleasePointerMoves(); 687 dispatcher()->ReleasePointerMoves();
688 RunAllPendingInMessageLoop(); 688 RunAllPendingInMessageLoop();
689 EXPECT_TRUE(filter->events().empty()); 689 EXPECT_TRUE(filter->events().empty());
690 } 690 }
691 691
692 // Tests that synthetic mouse events are ignored when mouse 692 // Tests that synthetic mouse events are ignored when mouse
693 // events are disabled. 693 // events are disabled.
694 TEST_F(RootWindowTest, DispatchSyntheticMouseEvents) { 694 TEST_F(RootWindowTest, DispatchSyntheticMouseEvents) {
695 EventFilterRecorder* filter = new EventFilterRecorder; 695 EventFilterRecorder* filter = new EventFilterRecorder;
696 root_window()->SetEventFilter(filter); // passes ownership 696 root_window()->SetEventFilter(filter); // passes ownership
697 697
698 test::TestWindowDelegate delegate; 698 test::TestWindowDelegate delegate;
699 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 699 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
700 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); 700 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window()));
701 window->Show(); 701 window->Show();
702 window->SetCapture(); 702 window->SetCapture();
703 703
704 test::TestCursorClient cursor_client(root_window()); 704 test::TestCursorClient cursor_client(root_window());
705 705
706 // Dispatch a non-synthetic mouse event when mouse events are enabled. 706 // Dispatch a non-synthetic mouse event when mouse events are enabled.
707 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 707 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
708 gfx::Point(10, 10), 0); 708 gfx::Point(10, 10), 0);
709 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); 709 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1);
710 EXPECT_FALSE(filter->events().empty()); 710 EXPECT_FALSE(filter->events().empty());
711 filter->events().clear(); 711 filter->events().clear();
712 712
713 // Dispatch a synthetic mouse event when mouse events are enabled. 713 // Dispatch a synthetic mouse event when mouse events are enabled.
714 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 714 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
715 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED); 715 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED);
716 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); 716 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2);
717 EXPECT_FALSE(filter->events().empty()); 717 EXPECT_FALSE(filter->events().empty());
718 filter->events().clear(); 718 filter->events().clear();
719 719
720 // Dispatch a synthetic mouse event when mouse events are disabled. 720 // Dispatch a synthetic mouse event when mouse events are disabled.
721 cursor_client.DisableMouseEvents(); 721 cursor_client.DisableMouseEvents();
722 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); 722 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2);
723 EXPECT_TRUE(filter->events().empty()); 723 EXPECT_TRUE(filter->events().empty());
724 } 724 }
725 725
726 // Tests that a mouse exit is dispatched to the last known cursor location 726 // Tests that a mouse exit is dispatched to the last known cursor location
727 // when the cursor becomes invisible. 727 // when the cursor becomes invisible.
728 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { 728 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) {
729 EventFilterRecorder* filter = new EventFilterRecorder; 729 EventFilterRecorder* filter = new EventFilterRecorder;
730 root_window()->SetEventFilter(filter); // passes ownership 730 root_window()->SetEventFilter(filter); // passes ownership
731 731
732 test::TestWindowDelegate delegate; 732 test::TestWindowDelegate delegate;
733 gfx::Point window_origin(7, 18); 733 gfx::Point window_origin(7, 18);
734 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 734 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
735 &delegate, 1234, gfx::Rect(window_origin, 735 &delegate, 1234, gfx::Rect(window_origin,
736 gfx::Size(100, 100)), root_window())); 736 gfx::Size(100, 100)), root_window()));
737 window->Show(); 737 window->Show();
738 738
739 // Dispatch a mouse move event into the window. 739 // Dispatch a mouse move event into the window.
740 gfx::Point mouse_location(gfx::Point(15, 25)); 740 gfx::Point mouse_location(gfx::Point(15, 25));
741 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, 741 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location,
742 mouse_location, 0); 742 mouse_location, 0);
743 EXPECT_TRUE(filter->events().empty()); 743 EXPECT_TRUE(filter->events().empty());
744 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); 744 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1);
745 EXPECT_FALSE(filter->events().empty()); 745 EXPECT_FALSE(filter->events().empty());
746 filter->events().clear(); 746 filter->events().clear();
747 747
748 // Hide the cursor and verify a mouse exit was dispatched. 748 // Hide the cursor and verify a mouse exit was dispatched.
749 dispatcher()->OnCursorVisibilityChanged(false); 749 dispatcher()->OnCursorVisibilityChanged(false);
750 EXPECT_FALSE(filter->events().empty()); 750 EXPECT_FALSE(filter->events().empty());
751 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); 751 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events()));
752 752
753 // Verify the mouse exit was dispatched at the correct location 753 // Verify the mouse exit was dispatched at the correct location
754 // (in the correct coordinate space). 754 // (in the correct coordinate space).
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 private: 1175 private:
1176 bool* got_destroying_; 1176 bool* got_destroying_;
1177 bool* has_valid_root_; 1177 bool* has_valid_root_;
1178 1178
1179 DISALLOW_COPY_AND_ASSIGN(ValidRootDuringDestructionWindowObserver); 1179 DISALLOW_COPY_AND_ASSIGN(ValidRootDuringDestructionWindowObserver);
1180 }; 1180 };
1181 1181
1182 } // namespace 1182 } // namespace
1183 1183
1184 #if defined(USE_OZONE) 1184 #if defined(USE_OZONE)
1185 // Creating multiple WindowTreeHostOzone instances is broken. 1185 // Creating multiple RootWindowHostOzone instances is broken.
1186 #define MAYBE_ValidRootDuringDestruction DISABLED_ValidRootDuringDestruction 1186 #define MAYBE_ValidRootDuringDestruction DISABLED_ValidRootDuringDestruction
1187 #else 1187 #else
1188 #define MAYBE_ValidRootDuringDestruction ValidRootDuringDestruction 1188 #define MAYBE_ValidRootDuringDestruction ValidRootDuringDestruction
1189 #endif 1189 #endif
1190 1190
1191 // Verifies GetRootWindow() from ~Window returns a valid root. 1191 // Verifies GetRootWindow() from ~Window returns a valid root.
1192 TEST_F(RootWindowTest, MAYBE_ValidRootDuringDestruction) { 1192 TEST_F(RootWindowTest, MAYBE_ValidRootDuringDestruction) {
1193 bool got_destroying = false; 1193 bool got_destroying = false;
1194 bool has_valid_root = false; 1194 bool has_valid_root = false;
1195 ValidRootDuringDestructionWindowObserver observer(&got_destroying, 1195 ValidRootDuringDestructionWindowObserver observer(&got_destroying,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 } // namespace 1239 } // namespace
1240 1240
1241 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after 1241 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after
1242 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which 1242 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which
1243 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events 1243 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events
1244 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to 1244 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to
1245 // schedule another reposted event. 1245 // schedule another reposted event.
1246 TEST_F(RootWindowTest, DontResetHeldEvent) { 1246 TEST_F(RootWindowTest, DontResetHeldEvent) {
1247 DontResetHeldEventWindowDelegate delegate(root_window()); 1247 DontResetHeldEventWindowDelegate delegate(root_window());
1248 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); 1248 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate));
1249 WindowTreeHostDelegate* root_window_delegate = 1249 RootWindowHostDelegate* root_window_delegate =
1250 static_cast<WindowTreeHostDelegate*>(root_window()->GetDispatcher()); 1250 static_cast<RootWindowHostDelegate*>(root_window()->GetDispatcher());
1251 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); 1251 w1->SetBounds(gfx::Rect(0, 0, 40, 40));
1252 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, 1252 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED,
1253 gfx::Point(10, 10), gfx::Point(10, 10), 1253 gfx::Point(10, 10), gfx::Point(10, 10),
1254 ui::EF_SHIFT_DOWN); 1254 ui::EF_SHIFT_DOWN);
1255 root_window()->GetDispatcher()->RepostEvent(pressed); 1255 root_window()->GetDispatcher()->RepostEvent(pressed);
1256 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, 1256 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED,
1257 gfx::Point(10, 10), gfx::Point(10, 10), 0); 1257 gfx::Point(10, 10), gfx::Point(10, 10), 0);
1258 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent(). 1258 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent().
1259 root_window_delegate->OnHostMouseEvent(&pressed2); 1259 root_window_delegate->OnHostMouseEvent(&pressed2);
1260 // Delegate should have seen reposted event (identified by way of 1260 // Delegate should have seen reposted event (identified by way of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 RootWindow* root_; 1295 RootWindow* root_;
1296 bool got_mouse_event_; 1296 bool got_mouse_event_;
1297 bool got_destroy_; 1297 bool got_destroy_;
1298 1298
1299 DISALLOW_COPY_AND_ASSIGN(DeleteRootFromHeldMouseEventDelegate); 1299 DISALLOW_COPY_AND_ASSIGN(DeleteRootFromHeldMouseEventDelegate);
1300 }; 1300 };
1301 1301
1302 } // namespace 1302 } // namespace
1303 1303
1304 #if defined(USE_OZONE) 1304 #if defined(USE_OZONE)
1305 // Creating multiple WindowTreeHostOzone instances is broken. 1305 // Creating multiple RootWindowHostOzone instances is broken.
1306 #define MAYBE_DeleteRootFromHeldMouseEvent DISABLED_DeleteRootFromHeldMouseEvent 1306 #define MAYBE_DeleteRootFromHeldMouseEvent DISABLED_DeleteRootFromHeldMouseEvent
1307 #else 1307 #else
1308 #define MAYBE_DeleteRootFromHeldMouseEvent DeleteRootFromHeldMouseEvent 1308 #define MAYBE_DeleteRootFromHeldMouseEvent DeleteRootFromHeldMouseEvent
1309 #endif 1309 #endif
1310 1310
1311 // Verifies if a RootWindow is deleted from dispatching a held mouse event we 1311 // Verifies if a RootWindow is deleted from dispatching a held mouse event we
1312 // don't crash. 1312 // don't crash.
1313 TEST_F(RootWindowTest, MAYBE_DeleteRootFromHeldMouseEvent) { 1313 TEST_F(RootWindowTest, MAYBE_DeleteRootFromHeldMouseEvent) {
1314 // Should be deleted by |delegate|. 1314 // Should be deleted by |delegate|.
1315 RootWindow* r2 = 1315 RootWindow* r2 =
1316 new RootWindow(RootWindow::CreateParams(gfx::Rect(0, 0, 100, 100))); 1316 new RootWindow(RootWindow::CreateParams(gfx::Rect(0, 0, 100, 100)));
1317 r2->Init(); 1317 r2->Init();
1318 DeleteRootFromHeldMouseEventDelegate delegate(r2); 1318 DeleteRootFromHeldMouseEventDelegate delegate(r2);
1319 // Owned by |r2|. 1319 // Owned by |r2|.
1320 Window* w1 = CreateNormalWindow(1, r2->window(), &delegate); 1320 Window* w1 = CreateNormalWindow(1, r2->window(), &delegate);
1321 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); 1321 w1->SetBounds(gfx::Rect(0, 0, 40, 40));
1322 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, 1322 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED,
1323 gfx::Point(10, 10), gfx::Point(10, 10), 1323 gfx::Point(10, 10), gfx::Point(10, 10),
1324 ui::EF_SHIFT_DOWN); 1324 ui::EF_SHIFT_DOWN);
1325 r2->RepostEvent(pressed); 1325 r2->RepostEvent(pressed);
1326 // RunAllPendingInMessageLoop() to make sure the |pressed| is run. 1326 // RunAllPendingInMessageLoop() to make sure the |pressed| is run.
1327 RunAllPendingInMessageLoop(); 1327 RunAllPendingInMessageLoop();
1328 EXPECT_TRUE(delegate.got_mouse_event()); 1328 EXPECT_TRUE(delegate.got_mouse_event());
1329 EXPECT_TRUE(delegate.got_destroy()); 1329 EXPECT_TRUE(delegate.got_destroy());
1330 } 1330 }
1331 1331
1332 } // namespace aura 1332 } // namespace aura
OLDNEW
« no previous file with comments | « trunk/src/ui/aura/root_window_observer.h ('k') | trunk/src/ui/aura/test/event_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698