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

Unified Diff: ui/views/view_unittest.cc

Issue 1442683002: Fix views::View::BoundsChanged (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 38683cc303a93c5be3645c0793ad4adea9bf0993..310309f54144a889a3d916cc9bf3fc71e22dda29 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -202,6 +202,7 @@ class TestView : public View {
public:
TestView()
: View(),
+ did_layout_(false),
delete_on_pressed_(false),
did_paint_(false),
native_theme_(NULL),
@@ -211,6 +212,7 @@ class TestView : public View {
// Reset all test state
void Reset() {
did_change_bounds_ = false;
+ did_layout_ = false;
last_mouse_event_type_ = 0;
location_.SetPoint(0, 0);
received_mouse_enter_ = false;
@@ -239,6 +241,8 @@ class TestView : public View {
return can_process_events_within_subtree_;
}
+ void Layout() override;
sky 2015/11/18 16:55:50 inline the implementation like the rest.
flint 2015/11/18 19:57:44 Done.
+
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
@@ -256,6 +260,9 @@ class TestView : public View {
bool did_change_bounds_;
gfx::Rect new_bounds_;
+ // Layout.
+ bool did_layout_;
+
// MouseEvent.
int last_mouse_event_type_;
gfx::Point location_;
@@ -278,6 +285,40 @@ class TestView : public View {
};
////////////////////////////////////////////////////////////////////////////////
+// Layout
+////////////////////////////////////////////////////////////////////////////////
+
+void TestView::Layout() {
+ did_layout_ = true;
+ View::Layout();
+}
+
+TEST_F(ViewTest, LayoutCalledAfterLayoutIsInvalidated) {
sky 2015/11/18 16:55:50 Be more descriptive, eg LayoutCalledInvalidateAndO
flint 2015/11/18 19:57:44 Done.
+ TestView parent;
+ TestView* child = new TestView;
+ gfx::Rect parent_rect(0, 0, 100, 100);
+ parent.SetBoundsRect(parent_rect);
+
+ parent.Reset();
+ // |AddChildView| invalidates parent's layout.
+ parent.AddChildView(child);
+ // Change rect so that only rect's origin is affected.
+ parent.SetBoundsRect(parent_rect + gfx::Vector2d(10, 0));
+
+ EXPECT_TRUE(parent.did_layout_);
+
+ // After child layout is invalidated, parent and child must be laid out
+ // during parent->BoundsChanged(...) call.
+ parent.Reset();
+ child->Reset();
+
+ child->InvalidateLayout();
+ parent.SetBoundsRect(parent_rect + gfx::Vector2d(20, 0));
+ EXPECT_TRUE(parent.did_layout_);
+ EXPECT_TRUE(child->did_layout_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
// OnBoundsChanged
////////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698