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

Side by Side Diff: ui/aura/window_unittest.cc

Issue 8273040: Minimum size for aura window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressd comment Created 9 years, 2 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
« no previous file with comments | « ui/aura/window.cc ('k') | ui/gfx/point.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
24 #include "ui/base/keycodes/keyboard_codes.h" 25 #include "ui/base/keycodes/keyboard_codes.h"
25 26
26 namespace aura { 27 namespace aura {
27 namespace test { 28 namespace test {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 ASSERT_EQ(2u, parent.children().size()); 369 ASSERT_EQ(2u, parent.children().size());
369 EXPECT_EQ(&child1, parent.children()[1]); 370 EXPECT_EQ(&child1, parent.children()[1]);
370 EXPECT_EQ(&child2, parent.children()[0]); 371 EXPECT_EQ(&child2, parent.children()[0]);
371 ASSERT_EQ(2u, parent.layer()->children().size()); 372 ASSERT_EQ(2u, parent.layer()->children().size());
372 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); 373 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]);
373 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); 374 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
374 } 375 }
375 376
376 // Various destruction assertions. 377 // Various destruction assertions.
377 TEST_F(WindowTest, CaptureTests) { 378 TEST_F(WindowTest, CaptureTests) {
378 Desktop* desktop = Desktop::GetInstance(); 379 aura::Desktop* desktop = aura::Desktop::GetInstance();
379 CaptureWindowDelegateImpl delegate; 380 CaptureWindowDelegateImpl delegate;
380 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 381 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
381 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 382 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
382 EXPECT_FALSE(window->HasCapture()); 383 EXPECT_FALSE(window->HasCapture());
383 384
384 // Do a capture. 385 // Do a capture.
385 window->SetCapture(); 386 window->SetCapture();
386 EXPECT_TRUE(window->HasCapture()); 387 EXPECT_TRUE(window->HasCapture());
387 EXPECT_EQ(0, delegate.capture_lost_count()); 388 EXPECT_EQ(0, delegate.capture_lost_count());
389 EventGenerator generator(gfx::Point(50, 50));
390 generator.PressLeftButton();
391 EXPECT_EQ(1, delegate.mouse_event_count());
392 generator.ReleaseLeftButton();
388 393
389 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50),
390 ui::EF_LEFT_BUTTON_DOWN));
391 EXPECT_EQ(1, delegate.mouse_event_count());
392 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50),
393 ui::EF_LEFT_BUTTON_DOWN));
394 EXPECT_EQ(2, delegate.mouse_event_count()); 394 EXPECT_EQ(2, delegate.mouse_event_count());
395 delegate.set_mouse_event_count(0); 395 delegate.set_mouse_event_count(0);
396 396
397 desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 397 desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50),
398 0)); 398 0));
399 EXPECT_EQ(1, delegate.touch_event_count()); 399 EXPECT_EQ(1, delegate.touch_event_count());
400 delegate.set_touch_event_count(0); 400 delegate.set_touch_event_count(0);
401 401
402 window->ReleaseCapture(); 402 window->ReleaseCapture();
403 EXPECT_FALSE(window->HasCapture()); 403 EXPECT_FALSE(window->HasCapture());
404 EXPECT_EQ(1, delegate.capture_lost_count()); 404 EXPECT_EQ(1, delegate.capture_lost_count());
405 405
406 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), 406 generator.PressLeftButton();
407 ui::EF_LEFT_BUTTON_DOWN));
408 EXPECT_EQ(0, delegate.mouse_event_count()); 407 EXPECT_EQ(0, delegate.mouse_event_count());
409 408
410 desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 409 desktop->OnTouchEvent(TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50),
411 0)); 410 0));
412 EXPECT_EQ(0, delegate.touch_event_count()); 411 EXPECT_EQ(0, delegate.touch_event_count());
413 } 412 }
414 413
415 // Verifies capture is reset when a window is destroyed. 414 // Verifies capture is reset when a window is destroyed.
416 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { 415 TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
417 Desktop* desktop = Desktop::GetInstance(); 416 Desktop* desktop = Desktop::GetInstance();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 495
497 class ActivateWindowDelegate : public TestWindowDelegate { 496 class ActivateWindowDelegate : public TestWindowDelegate {
498 public: 497 public:
499 ActivateWindowDelegate() 498 ActivateWindowDelegate()
500 : activate_(true), 499 : activate_(true),
501 activated_count_(0), 500 activated_count_(0),
502 lost_active_count_(0), 501 lost_active_count_(0),
503 should_activate_count_(0) { 502 should_activate_count_(0) {
504 } 503 }
505 504
505 ActivateWindowDelegate(bool activate)
506 : activate_(activate),
507 activated_count_(0),
508 lost_active_count_(0),
509 should_activate_count_(0) {
510 }
511
506 void set_activate(bool v) { activate_ = v; } 512 void set_activate(bool v) { activate_ = v; }
507 int activated_count() const { return activated_count_; } 513 int activated_count() const { return activated_count_; }
508 int lost_active_count() const { return lost_active_count_; } 514 int lost_active_count() const { return lost_active_count_; }
509 int should_activate_count() const { return should_activate_count_; } 515 int should_activate_count() const { return should_activate_count_; }
510 void Clear() { 516 void Clear() {
511 activated_count_ = lost_active_count_ = should_activate_count_ = 0; 517 activated_count_ = lost_active_count_ = should_activate_count_ = 0;
512 } 518 }
513 519
514 virtual bool ShouldActivate(Event* event) OVERRIDE { 520 virtual bool ShouldActivate(Event* event) OVERRIDE {
515 should_activate_count_++; 521 should_activate_count_++;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 desktop->SetActiveWindow(w1.get(), NULL); 556 desktop->SetActiveWindow(w1.get(), NULL);
551 EXPECT_EQ(w1.get(), desktop->active_window()); 557 EXPECT_EQ(w1.get(), desktop->active_window());
552 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 558 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow());
553 EXPECT_EQ(1, d1.activated_count()); 559 EXPECT_EQ(1, d1.activated_count());
554 EXPECT_EQ(0, d1.lost_active_count()); 560 EXPECT_EQ(0, d1.lost_active_count());
555 d1.Clear(); 561 d1.Clear();
556 562
557 // Click on window2. 563 // Click on window2.
558 gfx::Point press_point = w2->bounds().CenterPoint(); 564 gfx::Point press_point = w2->bounds().CenterPoint();
559 Window::ConvertPointToWindow(w2->parent(), desktop->window(), &press_point); 565 Window::ConvertPointToWindow(w2->parent(), desktop->window(), &press_point);
560 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); 566 EventGenerator generator(press_point);
561 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0)); 567 generator.ClickLeftButton();
562 568
563 // Window2 should have become active. 569 // Window2 should have become active.
564 EXPECT_EQ(w2.get(), desktop->active_window()); 570 EXPECT_EQ(w2.get(), desktop->active_window());
565 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 571 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
566 EXPECT_EQ(0, d1.activated_count()); 572 EXPECT_EQ(0, d1.activated_count());
567 EXPECT_EQ(1, d1.lost_active_count()); 573 EXPECT_EQ(1, d1.lost_active_count());
568 EXPECT_EQ(1, d2.activated_count()); 574 EXPECT_EQ(1, d2.activated_count());
569 EXPECT_EQ(0, d2.lost_active_count()); 575 EXPECT_EQ(0, d2.lost_active_count());
570 d1.Clear(); 576 d1.Clear();
571 d2.Clear(); 577 d2.Clear();
572 578
573 // Click back on window1, but set it up so w1 doesn't activate on click. 579 // Click back on window1, but set it up so w1 doesn't activate on click.
574 press_point = w1->bounds().CenterPoint(); 580 press_point = w1->bounds().CenterPoint();
575 Window::ConvertPointToWindow(w1->parent(), desktop->window(), &press_point); 581 Window::ConvertPointToWindow(w1->parent(), desktop->window(), &press_point);
576 d1.set_activate(false); 582 d1.set_activate(false);
577 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); 583 generator.ClickLeftButton();
578 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0));
579 584
580 // Window2 should still be active and focused. 585 // Window2 should still be active and focused.
581 EXPECT_EQ(w2.get(), desktop->active_window()); 586 EXPECT_EQ(w2.get(), desktop->active_window());
582 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 587 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
583 EXPECT_EQ(0, d1.activated_count()); 588 EXPECT_EQ(0, d1.activated_count());
584 EXPECT_EQ(0, d1.lost_active_count()); 589 EXPECT_EQ(0, d1.lost_active_count());
585 EXPECT_EQ(0, d2.activated_count()); 590 EXPECT_EQ(0, d2.activated_count());
586 EXPECT_EQ(0, d2.lost_active_count()); 591 EXPECT_EQ(0, d2.lost_active_count());
587 d1.Clear(); 592 d1.Clear();
588 d2.Clear(); 593 d2.Clear();
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 EXPECT_EQ(original_bounds, w->bounds()); 818 EXPECT_EQ(original_bounds, w->bounds());
814 819
815 // Fullscreen 820 // Fullscreen
816 w->Fullscreen(); 821 w->Fullscreen();
817 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); 822 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state());
818 EXPECT_EQ(desktop_bounds, w->bounds()); 823 EXPECT_EQ(desktop_bounds, w->bounds());
819 w->Restore(); 824 w->Restore();
820 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); 825 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state());
821 EXPECT_EQ(original_bounds, w->bounds()); 826 EXPECT_EQ(original_bounds, w->bounds());
822 827
823 // Fullscreen twice 828 // Calling Fullscreen() twice should have no additional effect.
824 w->Fullscreen(); 829 w->Fullscreen();
825 w->Fullscreen(); 830 w->Fullscreen();
826 EXPECT_EQ(desktop_bounds, w->bounds()); 831 EXPECT_EQ(desktop_bounds, w->bounds());
827 w->Restore(); 832 w->Restore();
828 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); 833 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state());
829 EXPECT_EQ(original_bounds, w->bounds()); 834 EXPECT_EQ(original_bounds, w->bounds());
835
836 // Calling SetBounds() in fullscreen mode should only update the
837 // restore bounds not change the bounds of the window.
838 gfx::Rect new_bounds(50, 50, 50, 50);
839 w->Fullscreen();
840 w->SetBounds(new_bounds);
841 EXPECT_EQ(desktop_bounds, w->bounds());
842 w->Restore();
843 EXPECT_EQ(new_bounds, w->bounds());
830 } 844 }
831 845
832 TEST_F(WindowTest, Maximized) { 846 TEST_F(WindowTest, Maximized) {
833 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100); 847 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100);
834 gfx::Rect desktop_bounds(Desktop::GetInstance()->GetSize()); 848 gfx::Rect desktop_bounds(Desktop::GetInstance()->GetSize());
835 scoped_ptr<Window> w(CreateTestWindowWithDelegate( 849 scoped_ptr<Window> w(CreateTestWindowWithDelegate(
836 NULL, 1, original_bounds, NULL)); 850 NULL, 1, original_bounds, NULL));
837 EXPECT_EQ(original_bounds, w->bounds()); 851 EXPECT_EQ(original_bounds, w->bounds());
838 852
839 // Maximized 853 // Maximized
(...skipping 21 matching lines...) Expand all
861 EXPECT_EQ(max_bounds, w->bounds()); 875 EXPECT_EQ(max_bounds, w->bounds());
862 w->Fullscreen(); 876 w->Fullscreen();
863 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); 877 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state());
864 EXPECT_EQ(desktop_bounds, w->bounds()); 878 EXPECT_EQ(desktop_bounds, w->bounds());
865 w->Maximize(); 879 w->Maximize();
866 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); 880 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state());
867 EXPECT_EQ(max_bounds, w->bounds()); 881 EXPECT_EQ(max_bounds, w->bounds());
868 w->Restore(); 882 w->Restore();
869 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); 883 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state());
870 EXPECT_EQ(original_bounds, w->bounds()); 884 EXPECT_EQ(original_bounds, w->bounds());
885
886 // Calling SetBounds() in maximized mode mode should only update the
887 // restore bounds not change the bounds of the window.
888 gfx::Rect new_bounds(50, 50, 50, 50);
889 w->Maximize();
890 w->SetBounds(new_bounds);
891 EXPECT_EQ(max_bounds, w->bounds());
892 w->Restore();
893 EXPECT_EQ(new_bounds, w->bounds());
871 } 894 }
872 895
873 // Various assertions for activating/deactivating. 896 // Various assertions for activating/deactivating.
874 TEST_F(WindowTest, Deactivate) { 897 TEST_F(WindowTest, Deactivate) {
875 TestWindowDelegate d1; 898 TestWindowDelegate d1;
876 TestWindowDelegate d2; 899 TestWindowDelegate d2;
877 scoped_ptr<Window> w1( 900 scoped_ptr<Window> w1(
878 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); 901 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL));
879 scoped_ptr<Window> w2( 902 scoped_ptr<Window> w2(
880 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); 903 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL));
(...skipping 29 matching lines...) Expand all
910 Window* root = Desktop::GetInstance()->window(); 933 Window* root = Desktop::GetInstance()->window();
911 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); 934 EXPECT_FALSE(root->IsOrContainsFullscreenWindow());
912 935
913 w11->Fullscreen(); 936 w11->Fullscreen();
914 EXPECT_TRUE(root->IsOrContainsFullscreenWindow()); 937 EXPECT_TRUE(root->IsOrContainsFullscreenWindow());
915 938
916 w11->Hide(); 939 w11->Hide();
917 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); 940 EXPECT_FALSE(root->IsOrContainsFullscreenWindow());
918 } 941 }
919 942
943 class ToplevelWindowTest : public WindowTest {
944 public:
945 ToplevelWindowTest() {}
946 virtual ~ToplevelWindowTest() {}
947
948 virtual void SetUp() OVERRIDE {
949 WindowTest::SetUp();
950 toplevel_container_.Init();
951 toplevel_container_.SetParent(aura::Desktop::GetInstance()->window());
952 toplevel_container_.SetBounds(
953 aura::Desktop::GetInstance()->window()->bounds());
954 toplevel_container_.Show();
955 }
956
957 virtual void TearDown() OVERRIDE {
958 toplevel_container_.Hide();
959 toplevel_container_.SetParent(NULL);
960 WindowTest::TearDown();
961 }
962
963 Window* CreateTestToplevelWindow(
964 WindowDelegate* delegate, const gfx::Rect& bounds) {
965 return CreateTestWindowWithDelegate(
966 delegate, 0 /* id */, bounds, &toplevel_container_);
967 }
968
969 ToplevelWindowContainer toplevel_container_;
970
971 private:
972 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowTest);
973 };
974
975 TEST_F(ToplevelWindowTest, TopMostActivate) {
976 ActivateWindowDelegate activate;
977 ActivateWindowDelegate non_activate(false);
978
979 scoped_ptr<Window> w1(CreateTestToplevelWindow(&non_activate, gfx::Rect()));
980 scoped_ptr<Window> w2(CreateTestToplevelWindow(&activate, gfx::Rect()));
981 scoped_ptr<Window> w3(CreateTestToplevelWindow(&non_activate, gfx::Rect()));
982 EXPECT_EQ(w2.get(), toplevel_container_.GetTopmostWindowToActivate(NULL));
983 }
984
920 class WindowObserverTest : public WindowTest, 985 class WindowObserverTest : public WindowTest,
921 public WindowObserver { 986 public WindowObserver {
922 public: 987 public:
923 WindowObserverTest() : added_count_(0), removed_count_(0) {} 988 WindowObserverTest() : added_count_(0), removed_count_(0) {}
924 989
925 virtual ~WindowObserverTest() {} 990 virtual ~WindowObserverTest() {}
926 991
927 // Returns a description of the WindowObserver methods that have been invoked. 992 // Returns a description of the WindowObserver methods that have been invoked.
928 std::string WindowObserverCountStateAndClear() { 993 std::string WindowObserverCountStateAndClear() {
929 std::string result( 994 std::string result(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 1083
1019 w3->Activate(); 1084 w3->Activate();
1020 EXPECT_EQ(w2.get(), active()); 1085 EXPECT_EQ(w2.get(), active());
1021 1086
1022 w1->Activate(); 1087 w1->Activate();
1023 EXPECT_EQ(w1.get(), active()); 1088 EXPECT_EQ(w1.get(), active());
1024 } 1089 }
1025 1090
1026 } // namespace test 1091 } // namespace test
1027 } // namespace aura 1092 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | ui/gfx/point.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698