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

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

Issue 14307023: chrome: Use base::MessageLoop. (Part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/accessibility/accessibility_extension_api.h" 10 #include "chrome/browser/accessibility/accessibility_extension_api.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 virtual void TearDown() { 124 virtual void TearDown() {
125 #if defined(USE_AURA) 125 #if defined(USE_AURA)
126 aura_test_helper_->TearDown(); 126 aura_test_helper_->TearDown();
127 #endif 127 #endif
128 delete views::ViewsDelegate::views_delegate; 128 delete views::ViewsDelegate::views_delegate;
129 views::ViewsDelegate::views_delegate = NULL; 129 views::ViewsDelegate::views_delegate = NULL;
130 130
131 // The Widget's FocusManager is deleted using DeleteSoon - this 131 // The Widget's FocusManager is deleted using DeleteSoon - this
132 // forces it to be deleted now, so we don't have any memory leaks 132 // forces it to be deleted now, so we don't have any memory leaks
133 // when this method exits. 133 // when this method exits.
134 MessageLoop::current()->RunUntilIdle(); 134 base::MessageLoop::current()->RunUntilIdle();
135 135
136 #if defined(OS_WIN) 136 #if defined(OS_WIN)
137 ole_initializer_.reset(); 137 ole_initializer_.reset();
138 #endif 138 #endif
139 } 139 }
140 140
141 views::Widget* CreateWindowWithContents(views::View* contents) { 141 views::Widget* CreateWindowWithContents(views::View* contents) {
142 gfx::NativeView context = NULL; 142 gfx::NativeView context = NULL;
143 #if defined(USE_AURA) 143 #if defined(USE_AURA)
144 context = aura_test_helper_->root_window(); 144 context = aura_test_helper_->root_window();
(...skipping 27 matching lines...) Expand all
172 const content::NotificationSource& source, 172 const content::NotificationSource& source,
173 const content::NotificationDetails& details) OVERRIDE { 173 const content::NotificationDetails& details) OVERRIDE {
174 ASSERT_EQ(type, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED); 174 ASSERT_EQ(type, chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED);
175 const AccessibilityControlInfo* info = 175 const AccessibilityControlInfo* info =
176 content::Details<const AccessibilityControlInfo>(details).ptr(); 176 content::Details<const AccessibilityControlInfo>(details).ptr();
177 focus_event_count_++; 177 focus_event_count_++;
178 last_control_name_ = info->name(); 178 last_control_name_ = info->name();
179 last_control_context_ = info->context(); 179 last_control_context_ = info->context();
180 } 180 }
181 181
182 MessageLoopForUI message_loop_; 182 base::MessageLoopForUI message_loop_;
183 int focus_event_count_; 183 int focus_event_count_;
184 std::string last_control_name_; 184 std::string last_control_name_;
185 std::string last_control_context_; 185 std::string last_control_context_;
186 content::NotificationRegistrar registrar_; 186 content::NotificationRegistrar registrar_;
187 TestingProfile profile_; 187 TestingProfile profile_;
188 #if defined(OS_WIN) 188 #if defined(OS_WIN)
189 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; 189 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_;
190 #endif 190 #endif
191 #if defined(USE_AURA) 191 #if defined(USE_AURA)
192 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; 192 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 EnableAccessibilityAndListenToFocusNotifications(); 225 EnableAccessibilityAndListenToFocusNotifications();
226 226
227 // Change the accessible name of button3. 227 // Change the accessible name of button3.
228 button3->SetAccessibleName(ASCIIToUTF16(kButton3NewASCII)); 228 button3->SetAccessibleName(ASCIIToUTF16(kButton3NewASCII));
229 229
230 // Advance focus to the next button and test that we got the 230 // Advance focus to the next button and test that we got the
231 // expected notification with the name of button 2. 231 // expected notification with the name of button 2.
232 views::FocusManager* focus_manager = contents->GetWidget()->GetFocusManager(); 232 views::FocusManager* focus_manager = contents->GetWidget()->GetFocusManager();
233 focus_event_count_ = 0; 233 focus_event_count_ = 0;
234 focus_manager->AdvanceFocus(false); 234 focus_manager->AdvanceFocus(false);
235 MessageLoop::current()->RunUntilIdle(); 235 base::MessageLoop::current()->RunUntilIdle();
236 EXPECT_EQ(1, focus_event_count_); 236 EXPECT_EQ(1, focus_event_count_);
237 EXPECT_EQ(kButton2ASCII, last_control_name_); 237 EXPECT_EQ(kButton2ASCII, last_control_name_);
238 238
239 // Advance to button 3. Expect the new accessible name we assigned. 239 // Advance to button 3. Expect the new accessible name we assigned.
240 focus_manager->AdvanceFocus(false); 240 focus_manager->AdvanceFocus(false);
241 MessageLoop::current()->RunUntilIdle(); 241 base::MessageLoop::current()->RunUntilIdle();
242 EXPECT_EQ(2, focus_event_count_); 242 EXPECT_EQ(2, focus_event_count_);
243 EXPECT_EQ(kButton3NewASCII, last_control_name_); 243 EXPECT_EQ(kButton3NewASCII, last_control_name_);
244 244
245 // Advance to button 1 and check the notification. 245 // Advance to button 1 and check the notification.
246 focus_manager->AdvanceFocus(false); 246 focus_manager->AdvanceFocus(false);
247 MessageLoop::current()->RunUntilIdle(); 247 base::MessageLoop::current()->RunUntilIdle();
248 EXPECT_EQ(3, focus_event_count_); 248 EXPECT_EQ(3, focus_event_count_);
249 EXPECT_EQ(kButton1ASCII, last_control_name_); 249 EXPECT_EQ(kButton1ASCII, last_control_name_);
250 250
251 window->CloseNow(); 251 window->CloseNow();
252 } 252 }
253 253
254 TEST_F(AccessibilityEventRouterViewsTest, TestToolbarContext) { 254 TEST_F(AccessibilityEventRouterViewsTest, TestToolbarContext) {
255 const char kToolbarNameASCII[] = "MyToolbar"; 255 const char kToolbarNameASCII[] = "MyToolbar";
256 const char kButtonNameASCII[] = "MyButton"; 256 const char kButtonNameASCII[] = "MyButton";
257 257
258 // Create a toolbar with a button. 258 // Create a toolbar with a button.
259 views::View* contents = new ViewWithNameAndRole( 259 views::View* contents = new ViewWithNameAndRole(
260 ASCIIToUTF16(kToolbarNameASCII), 260 ASCIIToUTF16(kToolbarNameASCII),
261 ui::AccessibilityTypes::ROLE_TOOLBAR); 261 ui::AccessibilityTypes::ROLE_TOOLBAR);
262 views::LabelButton* button = new views::LabelButton( 262 views::LabelButton* button = new views::LabelButton(
263 NULL, ASCIIToUTF16(kButtonNameASCII)); 263 NULL, ASCIIToUTF16(kButtonNameASCII));
264 button->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); 264 button->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
265 contents->AddChildView(button); 265 contents->AddChildView(button);
266 266
267 // Put the view in a window. 267 // Put the view in a window.
268 views::Widget* window = CreateWindowWithContents(contents); 268 views::Widget* window = CreateWindowWithContents(contents);
269 269
270 EnableAccessibilityAndListenToFocusNotifications(); 270 EnableAccessibilityAndListenToFocusNotifications();
271 271
272 // Set focus to the button. 272 // Set focus to the button.
273 focus_event_count_ = 0; 273 focus_event_count_ = 0;
274 button->RequestFocus(); 274 button->RequestFocus();
275 275
276 MessageLoop::current()->RunUntilIdle(); 276 base::MessageLoop::current()->RunUntilIdle();
277 277
278 // Test that we got the event with the expected name and context. 278 // Test that we got the event with the expected name and context.
279 EXPECT_EQ(kInitialFocusCount, focus_event_count_); 279 EXPECT_EQ(kInitialFocusCount, focus_event_count_);
280 EXPECT_EQ(kButtonNameASCII, last_control_name_); 280 EXPECT_EQ(kButtonNameASCII, last_control_name_);
281 EXPECT_EQ(kToolbarNameASCII, last_control_context_); 281 EXPECT_EQ(kToolbarNameASCII, last_control_context_);
282 282
283 window->CloseNow(); 283 window->CloseNow();
284 } 284 }
285 285
286 TEST_F(AccessibilityEventRouterViewsTest, TestAlertContext) { 286 TEST_F(AccessibilityEventRouterViewsTest, TestAlertContext) {
(...skipping 13 matching lines...) Expand all
300 300
301 // Put the view in a window. 301 // Put the view in a window.
302 views::Widget* window = CreateWindowWithContents(contents); 302 views::Widget* window = CreateWindowWithContents(contents);
303 303
304 EnableAccessibilityAndListenToFocusNotifications(); 304 EnableAccessibilityAndListenToFocusNotifications();
305 305
306 // Set focus to the button. 306 // Set focus to the button.
307 focus_event_count_ = 0; 307 focus_event_count_ = 0;
308 button->RequestFocus(); 308 button->RequestFocus();
309 309
310 MessageLoop::current()->RunUntilIdle(); 310 base::MessageLoop::current()->RunUntilIdle();
311 311
312 // Test that we got the event with the expected name and context. 312 // Test that we got the event with the expected name and context.
313 EXPECT_EQ(kInitialFocusCount, focus_event_count_); 313 EXPECT_EQ(kInitialFocusCount, focus_event_count_);
314 EXPECT_EQ(kButtonNameASCII, last_control_name_); 314 EXPECT_EQ(kButtonNameASCII, last_control_name_);
315 EXPECT_EQ(kAlertTextASCII, last_control_context_); 315 EXPECT_EQ(kAlertTextASCII, last_control_context_);
316 316
317 window->CloseNow(); 317 window->CloseNow();
318 } 318 }
319 319
320 TEST_F(AccessibilityEventRouterViewsTest, StateChangeAfterNotification) { 320 TEST_F(AccessibilityEventRouterViewsTest, StateChangeAfterNotification) {
(...skipping 21 matching lines...) Expand all
342 child->RequestFocus(); 342 child->RequestFocus();
343 343
344 // Change the child's name after the focus notification. 344 // Change the child's name after the focus notification.
345 child->set_name(ASCIIToUTF16(kNewNameASCII)); 345 child->set_name(ASCIIToUTF16(kNewNameASCII));
346 346
347 // We shouldn't get the notification right away. 347 // We shouldn't get the notification right away.
348 EXPECT_EQ(0, focus_event_count_); 348 EXPECT_EQ(0, focus_event_count_);
349 349
350 // Process anything in the event loop. Now we should get the notification, 350 // Process anything in the event loop. Now we should get the notification,
351 // and it should give us the new control name, not the old one. 351 // and it should give us the new control name, not the old one.
352 MessageLoop::current()->RunUntilIdle(); 352 base::MessageLoop::current()->RunUntilIdle();
353 EXPECT_EQ(kInitialFocusCount, focus_event_count_); 353 EXPECT_EQ(kInitialFocusCount, focus_event_count_);
354 EXPECT_EQ(kNewNameASCII, last_control_name_); 354 EXPECT_EQ(kNewNameASCII, last_control_name_);
355 355
356 window->CloseNow(); 356 window->CloseNow();
357 } 357 }
358 358
359 TEST_F(AccessibilityEventRouterViewsTest, NotificationOnDeletedObject) { 359 TEST_F(AccessibilityEventRouterViewsTest, NotificationOnDeletedObject) {
360 const char kContentsNameASCII[] = "Contents"; 360 const char kContentsNameASCII[] = "Contents";
361 const char kNameASCII[] = "OldName"; 361 const char kNameASCII[] = "OldName";
362 362
(...skipping 17 matching lines...) Expand all
380 child->RequestFocus(); 380 child->RequestFocus();
381 381
382 // Delete the child! 382 // Delete the child!
383 delete child; 383 delete child;
384 384
385 // We shouldn't get the notification right away. 385 // We shouldn't get the notification right away.
386 EXPECT_EQ(0, focus_event_count_); 386 EXPECT_EQ(0, focus_event_count_);
387 387
388 // Process anything in the event loop. We shouldn't get a notification 388 // Process anything in the event loop. We shouldn't get a notification
389 // because the view is no longer valid, and this shouldn't crash. 389 // because the view is no longer valid, and this shouldn't crash.
390 MessageLoop::current()->RunUntilIdle(); 390 base::MessageLoop::current()->RunUntilIdle();
391 EXPECT_EQ(0, focus_event_count_); 391 EXPECT_EQ(0, focus_event_count_);
392 392
393 window->CloseNow(); 393 window->CloseNow();
394 } 394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698