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> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/aura/client/window_parenting_client.h" | 23 #include "ui/aura/client/window_parenting_client.h" |
24 #include "ui/aura/layout_manager.h" | 24 #include "ui/aura/layout_manager.h" |
25 #include "ui/aura/test/aura_test_base.h" | 25 #include "ui/aura/test/aura_test_base.h" |
26 #include "ui/aura/test/aura_test_utils.h" | 26 #include "ui/aura/test/aura_test_utils.h" |
27 #include "ui/aura/test/test_window_delegate.h" | 27 #include "ui/aura/test/test_window_delegate.h" |
28 #include "ui/aura/test/test_windows.h" | 28 #include "ui/aura/test/test_windows.h" |
29 #include "ui/aura/test/window_test_api.h" | 29 #include "ui/aura/test/window_test_api.h" |
30 #include "ui/aura/window_delegate.h" | 30 #include "ui/aura/window_delegate.h" |
31 #include "ui/aura/window_event_dispatcher.h" | 31 #include "ui/aura/window_event_dispatcher.h" |
32 #include "ui/aura/window_observer.h" | 32 #include "ui/aura/window_observer.h" |
33 #include "ui/aura/window_property.h" | |
34 #include "ui/aura/window_tree_host.h" | 33 #include "ui/aura/window_tree_host.h" |
| 34 #include "ui/base/class_property.h" |
35 #include "ui/base/hit_test.h" | 35 #include "ui/base/hit_test.h" |
36 #include "ui/compositor/layer.h" | 36 #include "ui/compositor/layer.h" |
37 #include "ui/compositor/layer_animation_observer.h" | 37 #include "ui/compositor/layer_animation_observer.h" |
38 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 38 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
39 #include "ui/compositor/scoped_layer_animation_settings.h" | 39 #include "ui/compositor/scoped_layer_animation_settings.h" |
40 #include "ui/compositor/test/test_layers.h" | 40 #include "ui/compositor/test/test_layers.h" |
41 #include "ui/display/screen.h" | 41 #include "ui/display/screen.h" |
42 #include "ui/events/event.h" | 42 #include "ui/events/event.h" |
43 #include "ui/events/event_utils.h" | 43 #include "ui/events/event_utils.h" |
44 #include "ui/events/gesture_detection/gesture_configuration.h" | 44 #include "ui/events/gesture_detection/gesture_configuration.h" |
45 #include "ui/events/keycodes/keyboard_codes.h" | 45 #include "ui/events/keycodes/keyboard_codes.h" |
46 #include "ui/events/test/event_generator.h" | 46 #include "ui/events/test/event_generator.h" |
47 #include "ui/gfx/canvas.h" | 47 #include "ui/gfx/canvas.h" |
48 #include "ui/gfx/geometry/vector2d.h" | 48 #include "ui/gfx/geometry/vector2d.h" |
49 #include "ui/gfx/skia_util.h" | 49 #include "ui/gfx/skia_util.h" |
50 | 50 |
51 DECLARE_WINDOW_PROPERTY_TYPE(const char*) | 51 DECLARE_UI_CLASS_PROPERTY_TYPE(const char*) |
52 | 52 |
53 namespace { | 53 namespace { |
54 | 54 |
55 enum class DeletionOrder { | 55 enum class DeletionOrder { |
56 LAYOUT_MANAGER_FIRST, | 56 LAYOUT_MANAGER_FIRST, |
57 PROPERTY_FIRST, | 57 PROPERTY_FIRST, |
58 UNKNOWN, | 58 UNKNOWN, |
59 }; | 59 }; |
60 | 60 |
61 class DeletionTracker { | 61 class DeletionTracker { |
(...skipping 29 matching lines...) Expand all Loading... |
91 public: | 91 public: |
92 explicit DeletionTestProperty(DeletionTracker* tracker) : tracker_(tracker) {} | 92 explicit DeletionTestProperty(DeletionTracker* tracker) : tracker_(tracker) {} |
93 ~DeletionTestProperty() { tracker_->PropertyDeleted(); } | 93 ~DeletionTestProperty() { tracker_->PropertyDeleted(); } |
94 | 94 |
95 private: | 95 private: |
96 DeletionTracker* tracker_; | 96 DeletionTracker* tracker_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(DeletionTestProperty); | 98 DISALLOW_COPY_AND_ASSIGN(DeletionTestProperty); |
99 }; | 99 }; |
100 | 100 |
101 class TestProperty { | 101 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(DeletionTestProperty, |
102 public: | 102 kDeletionTestPropertyKey, |
103 TestProperty() {} | 103 nullptr); |
104 ~TestProperty() { | |
105 last_deleted_ = this; | |
106 } | |
107 static TestProperty* last_deleted() { return last_deleted_; } | |
108 | |
109 private: | |
110 static TestProperty* last_deleted_; | |
111 DISALLOW_COPY_AND_ASSIGN(TestProperty); | |
112 }; | |
113 | |
114 TestProperty* TestProperty::last_deleted_ = nullptr; | |
115 | |
116 DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); | |
117 DEFINE_OWNED_WINDOW_PROPERTY_KEY(DeletionTestProperty, | |
118 kDeletionTestPropertyKey, | |
119 nullptr); | |
120 | 104 |
121 } // namespace | 105 } // namespace |
122 | 106 |
123 DECLARE_WINDOW_PROPERTY_TYPE(TestProperty*); | 107 DECLARE_UI_CLASS_PROPERTY_TYPE(DeletionTestProperty*); |
124 | |
125 DECLARE_WINDOW_PROPERTY_TYPE(DeletionTestProperty*); | |
126 | 108 |
127 namespace aura { | 109 namespace aura { |
128 namespace test { | 110 namespace test { |
129 | 111 |
130 class WindowTest : public AuraTestBaseWithType { | 112 class WindowTest : public AuraTestBaseWithType { |
131 public: | 113 public: |
132 WindowTest() : max_separation_(0) { | 114 WindowTest() : max_separation_(0) { |
133 } | 115 } |
134 | 116 |
135 void SetUp() override { | 117 void SetUp() override { |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 transform.Translate(size.height(), 0.0); | 1630 transform.Translate(size.height(), 0.0); |
1649 transform.Rotate(90.0); | 1631 transform.Rotate(90.0); |
1650 host()->SetRootTransform(transform); | 1632 host()->SetRootTransform(transform); |
1651 | 1633 |
1652 ui::TouchEvent press( | 1634 ui::TouchEvent press( |
1653 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); | 1635 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); |
1654 DispatchEventUsingWindowDispatcher(&press); | 1636 DispatchEventUsingWindowDispatcher(&press); |
1655 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); | 1637 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); |
1656 } | 1638 } |
1657 | 1639 |
1658 namespace { | |
1659 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); | |
1660 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); | |
1661 } | |
1662 | |
1663 TEST_P(WindowTest, Property) { | 1640 TEST_P(WindowTest, Property) { |
1664 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); | 1641 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); |
1665 | 1642 |
1666 static const char native_prop_key[] = "fnord"; | 1643 static const char native_prop_key[] = "fnord"; |
1667 | 1644 |
1668 // Non-existent properties should return the default values. | 1645 // Non-existent properties should return the default values. |
1669 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | 1646 EXPECT_EQ(nullptr, w->GetNativeWindowProperty(native_prop_key)); |
1670 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | |
1671 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); | |
1672 | |
1673 // A set property value should be returned again (even if it's the default | |
1674 // value). | |
1675 w->SetProperty(kIntKey, INT_MAX); | |
1676 EXPECT_EQ(INT_MAX, w->GetProperty(kIntKey)); | |
1677 w->SetProperty(kIntKey, -2); | |
1678 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | |
1679 w->SetProperty(kIntKey, INT_MIN); | |
1680 EXPECT_EQ(INT_MIN, w->GetProperty(kIntKey)); | |
1681 | |
1682 w->SetProperty(kStringKey, static_cast<const char*>(NULL)); | |
1683 EXPECT_EQ(NULL, w->GetProperty(kStringKey)); | |
1684 w->SetProperty(kStringKey, "squeamish"); | |
1685 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | |
1686 w->SetProperty(kStringKey, "ossifrage"); | |
1687 EXPECT_EQ(std::string("ossifrage"), w->GetProperty(kStringKey)); | |
1688 | 1647 |
1689 w->SetNativeWindowProperty(native_prop_key, &*w); | 1648 w->SetNativeWindowProperty(native_prop_key, &*w); |
1690 EXPECT_EQ(&*w, w->GetNativeWindowProperty(native_prop_key)); | 1649 EXPECT_EQ(&*w, w->GetNativeWindowProperty(native_prop_key)); |
1691 w->SetNativeWindowProperty(native_prop_key, NULL); | 1650 w->SetNativeWindowProperty(native_prop_key, nullptr); |
1692 EXPECT_EQ(NULL, w->GetNativeWindowProperty(native_prop_key)); | 1651 EXPECT_EQ(nullptr, w->GetNativeWindowProperty(native_prop_key)); |
1693 | |
1694 // ClearProperty should restore the default value. | |
1695 w->ClearProperty(kIntKey); | |
1696 EXPECT_EQ(-2, w->GetProperty(kIntKey)); | |
1697 w->ClearProperty(kStringKey); | |
1698 EXPECT_EQ(std::string("squeamish"), w->GetProperty(kStringKey)); | |
1699 } | |
1700 | |
1701 TEST_P(WindowTest, OwnedProperty) { | |
1702 std::unique_ptr<Window> w(CreateTestWindowWithId(0, root_window())); | |
1703 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); | |
1704 TestProperty* last_deleted = TestProperty::last_deleted(); | |
1705 TestProperty* p1 = new TestProperty(); | |
1706 w->SetProperty(kOwnedKey, p1); | |
1707 EXPECT_EQ(p1, w->GetProperty(kOwnedKey)); | |
1708 EXPECT_EQ(last_deleted, TestProperty::last_deleted()); | |
1709 | |
1710 TestProperty* p2 = new TestProperty(); | |
1711 w->SetProperty(kOwnedKey, p2); | |
1712 EXPECT_EQ(p2, w->GetProperty(kOwnedKey)); | |
1713 EXPECT_EQ(p1, TestProperty::last_deleted()); | |
1714 | |
1715 w->ClearProperty(kOwnedKey); | |
1716 EXPECT_EQ(NULL, w->GetProperty(kOwnedKey)); | |
1717 EXPECT_EQ(p2, TestProperty::last_deleted()); | |
1718 | |
1719 TestProperty* p3 = new TestProperty(); | |
1720 w->SetProperty(kOwnedKey, p3); | |
1721 EXPECT_EQ(p3, w->GetProperty(kOwnedKey)); | |
1722 EXPECT_EQ(p2, TestProperty::last_deleted()); | |
1723 w.reset(); | |
1724 EXPECT_EQ(p3, TestProperty::last_deleted()); | |
1725 } | 1652 } |
1726 | 1653 |
1727 namespace { | 1654 namespace { |
1728 | 1655 |
1729 class DeletionTestLayoutManager : public LayoutManager { | 1656 class DeletionTestLayoutManager : public LayoutManager { |
1730 public: | 1657 public: |
1731 explicit DeletionTestLayoutManager(DeletionTracker* tracker) | 1658 explicit DeletionTestLayoutManager(DeletionTracker* tracker) |
1732 : tracker_(tracker) {} | 1659 : tracker_(tracker) {} |
1733 ~DeletionTestLayoutManager() override { tracker_->LayoutManagerDeleted(); } | 1660 ~DeletionTestLayoutManager() override { tracker_->LayoutManagerDeleted(); } |
1734 | 1661 |
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2987 ::testing::Values(BackendType::CLASSIC, | 2914 ::testing::Values(BackendType::CLASSIC, |
2988 BackendType::MUS)); | 2915 BackendType::MUS)); |
2989 | 2916 |
2990 INSTANTIATE_TEST_CASE_P(/* no prefix */, | 2917 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
2991 WindowObserverTest, | 2918 WindowObserverTest, |
2992 ::testing::Values(BackendType::CLASSIC, | 2919 ::testing::Values(BackendType::CLASSIC, |
2993 BackendType::MUS)); | 2920 BackendType::MUS)); |
2994 | 2921 |
2995 } // namespace test | 2922 } // namespace test |
2996 } // namespace aura | 2923 } // namespace aura |
OLD | NEW |