| 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" |
| 6 |
| 5 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/stringprintf.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/aura/desktop.h" | 11 #include "ui/aura/desktop.h" |
| 9 #include "ui/aura/event.h" | 12 #include "ui/aura/event.h" |
| 10 #include "ui/aura/focus_manager.h" | 13 #include "ui/aura/focus_manager.h" |
| 11 #include "ui/aura/hit_test.h" | 14 #include "ui/aura/hit_test.h" |
| 12 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 16 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/test/test_desktop_delegate.h" | 17 #include "ui/aura/test/test_desktop_delegate.h" |
| 15 #include "ui/aura/test/test_window_delegate.h" | 18 #include "ui/aura/test/test_window_delegate.h" |
| 16 #include "ui/aura/window_delegate.h" | 19 #include "ui/aura/window_delegate.h" |
| 20 #include "ui/aura/window_observer.h" |
| 17 #include "ui/gfx/canvas_skia.h" | 21 #include "ui/gfx/canvas_skia.h" |
| 18 #include "ui/gfx/compositor/layer.h" | 22 #include "ui/gfx/compositor/layer.h" |
| 19 #include "ui/base/keycodes/keyboard_codes.h" | 23 #include "ui/base/keycodes/keyboard_codes.h" |
| 20 | 24 |
| 21 namespace aura { | 25 namespace aura { |
| 22 namespace test { | 26 namespace test { |
| 23 | 27 |
| 24 namespace { | 28 namespace { |
| 25 | 29 |
| 26 // Used for verifying destruction methods are invoked. | 30 // 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()); | 757 EXPECT_FALSE(w2->IsActive()); |
| 754 EXPECT_EQ(w1.get(), parent->children()[1]); | 758 EXPECT_EQ(w1.get(), parent->children()[1]); |
| 755 | 759 |
| 756 // Deactivate w1 and make sure w2 becomes active and frontmost. | 760 // Deactivate w1 and make sure w2 becomes active and frontmost. |
| 757 w1->Deactivate(); | 761 w1->Deactivate(); |
| 758 EXPECT_FALSE(w1->IsActive()); | 762 EXPECT_FALSE(w1->IsActive()); |
| 759 EXPECT_TRUE(w2->IsActive()); | 763 EXPECT_TRUE(w2->IsActive()); |
| 760 EXPECT_EQ(w2.get(), parent->children()[1]); | 764 EXPECT_EQ(w2.get(), parent->children()[1]); |
| 761 } | 765 } |
| 762 | 766 |
| 767 class ObserverTest : public WindowTest, |
| 768 public WindowObserver { |
| 769 public: |
| 770 ObserverTest() : added_count_(0), removed_count_(0) {} |
| 771 |
| 772 virtual ~ObserverTest() {} |
| 773 |
| 774 // Returns a description of the WindowObserver methods that have been invoked. |
| 775 std::string WindowObserverCountStateAndClear() { |
| 776 std::string result( |
| 777 base::StringPrintf("added=%d removed=%d", |
| 778 added_count_, removed_count_)); |
| 779 added_count_ = removed_count_ = 0; |
| 780 return result; |
| 781 } |
| 782 |
| 783 private: |
| 784 virtual void OnWindowAdded(Window* new_window) OVERRIDE { |
| 785 added_count_++; |
| 786 } |
| 787 |
| 788 virtual void OnWillRemoveWindow(Window* window) OVERRIDE { |
| 789 removed_count_++; |
| 790 } |
| 791 |
| 792 int added_count_; |
| 793 int removed_count_; |
| 794 |
| 795 DISALLOW_COPY_AND_ASSIGN(ObserverTest); |
| 796 }; |
| 797 |
| 798 // Various assertions for WindowObserver. |
| 799 TEST_F(ObserverTest, WindowObserver) { |
| 800 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 801 w1->AddObserver(this); |
| 802 |
| 803 // Create a new window as a child of w1, our observer should be notified. |
| 804 scoped_ptr<Window> w2(CreateTestWindowWithId(2, w1.get())); |
| 805 EXPECT_EQ("added=1 removed=0", WindowObserverCountStateAndClear()); |
| 806 |
| 807 // Delete w2, which should result in the remove notification. |
| 808 w2.reset(); |
| 809 EXPECT_EQ("added=0 removed=1", WindowObserverCountStateAndClear()); |
| 810 |
| 811 // Create a window that isn't parented to w1, we shouldn't get any |
| 812 // notification. |
| 813 scoped_ptr<Window> w3(CreateTestWindowWithId(3, NULL)); |
| 814 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
| 815 |
| 816 // Similarly destroying w3 shouldn't notify us either. |
| 817 w3.reset(); |
| 818 EXPECT_EQ("added=0 removed=0", WindowObserverCountStateAndClear()); |
| 819 w1->RemoveObserver(this); |
| 820 } |
| 821 |
| 763 } // namespace test | 822 } // namespace test |
| 764 } // namespace aura | 823 } // namespace aura |
| OLD | NEW |