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

Side by Side Diff: content/browser/accessibility/accessibility_tree_formatter.h

Issue 790943002: Add DumpAccessibilityEvents test framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dump_acc_events_1
Patch Set: Created 6 years 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
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 #ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ 5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_
6 #define CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ 6 #define CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "content/browser/accessibility/browser_accessibility.h" 14 #include "content/browser/accessibility/browser_accessibility.h"
15 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 class WebContents; 19 class WebContents;
20 20
21 // A utility class for formatting platform-specific accessibility information, 21 // A utility class for formatting platform-specific accessibility information,
22 // for use in testing, debugging, and developer tools. 22 // for use in testing, debugging, and developer tools.
23 // This is extended by a subclass for each platform where accessibility is 23 // This is extended by a subclass for each platform where accessibility is
24 // implemented. 24 // implemented.
25 class CONTENT_EXPORT AccessibilityTreeFormatter { 25 class CONTENT_EXPORT AccessibilityTreeFormatter {
26 public: 26 public:
27 explicit AccessibilityTreeFormatter(BrowserAccessibility* root); 27 explicit AccessibilityTreeFormatter(BrowserAccessibility* root);
28 virtual ~AccessibilityTreeFormatter(); 28 virtual ~AccessibilityTreeFormatter();
29 29
30 // A single filter specification. See GetAllowString() and GetDenyString()
31 // for more information.
32 struct Filter {
33 enum Type {
34 ALLOW,
35 ALLOW_EMPTY,
36 DENY
37 };
38 base::string16 match_str;
39 Type type;
40
41 Filter(base::string16 match_str, Type type)
42 : match_str(match_str), type(type) {}
43 };
44
30 static AccessibilityTreeFormatter* Create(WebContents* wc); 45 static AccessibilityTreeFormatter* Create(WebContents* wc);
31 46
47 static bool MatchesFilters(
48 const std::vector<Filter>& filters,
49 const base::string16& text,
50 bool default_result);
51
32 // Populates the given DictionaryValue with the accessibility tree. 52 // Populates the given DictionaryValue with the accessibility tree.
33 // The dictionary contains a key/value pair for each attribute of the node, 53 // The dictionary contains a key/value pair for each attribute of the node,
34 // plus a "children" attribute containing a list of all child nodes. 54 // plus a "children" attribute containing a list of all child nodes.
35 // { 55 // {
36 // "AXName": "node", /* actual attributes will vary by platform */ 56 // "AXName": "node", /* actual attributes will vary by platform */
37 // "position": { /* some attributes may be dictionaries */ 57 // "position": { /* some attributes may be dictionaries */
38 // "x": 0, 58 // "x": 0,
39 // "y": 0 59 // "y": 0
40 // }, 60 // },
41 // /* ... more attributes of |node| */ 61 // /* ... more attributes of |node| */
42 // "children": [ { /* list of children created recursively */ 62 // "children": [ { /* list of children created recursively */
43 // "AXName": "child node 1", 63 // "AXName": "child node 1",
44 // /* ... more attributes */ 64 // /* ... more attributes */
45 // "children": [ ] 65 // "children": [ ]
46 // }, { 66 // }, {
47 // "AXName": "child name 2", 67 // "AXName": "child name 2",
48 // /* ... more attributes */ 68 // /* ... more attributes */
49 // "children": [ ] 69 // "children": [ ]
50 // } ] 70 // } ]
51 // } 71 // }
52 scoped_ptr<base::DictionaryValue> BuildAccessibilityTree(); 72 scoped_ptr<base::DictionaryValue> BuildAccessibilityTree();
53 73
54 // Dumps a BrowserAccessibility tree into a string. 74 // Dumps a BrowserAccessibility tree into a string.
55 void FormatAccessibilityTree(base::string16* contents); 75 void FormatAccessibilityTree(base::string16* contents);
56 76
57 // A single filter specification. See GetAllowString() and GetDenyString()
58 // for more information.
59 struct Filter {
60 enum Type {
61 ALLOW,
62 ALLOW_EMPTY,
63 DENY
64 };
65 base::string16 match_str;
66 Type type;
67
68 Filter(base::string16 match_str, Type type)
69 : match_str(match_str), type(type) {}
70 };
71
72 // Set regular expression filters that apply to each component of every 77 // Set regular expression filters that apply to each component of every
73 // line before it's output. 78 // line before it's output.
74 void SetFilters(const std::vector<Filter>& filters); 79 void SetFilters(const std::vector<Filter>& filters);
75 80
81 void set_show_ids(bool show_ids) { show_ids_ = show_ids; }
David Tseng 2014/12/16 16:53:05 nit: document
dmazzoni 2014/12/16 23:26:32 Done.
82
76 // Suffix of the expectation file corresponding to html file. 83 // Suffix of the expectation file corresponding to html file.
77 // Example: 84 // Example:
78 // HTML test: test-file.html 85 // HTML test: test-file.html
79 // Expected: test-file-expected-mac.txt. 86 // Expected: test-file-expected-mac.txt.
80 // Auto-generated: test-file-actual-mac.txt 87 // Auto-generated: test-file-actual-mac.txt
81 static const base::FilePath::StringType GetActualFileSuffix(); 88 static const base::FilePath::StringType GetActualFileSuffix();
82 static const base::FilePath::StringType GetExpectedFileSuffix(); 89 static const base::FilePath::StringType GetExpectedFileSuffix();
83 90
84 // A platform-specific string that indicates a given line in a file 91 // A platform-specific string that indicates a given line in a file
85 // is an allow-empty, allow or deny filter. Example: 92 // is an allow-empty, allow or deny filter. Example:
(...skipping 26 matching lines...) Expand all
112 // into the given dict. 119 // into the given dict.
113 void AddProperties(const BrowserAccessibility& node, 120 void AddProperties(const BrowserAccessibility& node,
114 base::DictionaryValue* dict); 121 base::DictionaryValue* dict);
115 122
116 base::string16 FormatCoordinates(const char* name, 123 base::string16 FormatCoordinates(const char* name,
117 const char* x_name, 124 const char* x_name,
118 const char* y_name, 125 const char* y_name,
119 const base::DictionaryValue& value); 126 const base::DictionaryValue& value);
120 127
121 // Returns a platform specific representation of a BrowserAccessibility. 128 // Returns a platform specific representation of a BrowserAccessibility.
122 // Should be zero or more complete lines, each with |prefix| prepended 129 base::string16 ToString(const base::DictionaryValue& node);
123 // (to indent each line).
124 base::string16 ToString(const base::DictionaryValue& node,
125 const base::string16& indent);
126 130
127 void Initialize(); 131 void Initialize();
128 132
129 bool MatchesFilters(const base::string16& text, bool default_result) const; 133 bool MatchesFilters(const base::string16& text, bool default_result) const;
130 134
131 // Writes the given attribute string out to |line| if it matches the filters. 135 // Writes the given attribute string out to |line| if it matches the filters.
132 void WriteAttribute(bool include_by_default, 136 void WriteAttribute(bool include_by_default,
133 const base::string16& attr, 137 const base::string16& attr,
134 base::string16* line); 138 base::string16* line);
135 void WriteAttribute(bool include_by_default, 139 void WriteAttribute(bool include_by_default,
136 const std::string& attr, 140 const std::string& attr,
137 base::string16* line); 141 base::string16* line);
138 142
139 BrowserAccessibility* root_; 143 BrowserAccessibility* root_;
140 144
141 // Filters used when formatting the accessibility tree as text. 145 // Filters used when formatting the accessibility tree as text.
142 std::vector<Filter> filters_; 146 std::vector<Filter> filters_;
143 147
148 // Whether or not node ids should be included in the dump.
149 bool show_ids_;
150
144 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); 151 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter);
145 }; 152 };
146 153
147 } // namespace content 154 } // namespace content
148 155
149 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ 156 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698