Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 using webkit_glue::WebAccessibility; | 28 using webkit_glue::WebAccessibility; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 class RendererAccessibilityBrowserTest : public InProcessBrowserTest { | 32 class RendererAccessibilityBrowserTest : public InProcessBrowserTest { |
| 33 public: | 33 public: |
| 34 RendererAccessibilityBrowserTest() {} | 34 RendererAccessibilityBrowserTest() {} |
| 35 | 35 |
| 36 // Tell the renderer to send an accessibility tree, then wait for the | 36 // Tell the renderer to send an accessibility tree, then wait for the |
| 37 // notification that it's been received. | 37 // notification that it's been received. |
| 38 const WebAccessibility& GetWebAccessibilityTree() { | 38 const WebAccessibility& GetWebAccessibilityTree( |
| 39 AccessibilityMode accessibility_mode = AccessibilityModeComplete) { | |
| 39 ui_test_utils::WindowedNotificationObserver tree_updated_observer( | 40 ui_test_utils::WindowedNotificationObserver tree_updated_observer( |
| 40 content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, | 41 content::NOTIFICATION_RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, |
| 41 content::NotificationService::AllSources()); | 42 content::NotificationService::AllSources()); |
| 42 content::RenderWidgetHostView* host_view = | 43 content::RenderWidgetHostView* host_view = |
| 43 browser()->GetSelectedWebContents()->GetRenderWidgetHostView(); | 44 browser()->GetSelectedWebContents()->GetRenderWidgetHostView(); |
| 44 RenderWidgetHostImpl* host = | 45 RenderWidgetHostImpl* host = |
| 45 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); | 46 RenderWidgetHostImpl::From(host_view->GetRenderWidgetHost()); |
| 46 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(host); | 47 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>(host); |
| 47 view_host->set_save_accessibility_tree_for_testing(true); | 48 view_host->set_save_accessibility_tree_for_testing(true); |
| 48 view_host->EnableRendererAccessibility(); | 49 view_host->SetAccessibilityMode(accessibility_mode); |
| 49 tree_updated_observer.Wait(); | 50 tree_updated_observer.Wait(); |
| 50 return view_host->accessibility_tree_for_testing(); | 51 return view_host->accessibility_tree_for_testing(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Make sure each node in the tree has an unique id. | 54 // Make sure each node in the tree has an unique id. |
| 54 void RecursiveAssertUniqueIds( | 55 void RecursiveAssertUniqueIds( |
| 55 const WebAccessibility& node, base::hash_set<int>* ids) { | 56 const WebAccessibility& node, base::hash_set<int>* ids) { |
| 56 ASSERT_TRUE(ids->find(node.id) == ids->end()); | 57 ASSERT_TRUE(ids->find(node.id) == ids->end()); |
| 57 ids->insert(node.id); | 58 ids->insert(node.id); |
| 58 for (size_t i = 0; i < node.children.size(); i++) | 59 for (size_t i = 0; i < node.children.size(); i++) |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 457 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
| 457 const WebAccessibility& tree = GetWebAccessibilityTree(); | 458 const WebAccessibility& tree = GetWebAccessibilityTree(); |
| 458 | 459 |
| 459 ASSERT_EQ(1U, tree.children.size()); | 460 ASSERT_EQ(1U, tree.children.size()); |
| 460 const WebAccessibility& textbox = tree.children[0]; | 461 const WebAccessibility& textbox = tree.children[0]; |
| 461 | 462 |
| 462 EXPECT_EQ( | 463 EXPECT_EQ( |
| 463 true, GetBoolAttr(textbox, WebAccessibility::ATTR_CAN_SET_VALUE)); | 464 true, GetBoolAttr(textbox, WebAccessibility::ATTR_CAN_SET_VALUE)); |
| 464 } | 465 } |
| 465 | 466 |
| 467 IN_PROC_BROWSER_TEST_F(RendererAccessibilityBrowserTest, | |
| 468 CrossPlatformEditableTextOnlyMode) { | |
| 469 const char url_str[] = | |
| 470 "data:text/html," | |
| 471 "<!doctype html>" | |
| 472 "<h1>Heading</h1>" | |
| 473 "<input type=text value=text0>" | |
| 474 "<textarea>text1</textarea>" | |
| 475 "<div role=textbox>text2</div>" | |
| 476 "<ul>" | |
| 477 " <li><input type=text value=text3>" | |
| 478 " <li><textarea>text4</textarea>" | |
| 479 " <li><div role=textbox>text5</div>" | |
|
David Tseng
2012/04/05 01:01:25
Maybe mix in a non-text input leaf node here?
dmazzoni
2012/04/06 21:47:22
Done.
| |
| 480 "</ul>"; | |
| 481 | |
| 482 GURL url(url_str); | |
| 483 browser()->OpenURL(OpenURLParams( | |
| 484 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | |
| 485 const WebAccessibility& tree = GetWebAccessibilityTree( | |
| 486 AccessibilityModeEditableTextOnly); | |
| 487 | |
| 488 const WebAccessibility& text0 = tree.children[0]; | |
| 489 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text0.role); | |
| 490 EXPECT_STREQ("text0", UTF16ToUTF8(text0.value).c_str()); | |
| 491 | |
| 492 const WebAccessibility& text1 = tree.children[1]; | |
| 493 EXPECT_EQ(WebAccessibility::ROLE_TEXTAREA, text1.role); | |
| 494 EXPECT_STREQ("text1", UTF16ToUTF8(text1.value).c_str()); | |
| 495 | |
| 496 const WebAccessibility& text2 = tree.children[2]; | |
| 497 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text2.role); | |
| 498 EXPECT_STREQ("text2", UTF16ToUTF8(text2.value).c_str()); | |
| 499 | |
| 500 const WebAccessibility& text3 = tree.children[3]; | |
| 501 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text3.role); | |
| 502 EXPECT_STREQ("text3", UTF16ToUTF8(text3.value).c_str()); | |
| 503 | |
| 504 const WebAccessibility& text4 = tree.children[4]; | |
| 505 EXPECT_EQ(WebAccessibility::ROLE_TEXTAREA, text4.role); | |
| 506 EXPECT_STREQ("text4", UTF16ToUTF8(text4.value).c_str()); | |
| 507 | |
| 508 const WebAccessibility& text5 = tree.children[5]; | |
| 509 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text5.role); | |
| 510 EXPECT_STREQ("text5", UTF16ToUTF8(text5.value).c_str()); | |
| 511 } | |
| 512 | |
| 466 } // namespace | 513 } // namespace |
| OLD | NEW |