OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_browsertest_base.h" | 5 #include "content/browser/accessibility/dump_accessibility_browsertest_base.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 filters->push_back(Filter(base::UTF8ToUTF16( | 113 filters->push_back(Filter(base::UTF8ToUTF16( |
114 line.substr(deny_str.size())), | 114 line.substr(deny_str.size())), |
115 Filter::DENY)); | 115 Filter::DENY)); |
116 } else if (StartsWithASCII(line, wait_str, true)) { | 116 } else if (StartsWithASCII(line, wait_str, true)) { |
117 *wait_for = line.substr(wait_str.size()); | 117 *wait_for = line.substr(wait_str.size()); |
118 } | 118 } |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void DumpAccessibilityTestBase::RunTest( | 122 void DumpAccessibilityTestBase::RunTest( |
123 const base::FilePath::CharType* file_path) { | 123 const base::FilePath file_path, const char* file_dir) { |
124 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 124 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
125 | 125 |
126 // Setup test paths. | |
127 base::FilePath dir_test_data; | |
128 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data)); | |
129 base::FilePath test_path( | |
130 dir_test_data.Append(FILE_PATH_LITERAL("accessibility"))); | |
131 ASSERT_TRUE(base::PathExists(test_path)) | |
132 << test_path.LossyDisplayName(); | |
133 | |
134 base::FilePath html_file = test_path.Append(base::FilePath(file_path)); | |
135 // Output the test path to help anyone who encounters a failure and needs | 126 // Output the test path to help anyone who encounters a failure and needs |
136 // to know where to look. | 127 // to know where to look. |
137 printf("Testing: %s\n", html_file.MaybeAsASCII().c_str()); | 128 printf("Testing: %s\n", file_path.MaybeAsASCII().c_str()); |
138 | 129 |
139 std::string html_contents; | 130 std::string html_contents; |
140 base::ReadFileToString(html_file, &html_contents); | 131 base::ReadFileToString(file_path, &html_contents); |
141 | 132 |
142 // Read the expected file. | 133 // Read the expected file. |
143 std::string expected_contents_raw; | 134 std::string expected_contents_raw; |
144 base::FilePath expected_file = | 135 base::FilePath expected_file = |
145 base::FilePath(html_file.RemoveExtension().value() + | 136 base::FilePath(file_path.RemoveExtension().value() + |
146 AccessibilityTreeFormatter::GetExpectedFileSuffix()); | 137 AccessibilityTreeFormatter::GetExpectedFileSuffix()); |
147 base::ReadFileToString(expected_file, &expected_contents_raw); | 138 base::ReadFileToString(expected_file, &expected_contents_raw); |
148 | 139 |
149 // Tolerate Windows-style line endings (\r\n) in the expected file: | 140 // Tolerate Windows-style line endings (\r\n) in the expected file: |
150 // normalize by deleting all \r from the file (if any) to leave only \n. | 141 // normalize by deleting all \r from the file (if any) to leave only \n. |
151 std::string expected_contents; | 142 std::string expected_contents; |
152 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); | 143 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); |
153 | 144 |
154 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { | 145 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { |
155 printf("Skipping this test on this platform.\n"); | 146 printf("Skipping this test on this platform.\n"); |
156 return; | 147 return; |
157 } | 148 } |
158 | 149 |
159 // Parse filters and other directives in the test file. | 150 // Parse filters and other directives in the test file. |
160 std::string wait_for; | 151 std::string wait_for; |
161 AddDefaultFilters(&filters_); | 152 AddDefaultFilters(&filters_); |
162 ParseHtmlForExtraDirectives(html_contents, &filters_, &wait_for); | 153 ParseHtmlForExtraDirectives(html_contents, &filters_, &wait_for); |
163 | 154 |
164 // Load the page. | 155 // Load the page. |
165 base::string16 html_contents16; | 156 base::string16 html_contents16; |
166 html_contents16 = base::UTF8ToUTF16(html_contents); | 157 html_contents16 = base::UTF8ToUTF16(html_contents); |
167 GURL url = GetTestUrl("accessibility", | 158 GURL url = GetTestUrl(file_dir, file_path.BaseName().MaybeAsASCII().c_str()); |
168 html_file.BaseName().MaybeAsASCII().c_str()); | |
169 | 159 |
170 // If there's a @WAIT-FOR directive, set up an accessibility notification | 160 // If there's a @WAIT-FOR directive, set up an accessibility notification |
171 // waiter that returns on any event; we'll stop when we get the text we're | 161 // waiter that returns on any event; we'll stop when we get the text we're |
172 // waiting for, or time out. Otherwise just wait specifically for | 162 // waiting for, or time out. Otherwise just wait specifically for |
173 // the "load complete" event. | 163 // the "load complete" event. |
174 scoped_ptr<AccessibilityNotificationWaiter> waiter; | 164 scoped_ptr<AccessibilityNotificationWaiter> waiter; |
175 if (!wait_for.empty()) { | 165 if (!wait_for.empty()) { |
176 waiter.reset(new AccessibilityNotificationWaiter( | 166 waiter.reset(new AccessibilityNotificationWaiter( |
177 shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE)); | 167 shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE)); |
178 } else { | 168 } else { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 printf("%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1, | 218 printf("%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1, |
229 expected_lines[line].c_str()); | 219 expected_lines[line].c_str()); |
230 } | 220 } |
231 printf("\nActual\n"); | 221 printf("\nActual\n"); |
232 printf("------\n"); | 222 printf("------\n"); |
233 printf("%s\n", actual_contents.c_str()); | 223 printf("%s\n", actual_contents.c_str()); |
234 } | 224 } |
235 | 225 |
236 if (!base::PathExists(expected_file)) { | 226 if (!base::PathExists(expected_file)) { |
237 base::FilePath actual_file = | 227 base::FilePath actual_file = |
238 base::FilePath(html_file.RemoveExtension().value() + | 228 base::FilePath(file_path.RemoveExtension().value() + |
239 AccessibilityTreeFormatter::GetActualFileSuffix()); | 229 AccessibilityTreeFormatter::GetActualFileSuffix()); |
240 | 230 |
241 EXPECT_TRUE(base::WriteFile( | 231 EXPECT_TRUE(base::WriteFile( |
242 actual_file, actual_contents.c_str(), actual_contents.size())); | 232 actual_file, actual_contents.c_str(), actual_contents.size())); |
243 | 233 |
244 ADD_FAILURE() << "No expectation found. Create it by doing:\n" | 234 ADD_FAILURE() << "No expectation found. Create it by doing:\n" |
245 << "mv " << actual_file.LossyDisplayName() << " " | 235 << "mv " << actual_file.LossyDisplayName() << " " |
246 << expected_file.LossyDisplayName(); | 236 << expected_file.LossyDisplayName(); |
247 } | 237 } |
248 } | 238 } |
249 | 239 |
250 } // namespace content | 240 } // namespace content |
OLD | NEW |