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 "components/mus/public/cpp/window.h" | 5 #include "components/mus/public/cpp/window.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 namespace { | 167 namespace { |
168 | 168 |
169 class TestProperty { | 169 class TestProperty { |
170 public: | 170 public: |
171 TestProperty() {} | 171 TestProperty() {} |
172 virtual ~TestProperty() { last_deleted_ = this; } | 172 virtual ~TestProperty() { last_deleted_ = this; } |
173 static TestProperty* last_deleted() { return last_deleted_; } | 173 static TestProperty* last_deleted() { return last_deleted_; } |
174 | 174 |
175 private: | 175 private: |
176 static TestProperty* last_deleted_; | 176 static TestProperty* last_deleted_; |
177 MOJO_DISALLOW_COPY_AND_ASSIGN(TestProperty); | 177 DISALLOW_COPY_AND_ASSIGN(TestProperty); |
178 }; | 178 }; |
179 | 179 |
180 TestProperty* TestProperty::last_deleted_ = NULL; | 180 TestProperty* TestProperty::last_deleted_ = NULL; |
181 | 181 |
182 MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); | 182 MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(TestProperty, kOwnedKey, NULL); |
183 | 183 |
184 } // namespace | 184 } // namespace |
185 | 185 |
186 TEST_F(WindowTest, OwnedProperty) { | 186 TEST_F(WindowTest, OwnedProperty) { |
187 TestProperty* p3 = NULL; | 187 TestProperty* p3 = NULL; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 void OnTreeChanging(const TreeChangeParams& params) override { | 239 void OnTreeChanging(const TreeChangeParams& params) override { |
240 received_params_.push_back(params); | 240 received_params_.push_back(params); |
241 } | 241 } |
242 void OnTreeChanged(const TreeChangeParams& params) override { | 242 void OnTreeChanged(const TreeChangeParams& params) override { |
243 received_params_.push_back(params); | 243 received_params_.push_back(params); |
244 } | 244 } |
245 | 245 |
246 Window* observee_; | 246 Window* observee_; |
247 std::vector<TreeChangeParams> received_params_; | 247 std::vector<TreeChangeParams> received_params_; |
248 | 248 |
249 MOJO_DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver); | 249 DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver); |
250 }; | 250 }; |
251 | 251 |
252 // Adds/Removes w11 to w1. | 252 // Adds/Removes w11 to w1. |
253 TEST_F(WindowObserverTest, TreeChange_SimpleAddRemove) { | 253 TEST_F(WindowObserverTest, TreeChange_SimpleAddRemove) { |
254 TestWindow w1; | 254 TestWindow w1; |
255 TreeChangeObserver o1(&w1); | 255 TreeChangeObserver o1(&w1); |
256 EXPECT_TRUE(o1.received_params().empty()); | 256 EXPECT_TRUE(o1.received_params().empty()); |
257 | 257 |
258 TestWindow w11; | 258 TestWindow w11; |
259 TreeChangeObserver o11(&w11); | 259 TreeChangeObserver o11(&w11); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 Change change; | 480 Change change; |
481 change.window = window; | 481 change.window = window; |
482 change.relative_window = relative_window; | 482 change.relative_window = relative_window; |
483 change.direction = direction; | 483 change.direction = direction; |
484 changes_.push_back(change); | 484 changes_.push_back(change); |
485 } | 485 } |
486 | 486 |
487 Window* observee_; | 487 Window* observee_; |
488 Changes changes_; | 488 Changes changes_; |
489 | 489 |
490 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); | 490 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); |
491 }; | 491 }; |
492 | 492 |
493 } // namespace | 493 } // namespace |
494 | 494 |
495 TEST_F(WindowObserverTest, Order) { | 495 TEST_F(WindowObserverTest, Order) { |
496 TestWindow w1, w11, w12, w13; | 496 TestWindow w1, w11, w12, w13; |
497 w1.AddChild(&w11); | 497 w1.AddChild(&w11); |
498 w1.AddChild(&w12); | 498 w1.AddChild(&w12); |
499 w1.AddChild(&w13); | 499 w1.AddChild(&w13); |
500 | 500 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 const gfx::Rect& new_bounds) override { | 626 const gfx::Rect& new_bounds) override { |
627 changes_.push_back(base::StringPrintf( | 627 changes_.push_back(base::StringPrintf( |
628 "window=%s old_bounds=%s new_bounds=%s phase=changed", | 628 "window=%s old_bounds=%s new_bounds=%s phase=changed", |
629 WindowIdToString(window->id()).c_str(), | 629 WindowIdToString(window->id()).c_str(), |
630 RectToString(old_bounds).c_str(), RectToString(new_bounds).c_str())); | 630 RectToString(old_bounds).c_str(), RectToString(new_bounds).c_str())); |
631 } | 631 } |
632 | 632 |
633 Window* window_; | 633 Window* window_; |
634 Changes changes_; | 634 Changes changes_; |
635 | 635 |
636 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); | 636 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); |
637 }; | 637 }; |
638 | 638 |
639 } // namespace | 639 } // namespace |
640 | 640 |
641 TEST_F(WindowObserverTest, SetBounds) { | 641 TEST_F(WindowObserverTest, SetBounds) { |
642 TestWindow w1; | 642 TestWindow w1; |
643 { | 643 { |
644 BoundsChangeObserver observer(&w1); | 644 BoundsChangeObserver observer(&w1); |
645 w1.SetBounds(gfx::Rect(0, 0, 100, 100)); | 645 w1.SetBounds(gfx::Rect(0, 0, 100, 100)); |
646 | 646 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 void OnWindowVisibilityChanged(Window* window) override { | 681 void OnWindowVisibilityChanged(Window* window) override { |
682 changes_.push_back( | 682 changes_.push_back( |
683 base::StringPrintf("window=%s phase=changed wisibility=%s", | 683 base::StringPrintf("window=%s phase=changed wisibility=%s", |
684 WindowIdToString(window->id()).c_str(), | 684 WindowIdToString(window->id()).c_str(), |
685 window->visible() ? "true" : "false")); | 685 window->visible() ? "true" : "false")); |
686 } | 686 } |
687 | 687 |
688 Window* window_; | 688 Window* window_; |
689 Changes changes_; | 689 Changes changes_; |
690 | 690 |
691 MOJO_DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); | 691 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); |
692 }; | 692 }; |
693 | 693 |
694 } // namespace | 694 } // namespace |
695 | 695 |
696 TEST_F(WindowObserverTest, SetVisible) { | 696 TEST_F(WindowObserverTest, SetVisible) { |
697 TestWindow w1; | 697 TestWindow w1; |
698 EXPECT_FALSE(w1.visible()); | 698 EXPECT_FALSE(w1.visible()); |
699 w1.SetVisible(true); | 699 w1.SetVisible(true); |
700 EXPECT_TRUE(w1.visible()); | 700 EXPECT_TRUE(w1.visible()); |
701 { | 701 { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 return "NULL"; | 793 return "NULL"; |
794 gfx::Size size = | 794 gfx::Size size = |
795 mojo::TypeConverter<gfx::Size, const std::vector<uint8_t>>::Convert( | 795 mojo::TypeConverter<gfx::Size, const std::vector<uint8_t>>::Convert( |
796 *data); | 796 *data); |
797 return base::StringPrintf("%d,%d", size.width(), size.height()); | 797 return base::StringPrintf("%d,%d", size.width(), size.height()); |
798 } | 798 } |
799 | 799 |
800 Window* window_; | 800 Window* window_; |
801 Changes changes_; | 801 Changes changes_; |
802 | 802 |
803 MOJO_DISALLOW_COPY_AND_ASSIGN(SharedPropertyChangeObserver); | 803 DISALLOW_COPY_AND_ASSIGN(SharedPropertyChangeObserver); |
804 }; | 804 }; |
805 | 805 |
806 } // namespace | 806 } // namespace |
807 | 807 |
808 TEST_F(WindowObserverTest, SetSharedProperty) { | 808 TEST_F(WindowObserverTest, SetSharedProperty) { |
809 TestWindow w1; | 809 TestWindow w1; |
810 gfx::Size size(100, 100); | 810 gfx::Size size(100, 100); |
811 | 811 |
812 { | 812 { |
813 // Change visibility from true to false and make sure we get notifications. | 813 // Change visibility from true to false and make sure we get notifications. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 const void* key, | 879 const void* key, |
880 intptr_t old) override { | 880 intptr_t old) override { |
881 property_key_ = key; | 881 property_key_ = key; |
882 old_property_value_ = old; | 882 old_property_value_ = old; |
883 } | 883 } |
884 | 884 |
885 Window* window_; | 885 Window* window_; |
886 const void* property_key_; | 886 const void* property_key_; |
887 intptr_t old_property_value_; | 887 intptr_t old_property_value_; |
888 | 888 |
889 MOJO_DISALLOW_COPY_AND_ASSIGN(LocalPropertyChangeObserver); | 889 DISALLOW_COPY_AND_ASSIGN(LocalPropertyChangeObserver); |
890 }; | 890 }; |
891 | 891 |
892 } // namespace | 892 } // namespace |
893 | 893 |
894 TEST_F(WindowObserverTest, LocalPropertyChanged) { | 894 TEST_F(WindowObserverTest, LocalPropertyChanged) { |
895 TestWindow w1; | 895 TestWindow w1; |
896 LocalPropertyChangeObserver o(&w1); | 896 LocalPropertyChangeObserver o(&w1); |
897 | 897 |
898 static const WindowProperty<int> prop = {-2}; | 898 static const WindowProperty<int> prop = {-2}; |
899 | 899 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 scoped_ptr<TestWindow> window0(CreateTestWindow(1, parent.get())); | 1126 scoped_ptr<TestWindow> window0(CreateTestWindow(1, parent.get())); |
1127 scoped_ptr<TestWindow> window1(CreateTestWindow(2, parent.get())); | 1127 scoped_ptr<TestWindow> window1(CreateTestWindow(2, parent.get())); |
1128 | 1128 |
1129 TestWindow* window2 = CreateTestWindow(3, parent.get()); | 1129 TestWindow* window2 = CreateTestWindow(3, parent.get()); |
1130 | 1130 |
1131 window0->AddTransientWindow(window2); | 1131 window0->AddTransientWindow(window2); |
1132 EXPECT_EQ("1 3 2", ChildWindowIDsAsString(parent.get())); | 1132 EXPECT_EQ("1 3 2", ChildWindowIDsAsString(parent.get())); |
1133 } | 1133 } |
1134 | 1134 |
1135 } // namespace mus | 1135 } // namespace mus |
OLD | NEW |