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

Side by Side 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 2 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 unified diff | Download patch
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 namespace views { 196 namespace views {
197 197
198 typedef ViewsTestBase ViewTest; 198 typedef ViewsTestBase ViewTest;
199 199
200 // A derived class for testing purpose. 200 // A derived class for testing purpose.
201 class TestView : public View { 201 class TestView : public View {
202 public: 202 public:
203 TestView() 203 TestView()
204 : View(), 204 : View(),
205 did_layout_(false),
205 delete_on_pressed_(false), 206 delete_on_pressed_(false),
206 did_paint_(false), 207 did_paint_(false),
207 native_theme_(NULL), 208 native_theme_(NULL),
208 can_process_events_within_subtree_(true) {} 209 can_process_events_within_subtree_(true) {}
209 ~TestView() override {} 210 ~TestView() override {}
210 211
211 // Reset all test state 212 // Reset all test state
212 void Reset() { 213 void Reset() {
213 did_change_bounds_ = false; 214 did_change_bounds_ = false;
215 did_layout_ = false;
214 last_mouse_event_type_ = 0; 216 last_mouse_event_type_ = 0;
215 location_.SetPoint(0, 0); 217 location_.SetPoint(0, 0);
216 received_mouse_enter_ = false; 218 received_mouse_enter_ = false;
217 received_mouse_exit_ = false; 219 received_mouse_exit_ = false;
218 did_paint_ = false; 220 did_paint_ = false;
219 accelerator_count_map_.clear(); 221 accelerator_count_map_.clear();
220 can_process_events_within_subtree_ = true; 222 can_process_events_within_subtree_ = true;
221 } 223 }
222 224
223 // Exposed as public for testing. 225 // Exposed as public for testing.
224 void DoFocus() { 226 void DoFocus() {
225 views::View::Focus(); 227 views::View::Focus();
226 } 228 }
227 229
228 void DoBlur() { 230 void DoBlur() {
229 views::View::Blur(); 231 views::View::Blur();
230 } 232 }
231 233
232 bool focusable() const { return View::focusable(); } 234 bool focusable() const { return View::focusable(); }
233 235
234 void set_can_process_events_within_subtree(bool can_process) { 236 void set_can_process_events_within_subtree(bool can_process) {
235 can_process_events_within_subtree_ = can_process; 237 can_process_events_within_subtree_ = can_process;
236 } 238 }
237 239
238 bool CanProcessEventsWithinSubtree() const override { 240 bool CanProcessEventsWithinSubtree() const override {
239 return can_process_events_within_subtree_; 241 return can_process_events_within_subtree_;
240 } 242 }
241 243
244 void Layout() override {
245 did_layout_ = true;
246 View::Layout();
247 }
248
242 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; 249 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
243 bool OnMousePressed(const ui::MouseEvent& event) override; 250 bool OnMousePressed(const ui::MouseEvent& event) override;
244 bool OnMouseDragged(const ui::MouseEvent& event) override; 251 bool OnMouseDragged(const ui::MouseEvent& event) override;
245 void OnMouseReleased(const ui::MouseEvent& event) override; 252 void OnMouseReleased(const ui::MouseEvent& event) override;
246 void OnMouseEntered(const ui::MouseEvent& event) override; 253 void OnMouseEntered(const ui::MouseEvent& event) override;
247 void OnMouseExited(const ui::MouseEvent& event) override; 254 void OnMouseExited(const ui::MouseEvent& event) override;
248 255
249 void OnPaint(gfx::Canvas* canvas) override; 256 void OnPaint(gfx::Canvas* canvas) override;
250 void SchedulePaintInRect(const gfx::Rect& rect) override; 257 void SchedulePaintInRect(const gfx::Rect& rect) override;
251 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; 258 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
252 259
253 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; 260 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override;
254 261
255 // OnBoundsChanged. 262 // OnBoundsChanged.
256 bool did_change_bounds_; 263 bool did_change_bounds_;
257 gfx::Rect new_bounds_; 264 gfx::Rect new_bounds_;
258 265
266 // Layout.
267 bool did_layout_;
268
259 // MouseEvent. 269 // MouseEvent.
260 int last_mouse_event_type_; 270 int last_mouse_event_type_;
261 gfx::Point location_; 271 gfx::Point location_;
262 bool received_mouse_enter_; 272 bool received_mouse_enter_;
263 bool received_mouse_exit_; 273 bool received_mouse_exit_;
264 bool delete_on_pressed_; 274 bool delete_on_pressed_;
265 275
266 // Painting. 276 // Painting.
267 std::vector<gfx::Rect> scheduled_paint_rects_; 277 std::vector<gfx::Rect> scheduled_paint_rects_;
268 bool did_paint_; 278 bool did_paint_;
269 279
270 // Accelerators. 280 // Accelerators.
271 std::map<ui::Accelerator, int> accelerator_count_map_; 281 std::map<ui::Accelerator, int> accelerator_count_map_;
272 282
273 // Native theme. 283 // Native theme.
274 const ui::NativeTheme* native_theme_; 284 const ui::NativeTheme* native_theme_;
275 285
276 // Value to return from CanProcessEventsWithinSubtree(). 286 // Value to return from CanProcessEventsWithinSubtree().
277 bool can_process_events_within_subtree_; 287 bool can_process_events_within_subtree_;
278 }; 288 };
279 289
280 //////////////////////////////////////////////////////////////////////////////// 290 ////////////////////////////////////////////////////////////////////////////////
291 // Layout
292 ////////////////////////////////////////////////////////////////////////////////
293
294 TEST_F(ViewTest, LayoutCalledInvalidateAndOriginChanges) {
295 TestView parent;
296 TestView* child = new TestView;
297 gfx::Rect parent_rect(0, 0, 100, 100);
298 parent.SetBoundsRect(parent_rect);
299
300 parent.Reset();
301 // |AddChildView| invalidates parent's layout.
302 parent.AddChildView(child);
303 // Change rect so that only rect's origin is affected.
304 parent.SetBoundsRect(parent_rect + gfx::Vector2d(10, 0));
305
306 EXPECT_TRUE(parent.did_layout_);
307
308 // After child layout is invalidated, parent and child must be laid out
309 // during parent->BoundsChanged(...) call.
310 parent.Reset();
311 child->Reset();
312
313 child->InvalidateLayout();
314 parent.SetBoundsRect(parent_rect + gfx::Vector2d(20, 0));
315 EXPECT_TRUE(parent.did_layout_);
316 EXPECT_TRUE(child->did_layout_);
317 }
318
319 ////////////////////////////////////////////////////////////////////////////////
281 // OnBoundsChanged 320 // OnBoundsChanged
282 //////////////////////////////////////////////////////////////////////////////// 321 ////////////////////////////////////////////////////////////////////////////////
283 322
284 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 323 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
285 did_change_bounds_ = true; 324 did_change_bounds_ = true;
286 new_bounds_ = bounds(); 325 new_bounds_ = bounds();
287 } 326 }
288 327
289 TEST_F(ViewTest, OnBoundsChanged) { 328 TEST_F(ViewTest, OnBoundsChanged) {
290 TestView v; 329 TestView v;
(...skipping 3802 matching lines...) Expand 10 before | Expand all | Expand 10 after
4093 // notification. 4132 // notification.
4094 TestView* test_view_child_2 = new TestView(); 4133 TestView* test_view_child_2 = new TestView();
4095 test_view->AddChildView(test_view_child_2); 4134 test_view->AddChildView(test_view_child_2);
4096 EXPECT_TRUE(test_view_child_2->native_theme_); 4135 EXPECT_TRUE(test_view_child_2->native_theme_);
4097 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); 4136 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_);
4098 4137
4099 widget->CloseNow(); 4138 widget->CloseNow();
4100 } 4139 }
4101 4140
4102 } // namespace views 4141 } // namespace views
OLDNEW
« 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