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

Side by Side Diff: content/browser/accessibility/dump_accessibility_browsertest_base.cc

Issue 815463006: Separating ARIA, HTML & event AX test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updating new image for bullet 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 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } else if (StartsWithASCII(line, deny_str, true)) { 112 } else if (StartsWithASCII(line, deny_str, true)) {
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::RunAriaTest(
123 const base::FilePath::CharType* file_path) { 123 const base::FilePath::CharType* file_path) {
124 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
125
126 // Setup test paths.
127 base::FilePath dir_test_data; 124 base::FilePath dir_test_data;
128 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data)); 125 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data));
129 base::FilePath test_path( 126 base::FilePath test_path(
130 dir_test_data.Append(FILE_PATH_LITERAL("accessibility"))); 127 dir_test_data.AppendASCII("accessibility/aria"));
128 ASSERT_TRUE(base::PathExists(test_path))
129 << test_path.LossyDisplayName();
130
131 base::FilePath aria_file = test_path.Append(base::FilePath(file_path));
132 RunTest(aria_file, "accessibility/aria");
133 }
134
135 void DumpAccessibilityTestBase::RunEventTest(
136 const base::FilePath::CharType* file_path) {
137 base::FilePath dir_test_data;
138 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data));
139 base::FilePath test_path(
140 dir_test_data.AppendASCII("accessibility/event"));
141 ASSERT_TRUE(base::PathExists(test_path))
142 << test_path.LossyDisplayName();
143
144 base::FilePath event_file = test_path.Append(base::FilePath(file_path));
145 RunTest(event_file, "accessibility/event");
146 }
147
148 void DumpAccessibilityTestBase::RunHtmlTest(
149 const base::FilePath::CharType* file_path) {
150 base::FilePath dir_test_data;
151 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &dir_test_data));
152 base::FilePath test_path(
153 dir_test_data.AppendASCII("accessibility/html"));
131 ASSERT_TRUE(base::PathExists(test_path)) 154 ASSERT_TRUE(base::PathExists(test_path))
132 << test_path.LossyDisplayName(); 155 << test_path.LossyDisplayName();
133 156
134 base::FilePath html_file = test_path.Append(base::FilePath(file_path)); 157 base::FilePath html_file = test_path.Append(base::FilePath(file_path));
158 RunTest(html_file, "accessibility/html");
159 }
160
161 void DumpAccessibilityTestBase::RunTest(
162 const base::FilePath file_path, const char* file_dir) {
163 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
164
135 // Output the test path to help anyone who encounters a failure and needs 165 // Output the test path to help anyone who encounters a failure and needs
136 // to know where to look. 166 // to know where to look.
137 printf("Testing: %s\n", html_file.MaybeAsASCII().c_str()); 167 printf("Testing: %s\n", file_path.MaybeAsASCII().c_str());
138 168
139 std::string html_contents; 169 std::string html_contents;
140 base::ReadFileToString(html_file, &html_contents); 170 base::ReadFileToString(file_path, &html_contents);
141 171
142 // Read the expected file. 172 // Read the expected file.
143 std::string expected_contents_raw; 173 std::string expected_contents_raw;
144 base::FilePath expected_file = 174 base::FilePath expected_file =
145 base::FilePath(html_file.RemoveExtension().value() + 175 base::FilePath(file_path.RemoveExtension().value() +
146 AccessibilityTreeFormatter::GetExpectedFileSuffix()); 176 AccessibilityTreeFormatter::GetExpectedFileSuffix());
147 base::ReadFileToString(expected_file, &expected_contents_raw); 177 base::ReadFileToString(expected_file, &expected_contents_raw);
148 178
149 // Tolerate Windows-style line endings (\r\n) in the expected file: 179 // 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. 180 // normalize by deleting all \r from the file (if any) to leave only \n.
151 std::string expected_contents; 181 std::string expected_contents;
152 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); 182 base::RemoveChars(expected_contents_raw, "\r", &expected_contents);
153 183
154 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { 184 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) {
155 printf("Skipping this test on this platform.\n"); 185 printf("Skipping this test on this platform.\n");
156 return; 186 return;
157 } 187 }
158 188
159 // Parse filters and other directives in the test file. 189 // Parse filters and other directives in the test file.
160 std::string wait_for; 190 std::string wait_for;
161 AddDefaultFilters(&filters_); 191 AddDefaultFilters(&filters_);
162 ParseHtmlForExtraDirectives(html_contents, &filters_, &wait_for); 192 ParseHtmlForExtraDirectives(html_contents, &filters_, &wait_for);
163 193
164 // Load the page. 194 // Load the page.
165 base::string16 html_contents16; 195 base::string16 html_contents16;
166 html_contents16 = base::UTF8ToUTF16(html_contents); 196 html_contents16 = base::UTF8ToUTF16(html_contents);
167 GURL url = GetTestUrl("accessibility", 197 GURL url = GetTestUrl(file_dir, file_path.BaseName().MaybeAsASCII().c_str());
shreeramk 2014/12/19 18:18:27 file_dir is needed to get the test url using GetTe
168 html_file.BaseName().MaybeAsASCII().c_str());
169 198
170 // If there's a @WAIT-FOR directive, set up an accessibility notification 199 // 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 200 // 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 201 // waiting for, or time out. Otherwise just wait specifically for
173 // the "load complete" event. 202 // the "load complete" event.
174 scoped_ptr<AccessibilityNotificationWaiter> waiter; 203 scoped_ptr<AccessibilityNotificationWaiter> waiter;
175 if (!wait_for.empty()) { 204 if (!wait_for.empty()) {
176 waiter.reset(new AccessibilityNotificationWaiter( 205 waiter.reset(new AccessibilityNotificationWaiter(
177 shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE)); 206 shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE));
178 } else { 207 } else {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 printf("%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1, 257 printf("%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1,
229 expected_lines[line].c_str()); 258 expected_lines[line].c_str());
230 } 259 }
231 printf("\nActual\n"); 260 printf("\nActual\n");
232 printf("------\n"); 261 printf("------\n");
233 printf("%s\n", actual_contents.c_str()); 262 printf("%s\n", actual_contents.c_str());
234 } 263 }
235 264
236 if (!base::PathExists(expected_file)) { 265 if (!base::PathExists(expected_file)) {
237 base::FilePath actual_file = 266 base::FilePath actual_file =
238 base::FilePath(html_file.RemoveExtension().value() + 267 base::FilePath(file_path.RemoveExtension().value() +
239 AccessibilityTreeFormatter::GetActualFileSuffix()); 268 AccessibilityTreeFormatter::GetActualFileSuffix());
240 269
241 EXPECT_TRUE(base::WriteFile( 270 EXPECT_TRUE(base::WriteFile(
242 actual_file, actual_contents.c_str(), actual_contents.size())); 271 actual_file, actual_contents.c_str(), actual_contents.size()));
243 272
244 ADD_FAILURE() << "No expectation found. Create it by doing:\n" 273 ADD_FAILURE() << "No expectation found. Create it by doing:\n"
245 << "mv " << actual_file.LossyDisplayName() << " " 274 << "mv " << actual_file.LossyDisplayName() << " "
246 << expected_file.LossyDisplayName(); 275 << expected_file.LossyDisplayName();
247 } 276 }
248 } 277 }
249 278
250 } // namespace content 279 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698