Chromium Code Reviews| Index: content/browser/accessibility/dump_accessibility_browsertest_base.cc |
| diff --git a/content/browser/accessibility/dump_accessibility_browsertest_base.cc b/content/browser/accessibility/dump_accessibility_browsertest_base.cc |
| index 60c5af63a0c9026b35f48f939bab2a17eebf1f1f..ae0f07641eecafe79074d353851af222f9663af1 100644 |
| --- a/content/browser/accessibility/dump_accessibility_browsertest_base.cc |
| +++ b/content/browser/accessibility/dump_accessibility_browsertest_base.cc |
| @@ -8,6 +8,7 @@ |
| #include <string> |
| #include <vector> |
| +#include "base/command_line.h" |
| #include "base/path_service.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/string_split.h" |
| @@ -20,6 +21,7 @@ |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/content_paths.h" |
| +#include "content/public/common/content_switches.h" |
| #include "content/public/common/url_constants.h" |
| #include "content/public/test/content_browser_test.h" |
| #include "content/public/test/content_browser_test_utils.h" |
| @@ -132,7 +134,7 @@ void DumpAccessibilityTestBase::RunTest( |
| // Output the test path to help anyone who encounters a failure and needs |
| // to know where to look. |
| - printf("Testing: %s\n", file_path.MaybeAsASCII().c_str()); |
| + LOG(INFO) << "Testing: " << file_path.LossyDisplayName(); |
|
Charlie Reis
2015/12/08 22:52:05
We're generally supposed to use DVLOG, right?
http
dmazzoni
2015/12/08 23:22:42
Yeah, it makes it harder to figure out what happen
|
| std::string html_contents; |
| base::ReadFileToString(file_path, &html_contents); |
| @@ -140,8 +142,18 @@ void DumpAccessibilityTestBase::RunTest( |
| // Read the expected file. |
| std::string expected_contents_raw; |
| base::FilePath expected_file = |
| - base::FilePath(file_path.RemoveExtension().value() + |
| - AccessibilityTreeFormatter::GetExpectedFileSuffix()); |
| + base::FilePath(file_path.RemoveExtension().value() + |
| + AccessibilityTreeFormatter::GetExpectedFileSuffix()); |
| + if (!base::PathExists(expected_file)) { |
| + LOG(INFO) << "File not found: " << expected_file.LossyDisplayName(); |
| + LOG(INFO) << "No expectation file present, ignoring test on this platform." |
| + << " To run this test anyway, create " |
| + << expected_file.LossyDisplayName() |
| + << " (it can be blank) and then run content_browsertests " |
|
Charlie Reis
2015/12/08 22:52:05
s/blank/empty/
dmazzoni
2015/12/09 22:23:19
Done.
|
| + << "with the switch: --" |
| + << switches::kGenerateAccessibilityTestExpectations; |
| + return; |
| + } |
| base::ReadFileToString(expected_file, &expected_contents_raw); |
| // Tolerate Windows-style line endings (\r\n) in the expected file: |
| @@ -150,7 +162,7 @@ void DumpAccessibilityTestBase::RunTest( |
| base::RemoveChars(expected_contents_raw, "\r", &expected_contents); |
| if (!expected_contents.compare(0, strlen(kMarkSkipFile), kMarkSkipFile)) { |
| - printf("Skipping this test on this platform.\n"); |
| + LOG(INFO) << "Skipping this test on this platform."; |
| return; |
| } |
| @@ -229,19 +241,15 @@ void DumpAccessibilityTestBase::RunTest( |
| printf("\nActual\n"); |
| printf("------\n"); |
| printf("%s\n", actual_contents.c_str()); |
| - } |
| - |
| - if (!base::PathExists(expected_file)) { |
| - base::FilePath actual_file = |
| - base::FilePath(file_path.RemoveExtension().value() + |
| - AccessibilityTreeFormatter::GetActualFileSuffix()); |
| - |
| - EXPECT_TRUE(base::WriteFile( |
| - actual_file, actual_contents.c_str(), actual_contents.size())); |
| - |
| - ADD_FAILURE() << "No expectation found. Create it by doing:\n" |
| - << "mv " << actual_file.LossyDisplayName() << " " |
| - << expected_file.LossyDisplayName(); |
| + fflush(stdout); |
| + |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kGenerateAccessibilityTestExpectations)) { |
| + EXPECT_TRUE(base::WriteFile( |
| + expected_file, actual_contents.c_str(), actual_contents.size())); |
| + LOG(ERROR) << "Wrote expectations to: " |
|
Charlie Reis
2015/12/08 22:52:05
Why ERROR in this case?
dmazzoni
2015/12/09 22:23:19
This only happens if the test failed anyway, so I
|
| + << expected_file.LossyDisplayName(); |
| + } |
| } |
| } |