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

Side by Side Diff: content/browser/accessibility/browser_accessibility_win_unittest.cc

Issue 1111163002: Fixed word and line navigation in multi-line text fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed first bunch of comments. Created 5 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
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "base/win/scoped_bstr.h" 7 #include "base/win/scoped_bstr.h"
8 #include "base/win/scoped_comptr.h" 8 #include "base/win/scoped_comptr.h"
9 #include "base/win/scoped_variant.h" 9 #include "base/win/scoped_variant.h"
10 #include "content/browser/accessibility/browser_accessibility_manager.h" 10 #include "content/browser/accessibility/browser_accessibility_manager.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 events.push_back(param); 316 events.push_back(param);
317 manager->OnAccessibilityEvents(events); 317 manager->OnAccessibilityEvents(events);
318 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances()); 318 ASSERT_EQ(1, CountedBrowserAccessibility::num_instances());
319 319
320 // Delete the manager and test that all BrowserAccessibility instances are 320 // Delete the manager and test that all BrowserAccessibility instances are
321 // deleted. 321 // deleted.
322 manager.reset(); 322 manager.reset();
323 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); 323 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
324 } 324 }
325 325
326 TEST_F(BrowserAccessibilityTest, DISABLED_TestTextBoundaries) { 326 TEST_F(BrowserAccessibilityTest, TestTextBoundaries) {
327 std::string text1_value = "One two three.\nFour five six."; 327 std::string line1 = "One two three.";
328 328 std::string line2 = "Four five six.";
329 ui::AXNodeData text1; 329 std::string text_value = line1 + '\n' + line2;
330 text1.id = 11;
331 text1.role = ui::AX_ROLE_TEXT_FIELD;
332 text1.state = 0;
333 text1.AddStringAttribute(ui::AX_ATTR_VALUE, text1_value);
334 std::vector<int32> line_breaks;
335 line_breaks.push_back(15);
336 text1.AddIntListAttribute(
337 ui::AX_ATTR_LINE_BREAKS, line_breaks);
338 330
339 ui::AXNodeData root; 331 ui::AXNodeData root;
340 root.id = 1; 332 root.id = 1;
341 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 333 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
342 root.state = 0; 334 root.child_ids.push_back(2);
343 root.child_ids.push_back(11); 335
336 ui::AXNodeData text_field;
337 text_field.id = 2;
338 text_field.role = ui::AX_ROLE_TEXT_FIELD;
339 text_field.AddStringAttribute(ui::AX_ATTR_VALUE, text_value);
340 std::vector<int32> line_start_offsets;
341 line_start_offsets.push_back(15);
342 text_field.AddIntListAttribute(
343 ui::AX_ATTR_LINE_BREAKS, line_start_offsets);
344 text_field.child_ids.push_back(3);
345 text_field.child_ids.push_back(5);
346 text_field.child_ids.push_back(6);
347
348 ui::AXNodeData static_text1;
349 static_text1.id = 3;
350 static_text1.role = ui::AX_ROLE_STATIC_TEXT;
351 static_text1.AddStringAttribute(ui::AX_ATTR_VALUE, line1);
352 static_text1.child_ids.push_back(4);
353
354 ui::AXNodeData inline_box1;
355 inline_box1.id = 4;
356 inline_box1.role = ui::AX_ROLE_INLINE_TEXT_BOX;
357 inline_box1.AddStringAttribute(ui::AX_ATTR_VALUE, line1);
358 std::vector<int32> word_start_offsets1;
359 word_start_offsets1.push_back(0);
360 word_start_offsets1.push_back(4);
361 word_start_offsets1.push_back(8);
362 inline_box1.AddIntListAttribute(
363 ui::AX_ATTR_WORD_STARTS, word_start_offsets1);
364
365 ui::AXNodeData line_break;
366 line_break.id = 5;
367 line_break.role = ui::AX_ROLE_LINE_BREAK;
368 line_break.AddStringAttribute(ui::AX_ATTR_VALUE, "\n");
369
370 ui::AXNodeData static_text2;
371 static_text2.id = 6;
372 static_text2.role = ui::AX_ROLE_STATIC_TEXT;
373 static_text2.AddStringAttribute(ui::AX_ATTR_VALUE, line2);
374 static_text2.child_ids.push_back(7);
375
376 ui::AXNodeData inline_box2;
377 inline_box2.id = 7;
378 inline_box2.role = ui::AX_ROLE_INLINE_TEXT_BOX;
379 inline_box2.AddStringAttribute(ui::AX_ATTR_VALUE, line2);
380 std::vector<int32> word_start_offsets2;
381 word_start_offsets2.push_back(0);
382 word_start_offsets2.push_back(5);
383 word_start_offsets2.push_back(10);
384 inline_box2.AddIntListAttribute(
385 ui::AX_ATTR_WORD_STARTS, word_start_offsets2);
344 386
345 CountedBrowserAccessibility::reset(); 387 CountedBrowserAccessibility::reset();
346 scoped_ptr<BrowserAccessibilityManager> manager( 388 scoped_ptr<BrowserAccessibilityManager> manager(
347 BrowserAccessibilityManager::Create( 389 BrowserAccessibilityManager::Create(
348 MakeAXTreeUpdate(root, text1), 390 MakeAXTreeUpdate(root, text_field, static_text1, inline_box1,
349 NULL, new CountedBrowserAccessibilityFactory())); 391 line_break, static_text2, inline_box2),
350 ASSERT_EQ(2, CountedBrowserAccessibility::num_instances()); 392 nullptr, new CountedBrowserAccessibilityFactory()));
393 ASSERT_EQ(7, CountedBrowserAccessibility::num_instances());
351 394
352 BrowserAccessibilityWin* root_obj = 395 BrowserAccessibilityWin* root_obj =
353 manager->GetRoot()->ToBrowserAccessibilityWin(); 396 manager->GetRoot()->ToBrowserAccessibilityWin();
354 BrowserAccessibilityWin* text1_obj = 397 ASSERT_NE(nullptr, root_obj);
398 ASSERT_EQ(1, root_obj->PlatformChildCount());
399
400 BrowserAccessibilityWin* text_field_obj =
355 root_obj->PlatformGetChild(0)->ToBrowserAccessibilityWin(); 401 root_obj->PlatformGetChild(0)->ToBrowserAccessibilityWin();
402 ASSERT_NE(nullptr, text_field_obj);
356 403
357 long text1_len; 404 long text_len;
358 ASSERT_EQ(S_OK, text1_obj->get_nCharacters(&text1_len)); 405 EXPECT_EQ(S_OK, text_field_obj->get_nCharacters(&text_len));
359 406
360 base::win::ScopedBstr text; 407 base::win::ScopedBstr text;
361 ASSERT_EQ(S_OK, text1_obj->get_text(0, text1_len, text.Receive())); 408 EXPECT_EQ(S_OK, text_field_obj->get_text(0, text_len, text.Receive()));
362 ASSERT_EQ(text1_value, base::UTF16ToUTF8(base::string16(text))); 409 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text)));
363 text.Reset(); 410 text.Reset();
364 411
365 ASSERT_EQ(S_OK, text1_obj->get_text(0, 4, text.Receive())); 412 EXPECT_EQ(S_OK, text_field_obj->get_text(0, 4, text.Receive()));
366 ASSERT_STREQ(L"One ", text); 413 EXPECT_STREQ(L"One ", text);
367 text.Reset(); 414 text.Reset();
368 415
369 long start; 416 long start;
370 long end; 417 long end;
371 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( 418 EXPECT_EQ(S_OK, text_field_obj->get_textAtOffset(
372 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); 419 1, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive()));
373 ASSERT_EQ(1, start); 420 EXPECT_EQ(1, start);
374 ASSERT_EQ(2, end); 421 EXPECT_EQ(2, end);
375 ASSERT_STREQ(L"n", text); 422 EXPECT_STREQ(L"n", text);
376 text.Reset(); 423 text.Reset();
377 424
378 ASSERT_EQ(S_FALSE, text1_obj->get_textAtOffset( 425 EXPECT_EQ(S_FALSE, text_field_obj->get_textAtOffset(
379 text1_len, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive())); 426 text_len, IA2_TEXT_BOUNDARY_CHAR, &start, &end, text.Receive()));
380 ASSERT_EQ(0, start); 427 EXPECT_EQ(0, start);
381 ASSERT_EQ(0, end); 428 EXPECT_EQ(0, end);
429 EXPECT_EQ(nullptr, text);
382 text.Reset(); 430 text.Reset();
383 431
384 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( 432 EXPECT_EQ(S_FALSE, text_field_obj->get_textAtOffset(
385 1, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); 433 text_len, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive()));
386 ASSERT_EQ(0, start); 434 EXPECT_EQ(0, start);
387 ASSERT_EQ(4, end); 435 EXPECT_EQ(0, end);
388 ASSERT_STREQ(L"One ", text); 436 EXPECT_EQ(nullptr, text);
389 text.Reset(); 437 text.Reset();
390 438
391 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( 439 EXPECT_EQ(S_OK, text_field_obj->get_textAtOffset(
392 6, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); 440 1, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive()));
393 ASSERT_EQ(4, start); 441 EXPECT_EQ(0, start);
394 ASSERT_EQ(8, end); 442 EXPECT_EQ(4, end);
395 ASSERT_STREQ(L"two\n", text); 443 EXPECT_STREQ(L"One ", text);
396 text.Reset(); 444 text.Reset();
397 445
398 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( 446 EXPECT_EQ(S_OK, text_field_obj->get_textAtOffset(
399 text1_len, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive())); 447 6, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive()));
400 ASSERT_EQ(25, start); 448 EXPECT_EQ(4, start);
401 ASSERT_EQ(29, end); 449 EXPECT_EQ(8, end);
402 ASSERT_STREQ(L"six.", text); 450 EXPECT_STREQ(L"two ", text);
403 text.Reset(); 451 text.Reset();
404 452
405 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( 453 EXPECT_EQ(S_OK, text_field_obj->get_textAtOffset(
406 1, IA2_TEXT_BOUNDARY_LINE, &start, &end, text.Receive())); 454 text_len - 1, IA2_TEXT_BOUNDARY_WORD, &start, &end, text.Receive()));
407 ASSERT_EQ(0, start); 455 EXPECT_EQ(25, start);
408 ASSERT_EQ(15, end); 456 EXPECT_EQ(29, end);
409 ASSERT_STREQ(L"One two three.\n", text); 457 EXPECT_STREQ(L"six.", text);
410 text.Reset(); 458 text.Reset();
411 459
412 ASSERT_EQ(S_OK, text1_obj->get_textAtOffset( 460 EXPECT_EQ(S_OK, text_field_obj->get_textAtOffset(
413 text1_len, IA2_TEXT_BOUNDARY_LINE, &start, &end, text.Receive())); 461 1, IA2_TEXT_BOUNDARY_LINE, &start, &end, text.Receive()));
414 ASSERT_EQ(15, start); 462 EXPECT_EQ(0, start);
415 ASSERT_EQ(text1_len, end); 463 EXPECT_EQ(15, end);
416 ASSERT_STREQ(L"Four five six.", text); 464 EXPECT_STREQ(L"One two three.\n", text);
417 text.Reset(); 465 text.Reset();
418 466
419 ASSERT_EQ(S_OK, 467 EXPECT_EQ(S_OK, text_field_obj->get_textAtOffset(
420 text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, text.Receive())); 468 text_len, IA2_TEXT_BOUNDARY_LINE, &start, &end, text.Receive()));
421 ASSERT_EQ(0, start); 469 EXPECT_EQ(15, start);
422 ASSERT_EQ(text1_len, end); 470 EXPECT_EQ(text_len, end);
423 ASSERT_STREQ(L"One two three.\nFour five six.", text); 471 EXPECT_STREQ(L"Four five six.", text);
472 text.Reset();
473
474 EXPECT_EQ(S_OK, text_field_obj->get_text(
475 0, IA2_TEXT_OFFSET_LENGTH, text.Receive()));
476 EXPECT_EQ(text_value, base::UTF16ToUTF8(base::string16(text)));
424 477
425 // Delete the manager and test that all BrowserAccessibility instances are 478 // Delete the manager and test that all BrowserAccessibility instances are
426 // deleted. 479 // deleted.
427 manager.reset(); 480 manager.reset();
428 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); 481 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
429 } 482 }
430 483
431 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { 484 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) {
432 const std::string text1_name = "One two three."; 485 const std::string text1_name = "One two three.";
433 const std::string text2_name = " Four five six."; 486 const std::string text2_name = " Four five six.";
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 0L /* selection_index */, &selection_start, &selection_end);; 911 0L /* selection_index */, &selection_start, &selection_end);;
859 EXPECT_EQ(S_OK, hr); 912 EXPECT_EQ(S_OK, hr);
860 EXPECT_EQ(1L, selection_start); 913 EXPECT_EQ(1L, selection_start);
861 EXPECT_EQ(2L, selection_end); 914 EXPECT_EQ(2L, selection_end);
862 915
863 manager.reset(); 916 manager.reset();
864 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); 917 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
865 } 918 }
866 919
867 } // namespace content 920 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility.cc ('k') | ui/accessibility/ax_text_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698