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

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

Issue 11421006: Desktop aura: Break aura::Window::SetParent in two. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: I think the content_unittests timeout on linux_aura is flake, but try to fix it anyway. Created 8 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
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/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
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 EXPECT_EQ(NULL, w123->GetFocusManager()); 212 EXPECT_EQ(NULL, w123->GetFocusManager());
213 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); 213 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev));
214 } 214 }
215 215
216 // Various assertion testing for activating windows. 216 // Various assertion testing for activating windows.
217 TEST_F(WindowManagerTest, ActivateOnMouse) { 217 TEST_F(WindowManagerTest, ActivateOnMouse) {
218 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 218 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
219 219
220 test::TestActivationDelegate d1; 220 test::TestActivationDelegate d1;
221 aura::test::TestWindowDelegate wd; 221 aura::test::TestWindowDelegate wd;
222 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 222 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
223 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); 223 &wd, -1, gfx::Rect(10, 10, 50, 50)));
224 d1.SetWindow(w1.get()); 224 d1.SetWindow(w1.get());
225 test::TestActivationDelegate d2; 225 test::TestActivationDelegate d2;
226 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 226 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
227 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL)); 227 &wd, -1, gfx::Rect(70, 70, 50, 50)));
228 d2.SetWindow(w2.get()); 228 d2.SetWindow(w2.get());
229 229
230 aura::FocusManager* focus_manager = w1->GetFocusManager(); 230 aura::FocusManager* focus_manager = w1->GetFocusManager();
231 231
232 d1.Clear(); 232 d1.Clear();
233 d2.Clear(); 233 d2.Clear();
234 234
235 // Activate window1. 235 // Activate window1.
236 wm::ActivateWindow(w1.get()); 236 wm::ActivateWindow(w1.get());
237 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 237 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 EXPECT_EQ(w1.get(), wm::GetActiveWindow()); 307 EXPECT_EQ(w1.get(), wm::GetActiveWindow());
308 } 308 }
309 309
310 // Clicking on a non-focusable window inside a background window should still 310 // Clicking on a non-focusable window inside a background window should still
311 // give focus to the background window. 311 // give focus to the background window.
312 { 312 {
313 NonFocusableDelegate nfd; 313 NonFocusableDelegate nfd;
314 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate( 314 scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
315 &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get())); 315 &nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get()));
316 // Move focus to |w2| first. 316 // Move focus to |w2| first.
317 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 317 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
318 &wd, -1, gfx::Rect(70, 70, 50, 50), NULL)); 318 &wd, -1, gfx::Rect(70, 70, 50, 50)));
319 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 319 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
320 w2.get()); 320 w2.get());
321 generator.ClickLeftButton(); 321 generator.ClickLeftButton();
322 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 322 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
323 EXPECT_FALSE(w11->CanFocus()); 323 EXPECT_FALSE(w11->CanFocus());
324 324
325 // Click on |w11|. This should focus w1. 325 // Click on |w11|. This should focus w1.
326 generator.MoveMouseToCenterOf(w11.get()); 326 generator.MoveMouseToCenterOf(w11.get());
327 generator.ClickLeftButton(); 327 generator.ClickLeftButton();
328 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 328 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow());
329 } 329 }
330 } 330 }
331 331
332 // Essentially the same as ActivateOnMouse, but for touch events. 332 // Essentially the same as ActivateOnMouse, but for touch events.
333 TEST_F(WindowManagerTest, ActivateOnTouch) { 333 TEST_F(WindowManagerTest, ActivateOnTouch) {
334 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 334 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
335 335
336 test::TestActivationDelegate d1; 336 test::TestActivationDelegate d1;
337 aura::test::TestWindowDelegate wd; 337 aura::test::TestWindowDelegate wd;
338 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( 338 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
339 &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); 339 &wd, -1, gfx::Rect(10, 10, 50, 50)));
340 d1.SetWindow(w1.get()); 340 d1.SetWindow(w1.get());
341 test::TestActivationDelegate d2; 341 test::TestActivationDelegate d2;
342 scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( 342 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
343 &wd, -2, gfx::Rect(70, 70, 50, 50), NULL)); 343 &wd, -2, gfx::Rect(70, 70, 50, 50)));
344 d2.SetWindow(w2.get()); 344 d2.SetWindow(w2.get());
345 345
346 aura::FocusManager* focus_manager = w1->GetFocusManager(); 346 aura::FocusManager* focus_manager = w1->GetFocusManager();
347 347
348 d1.Clear(); 348 d1.Clear();
349 d2.Clear(); 349 d2.Clear();
350 350
351 // Activate window1. 351 // Activate window1.
352 wm::ActivateWindow(w1.get()); 352 wm::ActivateWindow(w1.get());
353 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 353 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 EXPECT_EQ(0, d1.lost_active_count()); 400 EXPECT_EQ(0, d1.lost_active_count());
401 } 401 }
402 402
403 TEST_F(WindowManagerTest, MouseEventCursors) { 403 TEST_F(WindowManagerTest, MouseEventCursors) {
404 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 404 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
405 405
406 // Create a window. 406 // Create a window.
407 const int kWindowLeft = 123; 407 const int kWindowLeft = 123;
408 const int kWindowTop = 45; 408 const int kWindowTop = 45;
409 HitTestWindowDelegate window_delegate; 409 HitTestWindowDelegate window_delegate;
410 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( 410 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
411 &window_delegate, 411 &window_delegate,
412 -1, 412 -1,
413 gfx::Rect(kWindowLeft, kWindowTop, 640, 480), 413 gfx::Rect(kWindowLeft, kWindowTop, 640, 480)));
414 NULL));
415 414
416 // Create two mouse movement events we can switch between. 415 // Create two mouse movement events we can switch between.
417 gfx::Point point1(kWindowLeft, kWindowTop); 416 gfx::Point point1(kWindowLeft, kWindowTop);
418 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1); 417 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1);
419 418
420 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); 419 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1);
421 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2); 420 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2);
422 421
423 // Cursor starts as a pointer (set during Shell::Init()). 422 // Cursor starts as a pointer (set during Shell::Init()).
424 EXPECT_EQ(ui::kCursorPointer, root_window->last_cursor().native_type()); 423 EXPECT_EQ(ui::kCursorPointer, root_window->last_cursor().native_type());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 506
508 // Rotate it clock-wise 90 degrees. 507 // Rotate it clock-wise 90 degrees.
509 gfx::Transform transform; 508 gfx::Transform transform;
510 transform.SetRotate(90.0f); 509 transform.SetRotate(90.0f);
511 transform.ConcatTranslate(size.width(), 0); 510 transform.ConcatTranslate(size.width(), 0);
512 root_window->SetTransform(transform); 511 root_window->SetTransform(transform);
513 512
514 test::TestActivationDelegate d1; 513 test::TestActivationDelegate d1;
515 aura::test::TestWindowDelegate wd; 514 aura::test::TestWindowDelegate wd;
516 scoped_ptr<aura::Window> w1( 515 scoped_ptr<aura::Window> w1(
517 CreateTestWindowWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50), NULL)); 516 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50)));
518 d1.SetWindow(w1.get()); 517 d1.SetWindow(w1.get());
519 w1->Show(); 518 w1->Show();
520 519
521 gfx::Point miss_point(5, 5); 520 gfx::Point miss_point(5, 5);
522 transform.TransformPoint(miss_point); 521 transform.TransformPoint(miss_point);
523 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, 522 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED,
524 miss_point, 523 miss_point,
525 miss_point, 524 miss_point,
526 ui::EF_LEFT_MOUSE_BUTTON); 525 ui::EF_LEFT_MOUSE_BUTTON);
527 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1); 526 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1);
(...skipping 18 matching lines...) Expand all
546 TEST_F(WindowManagerTest, AdditionalFilters) { 545 TEST_F(WindowManagerTest, AdditionalFilters) {
547 // The IME event filter interferes with the basic key event propagation we 546 // The IME event filter interferes with the basic key event propagation we
548 // attempt to do here, so we remove it. 547 // attempt to do here, so we remove it.
549 Shell::TestApi shell_test(Shell::GetInstance()); 548 Shell::TestApi shell_test(Shell::GetInstance());
550 Shell::GetInstance()->RemovePreTargetHandler( 549 Shell::GetInstance()->RemovePreTargetHandler(
551 shell_test.input_method_event_filter()); 550 shell_test.input_method_event_filter());
552 551
553 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 552 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
554 553
555 // Creates a window and make it active 554 // Creates a window and make it active
556 scoped_ptr<aura::Window> w1(aura::test::CreateTestWindow( 555 scoped_ptr<aura::Window> w1(CreateTestWindowInShell(
557 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100), NULL)); 556 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100)));
558 wm::ActivateWindow(w1.get()); 557 wm::ActivateWindow(w1.get());
559 558
560 // Creates two addition filters 559 // Creates two addition filters
561 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); 560 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler);
562 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); 561 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler);
563 562
564 // Adds them to root window event filter. 563 // Adds them to root window event filter.
565 views::corewm::CompoundEventFilter* env_filter = 564 views::corewm::CompoundEventFilter* env_filter =
566 Shell::GetInstance()->env_filter(); 565 Shell::GetInstance()->env_filter();
567 env_filter->AddHandler(f1.get()); 566 env_filter->AddHandler(f1.get());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 EXPECT_EQ(1, f2->num_mouse_events()); 615 EXPECT_EQ(1, f2->num_mouse_events());
617 616
618 env_filter->RemoveHandler(f2.get()); 617 env_filter->RemoveHandler(f2.get());
619 } 618 }
620 619
621 // We should show and hide the cursor in response to mouse and touch events as 620 // We should show and hide the cursor in response to mouse and touch events as
622 // requested. 621 // requested.
623 TEST_F(WindowManagerTest, UpdateCursorVisibility) { 622 TEST_F(WindowManagerTest, UpdateCursorVisibility) {
624 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); 623 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
625 root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); 624 root_window->SetBounds(gfx::Rect(0, 0, 500, 500));
626 scoped_ptr<aura::Window> window(aura::test::CreateTestWindow( 625 scoped_ptr<aura::Window> window(CreateTestWindowInShell(
627 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500), NULL)); 626 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500)));
628 627
629 ash::CursorManager* cursor_manager = 628 ash::CursorManager* cursor_manager =
630 ash::Shell::GetInstance()->cursor_manager(); 629 ash::Shell::GetInstance()->cursor_manager();
631 630
632 ui::MouseEvent mouse_moved( 631 ui::MouseEvent mouse_moved(
633 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); 632 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0);
634 ui::TouchEvent touch_pressed1( 633 ui::TouchEvent touch_pressed1(
635 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime()); 634 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime());
636 ui::TouchEvent touch_pressed2( 635 ui::TouchEvent touch_pressed2(
637 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime()); 636 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime());
(...skipping 29 matching lines...) Expand all
667 EXPECT_TRUE(cursor_manager->cursor_visible()); 666 EXPECT_TRUE(cursor_manager->cursor_visible());
668 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); 667 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2);
669 EXPECT_FALSE(cursor_manager->cursor_visible()); 668 EXPECT_FALSE(cursor_manager->cursor_visible());
670 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); 669 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved);
671 EXPECT_TRUE(cursor_manager->cursor_visible()); 670 EXPECT_TRUE(cursor_manager->cursor_visible());
672 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); 671 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2);
673 EXPECT_TRUE(cursor_manager->cursor_visible()); 672 EXPECT_TRUE(cursor_manager->cursor_visible());
674 } 673 }
675 674
676 } // namespace ash 675 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698