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

Side by Side Diff: components/mus/public/cpp/tests/view_unittest.cc

Issue 1344573002: Mandoline: Rename components/view_manager to components/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 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 "components/view_manager/public/cpp/view.h" 5 #include "components/mus/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 "components/view_manager/public/cpp/lib/view_private.h" 9 #include "components/mus/public/cpp/lib/view_private.h"
10 #include "components/view_manager/public/cpp/util.h" 10 #include "components/mus/public/cpp/util.h"
11 #include "components/view_manager/public/cpp/view_observer.h" 11 #include "components/mus/public/cpp/view_observer.h"
12 #include "components/view_manager/public/cpp/view_property.h" 12 #include "components/mus/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() { ViewPrivate(this).set_id(1); }
25 ViewPrivate(this).set_id(1);
26 }
27 ~TestView() {} 25 ~TestView() {}
28 26
29 private: 27 private:
30 MOJO_DISALLOW_COPY_AND_ASSIGN(TestView); 28 MOJO_DISALLOW_COPY_AND_ASSIGN(TestView);
31 }; 29 };
32 30
33 TEST_F(ViewTest, AddChild) { 31 TEST_F(ViewTest, AddChild) {
34 TestView v1; 32 TestView v1;
35 TestView v11; 33 TestView v11;
36 v1.AddChild(&v11); 34 v1.AddChild(&v11);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 182
185 EXPECT_EQ(p3, TestProperty::last_deleted()); 183 EXPECT_EQ(p3, TestProperty::last_deleted());
186 } 184 }
187 185
188 // ViewObserver -------------------------------------------------------- 186 // ViewObserver --------------------------------------------------------
189 187
190 typedef testing::Test ViewObserverTest; 188 typedef testing::Test ViewObserverTest;
191 189
192 bool TreeChangeParamsMatch(const ViewObserver::TreeChangeParams& lhs, 190 bool TreeChangeParamsMatch(const ViewObserver::TreeChangeParams& lhs,
193 const ViewObserver::TreeChangeParams& rhs) { 191 const ViewObserver::TreeChangeParams& rhs) {
194 return lhs.target == rhs.target && lhs.old_parent == rhs.old_parent && 192 return lhs.target == rhs.target && lhs.old_parent == rhs.old_parent &&
195 lhs.new_parent == rhs.new_parent && lhs.receiver == rhs.receiver; 193 lhs.new_parent == rhs.new_parent && lhs.receiver == rhs.receiver;
196 } 194 }
197 195
198 class TreeChangeObserver : public ViewObserver { 196 class TreeChangeObserver : public ViewObserver {
199 public: 197 public:
200 explicit TreeChangeObserver(View* observee) : observee_(observee) { 198 explicit TreeChangeObserver(View* observee) : observee_(observee) {
201 observee_->AddObserver(this); 199 observee_->AddObserver(this);
202 } 200 }
203 ~TreeChangeObserver() override { observee_->RemoveObserver(this); } 201 ~TreeChangeObserver() override { observee_->RemoveObserver(this); }
204 202
205 void Reset() { 203 void Reset() { received_params_.clear(); }
206 received_params_.clear();
207 }
208 204
209 const std::vector<TreeChangeParams>& received_params() { 205 const std::vector<TreeChangeParams>& received_params() {
210 return received_params_; 206 return received_params_;
211 } 207 }
212 208
213 private: 209 private:
214 // Overridden from ViewObserver: 210 // Overridden from ViewObserver:
215 void OnTreeChanging(const TreeChangeParams& params) override { 211 void OnTreeChanging(const TreeChangeParams& params) override {
216 received_params_.push_back(params); 212 received_params_.push_back(params);
217 } 213 }
218 void OnTreeChanged(const TreeChangeParams& params) override { 214 void OnTreeChanged(const TreeChangeParams& params) override {
219 received_params_.push_back(params); 215 received_params_.push_back(params);
220 } 216 }
221 217
222 View* observee_; 218 View* observee_;
223 std::vector<TreeChangeParams> received_params_; 219 std::vector<TreeChangeParams> received_params_;
224 220
225 MOJO_DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver); 221 MOJO_DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver);
226 }; 222 };
227 223
228 // Adds/Removes v11 to v1. 224 // Adds/Removes v11 to v1.
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 EXPECT_EQ(&v12, changes[1].relative_view); 554 EXPECT_EQ(&v12, changes[1].relative_view);
559 EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[1].direction); 555 EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[1].direction);
560 } 556 }
561 } 557 }
562 558
563 namespace { 559 namespace {
564 560
565 typedef std::vector<std::string> Changes; 561 typedef std::vector<std::string> Changes;
566 562
567 std::string ViewIdToString(Id id) { 563 std::string ViewIdToString(Id id) {
568 return (id == 0) ? "null" : 564 return (id == 0) ? "null"
569 base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); 565 : base::StringPrintf("%d,%d", HiWord(id), LoWord(id));
570 } 566 }
571 567
572 std::string RectToString(const Rect& rect) { 568 std::string RectToString(const Rect& rect) {
573 return base::StringPrintf("%d,%d %dx%d", 569 return base::StringPrintf("%d,%d %dx%d", rect.x, rect.y, rect.width,
574 rect.x, rect.y, rect.width, rect.height); 570 rect.height);
575 } 571 }
576 572
577 class BoundsChangeObserver : public ViewObserver { 573 class BoundsChangeObserver : public ViewObserver {
578 public: 574 public:
579 explicit BoundsChangeObserver(View* view) : view_(view) { 575 explicit BoundsChangeObserver(View* view) : view_(view) {
580 view_->AddObserver(this); 576 view_->AddObserver(this);
581 } 577 }
582 ~BoundsChangeObserver() override { view_->RemoveObserver(this); } 578 ~BoundsChangeObserver() override { view_->RemoveObserver(this); }
583 579
584 Changes GetAndClearChanges() { 580 Changes GetAndClearChanges() {
585 Changes changes; 581 Changes changes;
586 changes.swap(changes_); 582 changes.swap(changes_);
587 return changes; 583 return changes;
588 } 584 }
589 585
590 private: 586 private:
591 // Overridden from ViewObserver: 587 // Overridden from ViewObserver:
592 void OnViewBoundsChanging(View* view, 588 void OnViewBoundsChanging(View* view,
593 const Rect& old_bounds, 589 const Rect& old_bounds,
594 const Rect& new_bounds) override { 590 const Rect& new_bounds) override {
595 changes_.push_back( 591 changes_.push_back(base::StringPrintf(
596 base::StringPrintf( 592 "view=%s old_bounds=%s new_bounds=%s phase=changing",
597 "view=%s old_bounds=%s new_bounds=%s phase=changing", 593 ViewIdToString(view->id()).c_str(), RectToString(old_bounds).c_str(),
598 ViewIdToString(view->id()).c_str(), 594 RectToString(new_bounds).c_str()));
599 RectToString(old_bounds).c_str(),
600 RectToString(new_bounds).c_str()));
601 } 595 }
602 void OnViewBoundsChanged(View* view, 596 void OnViewBoundsChanged(View* view,
603 const Rect& old_bounds, 597 const Rect& old_bounds,
604 const Rect& new_bounds) override { 598 const Rect& new_bounds) override {
605 changes_.push_back( 599 changes_.push_back(base::StringPrintf(
606 base::StringPrintf( 600 "view=%s old_bounds=%s new_bounds=%s phase=changed",
607 "view=%s old_bounds=%s new_bounds=%s phase=changed", 601 ViewIdToString(view->id()).c_str(), RectToString(old_bounds).c_str(),
608 ViewIdToString(view->id()).c_str(), 602 RectToString(new_bounds).c_str()));
609 RectToString(old_bounds).c_str(),
610 RectToString(new_bounds).c_str()));
611 } 603 }
612 604
613 View* view_; 605 View* view_;
614 Changes changes_; 606 Changes changes_;
615 607
616 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); 608 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
617 }; 609 };
618 610
619 } // namespace 611 } // namespace
620 612
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 815 }
824 } 816 }
825 817
826 namespace { 818 namespace {
827 819
828 typedef std::pair<const void*, intptr_t> PropertyChangeInfo; 820 typedef std::pair<const void*, intptr_t> PropertyChangeInfo;
829 821
830 class LocalPropertyChangeObserver : public ViewObserver { 822 class LocalPropertyChangeObserver : public ViewObserver {
831 public: 823 public:
832 explicit LocalPropertyChangeObserver(View* view) 824 explicit LocalPropertyChangeObserver(View* view)
833 : view_(view), 825 : view_(view), property_key_(nullptr), old_property_value_(-1) {
834 property_key_(nullptr),
835 old_property_value_(-1) {
836 view_->AddObserver(this); 826 view_->AddObserver(this);
837 } 827 }
838 ~LocalPropertyChangeObserver() override { view_->RemoveObserver(this); } 828 ~LocalPropertyChangeObserver() override { view_->RemoveObserver(this); }
839 829
840 PropertyChangeInfo PropertyChangeInfoAndClear() { 830 PropertyChangeInfo PropertyChangeInfoAndClear() {
841 PropertyChangeInfo result(property_key_, old_property_value_); 831 PropertyChangeInfo result(property_key_, old_property_value_);
842 property_key_ = NULL; 832 property_key_ = NULL;
843 old_property_value_ = -3; 833 old_property_value_ = -3;
844 return result; 834 return result;
845 } 835 }
(...skipping 24 matching lines...) Expand all
870 v1.SetLocalProperty(&prop, 1); 860 v1.SetLocalProperty(&prop, 1);
871 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); 861 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear());
872 v1.SetLocalProperty(&prop, -2); 862 v1.SetLocalProperty(&prop, -2);
873 EXPECT_EQ(PropertyChangeInfo(&prop, 1), o.PropertyChangeInfoAndClear()); 863 EXPECT_EQ(PropertyChangeInfo(&prop, 1), o.PropertyChangeInfoAndClear());
874 v1.SetLocalProperty(&prop, 3); 864 v1.SetLocalProperty(&prop, 3);
875 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); 865 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear());
876 v1.ClearLocalProperty(&prop); 866 v1.ClearLocalProperty(&prop);
877 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear()); 867 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear());
878 868
879 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. 869 // Sanity check to see if |PropertyChangeInfoAndClear| really clears.
880 EXPECT_EQ(PropertyChangeInfo( 870 EXPECT_EQ(PropertyChangeInfo(reinterpret_cast<const void*>(NULL), -3),
881 reinterpret_cast<const void*>(NULL), -3), o.PropertyChangeInfoAndClear()); 871 o.PropertyChangeInfoAndClear());
882 } 872 }
883 873
884 } // namespace mojo 874 } // namespace mojo
OLDNEW
« no previous file with comments | « components/mus/public/cpp/tests/view_manager_test_suite.cc ('k') | components/mus/public/cpp/types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698