OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 4081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4092 // Child view added after the widget hierarchy exists should also get the | 4092 // Child view added after the widget hierarchy exists should also get the |
4093 // notification. | 4093 // notification. |
4094 TestView* test_view_child_2 = new TestView(); | 4094 TestView* test_view_child_2 = new TestView(); |
4095 test_view->AddChildView(test_view_child_2); | 4095 test_view->AddChildView(test_view_child_2); |
4096 EXPECT_TRUE(test_view_child_2->native_theme_); | 4096 EXPECT_TRUE(test_view_child_2->native_theme_); |
4097 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 4097 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
4098 | 4098 |
4099 widget->CloseNow(); | 4099 widget->CloseNow(); |
4100 } | 4100 } |
4101 | 4101 |
4102 class CustomView : public View { | |
4103 public: | |
4104 CustomView() {} | |
4105 ~CustomView() override {} | |
4106 void Layout() override { | |
4107 layout_was_called = true; | |
4108 if (!has_children()) | |
4109 return; | |
4110 View* child = child_at(0); | |
4111 child->SetBoundsRect(GetContentsBounds() + | |
4112 gfx::Vector2d(child_x_offset, 0)); | |
4113 } | |
4114 using View::needs_layout; | |
4115 | |
4116 bool layout_was_called = false; | |
sky
2015/11/17 18:37:26
Make private (style guide says tests can use prote
| |
4117 int child_x_offset = 10; | |
4118 }; | |
sky
2015/11/17 18:37:26
private: DISALLOW...
| |
4119 | |
4120 TEST_F(ViewTest, SimpleInvalidateLayout) { | |
sky
2015/11/17 18:37:26
Please add description of what assertions your tes
| |
4121 scoped_ptr<CustomView> parent(new CustomView); | |
sky
2015/11/17 18:37:26
Why use a scoped_ptr here?
| |
4122 CustomView* child = new CustomView; | |
4123 | |
4124 parent->SetBounds(0, 0, 100, 100); | |
4125 | |
4126 parent->layout_was_called = false; | |
4127 parent->AddChildView(child); | |
4128 // SetBounds must call layout, because AddChildView invalidates layout of | |
4129 // |parent|. | |
4130 parent->SetBounds(10, 0, 100, 100); | |
flint
2015/11/13 10:05:37
Layout of parent is invalidated during parent->Add
| |
4131 | |
4132 EXPECT_EQ(parent->child_x_offset, child->bounds().x()); | |
4133 EXPECT_TRUE(parent->layout_was_called); | |
4134 EXPECT_FALSE(parent->needs_layout()); | |
4135 | |
4136 child->layout_was_called = false; | |
4137 child->InvalidateLayout(); | |
4138 // SetBounds must call layout, because we invalidates layout of |child| and | |
4139 // parent|. | |
4140 parent->SetBounds(20, 0, 100, 100); | |
flint
2015/11/13 10:05:37
The child view needs layout (i.e. its contents bec
| |
4141 | |
4142 EXPECT_EQ(parent->child_x_offset, child->bounds().x()); | |
4143 EXPECT_TRUE(parent->layout_was_called); | |
4144 EXPECT_FALSE(parent->needs_layout()); | |
4145 EXPECT_FALSE(child->needs_layout()); | |
4146 } | |
4147 | |
4148 TEST_F(ViewTest, InvalidateLayout) { | |
4149 scoped_ptr<CustomView> parent(new CustomView); | |
sky
2015/11/17 18:37:26
Same commeont about scoped_ptr.
| |
4150 CustomView* child = new CustomView; | |
4151 CustomView* subchild = new CustomView; | |
4152 | |
4153 parent->AddChildView(child); | |
4154 parent->SetBounds(0, 0, 100, 100); | |
4155 | |
4156 child->layout_was_called = false; | |
4157 // AddChildView invalidates Layout of |child|. | |
4158 child->AddChildView(subchild); | |
4159 parent->child_x_offset += 100; | |
4160 parent->Layout(); | |
4161 // But layout of child mist be called. | |
4162 EXPECT_TRUE(child->layout_was_called); | |
4163 EXPECT_EQ(10, subchild->bounds().x()); | |
4164 EXPECT_FALSE(child->needs_layout()); | |
4165 | |
4166 // If child origin changed Layout of child must call. | |
4167 parent->child_x_offset += 100; | |
4168 child->InvalidateLayout(); | |
4169 // Layout of |child| must be called because we invalidate it layout. | |
4170 parent->Layout(); | |
4171 | |
4172 EXPECT_TRUE(child->layout_was_called); | |
4173 EXPECT_EQ(10, subchild->bounds().x()); | |
4174 EXPECT_FALSE(child->needs_layout()); | |
4175 } | |
4176 | |
4102 } // namespace views | 4177 } // namespace views |
OLD | NEW |