From c019cf28f21df18517d130ee622b534aaa2398ab Mon Sep 17 00:00:00 2001 From: "huanr@chromium.org" Date: Wed, 19 Aug 2009 23:04:00 +0000 Subject: Port automated_ui_tests to linux. Original code review: http://codereview.chromium.org/174038 BUG=19758 TEST=automated_ui_tests works as expected. Review URL: http://codereview.chromium.org/173086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23774 0039d316-1c4b-4281-b951-d872f2087c98 --- .../test/automated_ui_tests/automated_ui_tests.cc | 105 ++++++++++----------- .../test/automated_ui_tests/automated_ui_tests.h | 26 ++--- 2 files changed, 63 insertions(+), 68 deletions(-) diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index 4b94cbf..facb5d4 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include +#include +#include #include "base/command_line.h" #include "base/file_util.h" @@ -178,11 +180,12 @@ void AutomatedUITest::RunReproduction() { } if (did_crash) { - std::string crash_dump = WideToASCII(GetMostRecentCrashDump()); - std::string result = - "*** Crash dump produced. See result file for more details. Dump = "; - result.append(crash_dump); - result.append(" ***\n"); + FilePath crash_dump = GetMostRecentCrashDump(); + FilePath::StringType result = + FILE_PATH_LITERAL("*** Crash dump produced. ") + FILE_PATH_LITERAL("See result file for more details. Dump = "); + result.append(crash_dump.value()); + result.append(FILE_PATH_LITERAL(" ***\n")); printf("%s", result.c_str()); LogCrashResult(crash_dump, command_complete); EXPECT_TRUE(false) << "Crash detected."; @@ -223,7 +226,7 @@ void AutomatedUITest::RunAutomatedUITest() { // Check for a crash right after startup. if (DidCrash(true)) { - LogCrashResult(WideToASCII(GetMostRecentCrashDump()), false); + LogCrashResult(GetMostRecentCrashDump(), false); // Try and start up again. CloseBrowserAndServer(); LaunchBrowserAndServer(); @@ -261,7 +264,7 @@ void AutomatedUITest::RunAutomatedUITest() { // This was the last action if we've returned to the initial depth // of the command subtree. bool wasLastAction = init_reader_.Depth() == start_depth; - LogCrashResult(WideToASCII(GetMostRecentCrashDump()), wasLastAction); + LogCrashResult(GetMostRecentCrashDump(), wasLastAction); // Skip to the beginning of the next command. while (init_reader_.Depth() != start_depth) { ASSERT_TRUE(init_reader_.Read()) << "Malformed XML file."; @@ -274,7 +277,7 @@ void AutomatedUITest::RunAutomatedUITest() { // a crash, log success for the entire command if this doesn't crash. DoAction("TearDown"); if (DidCrash(true)) - LogCrashResult(WideToASCII(GetMostRecentCrashDump()), true); + LogCrashResult(GetMostRecentCrashDump(), true); else LogSuccessResult(); } else { @@ -291,7 +294,7 @@ void AutomatedUITest::RunAutomatedUITest() { WriteReportToFile(); } -bool AutomatedUITest::DoAction(const std::string & action) { +bool AutomatedUITest::DoAction(const std::string& action) { bool did_complete_action = false; xml_writer_.StartElement(action); if (debug_logging_enabled_) @@ -667,7 +670,7 @@ bool AutomatedUITest::WriteReportToFile() { return true; } -void AutomatedUITest::AppendToOutputFile(const std::string &append_string) { +void AutomatedUITest::AppendToOutputFile(const std::string& append_string) { FilePath path = GetOutputFilePath(); std::ofstream error_file; if (!path.empty()) @@ -677,11 +680,15 @@ void AutomatedUITest::AppendToOutputFile(const std::string &append_string) { error_file.close(); } -void AutomatedUITest::LogCrashResult(const std::string &crash_dump, +void AutomatedUITest::LogCrashResult(const FilePath& crash_dump, bool command_completed) { xml_writer_.StartElement("result"); xml_writer_.StartElement("crash"); - xml_writer_.AddAttribute("crash_dump", crash_dump); +#if defined(OS_WIN) + xml_writer_.AddAttribute("crash_dump", WideToASCII(crash_dump.value())); +#else + xml_writer_.AddAttribute("crash_dump", crash_dump.value()); +#endif if (command_completed) xml_writer_.AddAttribute("command_completed", "yes"); else @@ -697,74 +704,60 @@ void AutomatedUITest::LogSuccessResult() { xml_writer_.EndElement(); } -void AutomatedUITest::AddInfoAttribute(const std::string &info) { +void AutomatedUITest::AddInfoAttribute(const std::string& info) { xml_writer_.AddAttribute("info", info); } -void AutomatedUITest::AddWarningAttribute(const std::string &warning) { +void AutomatedUITest::AddWarningAttribute(const std::string& warning) { xml_writer_.AddAttribute("warning", warning); } -void AutomatedUITest::AddErrorAttribute(const std::string &error) { +void AutomatedUITest::AddErrorAttribute(const std::string& error) { xml_writer_.AddAttribute("error", error); } -void AutomatedUITest::LogErrorMessage(const std::string &error) { +void AutomatedUITest::LogErrorMessage(const std::string& error) { AddErrorAttribute(error); } -void AutomatedUITest::LogWarningMessage(const std::string &warning) { +void AutomatedUITest::LogWarningMessage(const std::string& warning) { AddWarningAttribute(warning); } -void AutomatedUITest::LogInfoMessage(const std::string &info) { +void AutomatedUITest::LogInfoMessage(const std::string& info) { AddWarningAttribute(info); } -std::wstring AutomatedUITest::GetMostRecentCrashDump() { -// TODO(estade): port. -#if defined(OS_WIN) - std::wstring crash_dump_path; - int file_count = 0; - FILETIME most_recent_file_time; - std::wstring most_recent_file_name; - WIN32_FIND_DATA find_file_data; - +FilePath AutomatedUITest::GetMostRecentCrashDump() { + FilePath crash_dump_path; + FilePath most_recent_file_name; PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dump_path); - // All files in the given directory. - std::wstring filename_spec = crash_dump_path + L"\\*"; - HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data); - if (find_handle != INVALID_HANDLE_VALUE) { - most_recent_file_time = find_file_data.ftCreationTime; - most_recent_file_name = find_file_data.cFileName; - do { - // Don't count current or parent directories. - if ((wcscmp(find_file_data.cFileName, L"..") == 0) || - (wcscmp(find_file_data.cFileName, L".") == 0)) - continue; - - long result = CompareFileTime(&find_file_data.ftCreationTime, - &most_recent_file_time); - - // File was created on or after the current most recent file. - if ((result == 1) || (result == 0)) { - most_recent_file_time = find_file_data.ftCreationTime; - most_recent_file_name = find_file_data.cFileName; - } - } while (FindNextFile(find_handle, &find_file_data)); - FindClose(find_handle); + base::Time most_recent_file_time; + + bool first_file = true; + + file_util::FileEnumerator enumerator(crash_dump_path, + false, // not recursive + file_util::FileEnumerator::FILES); + for (FilePath path = enumerator.Next(); !path.value().empty(); + path = enumerator.Next()) { + file_util::FileInfo file_info; + GetFileInfo(path, &file_info); + if (first_file) { + most_recent_file_time = file_info.last_modified; + most_recent_file_name = path.BaseName(); + first_file = false; + } else if (file_info.last_modified >= most_recent_file_time) { + most_recent_file_time = file_info.last_modified; + most_recent_file_name = path.BaseName(); + } } - if (most_recent_file_name.empty()) { - return L""; + return FilePath(); } else { - file_util::AppendToPath(&crash_dump_path, most_recent_file_name); + crash_dump_path = crash_dump_path.Append(most_recent_file_name); return crash_dump_path; } -#else - NOTIMPLEMENTED(); - return std::wstring(); -#endif } bool AutomatedUITest::DidCrash(bool update_total_crashes) { diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h index 3b9fb01..1db44bb 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.h +++ b/chrome/test/automated_ui_tests/automated_ui_tests.h @@ -99,7 +99,8 @@ // // --wait-after-action : waits the specified amount of time (1s by default) // after each action. Useful for debugging. -// + +#include #include "chrome/test/automated_ui_tests/automated_ui_test_base.h" #include "chrome/test/ui/ui_test.h" @@ -123,7 +124,7 @@ class AutomatedUITest : public AutomatedUITestBase { // Attempts to perform an action based on the input string. See below for // possible actions. Returns true if the action completes, false otherwise. - bool DoAction(const std::string &action); + bool DoAction(const std::string& action); // Actions ------------------------------------------------------------------ @@ -333,7 +334,7 @@ class AutomatedUITest : public AutomatedUITestBase { bool WriteReportToFile(); // Appends the provided string to the output file. - void AppendToOutputFile(const std::string &append_string); + void AppendToOutputFile(const std::string& append_string); // Logs a crash to the xml_writer in the form of: // @@ -341,7 +342,8 @@ class AutomatedUITest : public AutomatedUITestBase { // crash_dump - Location of crash dump if applicable. // command_completed - True if all actions in the command were completed // before the crash occured. - void LogCrashResult(const std::string &crash_dump, bool command_completed); + void LogCrashResult(const FilePath& crash_dump, + bool command_completed); // Logs a successful command to the xml_writer in the form of: // @@ -349,16 +351,16 @@ class AutomatedUITest : public AutomatedUITestBase { // Adds the attribute "reason=|reason|" to the current element. // Used to log the reason for a given failure while performing an action. - void LogActionFailureReason(const std::string &reason); + void LogActionFailureReason(const std::string& reason); // Adds the attribute 'info="|info|"' to the current element. Used when an // action could not complete for a non-serious issue. Usually because the // state of the test wouldn't allow for a particular action. - void AddInfoAttribute(const std::string &info); + void AddInfoAttribute(const std::string& info); // Adds the attribute "warning=|warning|" to the current element. Used when // an action could not complete because of a potentially troublesome issue. - void AddWarningAttribute(const std::string &warning); + void AddWarningAttribute(const std::string& warning); // Adds the attribute "error=|error|" to the current element. Used when an // action could not complete due to an unexpected problem which might @@ -366,12 +368,12 @@ class AutomatedUITest : public AutomatedUITestBase { // This is usually used when the testing environment isn't acting as we'd // expect. For example, no chrome windows are focused, or key presses aren't // being registered. - void AddErrorAttribute(const std::string &error); + void AddErrorAttribute(const std::string& error); // Returns the full path of the crash dump. This is likely to be the // .txt file, not the actual crash dump. Although they do share // a common name. - std::wstring GetMostRecentCrashDump(); + FilePath GetMostRecentCrashDump(); // Returns true if the test has produced any new crash logs. // A "new" crash log is one that was produced since DidCrash was last called @@ -379,9 +381,9 @@ class AutomatedUITest : public AutomatedUITestBase { bool DidCrash(bool update_total_crashes); // Override the message logging in AutomatedUITestBase. - virtual void LogErrorMessage(const std::string &error); - virtual void LogWarningMessage(const std::string &warning); - virtual void LogInfoMessage(const std::string &info); + virtual void LogErrorMessage(const std::string& error); + virtual void LogWarningMessage(const std::string& warning); + virtual void LogInfoMessage(const std::string& info); // Overridden so that UI Test doesn't set up when the tests start. // We use DoAction("SetUp") to set up, because it logs it and makes -- cgit v1.1