| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/aura/desktop.h" | 8 #include "ui/aura/desktop.h" |
| 9 #include "ui/aura/desktop_observer.h" |
| 9 #include "ui/aura/event.h" | 10 #include "ui/aura/event.h" |
| 10 #include "ui/aura/focus_manager.h" | 11 #include "ui/aura/focus_manager.h" |
| 11 #include "ui/aura/hit_test.h" | 12 #include "ui/aura/hit_test.h" |
| 12 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 14 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/test/test_desktop_delegate.h" | 15 #include "ui/aura/test/test_desktop_delegate.h" |
| 15 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
| 16 #include "ui/aura/window_delegate.h" | 17 #include "ui/aura/window_delegate.h" |
| 18 #include "ui/aura/window_observer.h" |
| 17 #include "ui/gfx/canvas_skia.h" | 19 #include "ui/gfx/canvas_skia.h" |
| 18 #include "ui/gfx/compositor/layer.h" | 20 #include "ui/gfx/compositor/layer.h" |
| 19 #include "ui/base/keycodes/keyboard_codes.h" | 21 #include "ui/base/keycodes/keyboard_codes.h" |
| 20 | 22 |
| 21 namespace aura { | 23 namespace aura { |
| 22 namespace test { | 24 namespace test { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Used for verifying destruction methods are invoked. | 28 // Used for verifying destruction methods are invoked. |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 EXPECT_FALSE(w2->IsActive()); | 755 EXPECT_FALSE(w2->IsActive()); |
| 754 EXPECT_EQ(w1.get(), parent->children()[1]); | 756 EXPECT_EQ(w1.get(), parent->children()[1]); |
| 755 | 757 |
| 756 // Deactivate w1 and make sure w2 becomes active and frontmost. | 758 // Deactivate w1 and make sure w2 becomes active and frontmost. |
| 757 w1->Deactivate(); | 759 w1->Deactivate(); |
| 758 EXPECT_FALSE(w1->IsActive()); | 760 EXPECT_FALSE(w1->IsActive()); |
| 759 EXPECT_TRUE(w2->IsActive()); | 761 EXPECT_TRUE(w2->IsActive()); |
| 760 EXPECT_EQ(w2.get(), parent->children()[1]); | 762 EXPECT_EQ(w2.get(), parent->children()[1]); |
| 761 } | 763 } |
| 762 | 764 |
| 765 class ObserverTest : public WindowTest, |
| 766 public DesktopObserver, |
| 767 public WindowObserver { |
| 768 public: |
| 769 ObserverTest() |
| 770 : active_(NULL), |
| 771 shown_(NULL), |
| 772 hidden_(NULL) { |
| 773 } |
| 774 |
| 775 virtual ~ObserverTest() {} |
| 776 |
| 777 Window* active() const { return active_; } |
| 778 Window* shown() const { return shown_; } |
| 779 Window* hidden() const { return hidden_; } |
| 780 |
| 781 void Reset() { |
| 782 active_ = NULL; |
| 783 shown_ = NULL; |
| 784 hidden_ = NULL; |
| 785 } |
| 786 |
| 787 private: |
| 788 virtual void SetUp() OVERRIDE { |
| 789 WindowTest::SetUp(); |
| 790 Desktop::GetInstance()->AddObserver(this); |
| 791 } |
| 792 |
| 793 virtual void TearDown() OVERRIDE { |
| 794 Desktop::GetInstance()->RemoveObserver(this); |
| 795 WindowTest::TearDown(); |
| 796 } |
| 797 |
| 798 virtual void OnActiveWindowChanged(Window* active) OVERRIDE { |
| 799 active_ = active; |
| 800 } |
| 801 |
| 802 virtual void OnWindowVisibilityChanged(Window* window) OVERRIDE { |
| 803 if (window->IsVisible()) |
| 804 shown_ = window; |
| 805 else |
| 806 hidden_ = window; |
| 807 } |
| 808 |
| 809 Window* active_; |
| 810 Window* shown_; |
| 811 Window* hidden_; |
| 812 |
| 813 DISALLOW_COPY_AND_ASSIGN(ObserverTest); |
| 814 }; |
| 815 |
| 816 TEST_F(ObserverTest, WindowActivationObserve) { |
| 817 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 818 scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL)); |
| 819 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); |
| 820 |
| 821 EXPECT_EQ(NULL, active()); |
| 822 |
| 823 w2->Activate(); |
| 824 EXPECT_EQ(w2.get(), active()); |
| 825 |
| 826 w3->Activate(); |
| 827 EXPECT_EQ(w2.get(), active()); |
| 828 |
| 829 w1->Activate(); |
| 830 EXPECT_EQ(w1.get(), active()); |
| 831 } |
| 832 |
| 833 TEST_F(ObserverTest, WindowVisibilityObserve) { |
| 834 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 835 scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL)); |
| 836 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); |
| 837 |
| 838 w1->AddObserver(this); |
| 839 w2->AddObserver(this); |
| 840 w3->AddObserver(this); |
| 841 |
| 842 Reset(); |
| 843 w1->Show(); |
| 844 EXPECT_EQ(w1.get(), shown()); |
| 845 |
| 846 w2->Show(); |
| 847 EXPECT_EQ(w2.get(), shown()); |
| 848 |
| 849 w3->Show(); |
| 850 EXPECT_EQ(w3.get(), shown()); |
| 851 |
| 852 w1->Hide(); |
| 853 EXPECT_EQ(w1.get(), hidden()); |
| 854 |
| 855 w3->Hide(); |
| 856 EXPECT_EQ(w3.get(), hidden()); |
| 857 } |
| 858 |
| 763 } // namespace test | 859 } // namespace test |
| 764 } // namespace aura | 860 } // namespace aura |
| OLD | NEW |