| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/keyboard_codes.h" | |
| 8 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 10 #include "gfx/canvas_skia.h" | 9 #include "gfx/canvas_skia.h" |
| 11 #include "gfx/path.h" | 10 #include "gfx/path.h" |
| 12 #include "ui/base/clipboard/clipboard.h" | 11 #include "ui/base/clipboard/clipboard.h" |
| 12 #include "ui/base/keycodes/keyboard_codes.h" |
| 13 #include "views/background.h" | 13 #include "views/background.h" |
| 14 #include "views/controls/button/checkbox.h" | 14 #include "views/controls/button/checkbox.h" |
| 15 #include "views/controls/native/native_view_host.h" | 15 #include "views/controls/native/native_view_host.h" |
| 16 #include "views/controls/scroll_view.h" | 16 #include "views/controls/scroll_view.h" |
| 17 #include "views/controls/textfield/textfield.h" | 17 #include "views/controls/textfield/textfield.h" |
| 18 #include "views/event.h" | 18 #include "views/event.h" |
| 19 #include "views/focus/accelerator_handler.h" | 19 #include "views/focus/accelerator_handler.h" |
| 20 #include "views/focus/view_storage.h" | 20 #include "views/focus/view_storage.h" |
| 21 #include "views/test/views_test_base.h" | 21 #include "views/test/views_test_base.h" |
| 22 #include "views/view.h" | 22 #include "views/view.h" |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 // Accelerators | 943 // Accelerators |
| 944 //////////////////////////////////////////////////////////////////////////////// | 944 //////////////////////////////////////////////////////////////////////////////// |
| 945 bool TestView::AcceleratorPressed(const Accelerator& accelerator) { | 945 bool TestView::AcceleratorPressed(const Accelerator& accelerator) { |
| 946 accelerator_count_map_[accelerator]++; | 946 accelerator_count_map_[accelerator]++; |
| 947 return true; | 947 return true; |
| 948 } | 948 } |
| 949 | 949 |
| 950 #if defined(OS_WIN) | 950 #if defined(OS_WIN) |
| 951 TEST_F(ViewTest, ActivateAccelerator) { | 951 TEST_F(ViewTest, ActivateAccelerator) { |
| 952 // Register a keyboard accelerator before the view is added to a window. | 952 // Register a keyboard accelerator before the view is added to a window. |
| 953 views::Accelerator return_accelerator(app::VKEY_RETURN, false, false, false); | 953 views::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); |
| 954 TestView* view = new TestView(); | 954 TestView* view = new TestView(); |
| 955 view->Reset(); | 955 view->Reset(); |
| 956 view->AddAccelerator(return_accelerator); | 956 view->AddAccelerator(return_accelerator); |
| 957 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 957 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
| 958 | 958 |
| 959 // Create a window and add the view as its child. | 959 // Create a window and add the view as its child. |
| 960 WidgetWin window; | 960 WidgetWin window; |
| 961 window.Init(NULL, gfx::Rect(0, 0, 100, 100)); | 961 window.Init(NULL, gfx::Rect(0, 0, 100, 100)); |
| 962 window.set_delete_on_destroy(false); | 962 window.set_delete_on_destroy(false); |
| 963 window.set_window_style(WS_OVERLAPPEDWINDOW); | 963 window.set_window_style(WS_OVERLAPPEDWINDOW); |
| 964 RootView* root = window.GetRootView(); | 964 RootView* root = window.GetRootView(); |
| 965 root->AddChildView(view); | 965 root->AddChildView(view); |
| 966 | 966 |
| 967 // Get the focus manager. | 967 // Get the focus manager. |
| 968 views::FocusManager* focus_manager = | 968 views::FocusManager* focus_manager = |
| 969 views::FocusManager::GetFocusManagerForNativeView(window.GetNativeView()); | 969 views::FocusManager::GetFocusManagerForNativeView(window.GetNativeView()); |
| 970 ASSERT_TRUE(focus_manager); | 970 ASSERT_TRUE(focus_manager); |
| 971 | 971 |
| 972 // Hit the return key and see if it takes effect. | 972 // Hit the return key and see if it takes effect. |
| 973 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); | 973 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 974 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 974 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
| 975 | 975 |
| 976 // Hit the escape key. Nothing should happen. | 976 // Hit the escape key. Nothing should happen. |
| 977 views::Accelerator escape_accelerator(app::VKEY_ESCAPE, false, false, false); | 977 views::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); |
| 978 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); | 978 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); |
| 979 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 979 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
| 980 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); | 980 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); |
| 981 | 981 |
| 982 // Now register the escape key and hit it again. | 982 // Now register the escape key and hit it again. |
| 983 view->AddAccelerator(escape_accelerator); | 983 view->AddAccelerator(escape_accelerator); |
| 984 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator)); | 984 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator)); |
| 985 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); | 985 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); |
| 986 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1); | 986 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1); |
| 987 | 987 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 window->Show(); | 1223 window->Show(); |
| 1224 focus_manager_ = test_dialog_->contents_->GetFocusManager(); | 1224 focus_manager_ = test_dialog_->contents_->GetFocusManager(); |
| 1225 ASSERT_TRUE(focus_manager_ != NULL); | 1225 ASSERT_TRUE(focus_manager_ != NULL); |
| 1226 client_view_ = | 1226 client_view_ = |
| 1227 static_cast<views::DialogClientView*>(window->GetClientView()); | 1227 static_cast<views::DialogClientView*>(window->GetClientView()); |
| 1228 ok_button_ = client_view_->ok_button(); | 1228 ok_button_ = client_view_->ok_button(); |
| 1229 cancel_button_ = client_view_->cancel_button(); | 1229 cancel_button_ = client_view_->cancel_button(); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 void SimularePressingEnterAndCheckDefaultButton(ButtonID button_id) { | 1232 void SimularePressingEnterAndCheckDefaultButton(ButtonID button_id) { |
| 1233 KeyEvent event(Event::ET_KEY_PRESSED, app::VKEY_RETURN, 0, 0, 0); | 1233 KeyEvent event(Event::ET_KEY_PRESSED, ui::VKEY_RETURN, 0, 0, 0); |
| 1234 focus_manager_->OnKeyEvent(event); | 1234 focus_manager_->OnKeyEvent(event); |
| 1235 switch (button_id) { | 1235 switch (button_id) { |
| 1236 case OK: | 1236 case OK: |
| 1237 EXPECT_TRUE(test_dialog_->oked_); | 1237 EXPECT_TRUE(test_dialog_->oked_); |
| 1238 EXPECT_FALSE(test_dialog_->canceled_); | 1238 EXPECT_FALSE(test_dialog_->canceled_); |
| 1239 EXPECT_FALSE(test_dialog_->last_pressed_button_); | 1239 EXPECT_FALSE(test_dialog_->last_pressed_button_); |
| 1240 break; | 1240 break; |
| 1241 case CANCEL: | 1241 case CANCEL: |
| 1242 EXPECT_FALSE(test_dialog_->oked_); | 1242 EXPECT_FALSE(test_dialog_->oked_); |
| 1243 EXPECT_TRUE(test_dialog_->canceled_); | 1243 EXPECT_TRUE(test_dialog_->canceled_); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 #endif | 1467 #endif |
| 1468 } | 1468 } |
| 1469 | 1469 |
| 1470 TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) { | 1470 TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) { |
| 1471 // TODO(georgey): Fix the test for Linux | 1471 // TODO(georgey): Fix the test for Linux |
| 1472 #if defined(OS_WIN) | 1472 #if defined(OS_WIN) |
| 1473 TestChangeNativeViewHierarchy test(this); | 1473 TestChangeNativeViewHierarchy test(this); |
| 1474 test.CheckChangingHierarhy(); | 1474 test.CheckChangingHierarhy(); |
| 1475 #endif | 1475 #endif |
| 1476 } | 1476 } |
| OLD | NEW |