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

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

Issue 8894018: Move the concept of Activation to the Shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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"
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 Window::ConvertPointToWindow(w2->parent(), root_window, &move_point); 508 Window::ConvertPointToWindow(w2->parent(), root_window, &move_point);
509 MouseEvent mouseev2(ui::ET_MOUSE_MOVED, move_point, 0); 509 MouseEvent mouseev2(ui::ET_MOUSE_MOVED, move_point, 0);
510 root_window->DispatchMouseEvent(&mouseev2); 510 root_window->DispatchMouseEvent(&mouseev2);
511 511
512 EXPECT_TRUE(d1.entered()); 512 EXPECT_TRUE(d1.entered());
513 EXPECT_TRUE(d1.exited()); 513 EXPECT_TRUE(d1.exited());
514 EXPECT_TRUE(d2.entered()); 514 EXPECT_TRUE(d2.entered());
515 EXPECT_FALSE(d2.exited()); 515 EXPECT_FALSE(d2.exited());
516 } 516 }
517 517
518 namespace {
519
520 class ActiveWindowDelegate : public TestWindowDelegate {
521 public:
522 ActiveWindowDelegate() : window_(NULL), was_active_(false), hit_count_(0) {
523 }
524
525 void set_window(Window* window) { window_ = window; }
526
527 // Number of times OnLostActive has been invoked.
528 int hit_count() const { return hit_count_; }
529
530 // Was the window active from the first call to OnLostActive?
531 bool was_active() const { return was_active_; }
532
533 virtual void OnLostActive() OVERRIDE {
534 if (hit_count_++ == 0)
535 was_active_ = window_->IsActive();
536 }
537
538 private:
539 Window* window_;
540
541 // See description above getters for details on these.
542 bool was_active_;
543 int hit_count_;
544
545 DISALLOW_COPY_AND_ASSIGN(ActiveWindowDelegate);
546 };
547
548 } // namespace
549
550 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not
551 // active.
552 TEST_F(WindowTest, NotActiveInLostActive) {
553 RootWindow* root_window = RootWindow::GetInstance();
554
555 ActiveWindowDelegate d1;
556 scoped_ptr<Window> w1(
557 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
558 d1.set_window(w1.get());
559 scoped_ptr<Window> w2(
560 CreateTestWindowWithDelegate(NULL, 1, gfx::Rect(10, 10, 50, 50), NULL));
561
562 // Activate w1.
563 root_window->SetActiveWindow(w1.get(), NULL);
564 EXPECT_EQ(w1.get(), root_window->active_window());
565
566 // Should not have gotten a OnLostActive yet.
567 EXPECT_EQ(0, d1.hit_count());
568
569 // SetActiveWindow(NULL) should not change the active window.
570 root_window->SetActiveWindow(NULL, NULL);
571 EXPECT_TRUE(root_window->active_window() == w1.get());
572
573 // Now activate another window.
574 root_window->SetActiveWindow(w2.get(), NULL);
575
576 // Should have gotten OnLostActive and w1 should not have been active at that
577 // time.
578 EXPECT_EQ(1, d1.hit_count());
579 EXPECT_FALSE(d1.was_active());
580 }
581
582 // Creates a window with a delegate (w111) that can handle events at a lower 518 // Creates a window with a delegate (w111) that can handle events at a lower
583 // z-index than a window without a delegate (w12). w12 is sized to fill the 519 // z-index than a window without a delegate (w12). w12 is sized to fill the
584 // entire bounds of the container. This test verifies that 520 // entire bounds of the container. This test verifies that
585 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event, 521 // GetEventHandlerForPoint() skips w12 even though its bounds contain the event,
586 // because it has no children that can handle the event and it has no delegate 522 // because it has no children that can handle the event and it has no delegate
587 // allowing it to handle the event itself. 523 // allowing it to handle the event itself.
588 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) { 524 TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) {
589 TestWindowDelegate d111; 525 TestWindowDelegate d111;
590 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, 526 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1,
591 gfx::Rect(0, 0, 500, 500), NULL)); 527 gfx::Rect(0, 0, 500, 500), NULL));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 675
740 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); 676 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
741 w121->set_ignore_events(true); 677 w121->set_ignore_events(true);
742 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); 678 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
743 w12->set_ignore_events(true); 679 w12->set_ignore_events(true);
744 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); 680 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
745 w111->set_ignore_events(true); 681 w111->set_ignore_events(true);
746 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); 682 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
747 } 683 }
748 684
749 // Various assertions for activating/deactivating.
750 TEST_F(WindowTest, Deactivate) {
751 TestWindowDelegate d1;
752 TestWindowDelegate d2;
753 scoped_ptr<Window> w1(
754 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL));
755 scoped_ptr<Window> w2(
756 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL));
757 Window* parent = w1->parent();
758 parent->Show();
759 ASSERT_TRUE(parent);
760 ASSERT_EQ(2u, parent->children().size());
761 // Activate w2 and make sure it's active and frontmost.
762 w2->Activate();
763 EXPECT_TRUE(w2->IsActive());
764 EXPECT_FALSE(w1->IsActive());
765 EXPECT_EQ(w2.get(), parent->children()[1]);
766
767 // Activate w1 and make sure it's active and frontmost.
768 w1->Activate();
769 EXPECT_TRUE(w1->IsActive());
770 EXPECT_FALSE(w2->IsActive());
771 EXPECT_EQ(w1.get(), parent->children()[1]);
772
773 // Deactivate w1 and make sure w2 becomes active and frontmost.
774 w1->Deactivate();
775 EXPECT_FALSE(w1->IsActive());
776 EXPECT_TRUE(w2->IsActive());
777 EXPECT_EQ(w2.get(), parent->children()[1]);
778 }
779
780 // Tests transformation on the root window. 685 // Tests transformation on the root window.
781 TEST_F(WindowTest, Transform) { 686 TEST_F(WindowTest, Transform) {
782 RootWindow* root_window = RootWindow::GetInstance(); 687 RootWindow* root_window = RootWindow::GetInstance();
783 gfx::Size size = root_window->GetHostSize(); 688 gfx::Size size = root_window->GetHostSize();
784 EXPECT_EQ(gfx::Rect(size), 689 EXPECT_EQ(gfx::Rect(size),
785 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point())); 690 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()));
786 691
787 // Rotate it clock-wise 90 degrees. 692 // Rotate it clock-wise 90 degrees.
788 ui::Transform transform; 693 ui::Transform transform;
789 transform.SetRotate(90.0f); 694 transform.SetRotate(90.0f);
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 EXPECT_EQ(2, w1->GetIntProperty(key)); 990 EXPECT_EQ(2, w1->GetIntProperty(key));
1086 EXPECT_EQ(reinterpret_cast<void*>(2), w1->GetProperty(key)); 991 EXPECT_EQ(reinterpret_cast<void*>(2), w1->GetProperty(key));
1087 EXPECT_EQ("name=test old=1 new=2", PropertyChangeInfoAndClear()); 992 EXPECT_EQ("name=test old=1 new=2", PropertyChangeInfoAndClear());
1088 w1->SetProperty(key, NULL); 993 w1->SetProperty(key, NULL);
1089 EXPECT_EQ("name=test old=2 new=0", PropertyChangeInfoAndClear()); 994 EXPECT_EQ("name=test old=2 new=0", PropertyChangeInfoAndClear());
1090 995
1091 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. 996 // Sanity check to see if |PropertyChangeInfoAndClear| really clears.
1092 EXPECT_EQ("name= old=0 new=0", PropertyChangeInfoAndClear()); 997 EXPECT_EQ("name= old=0 new=0", PropertyChangeInfoAndClear());
1093 } 998 }
1094 999
1095 class RootWindowObserverTest : public WindowTest,
1096 public RootWindowObserver {
1097 public:
1098 RootWindowObserverTest() : active_(NULL) {
1099 }
1100
1101 virtual ~RootWindowObserverTest() {}
1102
1103 Window* active() const { return active_; }
1104
1105 void Reset() {
1106 active_ = NULL;
1107 }
1108
1109 private:
1110 virtual void SetUp() OVERRIDE {
1111 WindowTest::SetUp();
1112 RootWindow::GetInstance()->AddObserver(this);
1113 }
1114
1115 virtual void TearDown() OVERRIDE {
1116 RootWindow::GetInstance()->RemoveObserver(this);
1117 WindowTest::TearDown();
1118 }
1119
1120 virtual void OnActiveWindowChanged(Window* active) OVERRIDE {
1121 active_ = active;
1122 }
1123
1124 Window* active_;
1125
1126 DISALLOW_COPY_AND_ASSIGN(RootWindowObserverTest);
1127 };
1128
1129 TEST_F(RootWindowObserverTest, WindowActivationObserve) {
1130 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
1131 scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL));
1132 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get()));
1133
1134 EXPECT_EQ(NULL, active());
1135
1136 w2->Activate();
1137 EXPECT_EQ(w2.get(), active());
1138
1139 w3->Activate();
1140 EXPECT_EQ(w2.get(), active());
1141
1142 w1->Activate();
1143 EXPECT_EQ(w1.get(), active());
1144 }
1145
1146 } // namespace test 1000 } // namespace test
1147 } // namespace aura 1001 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698