OLD | NEW |
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/test_activation_delegate.h" | 8 #include "ash/test/test_activation_delegate.h" |
9 #include "ash/wm/activation_controller.h" | 9 #include "ash/wm/activation_controller.h" |
10 #include "ash/wm/cursor_manager.h" | 10 #include "ash/wm/cursor_manager.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 Shell::TestApi shell_test(Shell::GetInstance()); | 112 Shell::TestApi shell_test(Shell::GetInstance()); |
113 Shell::GetInstance()->RemovePreTargetHandler( | 113 Shell::GetInstance()->RemovePreTargetHandler( |
114 shell_test.input_method_event_filter()); | 114 shell_test.input_method_event_filter()); |
115 | 115 |
116 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 116 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
117 root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); | 117 root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); |
118 | 118 |
119 // Supplied ids are negative so as not to collide with shell ids. | 119 // Supplied ids are negative so as not to collide with shell ids. |
120 // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe | 120 // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe |
121 // id beyond shell id max? | 121 // id beyond shell id max? |
122 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindow( | 122 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
123 SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500), NULL)); | 123 SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500))); |
124 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindow( | 124 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindow( |
125 SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get())); | 125 SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get())); |
126 scoped_ptr<aura::Window> w111(aura::test::CreateTestWindow( | 126 scoped_ptr<aura::Window> w111(aura::test::CreateTestWindow( |
127 SK_ColorCYAN, -111, gfx::Rect(5, 5, 75, 75), w11.get())); | 127 SK_ColorCYAN, -111, gfx::Rect(5, 5, 75, 75), w11.get())); |
128 scoped_ptr<aura::Window> w1111(aura::test::CreateTestWindow( | 128 scoped_ptr<aura::Window> w1111(aura::test::CreateTestWindow( |
129 SK_ColorRED, -1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 129 SK_ColorRED, -1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
130 scoped_ptr<aura::Window> w12(aura::test::CreateTestWindow( | 130 scoped_ptr<aura::Window> w12(aura::test::CreateTestWindow( |
131 SK_ColorMAGENTA, -12, gfx::Rect(10, 420, 25, 25), w1.get())); | 131 SK_ColorMAGENTA, -12, gfx::Rect(10, 420, 25, 25), w1.get())); |
132 aura::test::ColorTestWindowDelegate* w121delegate = | 132 aura::test::ColorTestWindowDelegate* w121delegate = |
133 new aura::test::ColorTestWindowDelegate(SK_ColorYELLOW); | 133 new aura::test::ColorTestWindowDelegate(SK_ColorYELLOW); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); | 220 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); |
221 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); | 221 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); |
222 } | 222 } |
223 | 223 |
224 // Various assertion testing for activating windows. | 224 // Various assertion testing for activating windows. |
225 TEST_F(WindowManagerTest, ActivateOnMouse) { | 225 TEST_F(WindowManagerTest, ActivateOnMouse) { |
226 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 226 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
227 | 227 |
228 test::TestActivationDelegate d1; | 228 test::TestActivationDelegate d1; |
229 aura::test::TestWindowDelegate wd; | 229 aura::test::TestWindowDelegate wd; |
230 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 230 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
231 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); | 231 &wd, -1, gfx::Rect(10, 10, 50, 50))); |
232 d1.SetWindow(w1.get()); | 232 d1.SetWindow(w1.get()); |
233 test::TestActivationDelegate d2; | 233 test::TestActivationDelegate d2; |
234 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 234 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
235 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL)); | 235 &wd, -1, gfx::Rect(70, 70, 50, 50))); |
236 d2.SetWindow(w2.get()); | 236 d2.SetWindow(w2.get()); |
237 | 237 |
238 aura::client::FocusClient* focus_client = | 238 aura::client::FocusClient* focus_client = |
239 aura::client::GetFocusClient(w1.get()); | 239 aura::client::GetFocusClient(w1.get()); |
240 | 240 |
241 d1.Clear(); | 241 d1.Clear(); |
242 d2.Clear(); | 242 d2.Clear(); |
243 | 243 |
244 // Activate window1. | 244 // Activate window1. |
245 wm::ActivateWindow(w1.get()); | 245 wm::ActivateWindow(w1.get()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 EXPECT_EQ(w1.get(), wm::GetActiveWindow()); | 316 EXPECT_EQ(w1.get(), wm::GetActiveWindow()); |
317 } | 317 } |
318 | 318 |
319 // Clicking on a non-focusable window inside a background window should still | 319 // Clicking on a non-focusable window inside a background window should still |
320 // give focus to the background window. | 320 // give focus to the background window. |
321 { | 321 { |
322 NonFocusableDelegate nfd; | 322 NonFocusableDelegate nfd; |
323 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate( | 323 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate( |
324 &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get())); | 324 &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get())); |
325 // Move focus to |w2| first. | 325 // Move focus to |w2| first. |
326 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 326 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
327 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL)); | 327 &wd, -1, gfx::Rect(70, 70, 50, 50))); |
328 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 328 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
329 w2.get()); | 329 w2.get()); |
330 generator.ClickLeftButton(); | 330 generator.ClickLeftButton(); |
331 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); | 331 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
332 EXPECT_FALSE(w11->CanFocus()); | 332 EXPECT_FALSE(w11->CanFocus()); |
333 | 333 |
334 // Click on |w11|. This should focus w1. | 334 // Click on |w11|. This should focus w1. |
335 generator.MoveMouseToCenterOf(w11.get()); | 335 generator.MoveMouseToCenterOf(w11.get()); |
336 generator.ClickLeftButton(); | 336 generator.ClickLeftButton(); |
337 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); | 337 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 // Essentially the same as ActivateOnMouse, but for touch events. | 341 // Essentially the same as ActivateOnMouse, but for touch events. |
342 TEST_F(WindowManagerTest, ActivateOnTouch) { | 342 TEST_F(WindowManagerTest, ActivateOnTouch) { |
343 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 343 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
344 | 344 |
345 test::TestActivationDelegate d1; | 345 test::TestActivationDelegate d1; |
346 aura::test::TestWindowDelegate wd; | 346 aura::test::TestWindowDelegate wd; |
347 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( | 347 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
348 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); | 348 &wd, -1, gfx::Rect(10, 10, 50, 50))); |
349 d1.SetWindow(w1.get()); | 349 d1.SetWindow(w1.get()); |
350 test::TestActivationDelegate d2; | 350 test::TestActivationDelegate d2; |
351 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( | 351 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
352 &wd, -2, gfx::Rect(70, 70, 50, 50), NULL)); | 352 &wd, -2, gfx::Rect(70, 70, 50, 50))); |
353 d2.SetWindow(w2.get()); | 353 d2.SetWindow(w2.get()); |
354 | 354 |
355 aura::client::FocusClient* focus_client = | 355 aura::client::FocusClient* focus_client = |
356 aura::client::GetFocusClient(w1.get()); | 356 aura::client::GetFocusClient(w1.get()); |
357 | 357 |
358 d1.Clear(); | 358 d1.Clear(); |
359 d2.Clear(); | 359 d2.Clear(); |
360 | 360 |
361 // Activate window1. | 361 // Activate window1. |
362 wm::ActivateWindow(w1.get()); | 362 wm::ActivateWindow(w1.get()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 EXPECT_EQ(0, d1.lost_active_count()); | 410 EXPECT_EQ(0, d1.lost_active_count()); |
411 } | 411 } |
412 | 412 |
413 TEST_F(WindowManagerTest, MouseEventCursors) { | 413 TEST_F(WindowManagerTest, MouseEventCursors) { |
414 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 414 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
415 | 415 |
416 // Create a window. | 416 // Create a window. |
417 const int kWindowLeft = 123; | 417 const int kWindowLeft = 123; |
418 const int kWindowTop = 45; | 418 const int kWindowTop = 45; |
419 HitTestWindowDelegate window_delegate; | 419 HitTestWindowDelegate window_delegate; |
420 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 420 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
421 &window_delegate, | 421 &window_delegate, |
422 -1, | 422 -1, |
423 gfx::Rect(kWindowLeft, kWindowTop, 640, 480), | 423 gfx::Rect(kWindowLeft, kWindowTop, 640, 480))); |
424 NULL)); | |
425 | 424 |
426 // Create two mouse movement events we can switch between. | 425 // Create two mouse movement events we can switch between. |
427 gfx::Point point1(kWindowLeft, kWindowTop); | 426 gfx::Point point1(kWindowLeft, kWindowTop); |
428 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1); | 427 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1); |
429 | 428 |
430 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); | 429 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); |
431 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2); | 430 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2); |
432 | 431 |
433 // Cursor starts as a pointer (set during Shell::Init()). | 432 // Cursor starts as a pointer (set during Shell::Init()). |
434 EXPECT_EQ(ui::kCursorPointer, root_window->last_cursor().native_type()); | 433 EXPECT_EQ(ui::kCursorPointer, root_window->last_cursor().native_type()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 516 |
518 // Rotate it clock-wise 90 degrees. | 517 // Rotate it clock-wise 90 degrees. |
519 gfx::Transform transform; | 518 gfx::Transform transform; |
520 transform.Translate(size.width(), 0); | 519 transform.Translate(size.width(), 0); |
521 transform.Rotate(90.0f); | 520 transform.Rotate(90.0f); |
522 root_window->SetTransform(transform); | 521 root_window->SetTransform(transform); |
523 | 522 |
524 test::TestActivationDelegate d1; | 523 test::TestActivationDelegate d1; |
525 aura::test::TestWindowDelegate wd; | 524 aura::test::TestWindowDelegate wd; |
526 scoped_ptr<aura::Window> w1( | 525 scoped_ptr<aura::Window> w1( |
527 CreateTestWindowWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50), NULL)); | 526 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50))); |
528 d1.SetWindow(w1.get()); | 527 d1.SetWindow(w1.get()); |
529 w1->Show(); | 528 w1->Show(); |
530 | 529 |
531 gfx::Point miss_point(5, 5); | 530 gfx::Point miss_point(5, 5); |
532 transform.TransformPoint(miss_point); | 531 transform.TransformPoint(miss_point); |
533 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, | 532 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, |
534 miss_point, | 533 miss_point, |
535 miss_point, | 534 miss_point, |
536 ui::EF_LEFT_MOUSE_BUTTON); | 535 ui::EF_LEFT_MOUSE_BUTTON); |
537 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1); | 536 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1); |
(...skipping 19 matching lines...) Expand all Loading... |
557 TEST_F(WindowManagerTest, AdditionalFilters) { | 556 TEST_F(WindowManagerTest, AdditionalFilters) { |
558 // The IME event filter interferes with the basic key event propagation we | 557 // The IME event filter interferes with the basic key event propagation we |
559 // attempt to do here, so we remove it. | 558 // attempt to do here, so we remove it. |
560 Shell::TestApi shell_test(Shell::GetInstance()); | 559 Shell::TestApi shell_test(Shell::GetInstance()); |
561 Shell::GetInstance()->RemovePreTargetHandler( | 560 Shell::GetInstance()->RemovePreTargetHandler( |
562 shell_test.input_method_event_filter()); | 561 shell_test.input_method_event_filter()); |
563 | 562 |
564 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 563 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
565 | 564 |
566 // Creates a window and make it active | 565 // Creates a window and make it active |
567 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindow( | 566 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
568 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100), NULL)); | 567 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
569 wm::ActivateWindow(w1.get()); | 568 wm::ActivateWindow(w1.get()); |
570 | 569 |
571 // Creates two addition filters | 570 // Creates two addition filters |
572 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); | 571 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); |
573 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); | 572 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); |
574 | 573 |
575 // Adds them to root window event filter. | 574 // Adds them to root window event filter. |
576 views::corewm::CompoundEventFilter* env_filter = | 575 views::corewm::CompoundEventFilter* env_filter = |
577 Shell::GetInstance()->env_filter(); | 576 Shell::GetInstance()->env_filter(); |
578 env_filter->AddHandler(f1.get()); | 577 env_filter->AddHandler(f1.get()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 EXPECT_EQ(1, f2->num_mouse_events()); | 626 EXPECT_EQ(1, f2->num_mouse_events()); |
628 | 627 |
629 env_filter->RemoveHandler(f2.get()); | 628 env_filter->RemoveHandler(f2.get()); |
630 } | 629 } |
631 | 630 |
632 // We should show and hide the cursor in response to mouse and touch events as | 631 // We should show and hide the cursor in response to mouse and touch events as |
633 // requested. | 632 // requested. |
634 TEST_F(WindowManagerTest, UpdateCursorVisibility) { | 633 TEST_F(WindowManagerTest, UpdateCursorVisibility) { |
635 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 634 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
636 root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); | 635 root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); |
637 scoped_ptr<aura::Window> window(aura::test::CreateTestWindow( | 636 scoped_ptr<aura::Window> window(CreateTestWindowInShell( |
638 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500), NULL)); | 637 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500))); |
639 | 638 |
640 ash::CursorManager* cursor_manager = | 639 ash::CursorManager* cursor_manager = |
641 ash::Shell::GetInstance()->cursor_manager(); | 640 ash::Shell::GetInstance()->cursor_manager(); |
642 | 641 |
643 ui::MouseEvent mouse_moved( | 642 ui::MouseEvent mouse_moved( |
644 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); | 643 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); |
645 ui::TouchEvent touch_pressed1( | 644 ui::TouchEvent touch_pressed1( |
646 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime()); | 645 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime()); |
647 ui::TouchEvent touch_pressed2( | 646 ui::TouchEvent touch_pressed2( |
648 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime()); | 647 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime()); |
(...skipping 29 matching lines...) Expand all Loading... |
678 EXPECT_TRUE(cursor_manager->cursor_visible()); | 677 EXPECT_TRUE(cursor_manager->cursor_visible()); |
679 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); | 678 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); |
680 EXPECT_FALSE(cursor_manager->cursor_visible()); | 679 EXPECT_FALSE(cursor_manager->cursor_visible()); |
681 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 680 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); |
682 EXPECT_TRUE(cursor_manager->cursor_visible()); | 681 EXPECT_TRUE(cursor_manager->cursor_visible()); |
683 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); | 682 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); |
684 EXPECT_TRUE(cursor_manager->cursor_visible()); | 683 EXPECT_TRUE(cursor_manager->cursor_visible()); |
685 } | 684 } |
686 | 685 |
687 } // namespace ash | 686 } // namespace ash |
OLD | NEW |