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 <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/ui/views/accessibility_event_router_views.h" | 11 #include "chrome/browser/ui/views/accessibility_event_router_views.h" |
| 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/test/testing_profile.h" | 13 #include "chrome/test/testing_profile.h" |
13 #include "content/common/notification_registrar.h" | 14 #include "content/common/notification_registrar.h" |
14 #include "content/common/notification_service.h" | 15 #include "content/common/notification_service.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "views/controls/button/native_button.h" | 17 #include "views/controls/button/native_button.h" |
17 #include "views/layout/grid_layout.h" | 18 #include "views/layout/grid_layout.h" |
18 #include "views/views_delegate.h" | 19 #include "views/views_delegate.h" |
19 #include "views/widget/native_widget.h" | 20 #include "views/widget/native_widget.h" |
20 #include "views/widget/root_view.h" | 21 #include "views/widget/root_view.h" |
21 #include "views/widget/widget.h" | 22 #include "views/widget/widget.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 108 |
108 views::Widget* CreateWindowWithContents(views::View* contents) { | 109 views::Widget* CreateWindowWithContents(views::View* contents) { |
109 window_delegate_ = new AccessibilityWindowDelegate(contents); | 110 window_delegate_ = new AccessibilityWindowDelegate(contents); |
110 return views::Widget::CreateWindowWithBounds(window_delegate_, | 111 return views::Widget::CreateWindowWithBounds(window_delegate_, |
111 gfx::Rect(0, 0, 500, 500)); | 112 gfx::Rect(0, 0, 500, 500)); |
112 } | 113 } |
113 | 114 |
114 protected: | 115 protected: |
115 // Implement NotificationObserver::Observe and store information about a | 116 // Implement NotificationObserver::Observe and store information about a |
116 // ACCESSIBILITY_CONTROL_FOCUSED event. | 117 // ACCESSIBILITY_CONTROL_FOCUSED event. |
117 virtual void Observe(NotificationType type, | 118 virtual void Observe(int type, |
118 const NotificationSource& source, | 119 const NotificationSource& source, |
119 const NotificationDetails& details) { | 120 const NotificationDetails& details) { |
120 ASSERT_EQ(type.value, NotificationType::ACCESSIBILITY_CONTROL_FOCUSED); | 121 ASSERT_EQ(type, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED); |
121 const AccessibilityControlInfo* info = | 122 const AccessibilityControlInfo* info = |
122 Details<const AccessibilityControlInfo>(details).ptr(); | 123 Details<const AccessibilityControlInfo>(details).ptr(); |
123 focus_event_count_++; | 124 focus_event_count_++; |
124 last_control_name_ = info->name(); | 125 last_control_name_ = info->name(); |
125 } | 126 } |
126 | 127 |
127 MessageLoopForUI message_loop_; | 128 MessageLoopForUI message_loop_; |
128 int focus_event_count_; | 129 int focus_event_count_; |
129 std::string last_control_name_; | 130 std::string last_control_name_; |
130 AccessibilityWindowDelegate* window_delegate_; | 131 AccessibilityWindowDelegate* window_delegate_; |
(...skipping 19 matching lines...) Expand all Loading... |
150 | 151 |
151 // Put the view in a window. | 152 // Put the view in a window. |
152 views::Widget* window = CreateWindowWithContents(contents); | 153 views::Widget* window = CreateWindowWithContents(contents); |
153 | 154 |
154 // Set focus to the first button initially. | 155 // Set focus to the first button initially. |
155 button1->RequestFocus(); | 156 button1->RequestFocus(); |
156 | 157 |
157 // Start listening to ACCESSIBILITY_CONTROL_FOCUSED notifications. | 158 // Start listening to ACCESSIBILITY_CONTROL_FOCUSED notifications. |
158 NotificationRegistrar registrar; | 159 NotificationRegistrar registrar; |
159 registrar.Add(this, | 160 registrar.Add(this, |
160 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, | 161 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, |
161 NotificationService::AllSources()); | 162 NotificationService::AllSources()); |
162 | 163 |
163 // Switch on accessibility event notifications. | 164 // Switch on accessibility event notifications. |
164 ExtensionAccessibilityEventRouter* accessibility_event_router = | 165 ExtensionAccessibilityEventRouter* accessibility_event_router = |
165 ExtensionAccessibilityEventRouter::GetInstance(); | 166 ExtensionAccessibilityEventRouter::GetInstance(); |
166 accessibility_event_router->SetAccessibilityEnabled(true); | 167 accessibility_event_router->SetAccessibilityEnabled(true); |
167 | 168 |
168 // Create a profile and associate it with this window. | 169 // Create a profile and associate it with this window. |
169 TestingProfile profile; | 170 TestingProfile profile; |
170 window->SetNativeWindowProperty(Profile::kProfileKey, &profile); | 171 window->SetNativeWindowProperty(Profile::kProfileKey, &profile); |
(...skipping 14 matching lines...) Expand all Loading... |
185 EXPECT_EQ(2, focus_event_count_); | 186 EXPECT_EQ(2, focus_event_count_); |
186 EXPECT_EQ(kButton3NewASCII, last_control_name_); | 187 EXPECT_EQ(kButton3NewASCII, last_control_name_); |
187 | 188 |
188 // Advance to button 1 and check the notification. | 189 // Advance to button 1 and check the notification. |
189 focus_manager->AdvanceFocus(false); | 190 focus_manager->AdvanceFocus(false); |
190 EXPECT_EQ(3, focus_event_count_); | 191 EXPECT_EQ(3, focus_event_count_); |
191 EXPECT_EQ(kButton1ASCII, last_control_name_); | 192 EXPECT_EQ(kButton1ASCII, last_control_name_); |
192 } | 193 } |
193 | 194 |
194 #endif // defined(TOOLKIT_VIEWS) | 195 #endif // defined(TOOLKIT_VIEWS) |
OLD | NEW |