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

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

Issue 2712963003: mustash: Use ui::chromeos::EventRewriter in mus (Closed)
Patch Set: Fix build issues. Created 3 years, 9 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) 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/common/wm_shell.h" 5 #include "ash/common/wm_shell.h"
6 #include "ash/public/cpp/shell_window_ids.h" 6 #include "ash/public/cpp/shell_window_ids.h"
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.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"
11 #include "ui/aura/client/cursor_client_observer.h" 11 #include "ui/aura/client/cursor_client_observer.h"
12 #include "ui/aura/client/focus_client.h" 12 #include "ui/aura/client/focus_client.h"
13 #include "ui/aura/env.h" 13 #include "ui/aura/env.h"
14 #include "ui/aura/test/aura_test_base.h" 14 #include "ui/aura/test/aura_test_base.h"
15 #include "ui/aura/test/test_window_delegate.h" 15 #include "ui/aura/test/test_window_delegate.h"
16 #include "ui/aura/test/test_windows.h" 16 #include "ui/aura/test/test_windows.h"
17 #include "ui/base/cursor/cursor.h" 17 #include "ui/base/cursor/cursor.h"
18 #include "ui/base/hit_test.h" 18 #include "ui/base/hit_test.h"
19 #include "ui/display/screen.h" 19 #include "ui/display/screen.h"
20 #include "ui/events/event.h" 20 #include "ui/events/event.h"
21 #include "ui/events/event_processor.h" 21 #include "ui/events/event_sink.h"
22 #include "ui/events/event_utils.h" 22 #include "ui/events/event_utils.h"
23 #include "ui/events/test/event_generator.h" 23 #include "ui/events/test/event_generator.h"
24 #include "ui/events/test/test_event_handler.h" 24 #include "ui/events/test/test_event_handler.h"
25 #include "ui/wm/core/compound_event_filter.h" 25 #include "ui/wm/core/compound_event_filter.h"
26 #include "ui/wm/public/activation_client.h" 26 #include "ui/wm/public/activation_client.h"
27 #include "ui/wm/public/activation_delegate.h" 27 #include "ui/wm/public/activation_delegate.h"
28 #include "ui/wm/test/testing_cursor_client_observer.h" 28 #include "ui/wm/test/testing_cursor_client_observer.h"
29 29
30 namespace { 30 namespace {
31 31
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get())); 144 SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get()));
145 145
146 // Click on a sub-window (w121) to focus it. 146 // Click on a sub-window (w121) to focus it.
147 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w121.get()); 147 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w121.get());
148 generator.ClickLeftButton(); 148 generator.ClickLeftButton();
149 149
150 aura::client::FocusClient* focus_client = 150 aura::client::FocusClient* focus_client =
151 aura::client::GetFocusClient(w121.get()); 151 aura::client::GetFocusClient(w121.get());
152 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow()); 152 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow());
153 153
154 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); 154 ui::EventSink* sink = root_window->GetHost()->event_sink();
155 155
156 // The key press should be sent to the focused sub-window. 156 // The key press should be sent to the focused sub-window.
157 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 157 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
158 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&keyev); 158 ui::EventDispatchDetails details = sink->OnEventFromSource(&keyev);
159 ASSERT_FALSE(details.dispatcher_destroyed); 159 ASSERT_FALSE(details.dispatcher_destroyed);
160 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); 160 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code());
161 161
162 // Touch on a sub-window (w122) to focus it. 162 // Touch on a sub-window (w122) to focus it.
163 gfx::Point click_point = w122->bounds().CenterPoint(); 163 gfx::Point click_point = w122->bounds().CenterPoint();
164 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point); 164 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point);
165 ui::TouchEvent touchev( 165 ui::TouchEvent touchev(
166 ui::ET_TOUCH_PRESSED, click_point, getTime(), 166 ui::ET_TOUCH_PRESSED, click_point, getTime(),
167 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); 167 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
168 details = dispatcher->OnEventFromSource(&touchev); 168 details = sink->OnEventFromSource(&touchev);
169 ASSERT_FALSE(details.dispatcher_destroyed); 169 ASSERT_FALSE(details.dispatcher_destroyed);
170 focus_client = aura::client::GetFocusClient(w122.get()); 170 focus_client = aura::client::GetFocusClient(w122.get());
171 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow()); 171 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow());
172 172
173 // The key press should be sent to the focused sub-window. 173 // The key press should be sent to the focused sub-window.
174 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 174 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
175 details = dispatcher->OnEventFromSource(&keyev); 175 details = sink->OnEventFromSource(&keyev);
176 ASSERT_FALSE(details.dispatcher_destroyed); 176 ASSERT_FALSE(details.dispatcher_destroyed);
177 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); 177 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code());
178 178
179 // Hiding the focused window will set the focus to its parent if 179 // Hiding the focused window will set the focus to its parent if
180 // it's focusable. 180 // it's focusable.
181 w122->Hide(); 181 w122->Hide();
182 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), 182 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
183 aura::client::GetFocusClient(w122.get())); 183 aura::client::GetFocusClient(w122.get()));
184 EXPECT_EQ(w12.get(), 184 EXPECT_EQ(w12.get(),
185 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 185 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
(...skipping 18 matching lines...) Expand all
204 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 204 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
205 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 205 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
206 206
207 // Hiding the focused window will set the focus to NULL because 207 // Hiding the focused window will set the focus to NULL because
208 // parent window is not focusable. 208 // parent window is not focusable.
209 w123->Hide(); 209 w123->Hide();
210 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), 210 EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
211 aura::client::GetFocusClient(w123.get())); 211 aura::client::GetFocusClient(w123.get()));
212 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 212 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
213 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 213 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
214 details = dispatcher->OnEventFromSource(&keyev); 214 details = sink->OnEventFromSource(&keyev);
215 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed); 215 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
216 216
217 // Set the focus back to w123 217 // Set the focus back to w123
218 aura::client::SetActivationDelegate(w1.get(), NULL); 218 aura::client::SetActivationDelegate(w1.get(), NULL);
219 w123->Show(); 219 w123->Show();
220 w123->Focus(); 220 w123->Focus();
221 EXPECT_EQ(w123.get(), 221 EXPECT_EQ(w123.get(),
222 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); 222 aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
223 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); 223 aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
224 224
225 // Removing the focused window will set the focus to NULL because 225 // Removing the focused window will set the focus to NULL because
226 // parent window is not focusable. 226 // parent window is not focusable.
227 w12->RemoveChild(w123.get()); 227 w12->RemoveChild(w123.get());
228 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); 228 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get()));
229 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE); 229 keyev = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, ui::EF_NONE);
230 details = dispatcher->OnEventFromSource(&keyev); 230 details = sink->OnEventFromSource(&keyev);
231 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed); 231 EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
232 232
233 // Must set to NULL since the activation delegate will be destroyed before 233 // Must set to NULL since the activation delegate will be destroyed before
234 // the windows. 234 // the windows.
235 aura::client::SetActivationDelegate(w1.get(), NULL); 235 aura::client::SetActivationDelegate(w1.get(), NULL);
236 } 236 }
237 237
238 // Various assertion testing for activating windows. 238 // Various assertion testing for activating windows.
239 TEST_F(WindowManagerTest, ActivateOnMouse) { 239 TEST_F(WindowManagerTest, ActivateOnMouse) {
240 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 240 aura::Window* root_window = Shell::GetPrimaryRootWindow();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 EXPECT_EQ(0, d1.lost_active_count()); 415 EXPECT_EQ(0, d1.lost_active_count());
416 d1.Clear(); 416 d1.Clear();
417 417
418 // Touch window2. 418 // Touch window2.
419 gfx::Point press_point = w2->bounds().CenterPoint(); 419 gfx::Point press_point = w2->bounds().CenterPoint();
420 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point); 420 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point);
421 ui::TouchEvent touchev1( 421 ui::TouchEvent touchev1(
422 ui::ET_TOUCH_PRESSED, press_point, getTime(), 422 ui::ET_TOUCH_PRESSED, press_point, getTime(),
423 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); 423 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
424 424
425 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); 425 ui::EventSink* sink = root_window->GetHost()->event_sink();
426 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&touchev1); 426 ui::EventDispatchDetails details = sink->OnEventFromSource(&touchev1);
427 ASSERT_FALSE(details.dispatcher_destroyed); 427 ASSERT_FALSE(details.dispatcher_destroyed);
428 428
429 // Window2 should have become active. 429 // Window2 should have become active.
430 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 430 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
431 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); 431 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
432 EXPECT_EQ(0, d1.activated_count()); 432 EXPECT_EQ(0, d1.activated_count());
433 EXPECT_EQ(1, d1.lost_active_count()); 433 EXPECT_EQ(1, d1.lost_active_count());
434 EXPECT_EQ(1, d2.activated_count()); 434 EXPECT_EQ(1, d2.activated_count());
435 EXPECT_EQ(0, d2.lost_active_count()); 435 EXPECT_EQ(0, d2.lost_active_count());
436 d1.Clear(); 436 d1.Clear();
437 d2.Clear(); 437 d2.Clear();
438 438
439 // Touch window1, but set it up so w1 doesn't activate on touch. 439 // Touch window1, but set it up so w1 doesn't activate on touch.
440 press_point = w1->bounds().CenterPoint(); 440 press_point = w1->bounds().CenterPoint();
441 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point); 441 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point);
442 d1.set_activate(false); 442 d1.set_activate(false);
443 ui::TouchEvent touchev2( 443 ui::TouchEvent touchev2(
444 ui::ET_TOUCH_PRESSED, press_point, getTime(), 444 ui::ET_TOUCH_PRESSED, press_point, getTime(),
445 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1)); 445 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1));
446 details = dispatcher->OnEventFromSource(&touchev2); 446 details = sink->OnEventFromSource(&touchev2);
447 ASSERT_FALSE(details.dispatcher_destroyed); 447 ASSERT_FALSE(details.dispatcher_destroyed);
448 448
449 // Window2 should still be active and focused. 449 // Window2 should still be active and focused.
450 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); 450 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
451 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); 451 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
452 EXPECT_EQ(0, d1.activated_count()); 452 EXPECT_EQ(0, d1.activated_count());
453 EXPECT_EQ(0, d1.lost_active_count()); 453 EXPECT_EQ(0, d1.lost_active_count());
454 EXPECT_EQ(0, d2.activated_count()); 454 EXPECT_EQ(0, d2.activated_count());
455 EXPECT_EQ(0, d2.lost_active_count()); 455 EXPECT_EQ(0, d2.lost_active_count());
456 d1.Clear(); 456 d1.Clear();
(...skipping 25 matching lines...) Expand all
482 &window_delegate, -1, gfx::Rect(kWindowLeft, kWindowTop, 640, 480))); 482 &window_delegate, -1, gfx::Rect(kWindowLeft, kWindowTop, 640, 480)));
483 483
484 // Create two mouse movement events we can switch between. 484 // Create two mouse movement events we can switch between.
485 gfx::Point point1(kWindowLeft, kWindowTop); 485 gfx::Point point1(kWindowLeft, kWindowTop);
486 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1); 486 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1);
487 487
488 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); 488 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1);
489 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2); 489 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2);
490 490
491 aura::WindowTreeHost* host = root_window->GetHost(); 491 aura::WindowTreeHost* host = root_window->GetHost();
492 ui::EventProcessor* dispatcher = host->event_processor(); 492 ui::EventSink* sink = host->event_sink();
493 493
494 // Cursor starts as a pointer (set during Shell::Init()). 494 // Cursor starts as a pointer (set during Shell::Init()).
495 EXPECT_EQ(ui::kCursorPointer, host->last_cursor().native_type()); 495 EXPECT_EQ(ui::kCursorPointer, host->last_cursor().native_type());
496 496
497 { 497 {
498 // Resize edges and corners show proper cursors. 498 // Resize edges and corners show proper cursors.
499 window_delegate.set_hittest_code(HTBOTTOM); 499 window_delegate.set_hittest_code(HTBOTTOM);
500 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 500 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1,
501 ui::EventTimeForNow(), 0, 0); 501 ui::EventTimeForNow(), 0, 0);
502 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); 502 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1);
503 ASSERT_FALSE(details.dispatcher_destroyed); 503 ASSERT_FALSE(details.dispatcher_destroyed);
504 EXPECT_EQ(ui::kCursorSouthResize, host->last_cursor().native_type()); 504 EXPECT_EQ(ui::kCursorSouthResize, host->last_cursor().native_type());
505 } 505 }
506 506
507 { 507 {
508 window_delegate.set_hittest_code(HTBOTTOMLEFT); 508 window_delegate.set_hittest_code(HTBOTTOMLEFT);
509 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 509 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2,
510 ui::EventTimeForNow(), 0, 0); 510 ui::EventTimeForNow(), 0, 0);
511 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); 511 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2);
512 ASSERT_FALSE(details.dispatcher_destroyed); 512 ASSERT_FALSE(details.dispatcher_destroyed);
513 EXPECT_EQ(ui::kCursorSouthWestResize, host->last_cursor().native_type()); 513 EXPECT_EQ(ui::kCursorSouthWestResize, host->last_cursor().native_type());
514 } 514 }
515 515
516 { 516 {
517 window_delegate.set_hittest_code(HTBOTTOMRIGHT); 517 window_delegate.set_hittest_code(HTBOTTOMRIGHT);
518 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 518 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1,
519 ui::EventTimeForNow(), 0, 0); 519 ui::EventTimeForNow(), 0, 0);
520 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); 520 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1);
521 ASSERT_FALSE(details.dispatcher_destroyed); 521 ASSERT_FALSE(details.dispatcher_destroyed);
522 EXPECT_EQ(ui::kCursorSouthEastResize, host->last_cursor().native_type()); 522 EXPECT_EQ(ui::kCursorSouthEastResize, host->last_cursor().native_type());
523 } 523 }
524 524
525 { 525 {
526 window_delegate.set_hittest_code(HTLEFT); 526 window_delegate.set_hittest_code(HTLEFT);
527 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 527 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2,
528 ui::EventTimeForNow(), 0, 0); 528 ui::EventTimeForNow(), 0, 0);
529 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); 529 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2);
530 ASSERT_FALSE(details.dispatcher_destroyed); 530 ASSERT_FALSE(details.dispatcher_destroyed);
531 EXPECT_EQ(ui::kCursorWestResize, host->last_cursor().native_type()); 531 EXPECT_EQ(ui::kCursorWestResize, host->last_cursor().native_type());
532 } 532 }
533 533
534 { 534 {
535 window_delegate.set_hittest_code(HTRIGHT); 535 window_delegate.set_hittest_code(HTRIGHT);
536 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 536 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1,
537 ui::EventTimeForNow(), 0, 0); 537 ui::EventTimeForNow(), 0, 0);
538 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); 538 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1);
539 ASSERT_FALSE(details.dispatcher_destroyed); 539 ASSERT_FALSE(details.dispatcher_destroyed);
540 EXPECT_EQ(ui::kCursorEastResize, host->last_cursor().native_type()); 540 EXPECT_EQ(ui::kCursorEastResize, host->last_cursor().native_type());
541 } 541 }
542 542
543 { 543 {
544 window_delegate.set_hittest_code(HTTOP); 544 window_delegate.set_hittest_code(HTTOP);
545 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 545 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2,
546 ui::EventTimeForNow(), 0, 0); 546 ui::EventTimeForNow(), 0, 0);
547 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); 547 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2);
548 ASSERT_FALSE(details.dispatcher_destroyed); 548 ASSERT_FALSE(details.dispatcher_destroyed);
549 EXPECT_EQ(ui::kCursorNorthResize, host->last_cursor().native_type()); 549 EXPECT_EQ(ui::kCursorNorthResize, host->last_cursor().native_type());
550 } 550 }
551 551
552 { 552 {
553 window_delegate.set_hittest_code(HTTOPLEFT); 553 window_delegate.set_hittest_code(HTTOPLEFT);
554 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 554 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1,
555 ui::EventTimeForNow(), 0, 0); 555 ui::EventTimeForNow(), 0, 0);
556 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); 556 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1);
557 ASSERT_FALSE(details.dispatcher_destroyed); 557 ASSERT_FALSE(details.dispatcher_destroyed);
558 EXPECT_EQ(ui::kCursorNorthWestResize, host->last_cursor().native_type()); 558 EXPECT_EQ(ui::kCursorNorthWestResize, host->last_cursor().native_type());
559 } 559 }
560 560
561 { 561 {
562 window_delegate.set_hittest_code(HTTOPRIGHT); 562 window_delegate.set_hittest_code(HTTOPRIGHT);
563 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 563 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2,
564 ui::EventTimeForNow(), 0, 0); 564 ui::EventTimeForNow(), 0, 0);
565 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2); 565 ui::EventDispatchDetails details = sink->OnEventFromSource(&move2);
566 ASSERT_FALSE(details.dispatcher_destroyed); 566 ASSERT_FALSE(details.dispatcher_destroyed);
567 EXPECT_EQ(ui::kCursorNorthEastResize, host->last_cursor().native_type()); 567 EXPECT_EQ(ui::kCursorNorthEastResize, host->last_cursor().native_type());
568 } 568 }
569 569
570 { 570 {
571 // Client area uses null cursor. 571 // Client area uses null cursor.
572 window_delegate.set_hittest_code(HTCLIENT); 572 window_delegate.set_hittest_code(HTCLIENT);
573 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 573 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1,
574 ui::EventTimeForNow(), 0, 0); 574 ui::EventTimeForNow(), 0, 0);
575 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1); 575 ui::EventDispatchDetails details = sink->OnEventFromSource(&move1);
576 ASSERT_FALSE(details.dispatcher_destroyed); 576 ASSERT_FALSE(details.dispatcher_destroyed);
577 EXPECT_EQ(ui::kCursorNull, host->last_cursor().native_type()); 577 EXPECT_EQ(ui::kCursorNull, host->last_cursor().native_type());
578 } 578 }
579 } 579 }
580 580
581 TEST_F(WindowManagerTest, TransformActivate) { 581 TEST_F(WindowManagerTest, TransformActivate) {
582 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 582 aura::Window* root_window = Shell::GetPrimaryRootWindow();
583 gfx::Size size = root_window->bounds().size(); 583 gfx::Size size = root_window->bounds().size();
584 EXPECT_EQ(gfx::Rect(size).ToString(), 584 EXPECT_EQ(gfx::Rect(size).ToString(),
585 display::Screen::GetScreen() 585 display::Screen::GetScreen()
(...skipping 12 matching lines...) Expand all
598 std::unique_ptr<aura::Window> w1( 598 std::unique_ptr<aura::Window> w1(
599 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 15, 50, 50))); 599 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 15, 50, 50)));
600 d1.SetWindow(w1.get()); 600 d1.SetWindow(w1.get());
601 w1->Show(); 601 w1->Show();
602 602
603 gfx::Point miss_point(5, 5); 603 gfx::Point miss_point(5, 5);
604 transform.TransformPoint(&miss_point); 604 transform.TransformPoint(&miss_point);
605 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, miss_point, miss_point, 605 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, miss_point, miss_point,
606 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 606 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
607 ui::EF_LEFT_MOUSE_BUTTON); 607 ui::EF_LEFT_MOUSE_BUTTON);
608 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); 608 ui::EventSink* sink = root_window->GetHost()->event_sink();
609 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&mouseev1); 609 ui::EventDispatchDetails details = sink->OnEventFromSource(&mouseev1);
610 ASSERT_FALSE(details.dispatcher_destroyed); 610 ASSERT_FALSE(details.dispatcher_destroyed);
611 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); 611 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
612 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, miss_point, miss_point, 612 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, miss_point, miss_point,
613 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 613 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
614 ui::EF_LEFT_MOUSE_BUTTON); 614 ui::EF_LEFT_MOUSE_BUTTON);
615 details = dispatcher->OnEventFromSource(&mouseup); 615 details = sink->OnEventFromSource(&mouseup);
616 ASSERT_FALSE(details.dispatcher_destroyed); 616 ASSERT_FALSE(details.dispatcher_destroyed);
617 617
618 gfx::Point hit_point(5, 15); 618 gfx::Point hit_point(5, 15);
619 transform.TransformPoint(&hit_point); 619 transform.TransformPoint(&hit_point);
620 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, hit_point, hit_point, 620 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, hit_point, hit_point,
621 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 621 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
622 ui::EF_LEFT_MOUSE_BUTTON); 622 ui::EF_LEFT_MOUSE_BUTTON);
623 details = dispatcher->OnEventFromSource(&mouseev2); 623 details = sink->OnEventFromSource(&mouseev2);
624 ASSERT_FALSE(details.dispatcher_destroyed); 624 ASSERT_FALSE(details.dispatcher_destroyed);
625 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 625 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
626 EXPECT_EQ(w1.get(), 626 EXPECT_EQ(w1.get(),
627 aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); 627 aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
628 } 628 }
629 629
630 TEST_F(WindowManagerTest, AdditionalFilters) { 630 TEST_F(WindowManagerTest, AdditionalFilters) {
631 // The IME event filter interferes with the basic key event propagation we 631 // The IME event filter interferes with the basic key event propagation we
632 // attempt to do here, so we disable it. 632 // attempt to do here, so we disable it.
633 DisableIME(); 633 DisableIME();
634 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 634 aura::Window* root_window = Shell::GetPrimaryRootWindow();
635 635
636 // Creates a window and make it active 636 // Creates a window and make it active
637 std::unique_ptr<aura::Window> w1( 637 std::unique_ptr<aura::Window> w1(
638 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); 638 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100)));
639 wm::ActivateWindow(w1.get()); 639 wm::ActivateWindow(w1.get());
640 640
641 // Creates two addition filters 641 // Creates two addition filters
642 std::unique_ptr<CustomEventHandler> f1(new CustomEventHandler); 642 std::unique_ptr<CustomEventHandler> f1(new CustomEventHandler);
643 std::unique_ptr<CustomEventHandler> f2(new CustomEventHandler); 643 std::unique_ptr<CustomEventHandler> f2(new CustomEventHandler);
644 644
645 // Adds them to root window event filter. 645 // Adds them to root window event filter.
646 ::wm::CompoundEventFilter* env_filter = Shell::GetInstance()->env_filter(); 646 ::wm::CompoundEventFilter* env_filter = Shell::GetInstance()->env_filter();
647 env_filter->AddHandler(f1.get()); 647 env_filter->AddHandler(f1.get());
648 env_filter->AddHandler(f2.get()); 648 env_filter->AddHandler(f2.get());
649 649
650 // Dispatches mouse and keyboard events. 650 // Dispatches mouse and keyboard events.
651 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); 651 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
652 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); 652 ui::EventSink* sink = root_window->GetHost()->event_sink();
653 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event); 653 ui::EventDispatchDetails details = sink->OnEventFromSource(&key_event);
654 ASSERT_FALSE(details.dispatcher_destroyed); 654 ASSERT_FALSE(details.dispatcher_destroyed);
655 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 655 ui::MouseEvent mouse_pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
656 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); 656 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0);
657 details = dispatcher->OnEventFromSource(&mouse_pressed); 657 details = sink->OnEventFromSource(&mouse_pressed);
658 ASSERT_FALSE(details.dispatcher_destroyed); 658 ASSERT_FALSE(details.dispatcher_destroyed);
659 659
660 // Both filters should get the events. 660 // Both filters should get the events.
661 EXPECT_EQ(1, f1->num_key_events()); 661 EXPECT_EQ(1, f1->num_key_events());
662 EXPECT_EQ(1, f1->num_mouse_events()); 662 EXPECT_EQ(1, f1->num_mouse_events());
663 EXPECT_EQ(1, f2->num_key_events()); 663 EXPECT_EQ(1, f2->num_key_events());
664 EXPECT_EQ(1, f2->num_mouse_events()); 664 EXPECT_EQ(1, f2->num_mouse_events());
665 665
666 f1->Reset(); 666 f1->Reset();
667 f2->Reset(); 667 f2->Reset();
668 668
669 // Makes f1 consume events. 669 // Makes f1 consume events.
670 f1->set_key_event_handling_result(ui::ER_CONSUMED); 670 f1->set_key_event_handling_result(ui::ER_CONSUMED);
671 f1->set_mouse_event_handling_result(ui::ER_CONSUMED); 671 f1->set_mouse_event_handling_result(ui::ER_CONSUMED);
672 672
673 // Dispatches events. 673 // Dispatches events.
674 details = dispatcher->OnEventFromSource(&key_event); 674 details = sink->OnEventFromSource(&key_event);
675 ASSERT_FALSE(details.dispatcher_destroyed); 675 ASSERT_FALSE(details.dispatcher_destroyed);
676 ui::MouseEvent mouse_released(ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), 676 ui::MouseEvent mouse_released(ui::ET_MOUSE_RELEASED, gfx::Point(0, 0),
677 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); 677 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0);
678 details = dispatcher->OnEventFromSource(&mouse_released); 678 details = sink->OnEventFromSource(&mouse_released);
679 ASSERT_FALSE(details.dispatcher_destroyed); 679 ASSERT_FALSE(details.dispatcher_destroyed);
680 680
681 // f1 should still get the events but f2 no longer gets them. 681 // f1 should still get the events but f2 no longer gets them.
682 EXPECT_EQ(1, f1->num_key_events()); 682 EXPECT_EQ(1, f1->num_key_events());
683 EXPECT_EQ(1, f1->num_mouse_events()); 683 EXPECT_EQ(1, f1->num_mouse_events());
684 EXPECT_EQ(0, f2->num_key_events()); 684 EXPECT_EQ(0, f2->num_key_events());
685 EXPECT_EQ(0, f2->num_mouse_events()); 685 EXPECT_EQ(0, f2->num_mouse_events());
686 686
687 f1->Reset(); 687 f1->Reset();
688 f2->Reset(); 688 f2->Reset();
689 689
690 // Remove f1 from additonal filters list. 690 // Remove f1 from additonal filters list.
691 env_filter->RemoveHandler(f1.get()); 691 env_filter->RemoveHandler(f1.get());
692 692
693 // Dispatches events. 693 // Dispatches events.
694 details = dispatcher->OnEventFromSource(&key_event); 694 details = sink->OnEventFromSource(&key_event);
695 ASSERT_FALSE(details.dispatcher_destroyed); 695 ASSERT_FALSE(details.dispatcher_destroyed);
696 details = dispatcher->OnEventFromSource(&mouse_pressed); 696 details = sink->OnEventFromSource(&mouse_pressed);
697 ASSERT_FALSE(details.dispatcher_destroyed); 697 ASSERT_FALSE(details.dispatcher_destroyed);
698 698
699 // f1 should get no events since it's out and f2 should get them. 699 // f1 should get no events since it's out and f2 should get them.
700 EXPECT_EQ(0, f1->num_key_events()); 700 EXPECT_EQ(0, f1->num_key_events());
701 EXPECT_EQ(0, f1->num_mouse_events()); 701 EXPECT_EQ(0, f1->num_mouse_events());
702 EXPECT_EQ(1, f2->num_key_events()); 702 EXPECT_EQ(1, f2->num_key_events());
703 EXPECT_EQ(1, f2->num_mouse_events()); 703 EXPECT_EQ(1, f2->num_mouse_events());
704 704
705 env_filter->RemoveHandler(f2.get()); 705 env_filter->RemoveHandler(f2.get());
706 } 706 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 observer_b.reset(); 856 observer_b.reset();
857 generator.MoveMouseTo(50, 50); 857 generator.MoveMouseTo(50, 50);
858 EXPECT_TRUE(observer_a.did_visibility_change()); 858 EXPECT_TRUE(observer_a.did_visibility_change());
859 EXPECT_FALSE(observer_b.did_visibility_change()); 859 EXPECT_FALSE(observer_b.did_visibility_change());
860 EXPECT_TRUE(observer_a.is_cursor_visible()); 860 EXPECT_TRUE(observer_a.is_cursor_visible());
861 861
862 cursor_manager->RemoveObserver(&observer_a); 862 cursor_manager->RemoveObserver(&observer_a);
863 } 863 }
864 864
865 } // namespace ash 865 } // namespace ash
OLDNEW
« no previous file with comments | « ash/host/ash_window_tree_host_x11.cc ('k') | chrome/browser/chromeos/accessibility/spoken_feedback_event_rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698