| OLD | NEW |
| 1 // Copyright (c) 2010 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 <gdk/gdkkeysyms.h> | 5 #include <gdk/gdkkeysyms.h> |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gfx/rect.h" | 8 #include "ui/gfx/rect.h" |
| 9 #include "ui/base/models/accelerator.h" |
| 9 #include "views/focus/accelerator_handler.h" | 10 #include "views/focus/accelerator_handler.h" |
| 10 #include "views/focus/focus_manager.h" | 11 #include "views/focus/focus_manager.h" |
| 11 #include "views/view.h" | 12 #include "views/view.h" |
| 12 #include "views/widget/widget.h" | 13 #include "views/widget/widget.h" |
| 13 #include "views/widget/widget_delegate.h" | 14 #include "views/widget/widget_delegate.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 class AcceleratorHandlerGtkTest | 18 class AcceleratorHandlerGtkTest |
| 18 : public testing::Test, | 19 : public testing::Test, |
| 19 public WidgetDelegate, | 20 public WidgetDelegate, |
| 20 public AcceleratorTarget { | 21 public ui::AcceleratorTarget { |
| 21 public: | 22 public: |
| 22 AcceleratorHandlerGtkTest() | 23 AcceleratorHandlerGtkTest() |
| 23 : kMenuAccelerator(ui::VKEY_MENU, false, false, false), | 24 : kMenuAccelerator(ui::VKEY_MENU, false, false, false), |
| 24 kHomepageAccelerator(ui::VKEY_HOME, false, false, true), | 25 kHomepageAccelerator(ui::VKEY_HOME, false, false, true), |
| 25 content_view_(NULL) { | 26 content_view_(NULL) { |
| 26 } | 27 } |
| 27 | 28 |
| 28 virtual void SetUp() { | 29 virtual void SetUp() { |
| 29 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 500, 500)); | 30 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 500, 500)); |
| 30 window_->Show(); | 31 window_->Show(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 // but the code should never depend on exact hardware keycodes, just the | 52 // but the code should never depend on exact hardware keycodes, just the |
| 52 // fact that the code for presses and releases of the same key match. | 53 // fact that the code for presses and releases of the same key match. |
| 53 evt.hardware_keycode = keyval; | 54 evt.hardware_keycode = keyval; |
| 54 evt.state = state; | 55 evt.state = state; |
| 55 GtkWidget* widget = GTK_WIDGET(window_->GetNativeWindow()); | 56 GtkWidget* widget = GTK_WIDGET(window_->GetNativeWindow()); |
| 56 evt.window = widget->window; | 57 evt.window = widget->window; |
| 57 return evt; | 58 return evt; |
| 58 } | 59 } |
| 59 | 60 |
| 60 // AcceleratorTarget implementation. | 61 // AcceleratorTarget implementation. |
| 61 virtual bool AcceleratorPressed(const Accelerator& accelerator) { | 62 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 62 if (accelerator == kMenuAccelerator) | 63 if (accelerator == kMenuAccelerator) |
| 63 menu_pressed_ = true; | 64 menu_pressed_ = true; |
| 64 else if (accelerator == kHomepageAccelerator) | 65 else if (accelerator == kHomepageAccelerator) |
| 65 home_pressed_ = true; | 66 home_pressed_ = true; |
| 66 return true; | 67 return true; |
| 67 } | 68 } |
| 68 | 69 |
| 69 // WidgetDelegate Implementation. | 70 // WidgetDelegate Implementation. |
| 70 virtual View* GetContentsView() { | 71 virtual View* GetContentsView() { |
| 71 if (!content_view_) | 72 if (!content_view_) |
| 72 content_view_ = new View(); | 73 content_view_ = new View(); |
| 73 return content_view_; | 74 return content_view_; |
| 74 } | 75 } |
| 75 virtual const views::Widget* GetWidget() const { | 76 virtual const views::Widget* GetWidget() const { |
| 76 return content_view_->GetWidget(); | 77 return content_view_->GetWidget(); |
| 77 } | 78 } |
| 78 virtual views::Widget* GetWidget() { | 79 virtual views::Widget* GetWidget() { |
| 79 return content_view_->GetWidget(); | 80 return content_view_->GetWidget(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 virtual void InitContentView() { | 83 virtual void InitContentView() { |
| 83 } | 84 } |
| 84 | 85 |
| 85 protected: | 86 protected: |
| 86 bool menu_pressed_; | 87 bool menu_pressed_; |
| 87 bool home_pressed_; | 88 bool home_pressed_; |
| 88 | 89 |
| 89 private: | 90 private: |
| 90 Accelerator kMenuAccelerator; | 91 ui::Accelerator kMenuAccelerator; |
| 91 Accelerator kHomepageAccelerator; | 92 ui::Accelerator kHomepageAccelerator; |
| 92 Widget* window_; | 93 Widget* window_; |
| 93 View* content_view_; | 94 View* content_view_; |
| 94 MessageLoopForUI message_loop_; | 95 MessageLoopForUI message_loop_; |
| 95 DISALLOW_COPY_AND_ASSIGN(AcceleratorHandlerGtkTest); | 96 DISALLOW_COPY_AND_ASSIGN(AcceleratorHandlerGtkTest); |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 // Test that the homepage accelerator (Alt+Home) is activated on key down | 99 // Test that the homepage accelerator (Alt+Home) is activated on key down |
| 99 // and that the menu accelerator (Alt) is never activated. | 100 // and that the menu accelerator (Alt) is never activated. |
| 100 TEST_F(AcceleratorHandlerGtkTest, TestHomepageAccelerator) { | 101 TEST_F(AcceleratorHandlerGtkTest, TestHomepageAccelerator) { |
| 101 AcceleratorHandler handler; | 102 AcceleratorHandler handler; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 190 |
| 190 // Release Alt - now this should trigger the menu shortcut. | 191 // Release Alt - now this should trigger the menu shortcut. |
| 191 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Alt_L, 0); | 192 evt = CreateKeyEvent(GDK_KEY_RELEASE, GDK_Alt_L, 0); |
| 192 evt.hardware_keycode = 0x40; | 193 evt.hardware_keycode = 0x40; |
| 193 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); | 194 EXPECT_TRUE(handler.Dispatch(reinterpret_cast<GdkEvent*>(&evt))); |
| 194 | 195 |
| 195 ASSERT_TRUE(menu_pressed_); | 196 ASSERT_TRUE(menu_pressed_); |
| 196 } | 197 } |
| 197 | 198 |
| 198 } // namespace views | 199 } // namespace views |
| OLD | NEW |