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

Side by Side Diff: ash/wm/window_manager_unittest.cc

Issue 147203004: aura: Remove event-dispatch methods from WindowTreeHostDelegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 10 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 | Annotate | Revision Log
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 "ash/shell.h" 5 #include "ash/shell.h"
6 #include "ash/shell_window_ids.h" 6 #include "ash/shell_window_ids.h"
7 #include "ash/test/ash_test_base.h" 7 #include "ash/test/ash_test_base.h"
8 #include "ash/test/shell_test_api.h" 8 #include "ash/test/shell_test_api.h"
9 #include "ash/test/test_activation_delegate.h" 9 #include "ash/test/test_activation_delegate.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 generator.ClickLeftButton(); 180 generator.ClickLeftButton();
181 181
182 aura::client::FocusClient* focus_client = 182 aura::client::FocusClient* focus_client =
183 aura::client::GetFocusClient(w121.get()); 183 aura::client::GetFocusClient(w121.get());
184 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow()); 184 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow());
185 185
186 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); 186 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher();
187 187
188 // The key press should be sent to the focused sub-window. 188 // The key press should be sent to the focused sub-window.
189 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false); 189 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false);
190 dispatcher->AsWindowTreeHostDelegate()->OnHostKeyEvent(&keyev); 190 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&keyev);
191 ASSERT_FALSE(details.dispatcher_destroyed);
191 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); 192 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code());
192 193
193 // Touch on a sub-window (w122) to focus it. 194 // Touch on a sub-window (w122) to focus it.
194 gfx::Point click_point = w122->bounds().CenterPoint(); 195 gfx::Point click_point = w122->bounds().CenterPoint();
195 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point); 196 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point);
196 ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime()); 197 ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime());
197 dispatcher->AsWindowTreeHostDelegate()->OnHostTouchEvent(&touchev); 198 details = dispatcher->OnEventFromSource(&touchev);
199 ASSERT_FALSE(details.dispatcher_destroyed);
198 focus_client = aura::client::GetFocusClient(w122.get()); 200 focus_client = aura::client::GetFocusClient(w122.get());
199 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow()); 201 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow());
200 202
201 // The key press should be sent to the focused sub-window. 203 // The key press should be sent to the focused sub-window.
202 dispatcher->AsWindowTreeHostDelegate()->OnHostKeyEvent(&keyev); 204 details = dispatcher->OnEventFromSource(&keyev);
205 ASSERT_FALSE(details.dispatcher_destroyed);
203 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); 206 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code());
204 207
205 // Hiding the focused window will set the focus to its parent if 208 // Hiding the focused window will set the focus to its parent if
206 // it's focusable. 209 // it's focusable.
207 w122->Hide(); 210 w122->Hide();
208 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), 211 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
209 aura::client::GetFocusClient(w122.get())); 212 aura::client::GetFocusClient(w122.get()));
210 EXPECT_EQ(w12.get(), 213 EXPECT_EQ(w12.get(),
211 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 214 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
212 215
(...skipping 16 matching lines...) Expand all
229 EXPECT_EQ(w123.get(), 232 EXPECT_EQ(w123.get(),
230 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 233 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
231 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 234 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
232 235
233 // Hiding the focused window will set the focus to NULL because 236 // Hiding the focused window will set the focus to NULL because
234 // parent window is not focusable. 237 // parent window is not focusable.
235 w123->Hide(); 238 w123->Hide();
236 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), 239 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
237 aura::client::GetFocusClient(w123.get())); 240 aura::client::GetFocusClient(w123.get()));
238 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 241 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
239 EXPECT_FALSE(dispatcher->AsWindowTreeHostDelegate()->OnHostKeyEvent(&keyev)); 242 details = dispatcher->OnEventFromSource(&keyev);
243 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
240 244
241 // Set the focus back to w123 245 // Set the focus back to w123
242 aura::client::SetActivationDelegate(w1.get(), NULL); 246 aura::client::SetActivationDelegate(w1.get(), NULL);
243 w123->Show(); 247 w123->Show();
244 w123->Focus(); 248 w123->Focus();
245 EXPECT_EQ(w123.get(), 249 EXPECT_EQ(w123.get(),
246 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 250 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
247 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 251 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
248 252
249 // Removing the focused window will set the focus to NULL because 253 // Removing the focused window will set the focus to NULL because
250 // parent window is not focusable. 254 // parent window is not focusable.
251 w12->RemoveChild(w123.get()); 255 w12->RemoveChild(w123.get());
252 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); 256 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get()));
253 EXPECT_FALSE(dispatcher->AsWindowTreeHostDelegate()->OnHostKeyEvent(&keyev)); 257 details = dispatcher->OnEventFromSource(&keyev);
258 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
254 } 259 }
255 260
256 // Various assertion testing for activating windows. 261 // Various assertion testing for activating windows.
257 TEST_F(WindowManagerTest, ActivateOnMouse) { 262 TEST_F(WindowManagerTest, ActivateOnMouse) {
258 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 263 aura::Window* root_window = Shell::GetPrimaryRootWindow();
259 264
260 test::TestActivationDelegate d1; 265 test::TestActivationDelegate d1;
261 aura::test::TestWindowDelegate wd; 266 aura::test::TestWindowDelegate wd;
262 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( 267 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
263 &wd, -1, gfx::Rect(10, 10, 50, 50))); 268 &wd, -1, gfx::Rect(10, 10, 50, 50)));
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 EXPECT_EQ(1, d1.activated_count()); 440 EXPECT_EQ(1, d1.activated_count());
436 EXPECT_EQ(0, d1.lost_active_count()); 441 EXPECT_EQ(0, d1.lost_active_count());
437 d1.Clear(); 442 d1.Clear();
438 443
439 // Touch window2. 444 // Touch window2.
440 gfx::Point press_point = w2->bounds().CenterPoint(); 445 gfx::Point press_point = w2->bounds().CenterPoint();
441 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point); 446 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point);
442 ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime()); 447 ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime());
443 448
444 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); 449 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher();
445 dispatcher->AsWindowTreeHostDelegate()->OnHostTouchEvent(&touchev1); 450 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&touchev1);
451 ASSERT_FALSE(details.dispatcher_destroyed);
446 452
447 // Window2 should have become active. 453 // Window2 should have become active.
448 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 454 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
449 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); 455 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
450 EXPECT_EQ(0, d1.activated_count()); 456 EXPECT_EQ(0, d1.activated_count());
451 EXPECT_EQ(1, d1.lost_active_count()); 457 EXPECT_EQ(1, d1.lost_active_count());
452 EXPECT_EQ(1, d2.activated_count()); 458 EXPECT_EQ(1, d2.activated_count());
453 EXPECT_EQ(0, d2.lost_active_count()); 459 EXPECT_EQ(0, d2.lost_active_count());
454 d1.Clear(); 460 d1.Clear();
455 d2.Clear(); 461 d2.Clear();
456 462
457 // Touch window1, but set it up so w1 doesn't activate on touch. 463 // Touch window1, but set it up so w1 doesn't activate on touch.
458 press_point = w1->bounds().CenterPoint(); 464 press_point = w1->bounds().CenterPoint();
459 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point); 465 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point);
460 d1.set_activate(false); 466 d1.set_activate(false);
461 ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime()); 467 ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime());
462 dispatcher->AsWindowTreeHostDelegate()->OnHostTouchEvent(&touchev2); 468 details = dispatcher->OnEventFromSource(&touchev2);
469 ASSERT_FALSE(details.dispatcher_destroyed);
463 470
464 // Window2 should still be active and focused. 471 // Window2 should still be active and focused.
465 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 472 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
466 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); 473 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
467 EXPECT_EQ(0, d1.activated_count()); 474 EXPECT_EQ(0, d1.activated_count());
468 EXPECT_EQ(0, d1.lost_active_count()); 475 EXPECT_EQ(0, d1.lost_active_count());
469 EXPECT_EQ(0, d2.activated_count()); 476 EXPECT_EQ(0, d2.activated_count());
470 EXPECT_EQ(0, d2.lost_active_count()); 477 EXPECT_EQ(0, d2.lost_active_count());
471 d1.Clear(); 478 d1.Clear();
472 d2.Clear(); 479 d2.Clear();
(...skipping 30 matching lines...) Expand all
503 510
504 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); 511 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher();
505 512
506 // Cursor starts as a pointer (set during Shell::Init()). 513 // Cursor starts as a pointer (set during Shell::Init()).
507 EXPECT_EQ(ui::kCursorPointer, dispatcher->last_cursor().native_type()); 514 EXPECT_EQ(ui::kCursorPointer, dispatcher->last_cursor().native_type());
508 515
509 { 516 {
510 // Resize edges and corners show proper cursors. 517 // Resize edges and corners show proper cursors.
511 window_delegate.set_hittest_code(HTBOTTOM); 518 window_delegate.set_hittest_code(HTBOTTOM);
512 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); 519 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
513 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move1); 520 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
521 ASSERT_FALSE(details.dispatcher_destroyed);
514 EXPECT_EQ(ui::kCursorSouthResize, dispatcher->last_cursor().native_type()); 522 EXPECT_EQ(ui::kCursorSouthResize, dispatcher->last_cursor().native_type());
515 } 523 }
516 524
517 { 525 {
518 window_delegate.set_hittest_code(HTBOTTOMLEFT); 526 window_delegate.set_hittest_code(HTBOTTOMLEFT);
519 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); 527 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
520 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move2); 528 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
529 ASSERT_FALSE(details.dispatcher_destroyed);
521 EXPECT_EQ(ui::kCursorSouthWestResize, 530 EXPECT_EQ(ui::kCursorSouthWestResize,
522 dispatcher->last_cursor().native_type()); 531 dispatcher->last_cursor().native_type());
523 } 532 }
524 533
525 { 534 {
526 window_delegate.set_hittest_code(HTBOTTOMRIGHT); 535 window_delegate.set_hittest_code(HTBOTTOMRIGHT);
527 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); 536 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
528 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move1); 537 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
538 ASSERT_FALSE(details.dispatcher_destroyed);
529 EXPECT_EQ(ui::kCursorSouthEastResize, 539 EXPECT_EQ(ui::kCursorSouthEastResize,
530 dispatcher->last_cursor().native_type()); 540 dispatcher->last_cursor().native_type());
531 } 541 }
532 542
533 { 543 {
534 window_delegate.set_hittest_code(HTLEFT); 544 window_delegate.set_hittest_code(HTLEFT);
535 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); 545 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
536 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move2); 546 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
547 ASSERT_FALSE(details.dispatcher_destroyed);
537 EXPECT_EQ(ui::kCursorWestResize, dispatcher->last_cursor().native_type()); 548 EXPECT_EQ(ui::kCursorWestResize, dispatcher->last_cursor().native_type());
538 } 549 }
539 550
540 { 551 {
541 window_delegate.set_hittest_code(HTRIGHT); 552 window_delegate.set_hittest_code(HTRIGHT);
542 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); 553 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
543 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move1); 554 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
555 ASSERT_FALSE(details.dispatcher_destroyed);
544 EXPECT_EQ(ui::kCursorEastResize, dispatcher->last_cursor().native_type()); 556 EXPECT_EQ(ui::kCursorEastResize, dispatcher->last_cursor().native_type());
545 } 557 }
546 558
547 { 559 {
548 window_delegate.set_hittest_code(HTTOP); 560 window_delegate.set_hittest_code(HTTOP);
549 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); 561 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
550 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move2); 562 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
563 ASSERT_FALSE(details.dispatcher_destroyed);
551 EXPECT_EQ(ui::kCursorNorthResize, dispatcher->last_cursor().native_type()); 564 EXPECT_EQ(ui::kCursorNorthResize, dispatcher->last_cursor().native_type());
552 } 565 }
553 566
554 { 567 {
555 window_delegate.set_hittest_code(HTTOPLEFT); 568 window_delegate.set_hittest_code(HTTOPLEFT);
556 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); 569 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
557 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move1); 570 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
571 ASSERT_FALSE(details.dispatcher_destroyed);
558 EXPECT_EQ(ui::kCursorNorthWestResize, 572 EXPECT_EQ(ui::kCursorNorthWestResize,
559 dispatcher->last_cursor().native_type()); 573 dispatcher->last_cursor().native_type());
560 } 574 }
561 575
562 { 576 {
563 window_delegate.set_hittest_code(HTTOPRIGHT); 577 window_delegate.set_hittest_code(HTTOPRIGHT);
564 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0); 578 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
565 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move2); 579 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
580 ASSERT_FALSE(details.dispatcher_destroyed);
566 EXPECT_EQ(ui::kCursorNorthEastResize, 581 EXPECT_EQ(ui::kCursorNorthEastResize,
567 dispatcher->last_cursor().native_type()); 582 dispatcher->last_cursor().native_type());
568 } 583 }
569 584
570 { 585 {
571 // Client area uses null cursor. 586 // Client area uses null cursor.
572 window_delegate.set_hittest_code(HTCLIENT); 587 window_delegate.set_hittest_code(HTCLIENT);
573 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0); 588 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
574 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&move1); 589 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
590 ASSERT_FALSE(details.dispatcher_destroyed);
575 EXPECT_EQ(ui::kCursorNull, dispatcher->last_cursor().native_type()); 591 EXPECT_EQ(ui::kCursorNull, dispatcher->last_cursor().native_type());
576 } 592 }
577 } 593 }
578 594
579 #if defined(OS_WIN) 595 #if defined(OS_WIN)
580 #define MAYBE_TransformActivate DISABLED_TransformActivate 596 #define MAYBE_TransformActivate DISABLED_TransformActivate
581 #else 597 #else
582 #define MAYBE_TransformActivate TransformActivate 598 #define MAYBE_TransformActivate TransformActivate
583 #endif 599 #endif
584 TEST_F(WindowManagerTest, MAYBE_TransformActivate) { 600 TEST_F(WindowManagerTest, MAYBE_TransformActivate) {
(...skipping 17 matching lines...) Expand all
602 w1->Show(); 618 w1->Show();
603 619
604 gfx::Point miss_point(5, 5); 620 gfx::Point miss_point(5, 5);
605 transform.TransformPoint(&miss_point); 621 transform.TransformPoint(&miss_point);
606 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, 622 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED,
607 miss_point, 623 miss_point,
608 miss_point, 624 miss_point,
609 ui::EF_LEFT_MOUSE_BUTTON, 625 ui::EF_LEFT_MOUSE_BUTTON,
610 ui::EF_LEFT_MOUSE_BUTTON); 626 ui::EF_LEFT_MOUSE_BUTTON);
611 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); 627 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher();
612 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouseev1); 628 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&mouseev1);
629 ASSERT_FALSE(details.dispatcher_destroyed);
613 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); 630 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
614 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, 631 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED,
615 miss_point, 632 miss_point,
616 miss_point, 633 miss_point,
617 ui::EF_LEFT_MOUSE_BUTTON, 634 ui::EF_LEFT_MOUSE_BUTTON,
618 ui::EF_LEFT_MOUSE_BUTTON); 635 ui::EF_LEFT_MOUSE_BUTTON);
619 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouseup); 636 details = dispatcher->OnEventFromSource(&mouseup);
637 ASSERT_FALSE(details.dispatcher_destroyed);
620 638
621 gfx::Point hit_point(5, 15); 639 gfx::Point hit_point(5, 15);
622 transform.TransformPoint(&hit_point); 640 transform.TransformPoint(&hit_point);
623 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, 641 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED,
624 hit_point, 642 hit_point,
625 hit_point, 643 hit_point,
626 ui::EF_LEFT_MOUSE_BUTTON, 644 ui::EF_LEFT_MOUSE_BUTTON,
627 ui::EF_LEFT_MOUSE_BUTTON); 645 ui::EF_LEFT_MOUSE_BUTTON);
628 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouseev2); 646 details = dispatcher->OnEventFromSource(&mouseev2);
647 ASSERT_FALSE(details.dispatcher_destroyed);
629 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 648 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
630 EXPECT_EQ(w1.get(), 649 EXPECT_EQ(w1.get(),
631 aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); 650 aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
632 } 651 }
633 652
634 TEST_F(WindowManagerTest, AdditionalFilters) { 653 TEST_F(WindowManagerTest, AdditionalFilters) {
635 // The IME event filter interferes with the basic key event propagation we 654 // The IME event filter interferes with the basic key event propagation we
636 // attempt to do here, so we remove it. 655 // attempt to do here, so we remove it.
637 test::ShellTestApi shell_test(Shell::GetInstance()); 656 test::ShellTestApi shell_test(Shell::GetInstance());
638 Shell::GetInstance()->RemovePreTargetHandler( 657 Shell::GetInstance()->RemovePreTargetHandler(
(...skipping 12 matching lines...) Expand all
651 670
652 // Adds them to root window event filter. 671 // Adds them to root window event filter.
653 views::corewm::CompoundEventFilter* env_filter = 672 views::corewm::CompoundEventFilter* env_filter =
654 Shell::GetInstance()->env_filter(); 673 Shell::GetInstance()->env_filter();
655 env_filter->AddHandler(f1.get()); 674 env_filter->AddHandler(f1.get());
656 env_filter->AddHandler(f2.get()); 675 env_filter->AddHandler(f2.get());
657 676
658 // Dispatches mouse and keyboard events. 677 // Dispatches mouse and keyboard events.
659 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); 678 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
660 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); 679 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher();
661 dispatcher->AsWindowTreeHostDelegate()->OnHostKeyEvent(&key_event); 680 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event);
681 ASSERT_FALSE(details.dispatcher_destroyed);
662 ui::MouseEvent mouse_pressed( 682 ui::MouseEvent mouse_pressed(
663 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); 683 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
664 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_pressed); 684 details = dispatcher->OnEventFromSource(&mouse_pressed);
685 ASSERT_FALSE(details.dispatcher_destroyed);
665 686
666 // Both filters should get the events. 687 // Both filters should get the events.
667 EXPECT_EQ(1, f1->num_key_events()); 688 EXPECT_EQ(1, f1->num_key_events());
668 EXPECT_EQ(1, f1->num_mouse_events()); 689 EXPECT_EQ(1, f1->num_mouse_events());
669 EXPECT_EQ(1, f2->num_key_events()); 690 EXPECT_EQ(1, f2->num_key_events());
670 EXPECT_EQ(1, f2->num_mouse_events()); 691 EXPECT_EQ(1, f2->num_mouse_events());
671 692
672 f1->Reset(); 693 f1->Reset();
673 f2->Reset(); 694 f2->Reset();
674 695
675 // Makes f1 consume events. 696 // Makes f1 consume events.
676 f1->set_key_event_handling_result(ui::ER_CONSUMED); 697 f1->set_key_event_handling_result(ui::ER_CONSUMED);
677 f1->set_mouse_event_handling_result(ui::ER_CONSUMED); 698 f1->set_mouse_event_handling_result(ui::ER_CONSUMED);
678 699
679 // Dispatches events. 700 // Dispatches events.
680 dispatcher->AsWindowTreeHostDelegate()->OnHostKeyEvent(&key_event); 701 details = dispatcher->OnEventFromSource(&key_event);
702 ASSERT_FALSE(details.dispatcher_destroyed);
681 ui::MouseEvent mouse_released( 703 ui::MouseEvent mouse_released(
682 ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0); 704 ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
683 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_released); 705 details = dispatcher->OnEventFromSource(&mouse_released);
706 ASSERT_FALSE(details.dispatcher_destroyed);
684 707
685 // f1 should still get the events but f2 no longer gets them. 708 // f1 should still get the events but f2 no longer gets them.
686 EXPECT_EQ(1, f1->num_key_events()); 709 EXPECT_EQ(1, f1->num_key_events());
687 EXPECT_EQ(1, f1->num_mouse_events()); 710 EXPECT_EQ(1, f1->num_mouse_events());
688 EXPECT_EQ(0, f2->num_key_events()); 711 EXPECT_EQ(0, f2->num_key_events());
689 EXPECT_EQ(0, f2->num_mouse_events()); 712 EXPECT_EQ(0, f2->num_mouse_events());
690 713
691 f1->Reset(); 714 f1->Reset();
692 f2->Reset(); 715 f2->Reset();
693 716
694 // Remove f1 from additonal filters list. 717 // Remove f1 from additonal filters list.
695 env_filter->RemoveHandler(f1.get()); 718 env_filter->RemoveHandler(f1.get());
696 719
697 // Dispatches events. 720 // Dispatches events.
698 dispatcher->AsWindowTreeHostDelegate()->OnHostKeyEvent(&key_event); 721 details = dispatcher->OnEventFromSource(&key_event);
699 dispatcher->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse_pressed); 722 ASSERT_FALSE(details.dispatcher_destroyed);
723 details = dispatcher->OnEventFromSource(&mouse_pressed);
724 ASSERT_FALSE(details.dispatcher_destroyed);
700 725
701 // f1 should get no events since it's out and f2 should get them. 726 // f1 should get no events since it's out and f2 should get them.
702 EXPECT_EQ(0, f1->num_key_events()); 727 EXPECT_EQ(0, f1->num_key_events());
703 EXPECT_EQ(0, f1->num_mouse_events()); 728 EXPECT_EQ(0, f1->num_mouse_events());
704 EXPECT_EQ(1, f2->num_key_events()); 729 EXPECT_EQ(1, f2->num_key_events());
705 EXPECT_EQ(1, f2->num_mouse_events()); 730 EXPECT_EQ(1, f2->num_mouse_events());
706 731
707 env_filter->RemoveHandler(f2.get()); 732 env_filter->RemoveHandler(f2.get());
708 } 733 }
709 734
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 observer_a.reset(); 835 observer_a.reset();
811 observer_b.reset(); 836 observer_b.reset();
812 generator.MoveMouseTo(50, 50); 837 generator.MoveMouseTo(50, 50);
813 EXPECT_TRUE(observer_a.did_visibility_change()); 838 EXPECT_TRUE(observer_a.did_visibility_change());
814 EXPECT_FALSE(observer_b.did_visibility_change()); 839 EXPECT_FALSE(observer_b.did_visibility_change());
815 EXPECT_TRUE(observer_a.is_cursor_visible()); 840 EXPECT_TRUE(observer_a.is_cursor_visible());
816 } 841 }
817 #endif // defined(OS_CHROMEOS) 842 #endif // defined(OS_CHROMEOS)
818 843
819 } // namespace ash 844 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/system_gesture_event_filter_unittest.cc ('k') | ash/wm/workspace/workspace_event_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698