Chromium Code Reviews| 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_restrictions.h" | |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "content/browser/accessibility/accessibility_tree_formatter.h" | 21 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
| 21 #include "content/browser/accessibility/accessibility_tree_formatter_blink.h" | 22 #include "content/browser/accessibility/accessibility_tree_formatter_blink.h" |
| 22 #include "content/browser/accessibility/browser_accessibility.h" | 23 #include "content/browser/accessibility/browser_accessibility.h" |
| 23 #include "content/browser/accessibility/browser_accessibility_manager.h" | 24 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 25 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 25 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 26 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 26 #include "content/browser/web_contents/web_contents_impl.h" | 27 #include "content/browser/web_contents/web_contents_impl.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 | 198 |
| 198 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 199 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 199 | 200 |
| 200 // Output the test path to help anyone who encounters a failure and needs | 201 // Output the test path to help anyone who encounters a failure and needs |
| 201 // to know where to look. | 202 // to know where to look. |
| 202 LOG(INFO) << "Testing: " << file_path.LossyDisplayName() | 203 LOG(INFO) << "Testing: " << file_path.LossyDisplayName() |
| 203 << (is_blink_pass_ ? " (internal Blink accessibility tree)" | 204 << (is_blink_pass_ ? " (internal Blink accessibility tree)" |
| 204 : " (native accessibility tree for this platform)"); | 205 : " (native accessibility tree for this platform)"); |
| 205 | 206 |
| 206 std::string html_contents; | 207 std::string html_contents; |
| 207 base::ReadFileToString(file_path, &html_contents); | 208 { |
| 209 base::ThreadRestrictions::ScopedAllowIO allow_io_for_reading_test_input; | |
| 210 base::ReadFileToString(file_path, &html_contents); | |
| 211 } | |
|
jam
2016/07/26 23:52:16
nit: seems more readable to keep this thread restr
Łukasz Anforowicz
2016/07/27 16:18:14
Done.
| |
| 208 | 212 |
| 209 // Read the expected file. | 213 // Read the expected file. |
| 210 std::string expected_contents_raw; | 214 std::string expected_contents_raw; |
| 211 base::FilePath expected_file = | 215 base::FilePath expected_file = |
| 212 base::FilePath(file_path.RemoveExtension().value() + | 216 base::FilePath(file_path.RemoveExtension().value() + |
| 213 formatter_->GetExpectedFileSuffix()); | 217 formatter_->GetExpectedFileSuffix()); |
| 214 if (!base::PathExists(expected_file)) { | 218 { |
| 215 LOG(INFO) << "File not found: " << expected_file.LossyDisplayName(); | 219 base::ThreadRestrictions::ScopedAllowIO allow_io_for_reading_expected_file; |
| 216 LOG(INFO) << "No expectation file present, ignoring test on this platform." | 220 if (!base::PathExists(expected_file)) { |
| 217 << " To run this test anyway, create " | 221 LOG(INFO) << "File not found: " << expected_file.LossyDisplayName(); |
| 218 << expected_file.LossyDisplayName() | 222 LOG(INFO) |
| 219 << " (it can be empty) and then run content_browsertests " | 223 << "No expectation file present, ignoring test on this platform." |
| 220 << "with the switch: --" | 224 << " To run this test anyway, create " |
| 221 << switches::kGenerateAccessibilityTestExpectations; | 225 << expected_file.LossyDisplayName() |
| 222 return; | 226 << " (it can be empty) and then run content_browsertests " |
| 227 << "with the switch: --" | |
| 228 << switches::kGenerateAccessibilityTestExpectations; | |
| 229 return; | |
| 230 } | |
| 231 base::ReadFileToString(expected_file, &expected_contents_raw); | |
| 223 } | 232 } |
| 224 base::ReadFileToString(expected_file, &expected_contents_raw); | |
| 225 | 233 |
| 226 // Tolerate Windows-style line endings (\r\n) in the expected file: | 234 // Tolerate Windows-style line endings (\r\n) in the expected file: |
| 227 // normalize by deleting all \r from the file (if any) to leave only \n. | 235 // normalize by deleting all \r from the file (if any) to leave only \n. |
| 228 std::string expected_contents; | 236 std::string expected_contents; |
| 229 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); | 237 base::RemoveChars(expected_contents_raw, "\r", &expected_contents); |
| 230 | 238 |
| 231 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { | 239 if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { |
| 232 LOG(INFO) << "Skipping this test on this platform."; | 240 LOG(INFO) << "Skipping this test on this platform."; |
| 233 return; | 241 return; |
| 234 } | 242 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 "%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1, | 381 "%1s %4d %s\n", is_diff? kSignalDiff : "", line + 1, |
| 374 expected_lines[line].c_str()); | 382 expected_lines[line].c_str()); |
| 375 } | 383 } |
| 376 diff += "\nActual\n"; | 384 diff += "\nActual\n"; |
| 377 diff += "------\n"; | 385 diff += "------\n"; |
| 378 diff += actual_contents; | 386 diff += actual_contents; |
| 379 LOG(ERROR) << "Diff:\n" << diff; | 387 LOG(ERROR) << "Diff:\n" << diff; |
| 380 | 388 |
| 381 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 389 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 382 switches::kGenerateAccessibilityTestExpectations)) { | 390 switches::kGenerateAccessibilityTestExpectations)) { |
| 391 base::ThreadRestrictions::ScopedAllowIO allow_io_to_write_expected_file; | |
| 383 CHECK(base::WriteFile( | 392 CHECK(base::WriteFile( |
| 384 expected_file, actual_contents.c_str(), actual_contents.size())); | 393 expected_file, actual_contents.c_str(), actual_contents.size())); |
| 385 LOG(INFO) << "Wrote expectations to: " | 394 LOG(INFO) << "Wrote expectations to: " |
| 386 << expected_file.LossyDisplayName(); | 395 << expected_file.LossyDisplayName(); |
| 387 } | 396 } |
| 388 } else { | 397 } else { |
| 389 LOG(INFO) << "Test output matches expectations."; | 398 LOG(INFO) << "Test output matches expectations."; |
| 390 } | 399 } |
| 391 } | 400 } |
| 392 | 401 |
| 393 } // namespace content | 402 } // namespace content |
| OLD | NEW |