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/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 } // namespace | 197 } // namespace |
198 | 198 |
199 namespace views { | 199 namespace views { |
200 | 200 |
201 typedef ViewsTestBase ViewTest; | 201 typedef ViewsTestBase ViewTest; |
202 | 202 |
203 // A derived class for testing purpose. | 203 // A derived class for testing purpose. |
204 class TestView : public View { | 204 class TestView : public View { |
205 public: | 205 public: |
206 TestView() : View(), delete_on_pressed_(false) {} | 206 TestView() : View(), delete_on_pressed_(false), native_theme_(NULL) {} |
207 virtual ~TestView() {} | 207 virtual ~TestView() {} |
208 | 208 |
209 // Reset all test state | 209 // Reset all test state |
210 void Reset() { | 210 void Reset() { |
211 did_change_bounds_ = false; | 211 did_change_bounds_ = false; |
212 last_mouse_event_type_ = 0; | 212 last_mouse_event_type_ = 0; |
213 location_.SetPoint(0, 0); | 213 location_.SetPoint(0, 0); |
214 received_mouse_enter_ = false; | 214 received_mouse_enter_ = false; |
215 received_mouse_exit_ = false; | 215 received_mouse_exit_ = false; |
216 last_gesture_event_type_ = 0; | 216 last_gesture_event_type_ = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
237 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 237 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
238 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 238 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
239 | 239 |
240 // Ignores GestureEvent by default. | 240 // Ignores GestureEvent by default. |
241 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 241 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
242 | 242 |
243 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; | 243 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; |
244 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | 244 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; |
245 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 245 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
246 | 246 |
| 247 virtual void OnNativeThemeChanged(const ui::NativeTheme* native_theme) |
| 248 OVERRIDE; |
| 249 |
247 // OnBoundsChanged. | 250 // OnBoundsChanged. |
248 bool did_change_bounds_; | 251 bool did_change_bounds_; |
249 gfx::Rect new_bounds_; | 252 gfx::Rect new_bounds_; |
250 | 253 |
251 // MouseEvent. | 254 // MouseEvent. |
252 int last_mouse_event_type_; | 255 int last_mouse_event_type_; |
253 gfx::Point location_; | 256 gfx::Point location_; |
254 bool received_mouse_enter_; | 257 bool received_mouse_enter_; |
255 bool received_mouse_exit_; | 258 bool received_mouse_exit_; |
256 bool delete_on_pressed_; | 259 bool delete_on_pressed_; |
257 | 260 |
258 // Painting. | 261 // Painting. |
259 std::vector<gfx::Rect> scheduled_paint_rects_; | 262 std::vector<gfx::Rect> scheduled_paint_rects_; |
260 | 263 |
261 // GestureEvent | 264 // GestureEvent |
262 int last_gesture_event_type_; | 265 int last_gesture_event_type_; |
263 bool last_gesture_event_was_handled_; | 266 bool last_gesture_event_was_handled_; |
264 | 267 |
265 // Painting. | 268 // Painting. |
266 SkRect last_clip_; | 269 SkRect last_clip_; |
267 | 270 |
268 // Accelerators. | 271 // Accelerators. |
269 std::map<ui::Accelerator, int> accelerator_count_map_; | 272 std::map<ui::Accelerator, int> accelerator_count_map_; |
| 273 |
| 274 // Native theme. |
| 275 const ui::NativeTheme* native_theme_; |
270 }; | 276 }; |
271 | 277 |
272 // A view subclass that consumes all Gesture events for testing purposes. | 278 // A view subclass that consumes all Gesture events for testing purposes. |
273 class TestViewConsumeGesture : public TestView { | 279 class TestViewConsumeGesture : public TestView { |
274 public: | 280 public: |
275 TestViewConsumeGesture() : TestView() {} | 281 TestViewConsumeGesture() : TestView() {} |
276 virtual ~TestViewConsumeGesture() {} | 282 virtual ~TestViewConsumeGesture() {} |
277 | 283 |
278 protected: | 284 protected: |
279 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 285 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
(...skipping 3332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3612 TEST_F(ViewTest, UpdateViewStorageOnDelete) { | 3618 TEST_F(ViewTest, UpdateViewStorageOnDelete) { |
3613 ViewStorage* view_storage = ViewStorage::GetInstance(); | 3619 ViewStorage* view_storage = ViewStorage::GetInstance(); |
3614 const int storage_id = view_storage->CreateStorageID(); | 3620 const int storage_id = view_storage->CreateStorageID(); |
3615 { | 3621 { |
3616 View view; | 3622 View view; |
3617 view_storage->StoreView(storage_id, &view); | 3623 view_storage->StoreView(storage_id, &view); |
3618 } | 3624 } |
3619 EXPECT_TRUE(view_storage->RetrieveView(storage_id) == NULL); | 3625 EXPECT_TRUE(view_storage->RetrieveView(storage_id) == NULL); |
3620 } | 3626 } |
3621 | 3627 |
| 3628 //////////////////////////////////////////////////////////////////////////////// |
| 3629 // NativeTheme |
| 3630 //////////////////////////////////////////////////////////////////////////////// |
| 3631 |
| 3632 void TestView::OnNativeThemeChanged(const ui::NativeTheme* native_theme) { |
| 3633 native_theme_ = native_theme; |
| 3634 } |
| 3635 |
| 3636 TEST_F(ViewTest, OnNativeThemeChanged) { |
| 3637 TestView* test_view = new TestView(); |
| 3638 EXPECT_FALSE(test_view->native_theme_); |
| 3639 TestView* test_view_child = new TestView(); |
| 3640 EXPECT_FALSE(test_view_child->native_theme_); |
| 3641 |
| 3642 // Child view added before the widget hierarchy exists should get the |
| 3643 // new native theme notification. |
| 3644 test_view->AddChildView(test_view_child); |
| 3645 |
| 3646 scoped_ptr<Widget> widget(new Widget); |
| 3647 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 3648 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 3649 widget->Init(params); |
| 3650 |
| 3651 widget->GetRootView()->AddChildView(test_view); |
| 3652 EXPECT_TRUE(test_view->native_theme_); |
| 3653 EXPECT_EQ(widget->GetNativeTheme(), test_view->native_theme_); |
| 3654 EXPECT_TRUE(test_view_child->native_theme_); |
| 3655 EXPECT_EQ(widget->GetNativeTheme(), test_view_child->native_theme_); |
| 3656 |
| 3657 // Child view added after the widget hierarchy exists should also get the |
| 3658 // notification. |
| 3659 TestView* test_view_child_2 = new TestView(); |
| 3660 test_view->AddChildView(test_view_child_2); |
| 3661 EXPECT_TRUE(test_view_child_2->native_theme_); |
| 3662 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
| 3663 |
| 3664 widget->CloseNow(); |
| 3665 } |
| 3666 |
3622 } // namespace views | 3667 } // namespace views |
OLD | NEW |