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

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

Issue 9939011: Add an accessibility mode for editable text fields only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments and rebased. Created 8 years, 8 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 #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
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
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>"
480 " <li><button>button</button>"
481 "</ul>";
482
483 GURL url(url_str);
484 browser()->OpenURL(OpenURLParams(
485 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false));
486 const WebAccessibility& tree = GetWebAccessibilityTree(
487 AccessibilityModeEditableTextOnly);
488
489 const WebAccessibility& text0 = tree.children[0];
490 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text0.role);
491 EXPECT_STREQ("text0", UTF16ToUTF8(text0.value).c_str());
492
493 const WebAccessibility& text1 = tree.children[1];
494 EXPECT_EQ(WebAccessibility::ROLE_TEXTAREA, text1.role);
495 EXPECT_STREQ("text1", UTF16ToUTF8(text1.value).c_str());
496
497 const WebAccessibility& text2 = tree.children[2];
498 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text2.role);
499 EXPECT_STREQ("text2", UTF16ToUTF8(text2.value).c_str());
500
501 const WebAccessibility& text3 = tree.children[3];
502 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text3.role);
503 EXPECT_STREQ("text3", UTF16ToUTF8(text3.value).c_str());
504
505 const WebAccessibility& text4 = tree.children[4];
506 EXPECT_EQ(WebAccessibility::ROLE_TEXTAREA, text4.role);
507 EXPECT_STREQ("text4", UTF16ToUTF8(text4.value).c_str());
508
509 const WebAccessibility& text5 = tree.children[5];
510 EXPECT_EQ(WebAccessibility::ROLE_TEXT_FIELD, text5.role);
511 EXPECT_STREQ("text5", UTF16ToUTF8(text5.value).c_str());
512 }
513
466 } // namespace 514 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698