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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; | |
sky
2015/11/18 16:55:50
inline the implementation like the rest.
flint
2015/11/18 19:57:44
Done.
| |
245 | |
242 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 246 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
243 bool OnMousePressed(const ui::MouseEvent& event) override; | 247 bool OnMousePressed(const ui::MouseEvent& event) override; |
244 bool OnMouseDragged(const ui::MouseEvent& event) override; | 248 bool OnMouseDragged(const ui::MouseEvent& event) override; |
245 void OnMouseReleased(const ui::MouseEvent& event) override; | 249 void OnMouseReleased(const ui::MouseEvent& event) override; |
246 void OnMouseEntered(const ui::MouseEvent& event) override; | 250 void OnMouseEntered(const ui::MouseEvent& event) override; |
247 void OnMouseExited(const ui::MouseEvent& event) override; | 251 void OnMouseExited(const ui::MouseEvent& event) override; |
248 | 252 |
249 void OnPaint(gfx::Canvas* canvas) override; | 253 void OnPaint(gfx::Canvas* canvas) override; |
250 void SchedulePaintInRect(const gfx::Rect& rect) override; | 254 void SchedulePaintInRect(const gfx::Rect& rect) override; |
251 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 255 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
252 | 256 |
253 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; | 257 void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override; |
254 | 258 |
255 // OnBoundsChanged. | 259 // OnBoundsChanged. |
256 bool did_change_bounds_; | 260 bool did_change_bounds_; |
257 gfx::Rect new_bounds_; | 261 gfx::Rect new_bounds_; |
258 | 262 |
263 // Layout. | |
264 bool did_layout_; | |
265 | |
259 // MouseEvent. | 266 // MouseEvent. |
260 int last_mouse_event_type_; | 267 int last_mouse_event_type_; |
261 gfx::Point location_; | 268 gfx::Point location_; |
262 bool received_mouse_enter_; | 269 bool received_mouse_enter_; |
263 bool received_mouse_exit_; | 270 bool received_mouse_exit_; |
264 bool delete_on_pressed_; | 271 bool delete_on_pressed_; |
265 | 272 |
266 // Painting. | 273 // Painting. |
267 std::vector<gfx::Rect> scheduled_paint_rects_; | 274 std::vector<gfx::Rect> scheduled_paint_rects_; |
268 bool did_paint_; | 275 bool did_paint_; |
269 | 276 |
270 // Accelerators. | 277 // Accelerators. |
271 std::map<ui::Accelerator, int> accelerator_count_map_; | 278 std::map<ui::Accelerator, int> accelerator_count_map_; |
272 | 279 |
273 // Native theme. | 280 // Native theme. |
274 const ui::NativeTheme* native_theme_; | 281 const ui::NativeTheme* native_theme_; |
275 | 282 |
276 // Value to return from CanProcessEventsWithinSubtree(). | 283 // Value to return from CanProcessEventsWithinSubtree(). |
277 bool can_process_events_within_subtree_; | 284 bool can_process_events_within_subtree_; |
278 }; | 285 }; |
279 | 286 |
280 //////////////////////////////////////////////////////////////////////////////// | 287 //////////////////////////////////////////////////////////////////////////////// |
288 // Layout | |
289 //////////////////////////////////////////////////////////////////////////////// | |
290 | |
291 void TestView::Layout() { | |
292 did_layout_ = true; | |
293 View::Layout(); | |
294 } | |
295 | |
296 TEST_F(ViewTest, LayoutCalledAfterLayoutIsInvalidated) { | |
sky
2015/11/18 16:55:50
Be more descriptive, eg LayoutCalledInvalidateAndO
flint
2015/11/18 19:57:44
Done.
| |
297 TestView parent; | |
298 TestView* child = new TestView; | |
299 gfx::Rect parent_rect(0, 0, 100, 100); | |
300 parent.SetBoundsRect(parent_rect); | |
301 | |
302 parent.Reset(); | |
303 // |AddChildView| invalidates parent's layout. | |
304 parent.AddChildView(child); | |
305 // Change rect so that only rect's origin is affected. | |
306 parent.SetBoundsRect(parent_rect + gfx::Vector2d(10, 0)); | |
307 | |
308 EXPECT_TRUE(parent.did_layout_); | |
309 | |
310 // After child layout is invalidated, parent and child must be laid out | |
311 // during parent->BoundsChanged(...) call. | |
312 parent.Reset(); | |
313 child->Reset(); | |
314 | |
315 child->InvalidateLayout(); | |
316 parent.SetBoundsRect(parent_rect + gfx::Vector2d(20, 0)); | |
317 EXPECT_TRUE(parent.did_layout_); | |
318 EXPECT_TRUE(child->did_layout_); | |
319 } | |
320 | |
321 //////////////////////////////////////////////////////////////////////////////// | |
281 // OnBoundsChanged | 322 // OnBoundsChanged |
282 //////////////////////////////////////////////////////////////////////////////// | 323 //////////////////////////////////////////////////////////////////////////////// |
283 | 324 |
284 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 325 void TestView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
285 did_change_bounds_ = true; | 326 did_change_bounds_ = true; |
286 new_bounds_ = bounds(); | 327 new_bounds_ = bounds(); |
287 } | 328 } |
288 | 329 |
289 TEST_F(ViewTest, OnBoundsChanged) { | 330 TEST_F(ViewTest, OnBoundsChanged) { |
290 TestView v; | 331 TestView v; |
(...skipping 3802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4093 // notification. | 4134 // notification. |
4094 TestView* test_view_child_2 = new TestView(); | 4135 TestView* test_view_child_2 = new TestView(); |
4095 test_view->AddChildView(test_view_child_2); | 4136 test_view->AddChildView(test_view_child_2); |
4096 EXPECT_TRUE(test_view_child_2->native_theme_); | 4137 EXPECT_TRUE(test_view_child_2->native_theme_); |
4097 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 4138 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
4098 | 4139 |
4099 widget->CloseNow(); | 4140 widget->CloseNow(); |
4100 } | 4141 } |
4101 | 4142 |
4102 } // namespace views | 4143 } // namespace views |
OLD | NEW |