| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/aura/client/capture_client.h" | 20 #include "ui/aura/client/capture_client.h" |
| 21 #include "ui/aura/client/focus_change_observer.h" | 21 #include "ui/aura/client/focus_change_observer.h" |
| 22 #include "ui/aura/client/visibility_client.h" | 22 #include "ui/aura/client/visibility_client.h" |
| 23 #include "ui/aura/client/window_tree_client.h" | 23 #include "ui/aura/client/window_tree_client.h" |
| 24 #include "ui/aura/layout_manager.h" |
| 24 #include "ui/aura/test/aura_test_base.h" | 25 #include "ui/aura/test/aura_test_base.h" |
| 25 #include "ui/aura/test/aura_test_utils.h" | 26 #include "ui/aura/test/aura_test_utils.h" |
| 26 #include "ui/aura/test/test_window_delegate.h" | 27 #include "ui/aura/test/test_window_delegate.h" |
| 27 #include "ui/aura/test/test_windows.h" | 28 #include "ui/aura/test/test_windows.h" |
| 28 #include "ui/aura/test/window_test_api.h" | 29 #include "ui/aura/test/window_test_api.h" |
| 29 #include "ui/aura/window_delegate.h" | 30 #include "ui/aura/window_delegate.h" |
| 30 #include "ui/aura/window_event_dispatcher.h" | 31 #include "ui/aura/window_event_dispatcher.h" |
| 31 #include "ui/aura/window_observer.h" | 32 #include "ui/aura/window_observer.h" |
| 32 #include "ui/aura/window_property.h" | 33 #include "ui/aura/window_property.h" |
| 33 #include "ui/aura/window_tree_host.h" | 34 #include "ui/aura/window_tree_host.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 #include "ui/events/test/event_generator.h" | 45 #include "ui/events/test/event_generator.h" |
| 45 #include "ui/gfx/canvas.h" | 46 #include "ui/gfx/canvas.h" |
| 46 #include "ui/gfx/geometry/vector2d.h" | 47 #include "ui/gfx/geometry/vector2d.h" |
| 47 #include "ui/gfx/screen.h" | 48 #include "ui/gfx/screen.h" |
| 48 #include "ui/gfx/skia_util.h" | 49 #include "ui/gfx/skia_util.h" |
| 49 | 50 |
| 50 DECLARE_WINDOW_PROPERTY_TYPE(const char*) | 51 DECLARE_WINDOW_PROPERTY_TYPE(const char*) |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| 53 | 54 |
| 55 enum class DeletionOrder { |
| 56 LAYOUT_MANAGER_FIRST, |
| 57 PROPERTY_FIRST, |
| 58 UNKNOWN, |
| 59 }; |
| 60 |
| 61 class DeletionTracker { |
| 62 public: |
| 63 DeletionTracker() {} |
| 64 ~DeletionTracker() {} |
| 65 |
| 66 DeletionOrder order() const { return order_; } |
| 67 bool property_deleted() const { return property_deleted_; } |
| 68 bool layout_manager_deleted() const { return layout_manager_deleted_; } |
| 69 |
| 70 void PropertyDeleted() { |
| 71 property_deleted_ = true; |
| 72 if (order_ == DeletionOrder::UNKNOWN) |
| 73 order_ = DeletionOrder::PROPERTY_FIRST; |
| 74 } |
| 75 |
| 76 void LayoutManagerDeleted() { |
| 77 layout_manager_deleted_ = true; |
| 78 if (order_ == DeletionOrder::UNKNOWN) |
| 79 order_ = DeletionOrder::LAYOUT_MANAGER_FIRST; |
| 80 } |
| 81 |
| 82 private: |
| 83 bool property_deleted_ = false; |
| 84 bool layout_manager_deleted_ = false; |
| 85 DeletionOrder order_ = DeletionOrder::UNKNOWN; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(DeletionTracker); |
| 88 }; |
| 89 |
| 90 class DeletionTestProperty { |
| 91 public: |
| 92 explicit DeletionTestProperty(DeletionTracker* tracker) : tracker_(tracker) {} |
| 93 ~DeletionTestProperty() { tracker_->PropertyDeleted(); } |
| 94 |
| 95 private: |
| 96 DeletionTracker* tracker_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(DeletionTestProperty); |
| 99 }; |
| 100 |
| 54 class TestProperty { | 101 class TestProperty { |
| 55 public: | 102 public: |
| 56 TestProperty() {} | 103 TestProperty() {} |
| 57 ~TestProperty() { | 104 ~TestProperty() { |
| 58 last_deleted_ = this; | 105 last_deleted_ = this; |
| 59 } | 106 } |
| 60 static TestProperty* last_deleted() { return last_deleted_; } | 107 static TestProperty* last_deleted() { return last_deleted_; } |
| 61 | 108 |
| 62 private: | 109 private: |
| 63 static TestProperty* last_deleted_; | 110 static TestProperty* last_deleted_; |
| 64 DISALLOW_COPY_AND_ASSIGN(TestProperty); | 111 DISALLOW_COPY_AND_ASSIGN(TestProperty); |
| 65 }; | 112 }; |
| 66 | 113 |
| 67 TestProperty* TestProperty::last_deleted_ = nullptr; | 114 TestProperty* TestProperty::last_deleted_ = nullptr; |
| 68 | 115 |
| 69 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); | 116 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); |
| 117 DEFINE_OWNED_WINDOW_PROPERTY_KEY(DeletionTestProperty, |
| 118 kDeletionTestPropertyKey, |
| 119 nullptr); |
| 70 | 120 |
| 71 } // namespace | 121 } // namespace |
| 72 | 122 |
| 73 DECLARE_WINDOW_PROPERTY_TYPE(TestProperty*); | 123 DECLARE_WINDOW_PROPERTY_TYPE(TestProperty*); |
| 74 | 124 |
| 125 DECLARE_WINDOW_PROPERTY_TYPE(DeletionTestProperty*); |
| 126 |
| 75 namespace aura { | 127 namespace aura { |
| 76 namespace test { | 128 namespace test { |
| 77 | 129 |
| 78 class WindowTest : public AuraTestBase { | 130 class WindowTest : public AuraTestBase { |
| 79 public: | 131 public: |
| 80 WindowTest() : max_separation_(0) { | 132 WindowTest() : max_separation_(0) { |
| 81 } | 133 } |
| 82 | 134 |
| 83 void SetUp() override { | 135 void SetUp() override { |
| 84 AuraTestBase::SetUp(); | 136 AuraTestBase::SetUp(); |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1664 EXPECT_EQ(p2, TestProperty::last_deleted()); | 1716 EXPECT_EQ(p2, TestProperty::last_deleted()); |
| 1665 | 1717 |
| 1666 TestProperty* p3 = new TestProperty(); | 1718 TestProperty* p3 = new TestProperty(); |
| 1667 w->SetProperty(kOwnedKey, p3); | 1719 w->SetProperty(kOwnedKey, p3); |
| 1668 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); | 1720 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); |
| 1669 EXPECT_EQ(p2, TestProperty::last_deleted()); | 1721 EXPECT_EQ(p2, TestProperty::last_deleted()); |
| 1670 w.reset(); | 1722 w.reset(); |
| 1671 EXPECT_EQ(p3, TestProperty::last_deleted()); | 1723 EXPECT_EQ(p3, TestProperty::last_deleted()); |
| 1672 } | 1724 } |
| 1673 | 1725 |
| 1726 namespace { |
| 1727 |
| 1728 class DeletionTestLayoutManager : public LayoutManager { |
| 1729 public: |
| 1730 explicit DeletionTestLayoutManager(DeletionTracker* tracker) |
| 1731 : tracker_(tracker) {} |
| 1732 ~DeletionTestLayoutManager() override { tracker_->LayoutManagerDeleted(); } |
| 1733 |
| 1734 private: |
| 1735 // LayoutManager: |
| 1736 void OnWindowResized() override {} |
| 1737 void OnWindowAddedToLayout(Window* child) override {} |
| 1738 void OnWillRemoveWindowFromLayout(Window* child) override {} |
| 1739 void OnWindowRemovedFromLayout(Window* child) override {} |
| 1740 void OnChildWindowVisibilityChanged(Window* child, bool visible) override {} |
| 1741 void SetChildBounds(Window* child, |
| 1742 const gfx::Rect& requested_bounds) override {} |
| 1743 |
| 1744 DeletionTracker* tracker_; |
| 1745 |
| 1746 DISALLOW_COPY_AND_ASSIGN(DeletionTestLayoutManager); |
| 1747 }; |
| 1748 |
| 1749 } // namespace |
| 1750 |
| 1751 TEST_F(WindowTest, DeleteLayoutManagerBeforeOwnedProps) { |
| 1752 DeletionTracker tracker; |
| 1753 { |
| 1754 Window w(nullptr); |
| 1755 w.Init(ui::LAYER_NOT_DRAWN); |
| 1756 w.SetLayoutManager(new DeletionTestLayoutManager(&tracker)); |
| 1757 w.SetProperty(kDeletionTestPropertyKey, new DeletionTestProperty(&tracker)); |
| 1758 } |
| 1759 EXPECT_TRUE(tracker.property_deleted()); |
| 1760 EXPECT_TRUE(tracker.layout_manager_deleted()); |
| 1761 EXPECT_EQ(DeletionOrder::LAYOUT_MANAGER_FIRST, tracker.order()); |
| 1762 } |
| 1763 |
| 1674 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { | 1764 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { |
| 1675 // We cannot short-circuit animations in this test. | 1765 // We cannot short-circuit animations in this test. |
| 1676 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 1766 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 1677 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 1767 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 1678 | 1768 |
| 1679 std::unique_ptr<Window> w1( | 1769 std::unique_ptr<Window> w1( |
| 1680 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); | 1770 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); |
| 1681 | 1771 |
| 1682 EXPECT_TRUE(w1->layer()); | 1772 EXPECT_TRUE(w1->layer()); |
| 1683 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); | 1773 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); |
| (...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2890 | 2980 |
| 2891 EXPECT_TRUE(animator.get()); | 2981 EXPECT_TRUE(animator.get()); |
| 2892 EXPECT_FALSE(animator->is_animating()); | 2982 EXPECT_FALSE(animator->is_animating()); |
| 2893 EXPECT_TRUE(observer.animation_completed()); | 2983 EXPECT_TRUE(observer.animation_completed()); |
| 2894 EXPECT_FALSE(observer.animation_aborted()); | 2984 EXPECT_FALSE(observer.animation_aborted()); |
| 2895 animator->RemoveObserver(&observer); | 2985 animator->RemoveObserver(&observer); |
| 2896 } | 2986 } |
| 2897 | 2987 |
| 2898 } // namespace test | 2988 } // namespace test |
| 2899 } // namespace aura | 2989 } // namespace aura |
| OLD | NEW |