OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" | |
6 | |
7 #include <oleacc.h> | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/files/file_path.h" | |
12 #include "base/string_util.h" | |
13 #include "base/stringprintf.h" | |
14 #include "base/utf_string_conversions.h" | |
15 #include "content/browser/accessibility/browser_accessibility_manager.h" | |
16 #include "content/browser/accessibility/browser_accessibility_win.h" | |
17 #include "content/common/accessibility_node_data.h" | |
18 #include "content/public/test/accessibility_test_utils_win.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 #include "third_party/iaccessible2/ia2_api_all.h" | |
21 #include "ui/base/win/atl_module.h" | |
22 | |
23 namespace content { | |
24 | |
25 void DumpAccessibilityTreeHelper::Initialize() { | |
26 ui::win::CreateATLModuleIfNeeded(); | |
27 } | |
28 | |
29 string16 DumpAccessibilityTreeHelper::ToString( | |
30 BrowserAccessibility* node, char* prefix) { | |
31 BrowserAccessibilityWin* acc_obj = node->ToBrowserAccessibilityWin(); | |
32 | |
33 // Get the computed name. | |
34 VARIANT variant_self; | |
35 variant_self.vt = VT_I4; | |
36 variant_self.lVal = CHILDID_SELF; | |
37 CComBSTR msaa_variant; | |
38 HRESULT hresult = acc_obj->get_accName(variant_self, &msaa_variant); | |
39 string16 name; | |
40 if (S_OK == hresult) | |
41 name = msaa_variant.m_str; | |
42 | |
43 hresult = acc_obj->get_accValue(variant_self, &msaa_variant); | |
44 string16 value; | |
45 if (S_OK == hresult) | |
46 value = msaa_variant.m_str; | |
47 | |
48 hresult = acc_obj->get_accDescription(variant_self, &msaa_variant); | |
49 string16 description; | |
50 if (S_OK == hresult) | |
51 description = msaa_variant.m_str; | |
52 | |
53 hresult = acc_obj->get_accHelp(variant_self, &msaa_variant); | |
54 string16 help; | |
55 if (S_OK == hresult) | |
56 help = msaa_variant.m_str; | |
57 | |
58 hresult = acc_obj->get_accDefaultAction(variant_self, &msaa_variant); | |
59 string16 default_action; | |
60 if (S_OK == hresult) | |
61 default_action = msaa_variant.m_str; | |
62 | |
63 hresult = acc_obj->get_accKeyboardShortcut(variant_self, &msaa_variant); | |
64 string16 keyboard_shortcut; | |
65 if (S_OK == hresult) | |
66 keyboard_shortcut = msaa_variant.m_str; | |
67 | |
68 // Get state strings. | |
69 std::vector<string16> state_strings; | |
70 IAccessibleStateToStringVector(acc_obj->ia_state(), &state_strings); | |
71 IAccessible2StateToStringVector(acc_obj->ia2_state(), &state_strings); | |
72 | |
73 // Get the attributes. | |
74 const std::vector<string16>& ia2_attributes = acc_obj->ia2_attributes(); | |
75 | |
76 // Build the line. | |
77 StartLine(); | |
78 Add(true, IAccessible2RoleToString(acc_obj->ia2_role())); | |
79 Add(true, L"name='" + name + L"'"); | |
80 Add(false, L"value='" + value + L"'"); | |
81 for (std::vector<string16>::const_iterator it = state_strings.begin(); | |
82 it != state_strings.end(); | |
83 ++it) { | |
84 Add(false, *it); | |
85 } | |
86 for (std::vector<string16>::const_iterator it = ia2_attributes.begin(); | |
87 it != ia2_attributes.end(); | |
88 ++it) { | |
89 Add(false, *it); | |
90 } | |
91 Add(false, L"role_name='" + acc_obj->role_name() + L"'"); | |
92 VARIANT currentValue; | |
93 if (acc_obj->get_currentValue(¤tValue) == S_OK) | |
94 Add(false, StringPrintf(L"currentValue=%.2f", V_R8(¤tValue))); | |
95 VARIANT minimumValue; | |
96 if (acc_obj->get_minimumValue(&minimumValue) == S_OK) | |
97 Add(false, StringPrintf(L"minimumValue=%.2f", V_R8(&minimumValue))); | |
98 VARIANT maximumValue; | |
99 if (acc_obj->get_maximumValue(&maximumValue) == S_OK) | |
100 Add(false, StringPrintf(L"maximumValue=%.2f", V_R8(&maximumValue))); | |
101 Add(false, L"description='" + description + L"'"); | |
102 Add(false, L"default_action='" + default_action + L"'"); | |
103 Add(false, L"keyboard_shortcut='" + keyboard_shortcut + L"'"); | |
104 BrowserAccessibility* root = node->manager()->GetRoot(); | |
105 LONG left, top, width, height; | |
106 LONG root_left, root_top, root_width, root_height; | |
107 if (S_FALSE != acc_obj->accLocation( | |
108 &left, &top, &width, &height, variant_self) && | |
109 S_FALSE != root->ToBrowserAccessibilityWin()->accLocation( | |
110 &root_left, &root_top, &root_width, &root_height, variant_self)) { | |
111 Add(false, StringPrintf(L"location=(%d, %d)", | |
112 left - root_left, top - root_top)); | |
113 Add(false, StringPrintf(L"size=(%d, %d)", width, height)); | |
114 } | |
115 LONG index_in_parent; | |
116 if (acc_obj->get_indexInParent(&index_in_parent) == S_OK) | |
117 Add(false, StringPrintf(L"index_in_parent=%d", index_in_parent)); | |
118 LONG n_relations; | |
119 if (acc_obj->get_nRelations(&n_relations) == S_OK) | |
120 Add(false, StringPrintf(L"n_relations=%d", n_relations)); | |
121 LONG group_level, similar_items_in_group, position_in_group; | |
122 if (acc_obj->get_groupPosition(&group_level, | |
123 &similar_items_in_group, | |
124 &position_in_group) == S_OK) { | |
125 Add(false, StringPrintf(L"group_level=%d", group_level)); | |
126 Add(false, StringPrintf(L"similar_items_in_group=%d", | |
127 similar_items_in_group)); | |
128 Add(false, StringPrintf(L"position_in_group=%d", position_in_group)); | |
129 } | |
130 LONG table_rows; | |
131 if (acc_obj->get_nRows(&table_rows) == S_OK) | |
132 Add(false, StringPrintf(L"table_rows=%d", table_rows)); | |
133 LONG table_columns; | |
134 if (acc_obj->get_nRows(&table_columns) == S_OK) | |
135 Add(false, StringPrintf(L"table_columns=%d", table_columns)); | |
136 LONG row_index; | |
137 if (acc_obj->get_rowIndex(&row_index) == S_OK) | |
138 Add(false, StringPrintf(L"row_index=%d", row_index)); | |
139 LONG column_index; | |
140 if (acc_obj->get_columnIndex(&column_index) == S_OK) | |
141 Add(false, StringPrintf(L"column_index=%d", column_index)); | |
142 LONG n_characters; | |
143 if (acc_obj->get_nCharacters(&n_characters) == S_OK) | |
144 Add(false, StringPrintf(L"n_characters=%d", n_characters)); | |
145 LONG caret_offset; | |
146 if (acc_obj->get_caretOffset(&caret_offset) == S_OK) | |
147 Add(false, StringPrintf(L"caret_offset=%d", caret_offset)); | |
148 LONG n_selections; | |
149 if (acc_obj->get_nSelections(&n_selections) == S_OK) { | |
150 Add(false, StringPrintf(L"n_selections=%d", n_selections)); | |
151 if (n_selections > 0) { | |
152 LONG start, end; | |
153 if (acc_obj->get_selection(0, &start, &end) == S_OK) { | |
154 Add(false, StringPrintf(L"selection_start=%d", start)); | |
155 Add(false, StringPrintf(L"selection_end=%d", end)); | |
156 } | |
157 } | |
158 } | |
159 | |
160 return UTF8ToUTF16(prefix) + FinishLine() + ASCIIToUTF16("\n"); | |
161 } | |
162 | |
163 const base::FilePath::StringType | |
164 DumpAccessibilityTreeHelper::GetActualFileSuffix() const { | |
165 return FILE_PATH_LITERAL("-actual-win.txt"); | |
166 } | |
167 | |
168 const base::FilePath::StringType | |
169 DumpAccessibilityTreeHelper::GetExpectedFileSuffix() const { | |
170 return FILE_PATH_LITERAL("-expected-win.txt"); | |
171 } | |
172 | |
173 const std::string DumpAccessibilityTreeHelper::GetAllowEmptyString() const { | |
174 return "@WIN-ALLOW-EMPTY:"; | |
175 } | |
176 | |
177 const std::string DumpAccessibilityTreeHelper::GetAllowString() const { | |
178 return "@WIN-ALLOW:"; | |
179 } | |
180 | |
181 const std::string DumpAccessibilityTreeHelper::GetDenyString() const { | |
182 return "@WIN-DENY:"; | |
183 } | |
184 | |
185 } // namespace content | |
OLD | NEW |