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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 // Actual file has been fully checked. | 87 // Actual file has been fully checked. |
88 return diff_lines; | 88 return diff_lines; |
89 } | 89 } |
90 | 90 |
91 void AddDefaultFilters(std::vector<Filter>* filters) { | 91 void AddDefaultFilters(std::vector<Filter>* filters) { |
92 filters->push_back(Filter(base::ASCIIToUTF16("FOCUSABLE"), Filter::ALLOW)); | 92 filters->push_back(Filter(base::ASCIIToUTF16("FOCUSABLE"), Filter::ALLOW)); |
93 filters->push_back(Filter(base::ASCIIToUTF16("READONLY"), Filter::ALLOW)); | 93 filters->push_back(Filter(base::ASCIIToUTF16("READONLY"), Filter::ALLOW)); |
94 filters->push_back(Filter(base::ASCIIToUTF16("*=''"), Filter::DENY)); | 94 filters->push_back(Filter(base::ASCIIToUTF16("*=''"), Filter::DENY)); |
95 } | 95 } |
96 | 96 |
97 void ParseFilters(const std::string& test_html, | 97 // Parse the test html file and parse special directives, usually |
98 std::vector<Filter>* filters) { | 98 // beginning with an '@' and inside an HTML comment, that control how the |
99 // test is run and how the results are interpreted. | |
100 // | |
101 // When the accessibility tree is dumped as text, each attribute is | |
102 // run through filters before being appended to the string. An "allow" | |
103 // filter specifies attribute strings that should be dumped, and a "deny" | |
104 // filter specifies strings that should be suppressed. As an example, | |
105 // @MAC-ALLOW:AXSubrole=* means that the AXSubrole attribute should be | |
106 // printed, while @MAC-ALLOW:AXSubrole=AXList* means that any subrole | |
107 // beginning with the text "AXList" should be printed. | |
108 // | |
109 // The @WAIT-FOR:text directive allows the test to specify that the document | |
110 // may dynamically change after initial load, and the test is to wait | |
111 // until the given string (e.g., "text") appears in the resulting dump. | |
112 // A test can make some changes to the document, then append a magic string | |
113 // indicating that the test is done, and this framework will wait for that | |
114 // string to appear before comparing the results. | |
115 void ParseHtmlForExtraDirectives(const std::string& test_html, | |
116 std::vector<Filter>* filters, | |
117 std::string* wait_for) { | |
99 std::vector<std::string> lines; | 118 std::vector<std::string> lines; |
100 base::SplitString(test_html, '\n', &lines); | 119 base::SplitString(test_html, '\n', &lines); |
101 for (std::vector<std::string>::const_iterator iter = lines.begin(); | 120 for (std::vector<std::string>::const_iterator iter = lines.begin(); |
102 iter != lines.end(); | 121 iter != lines.end(); |
103 ++iter) { | 122 ++iter) { |
104 const std::string& line = *iter; | 123 const std::string& line = *iter; |
105 const std::string& allow_empty_str = | 124 const std::string& allow_empty_str = |
106 AccessibilityTreeFormatter::GetAllowEmptyString(); | 125 AccessibilityTreeFormatter::GetAllowEmptyString(); |
107 const std::string& allow_str = | 126 const std::string& allow_str = |
108 AccessibilityTreeFormatter::GetAllowString(); | 127 AccessibilityTreeFormatter::GetAllowString(); |
109 const std::string& deny_str = | 128 const std::string& deny_str = |
110 AccessibilityTreeFormatter::GetDenyString(); | 129 AccessibilityTreeFormatter::GetDenyString(); |
130 const std::string& wait_str = "@WAIT-FOR:"; | |
111 if (StartsWithASCII(line, allow_empty_str, true)) { | 131 if (StartsWithASCII(line, allow_empty_str, true)) { |
112 filters->push_back( | 132 filters->push_back( |
113 Filter(base::UTF8ToUTF16(line.substr(allow_empty_str.size())), | 133 Filter(base::UTF8ToUTF16(line.substr(allow_empty_str.size())), |
114 Filter::ALLOW_EMPTY)); | 134 Filter::ALLOW_EMPTY)); |
115 } else if (StartsWithASCII(line, allow_str, true)) { | 135 } else if (StartsWithASCII(line, allow_str, true)) { |
116 filters->push_back(Filter(base::UTF8ToUTF16( | 136 filters->push_back(Filter(base::UTF8ToUTF16( |
117 line.substr(allow_str.size())), | 137 line.substr(allow_str.size())), |
118 Filter::ALLOW)); | 138 Filter::ALLOW)); |
119 } else if (StartsWithASCII(line, deny_str, true)) { | 139 } else if (StartsWithASCII(line, deny_str, true)) { |
120 filters->push_back(Filter(base::UTF8ToUTF16( | 140 filters->push_back(Filter(base::UTF8ToUTF16( |
121 line.substr(deny_str.size())), | 141 line.substr(deny_str.size())), |
122 Filter::DENY)); | 142 Filter::DENY)); |
143 } else if (StartsWithASCII(line, wait_str, true)) { | |
144 *wait_for = line.substr(wait_str.size()); | |
123 } | 145 } |
124 } | 146 } |
125 } | 147 } |
126 | 148 |
127 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 149 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
128 ContentBrowserTest::SetUpCommandLine(command_line); | 150 ContentBrowserTest::SetUpCommandLine(command_line); |
129 // Enable <dialog>, which is used in some tests. | 151 // Enable <dialog>, which is used in some tests. |
130 CommandLine::ForCurrentProcess()->AppendSwitch( | 152 CommandLine::ForCurrentProcess()->AppendSwitch( |
131 switches::kEnableExperimentalWebPlatformFeatures); | 153 switches::kEnableExperimentalWebPlatformFeatures); |
132 } | 154 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 // Tolerate Windows-style line endings (\r\n) in the expected file: | 186 // Tolerate Windows-style line endings (\r\n) in the expected file: |
165 // normalize by deleting all \r from the file (if any) to leave only \n. | 187 // normalize by deleting all \r from the file (if any) to leave only \n. |
166 std::string expected_contents; | 188 std::string expected_contents; |
167 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); | 189 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); |
168 | 190 |
169 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { | 191 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { |
170 printf("Skipping this test on this platform.\n"); | 192 printf("Skipping this test on this platform.\n"); |
171 return; | 193 return; |
172 } | 194 } |
173 | 195 |
196 // Parse filters and other directives in the test file. | |
197 std::vector<Filter> filters; | |
198 std::string wait_for; | |
199 AddDefaultFilters(&filters); | |
200 ParseHtmlForExtraDirectives(html_contents, &filters, &wait_for); | |
201 | |
174 // Load the page. | 202 // Load the page. |
175 base::string16 html_contents16; | 203 base::string16 html_contents16; |
176 html_contents16 = base::UTF8ToUTF16(html_contents); | 204 html_contents16 = base::UTF8ToUTF16(html_contents); |
177 GURL url = GetTestUrl("accessibility", | 205 GURL url = GetTestUrl("accessibility", |
178 html_file.BaseName().MaybeAsASCII().c_str()); | 206 html_file.BaseName().MaybeAsASCII().c_str()); |
179 AccessibilityNotificationWaiter waiter( | 207 |
180 shell(), AccessibilityModeComplete, | 208 // If there's a @WAIT-FOR directive, set up an accessibility notification |
181 ui::AX_EVENT_LOAD_COMPLETE); | 209 // waiter that returns on any event; we'll stop when we get the text we're |
210 // waiting for, or time out. Otherwise just wait specifically for | |
211 // the "load complete" event. | |
212 scoped_ptr<AccessibilityNotificationWaiter> waiter; | |
213 if (!wait_for.empty()) { | |
214 waiter.reset(new AccessibilityNotificationWaiter( | |
215 shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE)); | |
216 } else { | |
217 waiter.reset(new AccessibilityNotificationWaiter( | |
218 shell(), AccessibilityModeComplete, ui::AX_EVENT_LOAD_COMPLETE)); | |
219 } | |
220 | |
221 // Load the test html. | |
182 NavigateToURL(shell(), url); | 222 NavigateToURL(shell(), url); |
183 waiter.WaitForNotification(); | |
184 | 223 |
224 // Wait for notifications. If there's a @WAIT-FOR directive, break when | |
225 // the text we're waiting for appears in the dump, otherwise break after | |
226 // the first notification, which will be a load complete. | |
185 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 227 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
186 shell()->web_contents()); | 228 shell()->web_contents()); |
187 AccessibilityTreeFormatter formatter( | 229 std::string actual_contents; |
188 web_contents->GetRootBrowserAccessibilityManager()->GetRoot()); | 230 do { |
189 | 231 waiter->WaitForNotification(); |
190 // Parse filters in the test file. | 232 base::string16 actual_contents_utf16; |
191 std::vector<Filter> filters; | 233 AccessibilityTreeFormatter formatter( |
192 AddDefaultFilters(&filters); | 234 web_contents->GetRootBrowserAccessibilityManager()->GetRoot()); |
193 ParseFilters(html_contents, &filters); | 235 formatter.SetFilters(filters); |
194 formatter.SetFilters(filters); | 236 formatter.FormatAccessibilityTree(&actual_contents_utf16); |
237 actual_contents = base::UTF16ToUTF8(actual_contents_utf16); | |
238 if (wait_for.empty()) | |
aboxhall
2014/07/19 15:08:05
This if statement is redundant with the while stat
dmazzoni
2014/07/20 04:24:16
Oh, good point.
| |
239 break; | |
240 } while (!wait_for.empty() && | |
241 actual_contents.find(wait_for) == std::string::npos); | |
195 | 242 |
196 // Perform a diff (or write the initial baseline). | 243 // Perform a diff (or write the initial baseline). |
197 base::string16 actual_contents_utf16; | |
198 formatter.FormatAccessibilityTree(&actual_contents_utf16); | |
199 std::string actual_contents = base::UTF16ToUTF8(actual_contents_utf16); | |
200 std::vector<std::string> actual_lines, expected_lines; | 244 std::vector<std::string> actual_lines, expected_lines; |
201 Tokenize(actual_contents, "\n", &actual_lines); | 245 Tokenize(actual_contents, "\n", &actual_lines); |
202 Tokenize(expected_contents, "\n", &expected_lines); | 246 Tokenize(expected_contents, "\n", &expected_lines); |
203 // Marking the end of the file with a line of text ensures that | 247 // Marking the end of the file with a line of text ensures that |
204 // file length differences are found. | 248 // file length differences are found. |
205 expected_lines.push_back(kMarkEndOfFile); | 249 expected_lines.push_back(kMarkEndOfFile); |
206 actual_lines.push_back(kMarkEndOfFile); | 250 actual_lines.push_back(kMarkEndOfFile); |
207 | 251 |
208 std::vector<int> diff_lines = DiffLines(expected_lines, actual_lines); | 252 std::vector<int> diff_lines = DiffLines(expected_lines, actual_lines); |
209 bool is_different = diff_lines.size() > 0; | 253 bool is_different = diff_lines.size() > 0; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 } | 568 } |
525 | 569 |
526 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityTableSimple) { | 570 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityTableSimple) { |
527 RunTest(FILE_PATH_LITERAL("table-simple.html")); | 571 RunTest(FILE_PATH_LITERAL("table-simple.html")); |
528 } | 572 } |
529 | 573 |
530 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityTableSpans) { | 574 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityTableSpans) { |
531 RunTest(FILE_PATH_LITERAL("table-spans.html")); | 575 RunTest(FILE_PATH_LITERAL("table-spans.html")); |
532 } | 576 } |
533 | 577 |
578 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityTransition) { | |
579 RunTest(FILE_PATH_LITERAL("transition.html")); | |
580 } | |
581 | |
534 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, | 582 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, |
535 AccessibilityToggleButton) { | 583 AccessibilityToggleButton) { |
536 RunTest(FILE_PATH_LITERAL("togglebutton.html")); | 584 RunTest(FILE_PATH_LITERAL("togglebutton.html")); |
537 } | 585 } |
538 | 586 |
539 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { | 587 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityUl) { |
540 RunTest(FILE_PATH_LITERAL("ul.html")); | 588 RunTest(FILE_PATH_LITERAL("ul.html")); |
541 } | 589 } |
542 | 590 |
543 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { | 591 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, AccessibilityWbr) { |
544 RunTest(FILE_PATH_LITERAL("wbr.html")); | 592 RunTest(FILE_PATH_LITERAL("wbr.html")); |
545 } | 593 } |
546 | 594 |
547 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, | 595 IN_PROC_BROWSER_TEST_F(DumpAccessibilityTreeTest, |
548 AccessibilityAriaActivedescendant) { | 596 AccessibilityAriaActivedescendant) { |
549 RunTest(FILE_PATH_LITERAL("aria-activedescendant.html")); | 597 RunTest(FILE_PATH_LITERAL("aria-activedescendant.html")); |
550 } | 598 } |
551 | 599 |
552 } // namespace content | 600 } // namespace content |
OLD | NEW |