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

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: addressed comments. moved&merged tests 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
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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 ASSERT_EQ(2u, parent.children().size()); 345 ASSERT_EQ(2u, parent.children().size());
345 EXPECT_EQ(&child1, parent.children()[1]); 346 EXPECT_EQ(&child1, parent.children()[1]);
346 EXPECT_EQ(&child2, parent.children()[0]); 347 EXPECT_EQ(&child2, parent.children()[0]);
347 ASSERT_EQ(2u, parent.layer()->children().size()); 348 ASSERT_EQ(2u, parent.layer()->children().size());
348 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); 349 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]);
349 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); 350 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
350 } 351 }
351 352
352 // Various destruction assertions. 353 // Various destruction assertions.
353 TEST_F(WindowTest, CaptureTests) { 354 TEST_F(WindowTest, CaptureTests) {
354 Desktop* desktop = Desktop::GetInstance();
355 CaptureWindowDelegateImpl delegate; 355 CaptureWindowDelegateImpl delegate;
356 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 356 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
357 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 357 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
358 EXPECT_FALSE(window->HasCapture()); 358 EXPECT_FALSE(window->HasCapture());
359 359
360 // Do a capture. 360 // Do a capture.
361 window->SetCapture(); 361 window->SetCapture();
362 EXPECT_TRUE(window->HasCapture()); 362 EXPECT_TRUE(window->HasCapture());
363 EXPECT_EQ(0, delegate.capture_lost_count()); 363 EXPECT_EQ(0, delegate.capture_lost_count());
364 EventGenerator generator(gfx::Point(50, 50));
365 generator.PressLeftButton();
366 EXPECT_EQ(1, delegate.mouse_event_count());
367 generator.ReleaseLeftButton();
364 368
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()); 369 EXPECT_EQ(2, delegate.mouse_event_count());
371 delegate.set_mouse_event_count(0); 370 delegate.set_mouse_event_count(0);
372 371
373 window->ReleaseCapture(); 372 window->ReleaseCapture();
374 EXPECT_FALSE(window->HasCapture()); 373 EXPECT_FALSE(window->HasCapture());
375 EXPECT_EQ(1, delegate.capture_lost_count()); 374 EXPECT_EQ(1, delegate.capture_lost_count());
376 375
377 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), 376 generator.PressLeftButton();
378 ui::EF_LEFT_BUTTON_DOWN));
379 EXPECT_EQ(0, delegate.mouse_event_count()); 377 EXPECT_EQ(0, delegate.mouse_event_count());
380 } 378 }
381 379
382 // Verifies capture is reset when a window is destroyed. 380 // Verifies capture is reset when a window is destroyed.
383 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { 381 TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
384 Desktop* desktop = Desktop::GetInstance(); 382 Desktop* desktop = Desktop::GetInstance();
385 internal::RootWindow* root = 383 internal::RootWindow* root =
386 static_cast<internal::RootWindow*>(desktop->window()); 384 static_cast<internal::RootWindow*>(desktop->window());
387 CaptureWindowDelegateImpl delegate; 385 CaptureWindowDelegateImpl delegate;
388 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 386 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 461
464 class ActivateWindowDelegate : public TestWindowDelegate { 462 class ActivateWindowDelegate : public TestWindowDelegate {
465 public: 463 public:
466 ActivateWindowDelegate() 464 ActivateWindowDelegate()
467 : activate_(true), 465 : activate_(true),
468 activated_count_(0), 466 activated_count_(0),
469 lost_active_count_(0), 467 lost_active_count_(0),
470 should_activate_count_(0) { 468 should_activate_count_(0) {
471 } 469 }
472 470
471 ActivateWindowDelegate(bool activate)
472 : activate_(activate),
473 activated_count_(0),
474 lost_active_count_(0),
475 should_activate_count_(0) {
476 }
477
473 void set_activate(bool v) { activate_ = v; } 478 void set_activate(bool v) { activate_ = v; }
474 int activated_count() const { return activated_count_; } 479 int activated_count() const { return activated_count_; }
475 int lost_active_count() const { return lost_active_count_; } 480 int lost_active_count() const { return lost_active_count_; }
476 int should_activate_count() const { return should_activate_count_; } 481 int should_activate_count() const { return should_activate_count_; }
477 void Clear() { 482 void Clear() {
478 activated_count_ = lost_active_count_ = should_activate_count_ = 0; 483 activated_count_ = lost_active_count_ = should_activate_count_ = 0;
479 } 484 }
480 485
481 virtual bool ShouldActivate(MouseEvent* event) OVERRIDE { 486 virtual bool ShouldActivate(MouseEvent* event) OVERRIDE {
482 should_activate_count_++; 487 should_activate_count_++;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 desktop->SetActiveWindow(w1.get(), NULL); 522 desktop->SetActiveWindow(w1.get(), NULL);
518 EXPECT_EQ(w1.get(), desktop->active_window()); 523 EXPECT_EQ(w1.get(), desktop->active_window());
519 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow()); 524 EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow());
520 EXPECT_EQ(1, d1.activated_count()); 525 EXPECT_EQ(1, d1.activated_count());
521 EXPECT_EQ(0, d1.lost_active_count()); 526 EXPECT_EQ(0, d1.lost_active_count());
522 d1.Clear(); 527 d1.Clear();
523 528
524 // Click on window2. 529 // Click on window2.
525 gfx::Point press_point = w2->bounds().CenterPoint(); 530 gfx::Point press_point = w2->bounds().CenterPoint();
526 Window::ConvertPointToWindow(w2->parent(), desktop->window(), &press_point); 531 Window::ConvertPointToWindow(w2->parent(), desktop->window(), &press_point);
527 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); 532 EventGenerator generator(press_point);
528 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0)); 533 generator.ClickLeftButton();
529 534
530 // Window2 should have become active. 535 // Window2 should have become active.
531 EXPECT_EQ(w2.get(), desktop->active_window()); 536 EXPECT_EQ(w2.get(), desktop->active_window());
532 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 537 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
533 EXPECT_EQ(0, d1.activated_count()); 538 EXPECT_EQ(0, d1.activated_count());
534 EXPECT_EQ(1, d1.lost_active_count()); 539 EXPECT_EQ(1, d1.lost_active_count());
535 EXPECT_EQ(1, d2.activated_count()); 540 EXPECT_EQ(1, d2.activated_count());
536 EXPECT_EQ(0, d2.lost_active_count()); 541 EXPECT_EQ(0, d2.lost_active_count());
537 d1.Clear(); 542 d1.Clear();
538 d2.Clear(); 543 d2.Clear();
539 544
540 // Click back on window1, but set it up so w1 doesn't activate on click. 545 // Click back on window1, but set it up so w1 doesn't activate on click.
541 press_point = w1->bounds().CenterPoint(); 546 press_point = w1->bounds().CenterPoint();
542 Window::ConvertPointToWindow(w1->parent(), desktop->window(), &press_point); 547 Window::ConvertPointToWindow(w1->parent(), desktop->window(), &press_point);
543 d1.set_activate(false); 548 d1.set_activate(false);
544 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_PRESSED, press_point, 0)); 549 generator.ClickLeftButton();
545 desktop->OnMouseEvent(MouseEvent(ui::ET_MOUSE_RELEASED, press_point, 0));
546 550
547 // Window2 should still be active and focused. 551 // Window2 should still be active and focused.
548 EXPECT_EQ(w2.get(), desktop->active_window()); 552 EXPECT_EQ(w2.get(), desktop->active_window());
549 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow()); 553 EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
550 EXPECT_EQ(0, d1.activated_count()); 554 EXPECT_EQ(0, d1.activated_count());
551 EXPECT_EQ(0, d1.lost_active_count()); 555 EXPECT_EQ(0, d1.lost_active_count());
552 EXPECT_EQ(0, d2.activated_count()); 556 EXPECT_EQ(0, d2.activated_count());
553 EXPECT_EQ(0, d2.lost_active_count()); 557 EXPECT_EQ(0, d2.lost_active_count());
554 d1.Clear(); 558 d1.Clear();
555 d2.Clear(); 559 d2.Clear();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 EXPECT_EQ(original_bounds, w->bounds()); 719 EXPECT_EQ(original_bounds, w->bounds());
716 720
717 // Fullscreen 721 // Fullscreen
718 w->Fullscreen(); 722 w->Fullscreen();
719 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); 723 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state());
720 EXPECT_EQ(desktop_bounds, w->bounds()); 724 EXPECT_EQ(desktop_bounds, w->bounds());
721 w->Restore(); 725 w->Restore();
722 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); 726 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state());
723 EXPECT_EQ(original_bounds, w->bounds()); 727 EXPECT_EQ(original_bounds, w->bounds());
724 728
725 // Fullscreen twice 729 // Calling Fullscreen() twice should have no additional effect.
726 w->Fullscreen(); 730 w->Fullscreen();
727 w->Fullscreen(); 731 w->Fullscreen();
728 EXPECT_EQ(desktop_bounds, w->bounds()); 732 EXPECT_EQ(desktop_bounds, w->bounds());
729 w->Restore(); 733 w->Restore();
730 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); 734 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state());
731 EXPECT_EQ(original_bounds, w->bounds()); 735 EXPECT_EQ(original_bounds, w->bounds());
736
737 // Calling SetBounds() in fullscreen mode should only update the
738 // restore bounds not change the bounds of the window.
739 gfx::Rect new_bounds(50, 50, 50, 50);
740 w->Fullscreen();
741 w->SetBounds(new_bounds);
742 EXPECT_EQ(desktop_bounds, w->bounds());
743 w->Restore();
744 EXPECT_EQ(new_bounds, w->bounds());
732 } 745 }
733 746
734 TEST_F(WindowTest, Maximized) { 747 TEST_F(WindowTest, Maximized) {
735 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100); 748 gfx::Rect original_bounds = gfx::Rect(100, 100, 100, 100);
736 gfx::Rect desktop_bounds(Desktop::GetInstance()->GetSize()); 749 gfx::Rect desktop_bounds(Desktop::GetInstance()->GetSize());
737 scoped_ptr<Window> w(CreateTestWindowWithDelegate( 750 scoped_ptr<Window> w(CreateTestWindowWithDelegate(
738 NULL, 1, original_bounds, NULL)); 751 NULL, 1, original_bounds, NULL));
739 EXPECT_EQ(original_bounds, w->bounds()); 752 EXPECT_EQ(original_bounds, w->bounds());
740 753
741 // Maximized 754 // Maximized
(...skipping 21 matching lines...) Expand all
763 EXPECT_EQ(max_bounds, w->bounds()); 776 EXPECT_EQ(max_bounds, w->bounds());
764 w->Fullscreen(); 777 w->Fullscreen();
765 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state()); 778 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, w->show_state());
766 EXPECT_EQ(desktop_bounds, w->bounds()); 779 EXPECT_EQ(desktop_bounds, w->bounds());
767 w->Maximize(); 780 w->Maximize();
768 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state()); 781 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, w->show_state());
769 EXPECT_EQ(max_bounds, w->bounds()); 782 EXPECT_EQ(max_bounds, w->bounds());
770 w->Restore(); 783 w->Restore();
771 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state()); 784 EXPECT_EQ(ui::SHOW_STATE_NORMAL, w->show_state());
772 EXPECT_EQ(original_bounds, w->bounds()); 785 EXPECT_EQ(original_bounds, w->bounds());
786
787 // Calling SetBounds() in maximized mode mode should only update the
788 // restore bounds not change the bounds of the window.
789 gfx::Rect new_bounds(50, 50, 50, 50);
790 w->Maximize();
791 w->SetBounds(new_bounds);
792 EXPECT_EQ(max_bounds, w->bounds());
793 w->Restore();
794 EXPECT_EQ(new_bounds, w->bounds());
773 } 795 }
774 796
775 // Various assertions for activating/deactivating. 797 // Various assertions for activating/deactivating.
776 TEST_F(WindowTest, Deactivate) { 798 TEST_F(WindowTest, Deactivate) {
777 TestWindowDelegate d1; 799 TestWindowDelegate d1;
778 TestWindowDelegate d2; 800 TestWindowDelegate d2;
779 scoped_ptr<Window> w1( 801 scoped_ptr<Window> w1(
780 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); 802 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL));
781 scoped_ptr<Window> w2( 803 scoped_ptr<Window> w2(
782 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); 804 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL));
(...skipping 29 matching lines...) Expand all
812 Window* root = Desktop::GetInstance()->window(); 834 Window* root = Desktop::GetInstance()->window();
813 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); 835 EXPECT_FALSE(root->IsOrContainsFullscreenWindow());
814 836
815 w11->Fullscreen(); 837 w11->Fullscreen();
816 EXPECT_TRUE(root->IsOrContainsFullscreenWindow()); 838 EXPECT_TRUE(root->IsOrContainsFullscreenWindow());
817 839
818 w11->Hide(); 840 w11->Hide();
819 EXPECT_FALSE(root->IsOrContainsFullscreenWindow()); 841 EXPECT_FALSE(root->IsOrContainsFullscreenWindow());
820 } 842 }
821 843
844 class ToplevelWindowTest : public WindowTest {
845 public:
846 ToplevelWindowTest() {}
847 virtual ~ToplevelWindowTest() {}
848
849 virtual void SetUp() OVERRIDE {
850 WindowTest::SetUp();
851 toplevel_container_.Init();
852 toplevel_container_.SetParent(aura::Desktop::GetInstance()->window());
853 toplevel_container_.SetBounds(
854 aura::Desktop::GetInstance()->window()->bounds());
855 toplevel_container_.Show();
856 }
857
858 virtual void TearDown() OVERRIDE {
859 toplevel_container_.Hide();
860 toplevel_container_.SetParent(NULL);
861 WindowTest::TearDown();
862 }
863
864 Window* CreateTestToplevelWindow(
865 WindowDelegate* delegate, const gfx::Rect& bounds) {
866 return CreateTestWindowWithDelegate(
867 delegate, 0 /* id */, bounds, &toplevel_container_);
868 }
869
870 ToplevelWindowContainer toplevel_container_;
871
872 private:
873 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowTest);
874 };
875
876 TEST_F(ToplevelWindowTest, TopMostActivate) {
877 ActivateWindowDelegate activate;
878 ActivateWindowDelegate non_activate(false);
879
880 scoped_ptr<Window> w1(CreateTestToplevelWindow(&non_activate, gfx::Rect()));
881 scoped_ptr<Window> w2(CreateTestToplevelWindow(&activate, gfx::Rect()));
882 scoped_ptr<Window> w3(CreateTestToplevelWindow(&non_activate, gfx::Rect()));
883 EXPECT_EQ(w2.get(), toplevel_container_.GetTopmostWindowToActivate(NULL));
884 }
885
822 class WindowObserverTest : public WindowTest, 886 class WindowObserverTest : public WindowTest,
823 public WindowObserver { 887 public WindowObserver {
824 public: 888 public:
825 WindowObserverTest() : added_count_(0), removed_count_(0) {} 889 WindowObserverTest() : added_count_(0), removed_count_(0) {}
826 890
827 virtual ~WindowObserverTest() {} 891 virtual ~WindowObserverTest() {}
828 892
829 // Returns a description of the WindowObserver methods that have been invoked. 893 // Returns a description of the WindowObserver methods that have been invoked.
830 std::string WindowObserverCountStateAndClear() { 894 std::string WindowObserverCountStateAndClear() {
831 std::string result( 895 std::string result(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 984
921 w3->Activate(); 985 w3->Activate();
922 EXPECT_EQ(w2.get(), active()); 986 EXPECT_EQ(w2.get(), active());
923 987
924 w1->Activate(); 988 w1->Activate();
925 EXPECT_EQ(w1.get(), active()); 989 EXPECT_EQ(w1.get(), active());
926 } 990 }
927 991
928 } // namespace test 992 } // namespace test
929 } // namespace aura 993 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698