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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_accessibility_api.h" | 10 #include "chrome/browser/extensions/extension_accessibility_api.h" |
11 #include "chrome/browser/views/accessibility_event_router_views.h" | 11 #include "chrome/browser/views/accessibility_event_router_views.h" |
12 #include "chrome/browser/views/accessible_view_helper.h" | 12 #include "chrome/browser/views/accessible_view_helper.h" |
13 #include "chrome/common/notification_registrar.h" | 13 #include "chrome/common/notification_registrar.h" |
14 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
15 #include "chrome/test/testing_profile.h" | 15 #include "chrome/test/testing_profile.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "views/controls/button/native_button.h" | 17 #include "views/controls/button/native_button.h" |
18 #include "views/grid_layout.h" | 18 #include "views/grid_layout.h" |
| 19 #include "views/views_delegate.h" |
19 #include "views/widget/root_view.h" | 20 #include "views/widget/root_view.h" |
20 #include "views/window/window.h" | 21 #include "views/window/window.h" |
21 | 22 |
22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
23 #include "views/widget/widget_win.h" | 24 #include "views/widget/widget_win.h" |
24 #elif defined(OS_LINUX) | 25 #elif defined(OS_LINUX) |
25 #include "views/widget/widget_gtk.h" | 26 #include "views/widget/widget_gtk.h" |
26 #endif | 27 #endif |
27 | 28 |
28 #if defined(TOOLKIT_VIEWS) | 29 #if defined(TOOLKIT_VIEWS) |
29 | 30 |
| 31 class AccessibilityViewsDelegate : public views::ViewsDelegate { |
| 32 public: |
| 33 AccessibilityViewsDelegate() {} |
| 34 virtual ~AccessibilityViewsDelegate() {} |
| 35 |
| 36 // Overridden from views::ViewsDelegate: |
| 37 virtual Clipboard* GetClipboard() const { return NULL; } |
| 38 virtual void SaveWindowPlacement(const std::wstring& window_name, |
| 39 const gfx::Rect& bounds, |
| 40 bool maximized) { |
| 41 } |
| 42 virtual bool GetSavedWindowBounds(const std::wstring& window_name, |
| 43 gfx::Rect* bounds) const { |
| 44 return false; |
| 45 } |
| 46 virtual bool GetSavedMaximizedState(const std::wstring& window_name, |
| 47 bool* maximized) const { |
| 48 return false; |
| 49 } |
| 50 virtual void NotifyAccessibilityEvent( |
| 51 views::View* view, AccessibilityTypes::Event event_type) { |
| 52 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( |
| 53 view, event_type); |
| 54 } |
| 55 #if defined(OS_WIN) |
| 56 virtual HICON GetDefaultWindowIcon() const { |
| 57 return NULL; |
| 58 } |
| 59 #endif |
| 60 virtual void AddRef() {} |
| 61 virtual void ReleaseRef() {} |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate); |
| 64 }; |
| 65 |
30 class AccessibilityEventRouterViewsTest | 66 class AccessibilityEventRouterViewsTest |
31 : public testing::Test, | 67 : public testing::Test, |
32 public NotificationObserver { | 68 public NotificationObserver { |
33 public: | 69 public: |
| 70 virtual void SetUp() { |
| 71 views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate(); |
| 72 } |
| 73 |
| 74 virtual void TearDown() { |
| 75 delete views::ViewsDelegate::views_delegate; |
| 76 views::ViewsDelegate::views_delegate = NULL; |
| 77 } |
| 78 |
34 views::Widget* CreateWidget() { | 79 views::Widget* CreateWidget() { |
35 #if defined(OS_WIN) | 80 #if defined(OS_WIN) |
36 return new views::WidgetWin(); | 81 return new views::WidgetWin(); |
37 #elif defined(OS_LINUX) | 82 #elif defined(OS_LINUX) |
38 return new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); | 83 return new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW); |
39 #endif | 84 #endif |
40 } | 85 } |
| 86 |
41 protected: | 87 protected: |
42 // Implement NotificationObserver::Observe and store information about a | 88 // Implement NotificationObserver::Observe and store information about a |
43 // ACCESSIBILITY_CONTROL_FOCUSED event. | 89 // ACCESSIBILITY_CONTROL_FOCUSED event. |
44 virtual void Observe(NotificationType type, | 90 virtual void Observe(NotificationType type, |
45 const NotificationSource& source, | 91 const NotificationSource& source, |
46 const NotificationDetails& details) { | 92 const NotificationDetails& details) { |
47 ASSERT_EQ(type.value, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); | 93 ASSERT_EQ(type.value, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); |
48 const AccessibilityControlInfo* info = | 94 const AccessibilityControlInfo* info = |
49 Details<const AccessibilityControlInfo>(details).ptr(); | 95 Details<const AccessibilityControlInfo>(details).ptr(); |
50 focus_event_count_++; | 96 focus_event_count_++; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 focus_manager->AdvanceFocus(false); | 165 focus_manager->AdvanceFocus(false); |
120 EXPECT_EQ(1, focus_event_count_); | 166 EXPECT_EQ(1, focus_event_count_); |
121 | 167 |
122 // Advance to button 1 and check the notification. | 168 // Advance to button 1 and check the notification. |
123 focus_manager->AdvanceFocus(false); | 169 focus_manager->AdvanceFocus(false); |
124 EXPECT_EQ(2, focus_event_count_); | 170 EXPECT_EQ(2, focus_event_count_); |
125 EXPECT_EQ(kButton1ASCII, last_control_name_); | 171 EXPECT_EQ(kButton1ASCII, last_control_name_); |
126 } | 172 } |
127 | 173 |
128 #endif // defined(TOOLKIT_VIEWS) | 174 #endif // defined(TOOLKIT_VIEWS) |
OLD | NEW |