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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/win/scoped_comptr.h" | 6 #include "base/win/scoped_comptr.h" |
7 #include "content/browser/accessibility/browser_accessibility_manager.h" | 7 #include "content/browser/accessibility/browser_accessibility_manager.h" |
8 #include "content/browser/accessibility/browser_accessibility_win.h" | 8 #include "content/browser/accessibility/browser_accessibility_win.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 | 361 |
362 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); | 362 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); |
363 ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); | 363 ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); |
364 SysFreeString(text); | 364 SysFreeString(text); |
365 | 365 |
366 // Delete the manager and test that all BrowserAccessibility instances are | 366 // Delete the manager and test that all BrowserAccessibility instances are |
367 // deleted. | 367 // deleted. |
368 delete manager; | 368 delete manager; |
369 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 369 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
370 } | 370 } |
371 | |
372 TEST_F(BrowserAccessibilityTest, TestSimpleHypertext) { | |
373 WebAccessibility text1; | |
374 text1.id = 11; | |
375 text1.role = WebAccessibility::ROLE_STATIC_TEXT; | |
376 text1.state = 0; | |
377 text1.name = L"One two three."; | |
378 | |
379 WebAccessibility text2; | |
380 text2.id = 12; | |
381 text2.role = WebAccessibility::ROLE_STATIC_TEXT; | |
382 text2.state = 0; | |
383 text2.name = L" Four five six."; | |
384 | |
385 WebAccessibility root; | |
386 root.id = 1; | |
387 root.role = WebAccessibility::ROLE_DOCUMENT; | |
388 root.state = 0; | |
389 root.children.push_back(text1); | |
390 root.children.push_back(text2); | |
391 | |
392 CountedBrowserAccessibility::global_obj_count_ = 0; | |
393 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( | |
394 GetDesktopWindow(), root, NULL, | |
395 new CountedBrowserAccessibilityFactory()); | |
396 ASSERT_EQ(3, CountedBrowserAccessibility::global_obj_count_); | |
397 | |
398 BrowserAccessibilityWin* root_obj = | |
399 manager->GetRoot()->toBrowserAccessibilityWin(); | |
400 | |
401 BSTR text; | |
402 | |
403 long text_len; | |
404 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | |
405 | |
406 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); | |
407 EXPECT_EQ(text, text1.name + text2.name); | |
408 SysFreeString(text); | |
409 | |
410 long hyperlink_count; | |
411 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | |
412 EXPECT_EQ(0, hyperlink_count); | |
413 | |
414 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | |
415 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(-1, hyperlink.Receive())); | |
416 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(0, hyperlink.Receive())); | |
417 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(28, hyperlink.Receive())); | |
418 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(-1, hyperlink.Receive())); | |
419 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(29, hyperlink.Receive())); | |
420 | |
421 long hyperlink_index; | |
422 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | |
423 EXPECT_EQ(-1, hyperlink_index); | |
424 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | |
425 EXPECT_EQ(-1, hyperlink_index); | |
426 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(-1, &hyperlink_index)); | |
427 EXPECT_EQ(-1, hyperlink_index); | |
428 EXPECT_EQ(E_INVALIDARG, root_obj->get_hyperlinkIndex(29, &hyperlink_index)); | |
429 EXPECT_EQ(-1, hyperlink_index); | |
430 | |
431 // Delete the manager and test that all BrowserAccessibility instances are | |
432 // deleted. | |
433 delete manager; | |
434 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | |
435 } | |
436 | |
437 TEST_F(BrowserAccessibilityTest, TestComplexHypertext) { | |
438 WebAccessibility text1; | |
439 text1.id = 11; | |
440 text1.role = WebAccessibility::ROLE_STATIC_TEXT; | |
441 text1.state = 0; | |
442 text1.name = L"One two three."; | |
443 | |
444 WebAccessibility text2; | |
445 text2.id = 12; | |
446 text2.role = WebAccessibility::ROLE_STATIC_TEXT; | |
447 text2.state = 0; | |
448 text2.name = L" Four five six."; | |
449 | |
450 WebAccessibility button1, button1_text; | |
451 button1.id = 13; | |
452 button1_text.id = 15; | |
453 button1_text.name = L"red"; | |
454 button1.role = WebAccessibility::ROLE_BUTTON; | |
455 button1_text.role = WebAccessibility::ROLE_STATIC_TEXT; | |
456 button1.state = 0; | |
457 button1.children.push_back(button1_text); | |
458 | |
459 WebAccessibility link1, link1_text; | |
460 link1.id = 14; | |
461 link1_text.id = 16; | |
462 link1_text.name = L"blue"; | |
463 link1.role = WebAccessibility::ROLE_LINK; | |
464 link1_text.role = WebAccessibility::ROLE_STATIC_TEXT; | |
465 link1.state = 0; | |
466 link1.children.push_back(link1_text); | |
467 | |
468 WebAccessibility root; | |
469 root.id = 1; | |
470 root.role = WebAccessibility::ROLE_DOCUMENT; | |
471 root.state = 0; | |
472 root.children.push_back(text1); | |
473 root.children.push_back(button1); | |
474 root.children.push_back(text2); | |
475 root.children.push_back(link1); | |
476 | |
477 CountedBrowserAccessibility::global_obj_count_ = 0; | |
478 BrowserAccessibilityManager* manager = BrowserAccessibilityManager::Create( | |
479 GetDesktopWindow(), root, NULL, | |
480 new CountedBrowserAccessibilityFactory()); | |
481 ASSERT_EQ(7, CountedBrowserAccessibility::global_obj_count_); | |
482 | |
483 BrowserAccessibilityWin* root_obj = | |
484 manager->GetRoot()->toBrowserAccessibilityWin(); | |
485 | |
486 BSTR text; | |
487 | |
488 long text_len; | |
489 ASSERT_EQ(S_OK, root_obj->get_nCharacters(&text_len)); | |
490 | |
491 ASSERT_EQ(S_OK, root_obj->get_text(0, text_len, &text)); | |
492 const string16 embed = BrowserAccessibilityWin::kEmbeddedCharacter; | |
493 EXPECT_EQ(text, text1.name + embed + text2.name + embed); | |
494 SysFreeString(text); | |
495 | |
496 long hyperlink_count; | |
497 ASSERT_EQ(S_OK, root_obj->get_nHyperlinks(&hyperlink_count)); | |
498 EXPECT_EQ(2, hyperlink_count); | |
499 | |
500 base::win::ScopedComPtr<IAccessibleHyperlink> hyperlink; | |
501 base::win::ScopedComPtr<IAccessibleText> hypertext; | |
502 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(-1, hyperlink.Receive())); | |
503 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(0, hyperlink.Receive())); | |
dmazzoni
2011/11/01 05:08:34
I think this should return success - the docs say
David Tseng
2011/11/01 19:38:04
Done.
| |
504 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(28, hyperlink.Receive())); | |
505 EXPECT_EQ(E_FAIL, root_obj->get_hyperlink(-1, hyperlink.Receive())); | |
506 | |
507 EXPECT_EQ(S_OK, root_obj->get_hyperlink(14, hyperlink.Receive())); | |
508 EXPECT_EQ(S_OK, | |
509 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | |
510 EXPECT_EQ(S_OK, hypertext->get_text(0, 3, &text)); | |
511 EXPECT_EQ(text, string16(L"red")); | |
512 SysFreeString(text); | |
513 hyperlink.Release(); | |
514 hypertext.Release(); | |
515 | |
516 EXPECT_EQ(S_OK, root_obj->get_hyperlink(30, hyperlink.Receive())); | |
517 EXPECT_EQ(S_OK, | |
518 hyperlink.QueryInterface<IAccessibleText>(hypertext.Receive())); | |
519 EXPECT_EQ(S_OK, hypertext->get_text(0, 4, &text)); | |
520 EXPECT_EQ(text, string16(L"blue")); | |
521 SysFreeString(text); | |
522 hyperlink.Release(); | |
523 hypertext.Release(); | |
524 | |
525 long hyperlink_index; | |
526 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(0, &hyperlink_index)); | |
527 EXPECT_EQ(-1, hyperlink_index); | |
528 EXPECT_EQ(E_FAIL, root_obj->get_hyperlinkIndex(28, &hyperlink_index)); | |
529 EXPECT_EQ(-1, hyperlink_index); | |
530 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(14, &hyperlink_index)); | |
531 EXPECT_EQ(14, hyperlink_index); | |
532 EXPECT_EQ(S_OK, root_obj->get_hyperlinkIndex(30, &hyperlink_index)); | |
533 EXPECT_EQ(30, hyperlink_index); | |
534 | |
535 // Delete the manager and test that all BrowserAccessibility instances are | |
536 // deleted. | |
537 delete manager; | |
538 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | |
539 } | |
OLD | NEW |