OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/aura/desktop.h" | 11 #include "ui/aura/desktop.h" |
12 #include "ui/aura/desktop_observer.h" | 12 #include "ui/aura/desktop_observer.h" |
13 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
14 #include "ui/aura/focus_manager.h" | 14 #include "ui/aura/focus_manager.h" |
15 #include "ui/aura/hit_test.h" | 15 #include "ui/aura/hit_test.h" |
16 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
17 #include "ui/aura/test/aura_test_base.h" | 17 #include "ui/aura/test/aura_test_base.h" |
18 #include "ui/aura/test/event_generator.h" | |
18 #include "ui/aura/test/test_desktop_delegate.h" | 19 #include "ui/aura/test/test_desktop_delegate.h" |
19 #include "ui/aura/test/test_window_delegate.h" | 20 #include "ui/aura/test/test_window_delegate.h" |
20 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
21 #include "ui/aura/window_observer.h" | 22 #include "ui/aura/window_observer.h" |
22 #include "ui/gfx/canvas_skia.h" | 23 #include "ui/gfx/canvas_skia.h" |
23 #include "ui/gfx/compositor/layer.h" | 24 #include "ui/gfx/compositor/layer.h" |
25 #include "ui/gfx/screen.h" | |
24 #include "ui/base/keycodes/keyboard_codes.h" | 26 #include "ui/base/keycodes/keyboard_codes.h" |
25 | 27 |
26 namespace aura { | 28 namespace aura { |
27 namespace test { | 29 namespace test { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 // Used for verifying destruction methods are invoked. | 33 // Used for verifying destruction methods are invoked. |
32 class DestroyTrackingDelegateImpl : public TestWindowDelegate { | 34 class DestroyTrackingDelegateImpl : public TestWindowDelegate { |
33 public: | 35 public: |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 ASSERT_EQ(2u, parent.children().size()); | 346 ASSERT_EQ(2u, parent.children().size()); |
345 EXPECT_EQ(&child1, parent.children()[1]); | 347 EXPECT_EQ(&child1, parent.children()[1]); |
346 EXPECT_EQ(&child2, parent.children()[0]); | 348 EXPECT_EQ(&child2, parent.children()[0]); |
347 ASSERT_EQ(2u, parent.layer()->children().size()); | 349 ASSERT_EQ(2u, parent.layer()->children().size()); |
348 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 350 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
349 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 351 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
350 } | 352 } |
351 | 353 |
352 // Various destruction assertions. | 354 // Various destruction assertions. |
353 TEST_F(WindowTest, CaptureTests) { | 355 TEST_F(WindowTest, CaptureTests) { |
354 Desktop* desktop = Desktop::GetInstance(); | |
355 CaptureWindowDelegateImpl delegate; | 356 CaptureWindowDelegateImpl delegate; |
356 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 357 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
357 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); | 358 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); |
358 EXPECT_FALSE(window->HasCapture()); | 359 EXPECT_FALSE(window->HasCapture()); |
359 | 360 |
360 // Do a capture. | 361 // Do a capture. |
361 window->SetCapture(); | 362 window->SetCapture(); |
362 EXPECT_TRUE(window->HasCapture()); | 363 EXPECT_TRUE(window->HasCapture()); |
363 EXPECT_EQ(0, delegate.capture_lost_count()); | 364 EXPECT_EQ(0, delegate.capture_lost_count()); |
365 EventGenerator generator(gfx::Point(50, 50)); | |
366 generator.PressLeftButton(); | |
367 EXPECT_EQ(1, delegate.mouse_event_count()); | |
368 generator.ReleaseLeftButton(); | |
364 | 369 |
365 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), | |
366 ui::EF_LEFT_BUTTON_DOWN)); | |
367 EXPECT_EQ(1, delegate.mouse_event_count()); | |
368 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), | |
369 ui::EF_LEFT_BUTTON_DOWN)); | |
370 EXPECT_EQ(2, delegate.mouse_event_count()); | 370 EXPECT_EQ(2, delegate.mouse_event_count()); |
371 delegate.set_mouse_event_count(0); | 371 delegate.set_mouse_event_count(0); |
372 | 372 |
373 window->ReleaseCapture(); | 373 window->ReleaseCapture(); |
374 EXPECT_FALSE(window->HasCapture()); | 374 EXPECT_FALSE(window->HasCapture()); |
375 EXPECT_EQ(1, delegate.capture_lost_count()); | 375 EXPECT_EQ(1, delegate.capture_lost_count()); |
376 | 376 |
377 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), | 377 generator.PressLeftButton(); |
378 ui::EF_LEFT_BUTTON_DOWN)); | |
379 EXPECT_EQ(0, delegate.mouse_event_count()); | 378 EXPECT_EQ(0, delegate.mouse_event_count()); |
380 } | 379 } |
381 | 380 |
382 // Verifies capture is reset when a window is destroyed. | 381 // Verifies capture is reset when a window is destroyed. |
383 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { | 382 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { |
384 Desktop* desktop = Desktop::GetInstance(); | 383 Desktop* desktop = Desktop::GetInstance(); |
385 internal::RootWindow* root = | 384 internal::RootWindow* root = |
386 static_cast<internal::RootWindow*>(desktop->window()); | 385 static_cast<internal::RootWindow*>(desktop->window()); |
387 CaptureWindowDelegateImpl delegate; | 386 CaptureWindowDelegateImpl delegate; |
388 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 387 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 | 462 |
464 class ActivateWindowDelegate : public TestWindowDelegate { | 463 class ActivateWindowDelegate : public TestWindowDelegate { |
465 public: | 464 public: |
466 ActivateWindowDelegate() | 465 ActivateWindowDelegate() |
467 : activate_(true), | 466 : activate_(true), |
468 activated_count_(0), | 467 activated_count_(0), |
469 lost_active_count_(0), | 468 lost_active_count_(0), |
470 should_activate_count_(0) { | 469 should_activate_count_(0) { |
471 } | 470 } |
472 | 471 |
472 ActivateWindowDelegate(bool activate) | |
473 : activate_(activate), | |
474 activated_count_(0), | |
475 lost_active_count_(0), | |
476 should_activate_count_(0) { | |
477 } | |
478 | |
473 void set_activate(bool v) { activate_ = v; } | 479 void set_activate(bool v) { activate_ = v; } |
474 int activated_count() const { return activated_count_; } | 480 int activated_count() const { return activated_count_; } |
475 int lost_active_count() const { return lost_active_count_; } | 481 int lost_active_count() const { return lost_active_count_; } |
476 int should_activate_count() const { return should_activate_count_; } | 482 int should_activate_count() const { return should_activate_count_; } |
477 void Clear() { | 483 void Clear() { |
478 activated_count_ = lost_active_count_ = should_activate_count_ = 0; | 484 activated_count_ = lost_active_count_ = should_activate_count_ = 0; |
479 } | 485 } |
480 | 486 |
481 virtual bool ShouldActivate(MouseEvent* event) OVERRIDE { | 487 virtual bool ShouldActivate(MouseEvent* event) OVERRIDE { |
482 should_activate_count_++; | 488 should_activate_count_++; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 desktop->SetActiveWindow(w1.get(), NULL); | 523 desktop->SetActiveWindow(w1.get(), NULL); |
518 EXPECT_EQ(w1.get(), desktop->active_window()); | 524 EXPECT_EQ(w1.get(), desktop->active_window()); |
519 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); | 525 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); |
520 EXPECT_EQ(1, d1.activated_count()); | 526 EXPECT_EQ(1, d1.activated_count()); |
521 EXPECT_EQ(0, d1.lost_active_count()); | 527 EXPECT_EQ(0, d1.lost_active_count()); |
522 d1.Clear(); | 528 d1.Clear(); |
523 | 529 |
524 // Click on window2. | 530 // Click on window2. |
525 gfx::Point press_point = w2->bounds().CenterPoint(); | 531 gfx::Point press_point = w2->bounds().CenterPoint(); |
526 Window::ConvertPointToWindow(w2->parent(), desktop->window(), &press_point); | 532 Window::ConvertPointToWindow(w2->parent(), desktop->window(), &press_point); |
527 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); | 533 EventGenerator generator(press_point); |
528 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0)); | 534 generator.ClickLeftButton(); |
529 | 535 |
530 // Window2 should have become active. | 536 // Window2 should have become active. |
531 EXPECT_EQ(w2.get(), desktop->active_window()); | 537 EXPECT_EQ(w2.get(), desktop->active_window()); |
532 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); | 538 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); |
533 EXPECT_EQ(0, d1.activated_count()); | 539 EXPECT_EQ(0, d1.activated_count()); |
534 EXPECT_EQ(1, d1.lost_active_count()); | 540 EXPECT_EQ(1, d1.lost_active_count()); |
535 EXPECT_EQ(1, d2.activated_count()); | 541 EXPECT_EQ(1, d2.activated_count()); |
536 EXPECT_EQ(0, d2.lost_active_count()); | 542 EXPECT_EQ(0, d2.lost_active_count()); |
537 d1.Clear(); | 543 d1.Clear(); |
538 d2.Clear(); | 544 d2.Clear(); |
539 | 545 |
540 // Click back on window1, but set it up so w1 doesn't activate on click. | 546 // Click back on window1, but set it up so w1 doesn't activate on click. |
541 press_point = w1->bounds().CenterPoint(); | 547 press_point = w1->bounds().CenterPoint(); |
542 Window::ConvertPointToWindow(w1->parent(), desktop->window(), &press_point); | 548 Window::ConvertPointToWindow(w1->parent(), desktop->window(), &press_point); |
543 d1.set_activate(false); | 549 d1.set_activate(false); |
544 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); | 550 generator.ClickLeftButton(); |
545 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0)); | |
546 | 551 |
547 // Window2 should still be active and focused. | 552 // Window2 should still be active and focused. |
548 EXPECT_EQ(w2.get(), desktop->active_window()); | 553 EXPECT_EQ(w2.get(), desktop->active_window()); |
549 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); | 554 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); |
550 EXPECT_EQ(0, d1.activated_count()); | 555 EXPECT_EQ(0, d1.activated_count()); |
551 EXPECT_EQ(0, d1.lost_active_count()); | 556 EXPECT_EQ(0, d1.lost_active_count()); |
552 EXPECT_EQ(0, d2.activated_count()); | 557 EXPECT_EQ(0, d2.activated_count()); |
553 EXPECT_EQ(0, d2.lost_active_count()); | 558 EXPECT_EQ(0, d2.lost_active_count()); |
554 d1.Clear(); | 559 d1.Clear(); |
555 d2.Clear(); | 560 d2.Clear(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
715 EXPECT_EQ(original_bounds, w->bounds()); | 720 EXPECT_EQ(original_bounds, w->bounds()); |
716 | 721 |
717 // Fullscreen | 722 // Fullscreen |
718 w->Fullscreen(); | 723 w->Fullscreen(); |
719 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); | 724 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); |
720 EXPECT_EQ(desktop_bounds, w->bounds()); | 725 EXPECT_EQ(desktop_bounds, w->bounds()); |
721 w->Restore(); | 726 w->Restore(); |
722 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | 727 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); |
723 EXPECT_EQ(original_bounds, w->bounds()); | 728 EXPECT_EQ(original_bounds, w->bounds()); |
724 | 729 |
725 // Fullscreen twice | 730 // Calling Fullscreen() twice should have no additional effect. |
726 w->Fullscreen(); | 731 w->Fullscreen(); |
727 w->Fullscreen(); | 732 w->Fullscreen(); |
728 EXPECT_EQ(desktop_bounds, w->bounds()); | 733 EXPECT_EQ(desktop_bounds, w->bounds()); |
729 w->Restore(); | 734 w->Restore(); |
730 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | 735 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); |
731 EXPECT_EQ(original_bounds, w->bounds()); | 736 EXPECT_EQ(original_bounds, w->bounds()); |
737 | |
738 // Calling SetBounds() in fullscreen mode should only update the | |
739 // restore bounds not change the bounds of the window. | |
740 gfx::Rect new_bounds(50, 50, 50, 50); | |
741 w->Fullscreen(); | |
742 w->SetBounds(new_bounds); | |
743 EXPECT_EQ(desktop_bounds, w->bounds()); | |
744 w->Restore(); | |
745 EXPECT_EQ(new_bounds, w->bounds()); | |
732 } | 746 } |
733 | 747 |
734 TEST_F(WindowTest, Maximized) { | 748 TEST_F(WindowTest, Maximized) { |
735 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100); | 749 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100); |
736 gfx::Rect desktop_bounds(Desktop::GetInstance()->GetSize()); | 750 gfx::Rect desktop_bounds(Desktop::GetInstance()->GetSize()); |
737 scoped_ptr<Window> w(CreateTestWindowWithDelegate( | 751 scoped_ptr<Window> w(CreateTestWindowWithDelegate( |
738 NULL, 1, original_bounds, NULL)); | 752 NULL, 1, original_bounds, NULL)); |
739 EXPECT_EQ(original_bounds, w->bounds()); | 753 EXPECT_EQ(original_bounds, w->bounds()); |
740 | 754 |
741 // Maximized | 755 // Maximized |
(...skipping 21 matching lines...) Expand all Loading... | |
763 EXPECT_EQ(max_bounds, w->bounds()); | 777 EXPECT_EQ(max_bounds, w->bounds()); |
764 w->Fullscreen(); | 778 w->Fullscreen(); |
765 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); | 779 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); |
766 EXPECT_EQ(desktop_bounds, w->bounds()); | 780 EXPECT_EQ(desktop_bounds, w->bounds()); |
767 w->Maximize(); | 781 w->Maximize(); |
768 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); | 782 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); |
769 EXPECT_EQ(max_bounds, w->bounds()); | 783 EXPECT_EQ(max_bounds, w->bounds()); |
770 w->Restore(); | 784 w->Restore(); |
771 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); | 785 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); |
772 EXPECT_EQ(original_bounds, w->bounds()); | 786 EXPECT_EQ(original_bounds, w->bounds()); |
787 | |
788 // Calling SetBounds() in maximized mode mode should only update the | |
789 // restore bounds not change the bounds of the window. | |
790 gfx::Rect new_bounds(50, 50, 50, 50); | |
791 w->Maximize(); | |
792 w->SetBounds(new_bounds); | |
793 EXPECT_EQ(max_bounds, w->bounds()); | |
794 w->Restore(); | |
795 EXPECT_EQ(new_bounds, w->bounds()); | |
773 } | 796 } |
774 | 797 |
775 // Various assertions for activating/deactivating. | 798 // Various assertions for activating/deactivating. |
776 TEST_F(WindowTest, Deactivate) { | 799 TEST_F(WindowTest, Deactivate) { |
777 TestWindowDelegate d1; | 800 TestWindowDelegate d1; |
778 TestWindowDelegate d2; | 801 TestWindowDelegate d2; |
779 scoped_ptr<Window> w1( | 802 scoped_ptr<Window> w1( |
780 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); | 803 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); |
781 scoped_ptr<Window> w2( | 804 scoped_ptr<Window> w2( |
782 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); | 805 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); |
(...skipping 29 matching lines...) Expand all Loading... | |
812 Window* root = Desktop::GetInstance()->window(); | 835 Window* root = Desktop::GetInstance()->window(); |
813 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); | 836 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); |
814 | 837 |
815 w11->Fullscreen(); | 838 w11->Fullscreen(); |
816 EXPECT_TRUE(root->IsOrContainsFullscreenWindow()); | 839 EXPECT_TRUE(root->IsOrContainsFullscreenWindow()); |
817 | 840 |
818 w11->Hide(); | 841 w11->Hide(); |
819 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); | 842 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); |
820 } | 843 } |
821 | 844 |
845 class ToplevelWindowTest : public WindowTest { | |
846 public: | |
847 ToplevelWindowTest() {} | |
848 virtual ~ToplevelWindowTest() {} | |
849 | |
850 virtual void SetUp() OVERRIDE { | |
851 WindowTest::SetUp(); | |
852 toplevel_container_.Init(); | |
853 toplevel_container_.SetParent(aura::Desktop::GetInstance()->window()); | |
854 toplevel_container_.SetBounds( | |
855 aura::Desktop::GetInstance()->window()->bounds()); | |
856 toplevel_container_.Show(); | |
857 } | |
858 | |
859 virtual void TearDown() OVERRIDE { | |
860 toplevel_container_.Hide(); | |
861 toplevel_container_.SetParent(NULL); | |
862 WindowTest::TearDown(); | |
863 } | |
864 | |
865 Window* CreateTestToplevelWindow( | |
866 WindowDelegate* delegate, const gfx::Rect& bounds) { | |
867 return CreateTestWindowWithDelegate( | |
868 delegate, 0 /* id */, bounds, &toplevel_container_); | |
869 } | |
870 | |
871 ToplevelWindowContainer toplevel_container_; | |
872 | |
873 private: | |
874 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowTest); | |
875 }; | |
876 | |
877 // A window delegate that returns the specified window component type. | |
878 // Default type is |HTNOWHERE|. | |
879 class ComponentWindowDelegate : public TestWindowDelegate { | |
Ben Goodger (Google)
2011/10/15 05:36:30
This class and the test class above looks very sim
| |
880 public: | |
881 ComponentWindowDelegate() : window_component_(HTNOWHERE) {} | |
882 ComponentWindowDelegate(int component) : window_component_(component) {} | |
883 virtual ~ComponentWindowDelegate() {} | |
884 | |
885 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | |
886 return window_component_; | |
887 } | |
888 | |
889 void set_window_component(int component) { | |
890 window_component_ = component; | |
891 } | |
892 | |
893 private: | |
894 int window_component_; | |
895 }; | |
896 | |
897 TEST_F(ToplevelWindowTest, TopMostActivate) { | |
898 ActivateWindowDelegate activate; | |
899 ActivateWindowDelegate non_activate(false); | |
900 | |
901 scoped_ptr<Window> w1(CreateTestToplevelWindow(&non_activate, gfx::Rect())); | |
902 scoped_ptr<Window> w2(CreateTestToplevelWindow(&activate, gfx::Rect())); | |
903 scoped_ptr<Window> w3(CreateTestToplevelWindow(&non_activate, gfx::Rect())); | |
904 EXPECT_EQ(w2.get(), toplevel_container_.GetTopmostWindowToActivate(NULL)); | |
905 } | |
906 | |
907 TEST_F(ToplevelWindowTest, WindowDrag) { | |
908 ComponentWindowDelegate dd(HTCAPTION); | |
909 gfx::Rect bounds(100, 100, 100, 100); | |
910 scoped_ptr<Window> w1(CreateTestToplevelWindow(&dd, bounds)); | |
911 | |
912 EXPECT_EQ(bounds, w1->bounds()); | |
913 EventGenerator generator; | |
914 generator.MoveMouseTo(150, 150); | |
915 generator.DragMouseTo(300, 200); | |
916 EXPECT_EQ(gfx::Rect(250, 150, 100, 100), w1->bounds()); | |
917 | |
918 // Maximized window cannot be dragged. | |
919 w1->Maximize(); | |
920 generator.DragMouseTo(200, 150); | |
921 gfx::Rect workarea = gfx::Screen::GetMonitorWorkAreaNearestWindow(w1.get()); | |
922 EXPECT_EQ(workarea, w1->bounds()); | |
923 w1->Restore(); | |
924 | |
925 // Fullscreen cannot be dragged either. | |
926 w1->Fullscreen(); | |
927 gfx::Rect monitor = gfx::Screen::GetMonitorAreaNearestWindow(w1.get()); | |
928 generator.DragMouseTo(250, 200); | |
929 EXPECT_EQ(monitor, w1->bounds()); | |
930 } | |
931 | |
932 TEST_F(ToplevelWindowTest, WindowResize) { | |
Ben Goodger (Google)
2011/10/15 05:36:30
We already have tests for this in toplevel_event_f
| |
933 ComponentWindowDelegate dd; | |
934 gfx::Rect bounds(100, 100, 100, 100); | |
935 scoped_ptr<Window> w1(CreateTestToplevelWindow(&dd, bounds)); | |
936 EXPECT_EQ(bounds, w1->bounds()); | |
937 | |
938 // Resize using left edge. | |
939 dd.set_window_component(HTLEFT); | |
940 EventGenerator generator; | |
941 generator.MoveMouseTo(110, 150); | |
942 generator.DragMouseTo(50, 1000); | |
943 EXPECT_EQ(gfx::Rect(40, 100, 160, 100), w1->bounds()); | |
944 // Move y coord to normal and drag again to right. | |
945 generator.MoveMouseTo(50, 150); | |
946 generator.DragMouseTo(70, 1000); | |
947 EXPECT_EQ(gfx::Rect(60, 100, 140, 100), w1->bounds()); | |
948 | |
949 // Resize using right edge. | |
950 w1->SetBounds(bounds); | |
951 dd.set_window_component(HTRIGHT); | |
952 generator.MoveMouseTo(190, 150); | |
953 generator.DragMouseTo(250, 1000); | |
954 EXPECT_EQ(gfx::Rect(100, 100, 160, 100), w1->bounds()); | |
955 // Move y coord to normal and drag again to left. | |
956 generator.MoveMouseTo(250, 100); | |
957 generator.DragMouseTo(150, 1000); | |
958 EXPECT_EQ(gfx::Rect(100, 100, 60, 100), w1->bounds()); | |
959 | |
960 // Resize using top edge. | |
961 w1->SetBounds(bounds); | |
962 dd.set_window_component(HTTOP); | |
963 generator.MoveMouseTo(150, 110); | |
964 generator.DragMouseTo(1000, 50); | |
965 EXPECT_EQ(gfx::Rect(100, 40, 100, 160), w1->bounds()); | |
966 // Move x coord to normal and drag again to bottom. | |
967 generator.MoveMouseTo(150, 50); | |
968 generator.DragMouseTo(1000, 150); | |
969 EXPECT_EQ(gfx::Rect(100, 140, 100, 60), w1->bounds()); | |
970 | |
971 // Resize using bottom edge. | |
972 w1->SetBounds(bounds); | |
973 dd.set_window_component(HTBOTTOM); | |
974 generator.MoveMouseTo(150, 190); | |
975 generator.DragMouseTo(1000, 250); | |
976 EXPECT_EQ(gfx::Rect(100, 100, 100, 160), w1->bounds()); | |
977 // Move x coord to normal and drag again to bottom. | |
978 generator.MoveMouseTo(150, 250); | |
979 generator.DragMouseTo(1000, 150); | |
980 EXPECT_EQ(gfx::Rect(100, 100, 100, 60), w1->bounds()); | |
981 | |
982 // Resize using bottom right edge. | |
983 w1->SetBounds(bounds); | |
984 dd.set_window_component(HTBOTTOMRIGHT); | |
985 generator.MoveMouseTo(190, 190); | |
986 generator.DragMouseTo(300, 300); | |
987 EXPECT_EQ(gfx::Rect(100, 100, 210, 210), w1->bounds()); | |
988 generator.DragMouseTo(150, 150); | |
989 EXPECT_EQ(gfx::Rect(100, 100, 60, 60), w1->bounds()); | |
990 | |
991 // Minimum size must be enforced. | |
992 w1->set_minimum_size(gfx::Size(30, 30)); | |
Ben Goodger (Google)
2011/10/15 05:36:30
...except for this bit, which you can add a new te
| |
993 generator.DragMouseTo(100, 100); | |
994 EXPECT_EQ(gfx::Rect(100, 100, 30, 30), w1->bounds()); | |
995 generator.DragMouseTo(50, 50); | |
996 EXPECT_EQ(gfx::Rect(100, 100, 30, 30), w1->bounds()); | |
997 } | |
998 | |
822 class WindowObserverTest : public WindowTest, | 999 class WindowObserverTest : public WindowTest, |
823 public WindowObserver { | 1000 public WindowObserver { |
824 public: | 1001 public: |
825 WindowObserverTest() : added_count_(0), removed_count_(0) {} | 1002 WindowObserverTest() : added_count_(0), removed_count_(0) {} |
826 | 1003 |
827 virtual ~WindowObserverTest() {} | 1004 virtual ~WindowObserverTest() {} |
828 | 1005 |
829 // Returns a description of the WindowObserver methods that have been invoked. | 1006 // Returns a description of the WindowObserver methods that have been invoked. |
830 std::string WindowObserverCountStateAndClear() { | 1007 std::string WindowObserverCountStateAndClear() { |
831 std::string result( | 1008 std::string result( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 | 1097 |
921 w3->Activate(); | 1098 w3->Activate(); |
922 EXPECT_EQ(w2.get(), active()); | 1099 EXPECT_EQ(w2.get(), active()); |
923 | 1100 |
924 w1->Activate(); | 1101 w1->Activate(); |
925 EXPECT_EQ(w1.get(), active()); | 1102 EXPECT_EQ(w1.get(), active()); |
926 } | 1103 } |
927 | 1104 |
928 } // namespace test | 1105 } // namespace test |
929 } // namespace aura | 1106 } // namespace aura |
OLD | NEW |