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