OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <string> | |
6 #include <vector> | |
7 | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/browser.h" | |
10 #include "chrome/browser/browser_window.h" | |
11 #include "chrome/browser/renderer_host/render_view_host.h" | |
12 #include "chrome/browser/renderer_host/render_widget_host.h" | |
13 #include "chrome/browser/renderer_host/render_widget_host_view.h" | |
14 #include "chrome/browser/tab_contents/tab_contents.h" | |
15 #include "chrome/common/render_messages.h" | |
16 #include "chrome/common/notification_type.h" | |
17 #include "chrome/test/in_process_browser_test.h" | |
18 #include "chrome/test/ui_test_utils.h" | |
19 | |
20 using webkit_glue::WebAccessibility; | |
21 | |
22 namespace { | |
23 | |
24 class RendererAccessibilityBrowserTest : public InProcessBrowserTest { | |
25 public: | |
26 RendererAccessibilityBrowserTest() {} | |
27 | |
28 protected: | |
29 const char *GetAttr(const WebAccessibility& node, | |
30 const WebAccessibility::Attribute attr); | |
31 }; | |
32 | |
33 // Convenience method to get the value of a particular WebAccessibility | |
34 // node attribute as a UTF-8 const char*. | |
35 const char *RendererAccessibilityBrowserTest::GetAttr( | |
36 const WebAccessibility& node, const WebAccessibility::Attribute attr) { | |
37 std::map<int32, string16>::const_iterator iter = node.attributes.find(attr); | |
38 if (iter != node.attributes.end()) | |
39 return UTF16ToUTF8(iter->second).c_str(); | |
40 else | |
41 return ""; | |
42 } | |
43 | |
44 IN_PROC_BROWSER_TEST_F(RendererAccessibilityBrowserTest, | |
45 TestCrossPlatformAccessibilityTree) { | |
46 // Create a data url and load it. | |
47 const char url_str[] = | |
48 "data:text/html," | |
49 "<!doctype html>" | |
50 "<html><head><title>Accessibility Test</title></head>" | |
51 "<body><input type='button' value='push' /><input type='checkbox' />" | |
52 "</body></html>"; | |
53 GURL url(url_str); | |
54 browser()->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); | |
55 | |
56 // Tell the renderer to send an accessibility tree, then wait for the | |
57 // notification that it's been received. | |
58 RenderWidgetHostView* host_view = | |
59 browser()->GetSelectedTabContents()->GetRenderWidgetHostView(); | |
60 RenderWidgetHost* host = host_view->GetRenderWidgetHost(); | |
61 RenderViewHost* view_host = static_cast<RenderViewHost*>(host); | |
62 view_host->set_save_accessibility_tree_for_testing(true); | |
63 host->Send(new ViewMsg_GetAccessibilityTree(host->routing_id())); | |
64 ui_test_utils::WaitForNotification( | |
65 NotificationType::RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED); | |
66 | |
67 // Check properties of the root element of the tree. | |
68 const WebAccessibility& tree = view_host->accessibility_tree(); | |
69 EXPECT_STREQ(url_str, GetAttr(tree, WebAccessibility::ATTR_DOC_URL)); | |
70 EXPECT_STREQ("Accessibility Test", | |
71 GetAttr(tree, WebAccessibility::ATTR_DOC_TITLE)); | |
72 EXPECT_STREQ("html", GetAttr(tree, WebAccessibility::ATTR_DOC_DOCTYPE)); | |
73 EXPECT_STREQ("text/html", GetAttr(tree, WebAccessibility::ATTR_DOC_MIMETYPE)); | |
74 EXPECT_EQ(WebAccessibility::ROLE_WEB_AREA, tree.role); | |
75 | |
76 // Check properites of the BODY element. | |
77 ASSERT_EQ(1U, tree.children.size()); | |
78 const WebAccessibility& body = tree.children[0]; | |
79 EXPECT_EQ(WebAccessibility::ROLE_GROUP, body.role); | |
80 EXPECT_STREQ("BODY", GetAttr(body, WebAccessibility::ATTR_HTML_TAG)); | |
81 EXPECT_STREQ("block", GetAttr(body, WebAccessibility::ATTR_DISPLAY)); | |
82 | |
83 // Check properties of the two children of the BODY element. | |
84 ASSERT_EQ(2U, body.children.size()); | |
85 | |
86 const WebAccessibility& button = body.children[0]; | |
87 EXPECT_EQ(WebAccessibility::ROLE_BUTTON, button.role); | |
88 EXPECT_STREQ("INPUT", GetAttr(button, WebAccessibility::ATTR_HTML_TAG)); | |
89 EXPECT_STREQ("push", UTF16ToUTF8(button.name).c_str()); | |
90 EXPECT_STREQ("inline-block", GetAttr(button, WebAccessibility::ATTR_DISPLAY)); | |
91 ASSERT_EQ(2U, button.html_attributes.size()); | |
92 EXPECT_STREQ("type", UTF16ToUTF8(button.html_attributes[0].first).c_str()); | |
93 EXPECT_STREQ("button", UTF16ToUTF8(button.html_attributes[0].second).c_str()); | |
94 EXPECT_STREQ("value", UTF16ToUTF8(button.html_attributes[1].first).c_str()); | |
95 EXPECT_STREQ("push", UTF16ToUTF8(button.html_attributes[1].second).c_str()); | |
96 | |
97 const WebAccessibility& checkbox = body.children[1]; | |
98 EXPECT_EQ(WebAccessibility::ROLE_CHECKBOX, checkbox.role); | |
99 EXPECT_STREQ("INPUT", GetAttr(checkbox, WebAccessibility::ATTR_HTML_TAG)); | |
100 EXPECT_STREQ("inline-block", | |
101 GetAttr(checkbox, WebAccessibility::ATTR_DISPLAY)); | |
102 ASSERT_EQ(1U, checkbox.html_attributes.size()); | |
103 EXPECT_STREQ("type", | |
104 UTF16ToUTF8(checkbox.html_attributes[0].first).c_str()); | |
105 EXPECT_STREQ("checkbox", | |
106 UTF16ToUTF8(checkbox.html_attributes[0].second).c_str()); | |
107 } | |
108 | |
109 } // namespace | |
OLD | NEW |