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 "content/browser/accessibility/dump_accessibility_tree_helper.h" | 5 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" |
6 | 6 |
7 #include <oleacc.h> | 7 #include <oleacc.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "content/browser/accessibility/browser_accessibility_win.h" | 14 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 15 #include "content/common/accessibility_node_data.h" |
15 #include "content/public/test/accessibility_test_utils_win.h" | 16 #include "content/public/test/accessibility_test_utils_win.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/iaccessible2/ia2_api_all.h" | 18 #include "third_party/iaccessible2/ia2_api_all.h" |
| 19 #include "ui/base/win/atl_module.h" |
18 | 20 |
19 | 21 |
| 22 void DumpAccessibilityTreeHelper::Initialize() { |
| 23 ui::win::CreateATLModuleIfNeeded(); |
| 24 } |
| 25 |
20 string16 DumpAccessibilityTreeHelper::ToString( | 26 string16 DumpAccessibilityTreeHelper::ToString( |
21 BrowserAccessibility* node, char* prefix) { | 27 BrowserAccessibility* node, char* prefix) { |
22 BrowserAccessibilityWin* acc_obj = node->ToBrowserAccessibilityWin(); | 28 BrowserAccessibilityWin* acc_obj = node->ToBrowserAccessibilityWin(); |
23 | 29 |
24 // Get state string. | 30 // Get the computed name. |
25 VARIANT variant_self; | 31 VARIANT variant_self; |
26 variant_self.vt = VT_I4; | 32 variant_self.vt = VT_I4; |
27 variant_self.lVal = CHILDID_SELF; | 33 variant_self.lVal = CHILDID_SELF; |
28 VARIANT msaa_state_variant; | 34 CComBSTR msaa_name_variant; |
29 HRESULT hresult = acc_obj->get_accState(variant_self, &msaa_state_variant); | 35 HRESULT hresult = acc_obj->get_accName(variant_self, &msaa_name_variant); |
30 EXPECT_EQ(S_OK, hresult); | 36 string16 name; |
31 EXPECT_EQ(VT_I4, msaa_state_variant.vt); | 37 if (S_OK == hresult) |
32 string16 state_str = IAccessibleStateToString(msaa_state_variant.lVal); | 38 name = msaa_name_variant.m_str; |
33 string16 state2_str = IAccessible2StateToString(acc_obj->ia2_state()); | 39 |
34 if (!state2_str.empty()) { | 40 // Get state strings. |
35 if (!state_str.empty()) | 41 std::vector<string16> state_strings; |
36 state_str += L","; | 42 IAccessibleStateToStringVector(acc_obj->ia_state(), &state_strings); |
37 state_str += state2_str; | 43 IAccessible2StateToStringVector(acc_obj->ia2_state(), &state_strings); |
| 44 |
| 45 // Get the description and attributes. |
| 46 string16 description; |
| 47 acc_obj->GetStringAttribute(content::AccessibilityNodeData::ATTR_DESCRIPTION, |
| 48 &description); |
| 49 const std::vector<string16>& ia2_attributes = acc_obj->ia2_attributes(); |
| 50 |
| 51 // Build the line. |
| 52 StartLine(); |
| 53 Add(true, IAccessible2RoleToString(acc_obj->ia2_role())); |
| 54 Add(true, L"name='" + name + L"'"); |
| 55 for (std::vector<string16>::const_iterator it = state_strings.begin(); |
| 56 it != state_strings.end(); |
| 57 ++it) { |
| 58 Add(false, *it); |
38 } | 59 } |
39 | 60 for (std::vector<string16>::const_iterator it = ia2_attributes.begin(); |
40 // Get role string. | 61 it != ia2_attributes.end(); |
41 string16 role_str = IAccessible2RoleToString(acc_obj->ia2_role()); | 62 ++it) { |
42 | 63 Add(false, *it); |
43 return UTF8ToUTF16(prefix) + | 64 } |
44 role_str + | 65 Add(false, L"role_name='" + acc_obj->role_name() + L"'"); |
45 L" name='" + acc_obj->name() + | 66 Add(false, L"value='" + acc_obj->value() + L"'"); |
46 L"' state=" + state_str + L"\n"; | 67 Add(false, L"description='" + description + L"'"); |
| 68 return UTF8ToUTF16(prefix) + FinishLine() + ASCIIToUTF16("\n"); |
47 } | 69 } |
48 | 70 |
49 const FilePath::StringType DumpAccessibilityTreeHelper::GetActualFileSuffix() | 71 const FilePath::StringType DumpAccessibilityTreeHelper::GetActualFileSuffix() |
50 const { | 72 const { |
51 return FILE_PATH_LITERAL("-actual-win.txt"); | 73 return FILE_PATH_LITERAL("-actual-win.txt"); |
52 } | 74 } |
53 | 75 |
54 const FilePath::StringType DumpAccessibilityTreeHelper::GetExpectedFileSuffix() | 76 const FilePath::StringType DumpAccessibilityTreeHelper::GetExpectedFileSuffix() |
55 const { | 77 const { |
56 return FILE_PATH_LITERAL("-expected-win.txt"); | 78 return FILE_PATH_LITERAL("-expected-win.txt"); |
57 } | 79 } |
| 80 |
| 81 |
| 82 const std::string DumpAccessibilityTreeHelper::GetAllowString() const { |
| 83 return "@WIN-ALLOW:"; |
| 84 } |
| 85 |
| 86 const std::string DumpAccessibilityTreeHelper::GetDenyString() const { |
| 87 return "@WIN-DENY:"; |
| 88 } |
OLD | NEW |