OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
13 #include "ui/base/keycodes/keyboard_codes.h" | 13 #include "ui/base/keycodes/keyboard_codes.h" |
14 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
| 15 #include "ui/base/models/accelerator.h" |
15 #include "ui/gfx/canvas_skia.h" | 16 #include "ui/gfx/canvas_skia.h" |
16 #include "ui/gfx/compositor/compositor.h" | 17 #include "ui/gfx/compositor/compositor.h" |
17 #include "ui/gfx/compositor/layer.h" | 18 #include "ui/gfx/compositor/layer.h" |
18 #include "ui/gfx/compositor/layer_animator.h" | 19 #include "ui/gfx/compositor/layer_animator.h" |
19 #include "ui/gfx/compositor/test_compositor.h" | 20 #include "ui/gfx/compositor/test_compositor.h" |
20 #include "ui/gfx/compositor/test_texture.h" | 21 #include "ui/gfx/compositor/test_texture.h" |
21 #include "ui/gfx/path.h" | 22 #include "ui/gfx/path.h" |
22 #include "ui/gfx/transform.h" | 23 #include "ui/gfx/transform.h" |
23 #include "views/background.h" | 24 #include "views/background.h" |
24 #include "views/controls/button/button_dropdown.h" | 25 #include "views/controls/button/button_dropdown.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 accelerator_count_map_.clear(); | 209 accelerator_count_map_.clear(); |
209 } | 210 } |
210 | 211 |
211 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; | 212 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |
212 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; | 213 virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; |
213 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; | 214 virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; |
214 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; | 215 virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; |
215 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; | 216 virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; |
216 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; | 217 virtual void Paint(gfx::Canvas* canvas) OVERRIDE; |
217 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; | 218 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; |
218 virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; | 219 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
219 | 220 |
220 // OnBoundsChanged. | 221 // OnBoundsChanged. |
221 bool did_change_bounds_; | 222 bool did_change_bounds_; |
222 gfx::Rect new_bounds_; | 223 gfx::Rect new_bounds_; |
223 | 224 |
224 // MouseEvent. | 225 // MouseEvent. |
225 int last_mouse_event_type_; | 226 int last_mouse_event_type_; |
226 gfx::Point location_; | 227 gfx::Point location_; |
227 | 228 |
228 // Painting. | 229 // Painting. |
229 std::vector<gfx::Rect> scheduled_paint_rects_; | 230 std::vector<gfx::Rect> scheduled_paint_rects_; |
230 | 231 |
231 // TouchEvent. | 232 // TouchEvent. |
232 int last_touch_event_type_; | 233 int last_touch_event_type_; |
233 bool last_touch_event_was_handled_; | 234 bool last_touch_event_was_handled_; |
234 bool in_touch_sequence_; | 235 bool in_touch_sequence_; |
235 | 236 |
236 // Painting. | 237 // Painting. |
237 SkRect last_clip_; | 238 SkRect last_clip_; |
238 | 239 |
239 // Accelerators. | 240 // Accelerators. |
240 std::map<Accelerator, int> accelerator_count_map_; | 241 std::map<ui::Accelerator, int> accelerator_count_map_; |
241 }; | 242 }; |
242 | 243 |
243 // Mock instance of the GestureManager for testing. | 244 // Mock instance of the GestureManager for testing. |
244 class MockGestureManager : public GestureManager { | 245 class MockGestureManager : public GestureManager { |
245 public: | 246 public: |
246 // Reset all test state. | 247 // Reset all test state. |
247 void Reset() { | 248 void Reset() { |
248 last_touch_event_ = 0; | 249 last_touch_event_ = 0; |
249 last_view_ = NULL; | 250 last_view_ = NULL; |
250 previously_handled_flag_ = false; | 251 previously_handled_flag_ = false; |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 ::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0); | 957 ::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0); |
957 ::GetWindowText(normal->GetTestingHandle(), buffer, 1024); | 958 ::GetWindowText(normal->GetTestingHandle(), buffer, 1024); |
958 EXPECT_EQ(kReadOnlyText, string16(buffer)); | 959 EXPECT_EQ(kReadOnlyText, string16(buffer)); |
959 widget->CloseNow(); | 960 widget->CloseNow(); |
960 } | 961 } |
961 #endif | 962 #endif |
962 | 963 |
963 //////////////////////////////////////////////////////////////////////////////// | 964 //////////////////////////////////////////////////////////////////////////////// |
964 // Accelerators | 965 // Accelerators |
965 //////////////////////////////////////////////////////////////////////////////// | 966 //////////////////////////////////////////////////////////////////////////////// |
966 bool TestView::AcceleratorPressed(const Accelerator& accelerator) { | 967 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
967 accelerator_count_map_[accelerator]++; | 968 accelerator_count_map_[accelerator]++; |
968 return true; | 969 return true; |
969 } | 970 } |
970 | 971 |
971 #if defined(OS_WIN) && !defined(USE_AURA) | 972 #if defined(OS_WIN) && !defined(USE_AURA) |
972 TEST_F(ViewTest, ActivateAccelerator) { | 973 TEST_F(ViewTest, ActivateAccelerator) { |
973 // Register a keyboard accelerator before the view is added to a window. | 974 // Register a keyboard accelerator before the view is added to a window. |
974 Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); | 975 ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); |
975 TestView* view = new TestView(); | 976 TestView* view = new TestView(); |
976 view->Reset(); | 977 view->Reset(); |
977 view->AddAccelerator(return_accelerator); | 978 view->AddAccelerator(return_accelerator); |
978 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 979 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
979 | 980 |
980 // Create a window and add the view as its child. | 981 // Create a window and add the view as its child. |
981 scoped_ptr<Widget> widget(new Widget); | 982 scoped_ptr<Widget> widget(new Widget); |
982 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 983 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
983 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 984 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
984 params.bounds = gfx::Rect(0, 0, 100, 100); | 985 params.bounds = gfx::Rect(0, 0, 100, 100); |
985 widget->Init(params); | 986 widget->Init(params); |
986 View* root = widget->GetRootView(); | 987 View* root = widget->GetRootView(); |
987 root->AddChildView(view); | 988 root->AddChildView(view); |
988 widget->Show(); | 989 widget->Show(); |
989 | 990 |
990 // Get the focus manager. | 991 // Get the focus manager. |
991 FocusManager* focus_manager = widget->GetFocusManager(); | 992 FocusManager* focus_manager = widget->GetFocusManager(); |
992 ASSERT_TRUE(focus_manager); | 993 ASSERT_TRUE(focus_manager); |
993 | 994 |
994 // Hit the return key and see if it takes effect. | 995 // Hit the return key and see if it takes effect. |
995 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); | 996 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); |
996 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 997 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
997 | 998 |
998 // Hit the escape key. Nothing should happen. | 999 // Hit the escape key. Nothing should happen. |
999 Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); | 1000 ui::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); |
1000 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); | 1001 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); |
1001 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 1002 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
1002 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); | 1003 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); |
1003 | 1004 |
1004 // Now register the escape key and hit it again. | 1005 // Now register the escape key and hit it again. |
1005 view->AddAccelerator(escape_accelerator); | 1006 view->AddAccelerator(escape_accelerator); |
1006 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator)); | 1007 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator)); |
1007 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 1008 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
1008 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1); | 1009 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1); |
1009 | 1010 |
(...skipping 20 matching lines...) Expand all Loading... |
1030 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); | 1031 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); |
1031 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); | 1032 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2); |
1032 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); | 1033 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2); |
1033 | 1034 |
1034 widget->CloseNow(); | 1035 widget->CloseNow(); |
1035 } | 1036 } |
1036 #endif | 1037 #endif |
1037 | 1038 |
1038 #if defined(OS_WIN) && !defined(USE_AURA) | 1039 #if defined(OS_WIN) && !defined(USE_AURA) |
1039 TEST_F(ViewTest, HiddenViewWithAccelerator) { | 1040 TEST_F(ViewTest, HiddenViewWithAccelerator) { |
1040 Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); | 1041 ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); |
1041 TestView* view = new TestView(); | 1042 TestView* view = new TestView(); |
1042 view->Reset(); | 1043 view->Reset(); |
1043 view->AddAccelerator(return_accelerator); | 1044 view->AddAccelerator(return_accelerator); |
1044 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 1045 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
1045 | 1046 |
1046 scoped_ptr<Widget> widget(new Widget); | 1047 scoped_ptr<Widget> widget(new Widget); |
1047 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 1048 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
1048 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1049 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1049 params.bounds = gfx::Rect(0, 0, 100, 100); | 1050 params.bounds = gfx::Rect(0, 0, 100, 100); |
1050 widget->Init(params); | 1051 widget->Init(params); |
(...skipping 11 matching lines...) Expand all Loading... |
1062 view->SetVisible(true); | 1063 view->SetVisible(true); |
1063 EXPECT_EQ(view, | 1064 EXPECT_EQ(view, |
1064 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); | 1065 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); |
1065 | 1066 |
1066 widget->CloseNow(); | 1067 widget->CloseNow(); |
1067 } | 1068 } |
1068 #endif | 1069 #endif |
1069 | 1070 |
1070 #if defined(OS_WIN) && !defined(USE_AURA) | 1071 #if defined(OS_WIN) && !defined(USE_AURA) |
1071 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) { | 1072 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) { |
1072 Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); | 1073 ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); |
1073 TestView* view = new TestView(); | 1074 TestView* view = new TestView(); |
1074 view->Reset(); | 1075 view->Reset(); |
1075 view->AddAccelerator(return_accelerator); | 1076 view->AddAccelerator(return_accelerator); |
1076 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 1077 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
1077 | 1078 |
1078 scoped_ptr<Widget> widget(new Widget); | 1079 scoped_ptr<Widget> widget(new Widget); |
1079 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 1080 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
1080 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1081 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1081 params.bounds = gfx::Rect(0, 0, 100, 100); | 1082 params.bounds = gfx::Rect(0, 0, 100, 100); |
1082 widget->Init(params); | 1083 widget->Init(params); |
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3096 ScrambleTree(content); | 3097 ScrambleTree(content); |
3097 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3098 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
3098 | 3099 |
3099 ScrambleTree(content); | 3100 ScrambleTree(content); |
3100 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 3101 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
3101 } | 3102 } |
3102 | 3103 |
3103 #endif // VIEWS_COMPOSITOR | 3104 #endif // VIEWS_COMPOSITOR |
3104 | 3105 |
3105 } // namespace views | 3106 } // namespace views |
OLD | NEW |