| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/test/mini_installer_test/mini_installer_test_util.h" | 5 #include "chrome/test/mini_installer_test/mini_installer_test_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/platform_thread.h" | |
| 10 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 11 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 12 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "base/threading/platform_thread.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/installer/util/logging_installer.h" | 15 #include "chrome/installer/util/logging_installer.h" |
| 16 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" | 16 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 // Change current directory so that chrome.dll from current folder | 19 // Change current directory so that chrome.dll from current folder |
| 20 // will not be used as fall back. | 20 // will not be used as fall back. |
| 21 bool MiniInstallerTestUtil::ChangeCurrentDirectory(FilePath* current_path) { | 21 bool MiniInstallerTestUtil::ChangeCurrentDirectory(FilePath* current_path) { |
| 22 FilePath backup_path; | 22 FilePath backup_path; |
| 23 if (!file_util::GetCurrentDirectory(&backup_path)) | 23 if (!file_util::GetCurrentDirectory(&backup_path)) |
| 24 return false; | 24 return false; |
| 25 | 25 |
| 26 if (!file_util::SetCurrentDirectory(backup_path.DirName())) | 26 if (!file_util::SetCurrentDirectory(backup_path.DirName())) |
| 27 return false; | 27 return false; |
| 28 *current_path = backup_path; | 28 *current_path = backup_path; |
| 29 return true; | 29 return true; |
| 30 } | 30 } |
| 31 | 31 |
| 32 // Checks for all requested running processes and kills them. | 32 // Checks for all requested running processes and kills them. |
| 33 void MiniInstallerTestUtil::CloseProcesses( | 33 void MiniInstallerTestUtil::CloseProcesses( |
| 34 const std::wstring& executable_name) { | 34 const std::wstring& executable_name) { |
| 35 int timer = 0; | 35 int timer = 0; |
| 36 while ((base::GetProcessCount(executable_name, NULL) > 0) && | 36 while ((base::GetProcessCount(executable_name, NULL) > 0) && |
| 37 (timer < 20000)) { | 37 (timer < 20000)) { |
| 38 base::KillProcesses(executable_name, 1, NULL); | 38 base::KillProcesses(executable_name, 1, NULL); |
| 39 PlatformThread::Sleep(200); | 39 base::PlatformThread::Sleep(200); |
| 40 timer = timer + 200; | 40 timer = timer + 200; |
| 41 } | 41 } |
| 42 ASSERT_EQ(0, base::GetProcessCount(executable_name, NULL)); | 42 ASSERT_EQ(0, base::GetProcessCount(executable_name, NULL)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool MiniInstallerTestUtil::CloseWindow(const wchar_t* window_name, | 45 bool MiniInstallerTestUtil::CloseWindow(const wchar_t* window_name, |
| 46 UINT message) { | 46 UINT message) { |
| 47 int timer = 0; | 47 int timer = 0; |
| 48 bool return_val = false; | 48 bool return_val = false; |
| 49 HWND hndl = FindWindow(NULL, window_name); | 49 HWND hndl = FindWindow(NULL, window_name); |
| 50 while (hndl == NULL && (timer < 60000)) { | 50 while (hndl == NULL && (timer < 60000)) { |
| 51 hndl = FindWindow(NULL, window_name); | 51 hndl = FindWindow(NULL, window_name); |
| 52 PlatformThread::Sleep(200); | 52 base::PlatformThread::Sleep(200); |
| 53 timer = timer + 200; | 53 timer = timer + 200; |
| 54 } | 54 } |
| 55 if (hndl != NULL) { | 55 if (hndl != NULL) { |
| 56 LRESULT _result = SendMessage(hndl, message, 1, 0); | 56 LRESULT _result = SendMessage(hndl, message, 1, 0); |
| 57 return_val = true; | 57 return_val = true; |
| 58 } | 58 } |
| 59 return return_val; | 59 return return_val; |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool IsNewer(const FileInfo& file_rbegin, const FileInfo& file_rend) { | 62 bool IsNewer(const FileInfo& file_rbegin, const FileInfo& file_rend) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 | 268 |
| 269 void MiniInstallerTestUtil::VerifyProcessLaunch( | 269 void MiniInstallerTestUtil::VerifyProcessLaunch( |
| 270 const wchar_t* process_name, bool expected_status) { | 270 const wchar_t* process_name, bool expected_status) { |
| 271 int timer = 0, wait_time = 60000; | 271 int timer = 0, wait_time = 60000; |
| 272 if (!expected_status) | 272 if (!expected_status) |
| 273 wait_time = 8000; | 273 wait_time = 8000; |
| 274 | 274 |
| 275 while ((base::GetProcessCount(process_name, NULL) == 0) && | 275 while ((base::GetProcessCount(process_name, NULL) == 0) && |
| 276 (timer < wait_time)) { | 276 (timer < wait_time)) { |
| 277 PlatformThread::Sleep(200); | 277 base::PlatformThread::Sleep(200); |
| 278 timer = timer + 200; | 278 timer = timer + 200; |
| 279 } | 279 } |
| 280 | 280 |
| 281 if (expected_status) | 281 if (expected_status) |
| 282 ASSERT_NE(0, base::GetProcessCount(process_name, NULL)); | 282 ASSERT_NE(0, base::GetProcessCount(process_name, NULL)); |
| 283 else | 283 else |
| 284 ASSERT_EQ(0, base::GetProcessCount(process_name, NULL)); | 284 ASSERT_EQ(0, base::GetProcessCount(process_name, NULL)); |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool MiniInstallerTestUtil::VerifyProcessClose( | 287 bool MiniInstallerTestUtil::VerifyProcessClose( |
| 288 const wchar_t* process_name) { | 288 const wchar_t* process_name) { |
| 289 int timer = 0; | 289 int timer = 0; |
| 290 if (base::GetProcessCount(process_name, NULL) > 0) { | 290 if (base::GetProcessCount(process_name, NULL) > 0) { |
| 291 VLOG(1) << "Waiting for this process to end: " << process_name; | 291 VLOG(1) << "Waiting for this process to end: " << process_name; |
| 292 while ((base::GetProcessCount(process_name, NULL) > 0) && | 292 while ((base::GetProcessCount(process_name, NULL) > 0) && |
| 293 (timer < TestTimeouts::large_test_timeout_ms())) { | 293 (timer < TestTimeouts::large_test_timeout_ms())) { |
| 294 PlatformThread::Sleep(200); | 294 base::PlatformThread::Sleep(200); |
| 295 timer = timer + 200; | 295 timer = timer + 200; |
| 296 } | 296 } |
| 297 } else { | 297 } else { |
| 298 if (base::GetProcessCount(process_name, NULL) != 0) | 298 if (base::GetProcessCount(process_name, NULL) != 0) |
| 299 return false; | 299 return false; |
| 300 } | 300 } |
| 301 return true; | 301 return true; |
| 302 } | 302 } |
| 303 | 303 |
| 304 bool MiniInstallerTestUtil::VerifyProcessHandleClosed( | 304 bool MiniInstallerTestUtil::VerifyProcessHandleClosed( |
| 305 base::ProcessHandle handle) { | 305 base::ProcessHandle handle) { |
| 306 DWORD result = WaitForSingleObject(handle, | 306 DWORD result = WaitForSingleObject(handle, |
| 307 TestTimeouts::large_test_timeout_ms()); | 307 TestTimeouts::large_test_timeout_ms()); |
| 308 return result == WAIT_OBJECT_0; | 308 return result == WAIT_OBJECT_0; |
| 309 } | 309 } |
| OLD | NEW |