Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Side by Side Diff: services/ui/public/cpp/tests/window_unittest.cc

Issue 2387013003: Adds OnChildWindowVisibilityChanged to ui::WindowObserver (Closed)
Patch Set: fix test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
James Cook 2016/10/03 20:33:08 Thanks for fixing the wisibility.
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 walue and werify no notifications.
James Cook 2016/10/03 20:33:08 optional: walue and werify
sky 2016/10/03 20:52:13 Done.
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698