OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/view_manager/public/cpp/view.h" | 5 #include "mojo/services/view_manager/public/cpp/view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "mojo/services/view_manager/public/cpp/lib/view_private.h" | 9 #include "mojo/services/view_manager/public/cpp/lib/view_private.h" |
10 #include "mojo/services/view_manager/public/cpp/util.h" | 10 #include "mojo/services/view_manager/public/cpp/util.h" |
11 #include "mojo/services/view_manager/public/cpp/view_observer.h" | 11 #include "mojo/services/view_manager/public/cpp/view_observer.h" |
12 #include "mojo/services/view_manager/public/cpp/view_property.h" | 12 #include "mojo/services/view_manager/public/cpp/view_property.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 | 16 |
17 // View ------------------------------------------------------------------------ | 17 // View ------------------------------------------------------------------------ |
18 | 18 |
19 typedef testing::Test ViewTest; | 19 typedef testing::Test ViewTest; |
20 | 20 |
21 // Subclass with public ctor/dtor. | 21 // Subclass with public ctor/dtor. |
22 class TestView : public View { | 22 class TestView : public View { |
23 public: | 23 public: |
24 TestView() { | 24 TestView() { |
25 ViewPrivate(this).set_id(1); | 25 ViewPrivate(this).set_id(1); |
26 } | 26 } |
27 ~TestView() {} | 27 ~TestView() {} |
28 | 28 |
29 private: | 29 private: |
30 DISALLOW_COPY_AND_ASSIGN(TestView); | 30 MOJO_DISALLOW_COPY_AND_ASSIGN(TestView); |
31 }; | 31 }; |
32 | 32 |
33 TEST_F(ViewTest, AddChild) { | 33 TEST_F(ViewTest, AddChild) { |
34 TestView v1; | 34 TestView v1; |
35 TestView v11; | 35 TestView v11; |
36 v1.AddChild(&v11); | 36 v1.AddChild(&v11); |
37 EXPECT_EQ(1U, v1.children().size()); | 37 EXPECT_EQ(1U, v1.children().size()); |
38 } | 38 } |
39 | 39 |
40 TEST_F(ViewTest, RemoveChild) { | 40 TEST_F(ViewTest, RemoveChild) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 namespace { | 141 namespace { |
142 | 142 |
143 class TestProperty { | 143 class TestProperty { |
144 public: | 144 public: |
145 TestProperty() {} | 145 TestProperty() {} |
146 virtual ~TestProperty() { last_deleted_ = this; } | 146 virtual ~TestProperty() { last_deleted_ = this; } |
147 static TestProperty* last_deleted() { return last_deleted_; } | 147 static TestProperty* last_deleted() { return last_deleted_; } |
148 | 148 |
149 private: | 149 private: |
150 static TestProperty* last_deleted_; | 150 static TestProperty* last_deleted_; |
151 DISALLOW_COPY_AND_ASSIGN(TestProperty); | 151 MOJO_DISALLOW_COPY_AND_ASSIGN(TestProperty); |
152 }; | 152 }; |
153 | 153 |
154 TestProperty* TestProperty::last_deleted_ = NULL; | 154 TestProperty* TestProperty::last_deleted_ = NULL; |
155 | 155 |
156 DEFINE_OWNED_VIEW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); | 156 DEFINE_OWNED_VIEW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); |
157 | 157 |
158 } // namespace | 158 } // namespace |
159 | 159 |
160 TEST_F(ViewTest, OwnedProperty) { | 160 TEST_F(ViewTest, OwnedProperty) { |
161 TestProperty* p3 = NULL; | 161 TestProperty* p3 = NULL; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 void OnTreeChanging(const TreeChangeParams& params) override { | 215 void OnTreeChanging(const TreeChangeParams& params) override { |
216 received_params_.push_back(params); | 216 received_params_.push_back(params); |
217 } | 217 } |
218 void OnTreeChanged(const TreeChangeParams& params) override { | 218 void OnTreeChanged(const TreeChangeParams& params) override { |
219 received_params_.push_back(params); | 219 received_params_.push_back(params); |
220 } | 220 } |
221 | 221 |
222 View* observee_; | 222 View* observee_; |
223 std::vector<TreeChangeParams> received_params_; | 223 std::vector<TreeChangeParams> received_params_; |
224 | 224 |
225 DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver); | 225 MOJO_DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver); |
226 }; | 226 }; |
227 | 227 |
228 // Adds/Removes v11 to v1. | 228 // Adds/Removes v11 to v1. |
229 TEST_F(ViewObserverTest, TreeChange_SimpleAddRemove) { | 229 TEST_F(ViewObserverTest, TreeChange_SimpleAddRemove) { |
230 TestView v1; | 230 TestView v1; |
231 TreeChangeObserver o1(&v1); | 231 TreeChangeObserver o1(&v1); |
232 EXPECT_TRUE(o1.received_params().empty()); | 232 EXPECT_TRUE(o1.received_params().empty()); |
233 | 233 |
234 TestView v11; | 234 TestView v11; |
235 TreeChangeObserver o11(&v11); | 235 TreeChangeObserver o11(&v11); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 Change change; | 456 Change change; |
457 change.view = view; | 457 change.view = view; |
458 change.relative_view = relative_view; | 458 change.relative_view = relative_view; |
459 change.direction = direction; | 459 change.direction = direction; |
460 changes_.push_back(change); | 460 changes_.push_back(change); |
461 } | 461 } |
462 | 462 |
463 View* observee_; | 463 View* observee_; |
464 Changes changes_; | 464 Changes changes_; |
465 | 465 |
466 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); | 466 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); |
467 }; | 467 }; |
468 | 468 |
469 } // namespace | 469 } // namespace |
470 | 470 |
471 TEST_F(ViewObserverTest, Order) { | 471 TEST_F(ViewObserverTest, Order) { |
472 TestView v1, v11, v12, v13; | 472 TestView v1, v11, v12, v13; |
473 v1.AddChild(&v11); | 473 v1.AddChild(&v11); |
474 v1.AddChild(&v12); | 474 v1.AddChild(&v12); |
475 v1.AddChild(&v13); | 475 v1.AddChild(&v13); |
476 | 476 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 base::StringPrintf( | 606 base::StringPrintf( |
607 "view=%s old_bounds=%s new_bounds=%s phase=changed", | 607 "view=%s old_bounds=%s new_bounds=%s phase=changed", |
608 ViewIdToString(view->id()).c_str(), | 608 ViewIdToString(view->id()).c_str(), |
609 RectToString(old_bounds).c_str(), | 609 RectToString(old_bounds).c_str(), |
610 RectToString(new_bounds).c_str())); | 610 RectToString(new_bounds).c_str())); |
611 } | 611 } |
612 | 612 |
613 View* view_; | 613 View* view_; |
614 Changes changes_; | 614 Changes changes_; |
615 | 615 |
616 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); | 616 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); |
617 }; | 617 }; |
618 | 618 |
619 } // namespace | 619 } // namespace |
620 | 620 |
621 TEST_F(ViewObserverTest, SetBounds) { | 621 TEST_F(ViewObserverTest, SetBounds) { |
622 TestView v1; | 622 TestView v1; |
623 { | 623 { |
624 BoundsChangeObserver observer(&v1); | 624 BoundsChangeObserver observer(&v1); |
625 Rect rect; | 625 Rect rect; |
626 rect.width = rect.height = 100; | 626 rect.width = rect.height = 100; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 } | 662 } |
663 void OnViewVisibilityChanged(View* view) override { | 663 void OnViewVisibilityChanged(View* view) override { |
664 changes_.push_back(base::StringPrintf("view=%s phase=changed visibility=%s", | 664 changes_.push_back(base::StringPrintf("view=%s phase=changed visibility=%s", |
665 ViewIdToString(view->id()).c_str(), | 665 ViewIdToString(view->id()).c_str(), |
666 view->visible() ? "true" : "false")); | 666 view->visible() ? "true" : "false")); |
667 } | 667 } |
668 | 668 |
669 View* view_; | 669 View* view_; |
670 Changes changes_; | 670 Changes changes_; |
671 | 671 |
672 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); | 672 MOJO_DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); |
673 }; | 673 }; |
674 | 674 |
675 } // namespace | 675 } // namespace |
676 | 676 |
677 TEST_F(ViewObserverTest, SetVisible) { | 677 TEST_F(ViewObserverTest, SetVisible) { |
678 TestView v1; | 678 TestView v1; |
679 EXPECT_TRUE(v1.visible()); | 679 EXPECT_TRUE(v1.visible()); |
680 { | 680 { |
681 // Change visibility from true to false and make sure we get notifications. | 681 // Change visibility from true to false and make sure we get notifications. |
682 VisibilityChangeObserver observer(&v1); | 682 VisibilityChangeObserver observer(&v1); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 return "NULL"; | 768 return "NULL"; |
769 std::string s; | 769 std::string s; |
770 for (char c : *data) | 770 for (char c : *data) |
771 s += c; | 771 s += c; |
772 return s; | 772 return s; |
773 } | 773 } |
774 | 774 |
775 View* view_; | 775 View* view_; |
776 Changes changes_; | 776 Changes changes_; |
777 | 777 |
778 DISALLOW_COPY_AND_ASSIGN(SharedPropertyChangeObserver); | 778 MOJO_DISALLOW_COPY_AND_ASSIGN(SharedPropertyChangeObserver); |
779 }; | 779 }; |
780 | 780 |
781 } // namespace | 781 } // namespace |
782 | 782 |
783 TEST_F(ViewObserverTest, SetLocalProperty) { | 783 TEST_F(ViewObserverTest, SetLocalProperty) { |
784 TestView v1; | 784 TestView v1; |
785 std::vector<uint8_t> one(1, '1'); | 785 std::vector<uint8_t> one(1, '1'); |
786 | 786 |
787 { | 787 { |
788 // Change visibility from true to false and make sure we get notifications. | 788 // Change visibility from true to false and make sure we get notifications. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 const void* key, | 849 const void* key, |
850 intptr_t old) override { | 850 intptr_t old) override { |
851 property_key_ = key; | 851 property_key_ = key; |
852 old_property_value_ = old; | 852 old_property_value_ = old; |
853 } | 853 } |
854 | 854 |
855 View* view_; | 855 View* view_; |
856 const void* property_key_; | 856 const void* property_key_; |
857 intptr_t old_property_value_; | 857 intptr_t old_property_value_; |
858 | 858 |
859 DISALLOW_COPY_AND_ASSIGN(LocalPropertyChangeObserver); | 859 MOJO_DISALLOW_COPY_AND_ASSIGN(LocalPropertyChangeObserver); |
860 }; | 860 }; |
861 | 861 |
862 } // namespace | 862 } // namespace |
863 | 863 |
864 TEST_F(ViewObserverTest, LocalPropertyChanged) { | 864 TEST_F(ViewObserverTest, LocalPropertyChanged) { |
865 TestView v1; | 865 TestView v1; |
866 LocalPropertyChangeObserver o(&v1); | 866 LocalPropertyChangeObserver o(&v1); |
867 | 867 |
868 static const ViewProperty<int> prop = {-2}; | 868 static const ViewProperty<int> prop = {-2}; |
869 | 869 |
870 v1.SetLocalProperty(&prop, 1); | 870 v1.SetLocalProperty(&prop, 1); |
871 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); | 871 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); |
872 v1.SetLocalProperty(&prop, -2); | 872 v1.SetLocalProperty(&prop, -2); |
873 EXPECT_EQ(PropertyChangeInfo(&prop, 1), o.PropertyChangeInfoAndClear()); | 873 EXPECT_EQ(PropertyChangeInfo(&prop, 1), o.PropertyChangeInfoAndClear()); |
874 v1.SetLocalProperty(&prop, 3); | 874 v1.SetLocalProperty(&prop, 3); |
875 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); | 875 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); |
876 v1.ClearLocalProperty(&prop); | 876 v1.ClearLocalProperty(&prop); |
877 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear()); | 877 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear()); |
878 | 878 |
879 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. | 879 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. |
880 EXPECT_EQ(PropertyChangeInfo( | 880 EXPECT_EQ(PropertyChangeInfo( |
881 reinterpret_cast<const void*>(NULL), -3), o.PropertyChangeInfoAndClear()); | 881 reinterpret_cast<const void*>(NULL), -3), o.PropertyChangeInfoAndClear()); |
882 } | 882 } |
883 | 883 |
884 } // namespace mojo | 884 } // namespace mojo |
OLD | NEW |