Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(671)

Side by Side Diff: chrome/browser/ui/views/accessibility_event_router_views_unittest.cc

Issue 6961027: Change event routers from singletons to being owned by the ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: all is built on sand Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/accessibility_event_router_views.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/extensions/extension_service.h"
12 #include "chrome/browser/extensions/test_extension_service.h"
11 #include "chrome/browser/ui/views/accessibility_event_router_views.h" 13 #include "chrome/browser/ui/views/accessibility_event_router_views.h"
12 #include "chrome/test/testing_profile.h" 14 #include "chrome/test/testing_profile.h"
13 #include "content/common/notification_registrar.h" 15 #include "content/common/notification_registrar.h"
14 #include "content/common/notification_service.h" 16 #include "content/common/notification_service.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 #include "views/controls/button/native_button.h" 18 #include "views/controls/button/native_button.h"
17 #include "views/layout/grid_layout.h" 19 #include "views/layout/grid_layout.h"
18 #include "views/views_delegate.h" 20 #include "views/views_delegate.h"
19 #include "views/widget/native_widget.h" 21 #include "views/widget/native_widget.h"
20 #include "views/widget/root_view.h" 22 #include "views/widget/root_view.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 views::NativeButton* button2 = new views::NativeButton( 138 views::NativeButton* button2 = new views::NativeButton(
137 NULL, ASCIIToWide(kButton2ASCII)); 139 NULL, ASCIIToWide(kButton2ASCII));
138 contents->AddChildView(button2); 140 contents->AddChildView(button2);
139 views::NativeButton* button3 = new views::NativeButton( 141 views::NativeButton* button3 = new views::NativeButton(
140 NULL, ASCIIToWide(kButton3ASCII)); 142 NULL, ASCIIToWide(kButton3ASCII));
141 contents->AddChildView(button3); 143 contents->AddChildView(button3);
142 144
143 // Put the view in a window. 145 // Put the view in a window.
144 views::Window* window = CreateWindowWithContents(contents); 146 views::Window* window = CreateWindowWithContents(contents);
145 147
148 // Create a profile and associate it with this window.
149 TestingProfile profile;
150 window->AsWidget()->native_widget()->SetNativeWindowProperty(
151 Profile::kProfileKey, &profile);
152
153 // To begin with, accessibility event notifications are off.
154 AccessibilityEventRouterViews::GetInstance()->
155 SetAccessibilityEnabledForTesting(false);
156
146 // Set focus to the first button initially. 157 // Set focus to the first button initially.
147 button1->RequestFocus(); 158 button1->RequestFocus();
148 159
149 // Start listening to ACCESSIBILITY_CONTROL_FOCUSED notifications. 160 // Start listening to ACCESSIBILITY_CONTROL_FOCUSED notifications.
150 NotificationRegistrar registrar; 161 NotificationRegistrar registrar;
151 registrar.Add(this, 162 registrar.Add(this,
152 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, 163 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED,
153 NotificationService::AllSources()); 164 NotificationService::AllSources());
154 165
155 // Switch on accessibility event notifications. 166 // Switch on accessibility event notifications.
156 ExtensionAccessibilityEventRouter* accessibility_event_router = 167 AccessibilityEventRouterViews::GetInstance()->
157 ExtensionAccessibilityEventRouter::GetInstance(); 168 SetAccessibilityEnabledForTesting(true);
158 accessibility_event_router->SetAccessibilityEnabled(true);
159
160 // Create a profile and associate it with this window.
161 TestingProfile profile;
162 window->AsWidget()->native_widget()->SetNativeWindowProperty(
163 Profile::kProfileKey, &profile);
164 169
165 // Change the accessible name of button3. 170 // Change the accessible name of button3.
166 button3->SetAccessibleName(ASCIIToUTF16(kButton3NewASCII)); 171 button3->SetAccessibleName(ASCIIToUTF16(kButton3NewASCII));
167 172
168 // Advance focus to the next button and test that we got the 173 // Advance focus to the next button and test that we got the
169 // expected notification with the name of button 2. 174 // expected notification with the name of button 2.
170 views::FocusManager* focus_manager = contents->GetWidget()->GetFocusManager(); 175 views::FocusManager* focus_manager = contents->GetWidget()->GetFocusManager();
171 focus_event_count_ = 0; 176 focus_event_count_ = 0;
172 focus_manager->AdvanceFocus(false); 177 focus_manager->AdvanceFocus(false);
173 EXPECT_EQ(1, focus_event_count_); 178 EXPECT_EQ(1, focus_event_count_);
174 EXPECT_EQ(kButton2ASCII, last_control_name_); 179 EXPECT_EQ(kButton2ASCII, last_control_name_);
175 180
176 // Advance to button 3. Expect the new accessible name we assigned. 181 // Advance to button 3. Expect the new accessible name we assigned.
177 focus_manager->AdvanceFocus(false); 182 focus_manager->AdvanceFocus(false);
178 EXPECT_EQ(2, focus_event_count_); 183 EXPECT_EQ(2, focus_event_count_);
179 EXPECT_EQ(kButton3NewASCII, last_control_name_); 184 EXPECT_EQ(kButton3NewASCII, last_control_name_);
180 185
181 // Advance to button 1 and check the notification. 186 // Advance to button 1 and check the notification.
182 focus_manager->AdvanceFocus(false); 187 focus_manager->AdvanceFocus(false);
183 EXPECT_EQ(3, focus_event_count_); 188 EXPECT_EQ(3, focus_event_count_);
184 EXPECT_EQ(kButton1ASCII, last_control_name_); 189 EXPECT_EQ(kButton1ASCII, last_control_name_);
185 } 190 }
186 191
187 #endif // defined(TOOLKIT_VIEWS) 192 #endif // defined(TOOLKIT_VIEWS)
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/accessibility_event_router_views.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698