| 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 "services/ui/public/cpp/window.h" | 5 #include "services/ui/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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 139 } |
| 140 | 140 |
| 141 namespace { | 141 namespace { |
| 142 MUS_DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); | 142 MUS_DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); |
| 143 MUS_DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); | 143 MUS_DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST_F(WindowTest, Property) { | 146 TEST_F(WindowTest, Property) { |
| 147 TestWindow w; | 147 TestWindow w; |
| 148 | 148 |
| 149 // Non-existent properties should return the default walues. | 149 // Non-existent properties should return the default values. |
| 150 EXPECT_EQ(-2, w.GetLocalProperty(kIntKey)); | 150 EXPECT_EQ(-2, w.GetLocalProperty(kIntKey)); |
| 151 EXPECT_EQ(std::string("squeamish"), w.GetLocalProperty(kStringKey)); | 151 EXPECT_EQ(std::string("squeamish"), w.GetLocalProperty(kStringKey)); |
| 152 | 152 |
| 153 // A set property walue should be returned again (even if it's the default | 153 // A set property value should be returned again (even if it's the default |
| 154 // walue). | 154 // value). |
| 155 w.SetLocalProperty(kIntKey, INT_MAX); | 155 w.SetLocalProperty(kIntKey, INT_MAX); |
| 156 EXPECT_EQ(INT_MAX, w.GetLocalProperty(kIntKey)); | 156 EXPECT_EQ(INT_MAX, w.GetLocalProperty(kIntKey)); |
| 157 w.SetLocalProperty(kIntKey, -2); | 157 w.SetLocalProperty(kIntKey, -2); |
| 158 EXPECT_EQ(-2, w.GetLocalProperty(kIntKey)); | 158 EXPECT_EQ(-2, w.GetLocalProperty(kIntKey)); |
| 159 w.SetLocalProperty(kIntKey, INT_MIN); | 159 w.SetLocalProperty(kIntKey, INT_MIN); |
| 160 EXPECT_EQ(INT_MIN, w.GetLocalProperty(kIntKey)); | 160 EXPECT_EQ(INT_MIN, w.GetLocalProperty(kIntKey)); |
| 161 | 161 |
| 162 w.SetLocalProperty(kStringKey, static_cast<const char*>(NULL)); | 162 w.SetLocalProperty(kStringKey, static_cast<const char*>(NULL)); |
| 163 EXPECT_EQ(NULL, w.GetLocalProperty(kStringKey)); | 163 EXPECT_EQ(NULL, w.GetLocalProperty(kStringKey)); |
| 164 w.SetLocalProperty(kStringKey, "squeamish"); | 164 w.SetLocalProperty(kStringKey, "squeamish"); |
| 165 EXPECT_EQ(std::string("squeamish"), w.GetLocalProperty(kStringKey)); | 165 EXPECT_EQ(std::string("squeamish"), w.GetLocalProperty(kStringKey)); |
| 166 w.SetLocalProperty(kStringKey, "ossifrage"); | 166 w.SetLocalProperty(kStringKey, "ossifrage"); |
| 167 EXPECT_EQ(std::string("ossifrage"), w.GetLocalProperty(kStringKey)); | 167 EXPECT_EQ(std::string("ossifrage"), w.GetLocalProperty(kStringKey)); |
| 168 | 168 |
| 169 // ClearProperty should restore the default walue. | 169 // ClearProperty should restore the default value. |
| 170 w.ClearLocalProperty(kIntKey); | 170 w.ClearLocalProperty(kIntKey); |
| 171 EXPECT_EQ(-2, w.GetLocalProperty(kIntKey)); | 171 EXPECT_EQ(-2, w.GetLocalProperty(kIntKey)); |
| 172 w.ClearLocalProperty(kStringKey); | 172 w.ClearLocalProperty(kStringKey); |
| 173 EXPECT_EQ(std::string("squeamish"), w.GetLocalProperty(kStringKey)); | 173 EXPECT_EQ(std::string("squeamish"), w.GetLocalProperty(kStringKey)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 namespace { | 176 namespace { |
| 177 | 177 |
| 178 class TestProperty { | 178 class TestProperty { |
| 179 public: | 179 public: |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 ~VisibilityChangeObserver() override { window_->RemoveObserver(this); } | 672 ~VisibilityChangeObserver() override { window_->RemoveObserver(this); } |
| 673 | 673 |
| 674 Changes GetAndClearChanges() { | 674 Changes GetAndClearChanges() { |
| 675 Changes changes; | 675 Changes changes; |
| 676 changes.swap(changes_); | 676 changes.swap(changes_); |
| 677 return changes; | 677 return changes; |
| 678 } | 678 } |
| 679 | 679 |
| 680 private: | 680 private: |
| 681 // Overridden from WindowObserver: | 681 // Overridden from WindowObserver: |
| 682 void OnWindowVisibilityChanging(Window* window) override { | 682 void OnWindowVisibilityChanging(Window* window, bool visible) override { |
| 683 changes_.push_back(base::StringPrintf( | 683 changes_.push_back( |
| 684 "window=%d phase=changing wisibility=%s", window->local_id(), | 684 base::StringPrintf("window=%d phase=changing visibility=%s", |
| 685 window->visible() ? "true" : "false")); | 685 window->local_id(), visible ? "true" : "false")); |
| 686 } | 686 } |
| 687 void OnWindowVisibilityChanged(Window* window) override { | 687 void OnChildWindowVisibilityChanged(Window* window, bool visible) override { |
| 688 changes_.push_back(base::StringPrintf( | 688 changes_.push_back( |
| 689 "window=%d phase=changed wisibility=%s", window->local_id(), | 689 base::StringPrintf("window=%d phase=child-changed visibility=%s", |
| 690 window->visible() ? "true" : "false")); | 690 window->local_id(), visible ? "true" : "false")); |
| 691 } |
| 692 void OnWindowVisibilityChanged(Window* window, bool visible) override { |
| 693 changes_.push_back( |
| 694 base::StringPrintf("window=%d phase=changed visibility=%s", |
| 695 window->local_id(), visible ? "true" : "false")); |
| 691 } | 696 } |
| 692 | 697 |
| 693 Window* window_; | 698 Window* window_; |
| 694 Changes changes_; | 699 Changes changes_; |
| 695 | 700 |
| 696 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); | 701 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); |
| 697 }; | 702 }; |
| 698 | 703 |
| 699 } // namespace | 704 } // namespace |
| 700 | 705 |
| 701 TEST_F(WindowObserverTest, SetVisible) { | 706 TEST_F(WindowObserverTest, SetVisible) { |
| 702 TestWindow w1; | 707 TestWindow w1; |
| 703 EXPECT_FALSE(w1.visible()); | 708 EXPECT_FALSE(w1.visible()); |
| 704 w1.set_local_id(1); | 709 w1.set_local_id(1); |
| 705 w1.SetVisible(true); | 710 w1.SetVisible(true); |
| 706 EXPECT_TRUE(w1.visible()); | 711 EXPECT_TRUE(w1.visible()); |
| 707 { | 712 { |
| 708 // Change wisibility from true to false and make sure we get notifications. | 713 // Change visibility from true to false and make sure we get notifications. |
| 709 VisibilityChangeObserver observer(&w1); | 714 VisibilityChangeObserver observer(&w1); |
| 710 w1.SetVisible(false); | 715 w1.SetVisible(false); |
| 711 | 716 |
| 712 Changes changes = observer.GetAndClearChanges(); | 717 Changes changes = observer.GetAndClearChanges(); |
| 713 ASSERT_EQ(2U, changes.size()); | 718 ASSERT_EQ(2U, changes.size()); |
| 714 EXPECT_EQ("window=1 phase=changing wisibility=true", changes[0]); | 719 EXPECT_EQ("window=1 phase=changing visibility=false", changes[0]); |
| 715 EXPECT_EQ("window=1 phase=changed wisibility=false", changes[1]); | 720 EXPECT_EQ("window=1 phase=changed visibility=false", changes[1]); |
| 716 } | 721 } |
| 717 { | 722 { |
| 718 // Set visible to existing walue and werify no notifications. | 723 // Set visible to existing value and verify no notifications. |
| 719 VisibilityChangeObserver observer(&w1); | 724 VisibilityChangeObserver observer(&w1); |
| 720 w1.SetVisible(false); | 725 w1.SetVisible(false); |
| 721 EXPECT_TRUE(observer.GetAndClearChanges().empty()); | 726 EXPECT_TRUE(observer.GetAndClearChanges().empty()); |
| 722 } | 727 } |
| 723 } | 728 } |
| 724 | 729 |
| 725 TEST_F(WindowObserverTest, SetVisibleParent) { | 730 TEST_F(WindowObserverTest, SetVisibleParent) { |
| 726 TestWindow parent; | 731 TestWindow parent; |
| 727 parent.SetVisible(true); | 732 parent.SetVisible(true); |
| 728 parent.set_local_id(1); | 733 parent.set_local_id(1); |
| 729 TestWindow child; | 734 TestWindow child; |
| 730 child.SetVisible(true); | 735 child.SetVisible(true); |
| 731 child.set_local_id(2); | 736 child.set_local_id(2); |
| 732 parent.AddChild(&child); | 737 parent.AddChild(&child); |
| 733 EXPECT_TRUE(parent.visible()); | 738 EXPECT_TRUE(parent.visible()); |
| 734 EXPECT_TRUE(child.visible()); | 739 EXPECT_TRUE(child.visible()); |
| 735 { | 740 { |
| 736 // Change wisibility from true to false and make sure we get notifications | 741 // Change visibility from true to false and make sure we get notifications |
| 737 // on the parent. | 742 // on the parent. |
| 738 VisibilityChangeObserver observer(&parent); | 743 VisibilityChangeObserver observer(&parent); |
| 739 child.SetVisible(false); | 744 child.SetVisible(false); |
| 740 | 745 |
| 741 Changes changes = observer.GetAndClearChanges(); | 746 Changes changes = observer.GetAndClearChanges(); |
| 742 ASSERT_EQ(1U, changes.size()); | 747 ASSERT_EQ(2U, changes.size()); |
| 743 EXPECT_EQ("window=2 phase=changed wisibility=false", changes[0]); | 748 EXPECT_EQ("window=2 phase=child-changed visibility=false", changes[0]); |
| 749 EXPECT_EQ("window=2 phase=changed visibility=false", changes[1]); |
| 744 } | 750 } |
| 745 } | 751 } |
| 746 | 752 |
| 747 TEST_F(WindowObserverTest, SetVisibleChild) { | 753 TEST_F(WindowObserverTest, SetVisibleChild) { |
| 748 TestWindow parent; | 754 TestWindow parent; |
| 749 parent.SetVisible(true); | 755 parent.SetVisible(true); |
| 750 parent.set_local_id(1); | 756 parent.set_local_id(1); |
| 751 TestWindow child; | 757 TestWindow child; |
| 752 child.SetVisible(true); | 758 child.SetVisible(true); |
| 753 child.set_local_id(2); | 759 child.set_local_id(2); |
| 754 parent.AddChild(&child); | 760 parent.AddChild(&child); |
| 755 EXPECT_TRUE(parent.visible()); | 761 EXPECT_TRUE(parent.visible()); |
| 756 EXPECT_TRUE(child.visible()); | 762 EXPECT_TRUE(child.visible()); |
| 757 { | 763 { |
| 758 // Change wisibility from true to false and make sure we get notifications | 764 // Change visibility from true to false and make sure we get notifications |
| 759 // on the child. | 765 // on the child. |
| 760 VisibilityChangeObserver observer(&child); | 766 VisibilityChangeObserver observer(&child); |
| 761 parent.SetVisible(false); | 767 parent.SetVisible(false); |
| 762 | 768 |
| 763 Changes changes = observer.GetAndClearChanges(); | 769 Changes changes = observer.GetAndClearChanges(); |
| 764 ASSERT_EQ(1U, changes.size()); | 770 ASSERT_EQ(1U, changes.size()); |
| 765 EXPECT_EQ("window=1 phase=changed wisibility=false", changes[0]); | 771 EXPECT_EQ("window=1 phase=changed visibility=false", changes[0]); |
| 766 } | 772 } |
| 767 } | 773 } |
| 768 | 774 |
| 769 namespace { | 775 namespace { |
| 770 | 776 |
| 771 class OpacityChangeObserver : public WindowObserver { | 777 class OpacityChangeObserver : public WindowObserver { |
| 772 public: | 778 public: |
| 773 explicit OpacityChangeObserver(Window* window) : window_(window) { | 779 explicit OpacityChangeObserver(Window* window) : window_(window) { |
| 774 window_->AddObserver(this); | 780 window_->AddObserver(this); |
| 775 } | 781 } |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 EXPECT_EQ(0, observer.removed_count()); | 1256 EXPECT_EQ(0, observer.removed_count()); |
| 1251 observer.ResetCounts(); | 1257 observer.ResetCounts(); |
| 1252 | 1258 |
| 1253 child.reset(); | 1259 child.reset(); |
| 1254 EXPECT_EQ(0, observer.added_count()); | 1260 EXPECT_EQ(0, observer.added_count()); |
| 1255 EXPECT_EQ(1, observer.removed_count()); | 1261 EXPECT_EQ(1, observer.removed_count()); |
| 1256 observer.ResetCounts(); | 1262 observer.ResetCounts(); |
| 1257 } | 1263 } |
| 1258 | 1264 |
| 1259 } // namespace ui | 1265 } // namespace ui |
| OLD | NEW |