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), native_theme_(NULL) {} | 206 TestView() : View(), delete_on_pressed_(false) {} |
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 | |
250 // OnBoundsChanged. | 247 // OnBoundsChanged. |
251 bool did_change_bounds_; | 248 bool did_change_bounds_; |
252 gfx::Rect new_bounds_; | 249 gfx::Rect new_bounds_; |
253 | 250 |
254 // MouseEvent. | 251 // MouseEvent. |
255 int last_mouse_event_type_; | 252 int last_mouse_event_type_; |
256 gfx::Point location_; | 253 gfx::Point location_; |
257 bool received_mouse_enter_; | 254 bool received_mouse_enter_; |
258 bool received_mouse_exit_; | 255 bool received_mouse_exit_; |
259 bool delete_on_pressed_; | 256 bool delete_on_pressed_; |
260 | 257 |
261 // Painting. | 258 // Painting. |
262 std::vector<gfx::Rect> scheduled_paint_rects_; | 259 std::vector<gfx::Rect> scheduled_paint_rects_; |
263 | 260 |
264 // GestureEvent | 261 // GestureEvent |
265 int last_gesture_event_type_; | 262 int last_gesture_event_type_; |
266 bool last_gesture_event_was_handled_; | 263 bool last_gesture_event_was_handled_; |
267 | 264 |
268 // Painting. | 265 // Painting. |
269 SkRect last_clip_; | 266 SkRect last_clip_; |
270 | 267 |
271 // Accelerators. | 268 // Accelerators. |
272 std::map<ui::Accelerator, int> accelerator_count_map_; | 269 std::map<ui::Accelerator, int> accelerator_count_map_; |
273 | |
274 // Native theme. | |
275 const ui::NativeTheme* native_theme_; | |
276 }; | 270 }; |
277 | 271 |
278 // A view subclass that consumes all Gesture events for testing purposes. | 272 // A view subclass that consumes all Gesture events for testing purposes. |
279 class TestViewConsumeGesture : public TestView { | 273 class TestViewConsumeGesture : public TestView { |
280 public: | 274 public: |
281 TestViewConsumeGesture() : TestView() {} | 275 TestViewConsumeGesture() : TestView() {} |
282 virtual ~TestViewConsumeGesture() {} | 276 virtual ~TestViewConsumeGesture() {} |
283 | 277 |
284 protected: | 278 protected: |
285 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 279 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
(...skipping 3332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3618 TEST_F(ViewTest, UpdateViewStorageOnDelete) { | 3612 TEST_F(ViewTest, UpdateViewStorageOnDelete) { |
3619 ViewStorage* view_storage = ViewStorage::GetInstance(); | 3613 ViewStorage* view_storage = ViewStorage::GetInstance(); |
3620 const int storage_id = view_storage->CreateStorageID(); | 3614 const int storage_id = view_storage->CreateStorageID(); |
3621 { | 3615 { |
3622 View view; | 3616 View view; |
3623 view_storage->StoreView(storage_id, &view); | 3617 view_storage->StoreView(storage_id, &view); |
3624 } | 3618 } |
3625 EXPECT_TRUE(view_storage->RetrieveView(storage_id) == NULL); | 3619 EXPECT_TRUE(view_storage->RetrieveView(storage_id) == NULL); |
3626 } | 3620 } |
3627 | 3621 |
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 | |
3667 } // namespace views | 3622 } // namespace views |
OLD | NEW |