| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_frame/test/chrome_frame_test_utils.h" | 5 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 6 | 6 |
| 7 #include <atlapp.h> | 7 #include <atlapp.h> |
| 8 #include <atlmisc.h> | 8 #include <atlmisc.h> |
| 9 #include <iepmapi.h> | 9 #include <iepmapi.h> |
| 10 #include <sddl.h> | 10 #include <sddl.h> |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 path = FormatCommandForApp(executable, argument); | 169 path = FormatCommandForApp(executable, argument); |
| 170 if (path.empty()) { | 170 if (path.empty()) { |
| 171 LOG(ERROR) << "Failed to find executable: " << executable; | 171 LOG(ERROR) << "Failed to find executable: " << executable; |
| 172 } else { | 172 } else { |
| 173 CommandLine cmdline = CommandLine::FromString(path); | 173 CommandLine cmdline = CommandLine::FromString(path); |
| 174 if (!base::LaunchProcess(cmdline, base::LaunchOptions(), &process)) { | 174 if (!base::LaunchProcess(cmdline, base::LaunchOptions(), &process)) { |
| 175 LOG(ERROR) << "LaunchProcess failed: " << ::GetLastError(); | 175 LOG(ERROR) << "LaunchProcess failed: " << ::GetLastError(); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 } else { | 178 } else { |
| 179 CommandLine cmdline((FilePath(path))); | 179 CommandLine cmdline((base::FilePath(path))); |
| 180 cmdline.AppendArgNative(argument); | 180 cmdline.AppendArgNative(argument); |
| 181 if (!base::LaunchProcess(cmdline, base::LaunchOptions(), &process)) { | 181 if (!base::LaunchProcess(cmdline, base::LaunchOptions(), &process)) { |
| 182 LOG(ERROR) << "LaunchProcess failed: " << ::GetLastError(); | 182 LOG(ERROR) << "LaunchProcess failed: " << ::GetLastError(); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 return process; | 185 return process; |
| 186 } | 186 } |
| 187 | 187 |
| 188 base::ProcessHandle LaunchChrome(const std::wstring& url, | 188 base::ProcessHandle LaunchChrome(const std::wstring& url, |
| 189 const FilePath& user_data_dir) { | 189 const base::FilePath& user_data_dir) { |
| 190 FilePath path; | 190 base::FilePath path; |
| 191 PathService::Get(base::DIR_MODULE, &path); | 191 PathService::Get(base::DIR_MODULE, &path); |
| 192 path = path.AppendASCII(kChromeImageName); | 192 path = path.AppendASCII(kChromeImageName); |
| 193 | 193 |
| 194 CommandLine cmd(path); | 194 CommandLine cmd(path); |
| 195 cmd.AppendSwitch(switches::kNoFirstRun); | 195 cmd.AppendSwitch(switches::kNoFirstRun); |
| 196 if (!user_data_dir.empty()) | 196 if (!user_data_dir.empty()) |
| 197 cmd.AppendSwitchPath(switches::kUserDataDir, user_data_dir); | 197 cmd.AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 198 cmd.AppendArgNative(url); | 198 cmd.AppendArgNative(url); |
| 199 | 199 |
| 200 base::ProcessHandle process = NULL; | 200 base::ProcessHandle process = NULL; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 410 |
| 411 hr = ::CoCreateInstance(CLSID_InternetExplorer, NULL, | 411 hr = ::CoCreateInstance(CLSID_InternetExplorer, NULL, |
| 412 cocreate_flags, IID_IWebBrowser2, | 412 cocreate_flags, IID_IWebBrowser2, |
| 413 reinterpret_cast<void**>(web_browser)); | 413 reinterpret_cast<void**>(web_browser)); |
| 414 // ~LowIntegrityToken() will switch integrity back to medium. | 414 // ~LowIntegrityToken() will switch integrity back to medium. |
| 415 return hr; | 415 return hr; |
| 416 } | 416 } |
| 417 | 417 |
| 418 std::wstring GetExeVersion(const std::wstring& exe_path) { | 418 std::wstring GetExeVersion(const std::wstring& exe_path) { |
| 419 scoped_ptr<FileVersionInfo> ie_version_info( | 419 scoped_ptr<FileVersionInfo> ie_version_info( |
| 420 FileVersionInfo::CreateFileVersionInfo(FilePath(exe_path))); | 420 FileVersionInfo::CreateFileVersionInfo(base::FilePath(exe_path))); |
| 421 return ie_version_info->product_version(); | 421 return ie_version_info->product_version(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 IEVersion GetInstalledIEVersion() { | 424 IEVersion GetInstalledIEVersion() { |
| 425 std::wstring path(chrome_frame_test::GetExecutableAppPath(kIEImageName)); | 425 std::wstring path(chrome_frame_test::GetExecutableAppPath(kIEImageName)); |
| 426 std::wstring version(GetExeVersion(path)); | 426 std::wstring version(GetExeVersion(path)); |
| 427 size_t first_dot = version.find(L'.'); | 427 size_t first_dot = version.find(L'.'); |
| 428 int major_version = 0; | 428 int major_version = 0; |
| 429 if (!base::StringToInt(base::StringPiece16( | 429 if (!base::StringToInt(base::StringPiece16( |
| 430 version.data(), | 430 version.data(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 444 return IE_9; | 444 return IE_9; |
| 445 case 10: | 445 case 10: |
| 446 return IE_10; | 446 return IE_10; |
| 447 default: | 447 default: |
| 448 break; | 448 break; |
| 449 } | 449 } |
| 450 | 450 |
| 451 return IE_UNSUPPORTED; | 451 return IE_UNSUPPORTED; |
| 452 } | 452 } |
| 453 | 453 |
| 454 FilePath GetProfilePathForIE() { | 454 base::FilePath GetProfilePathForIE() { |
| 455 FilePath profile_path; | 455 base::FilePath profile_path; |
| 456 // Browsers without IDeleteBrowsingHistory in non-priv mode | 456 // Browsers without IDeleteBrowsingHistory in non-priv mode |
| 457 // have their profiles moved into "Temporary Internet Files". | 457 // have their profiles moved into "Temporary Internet Files". |
| 458 // The code below basically retrieves the version of IE and computes | 458 // The code below basically retrieves the version of IE and computes |
| 459 // the profile directory accordingly. | 459 // the profile directory accordingly. |
| 460 if (GetInstalledIEVersion() <= IE_7) { | 460 if (GetInstalledIEVersion() <= IE_7) { |
| 461 profile_path = GetIETemporaryFilesFolder(); | 461 profile_path = GetIETemporaryFilesFolder(); |
| 462 profile_path = profile_path.Append(L"Google Chrome Frame"); | 462 profile_path = profile_path.Append(L"Google Chrome Frame"); |
| 463 } else { | 463 } else { |
| 464 GetChromeFrameProfilePath(kIEProfileName, &profile_path); | 464 GetChromeFrameProfilePath(kIEProfileName, &profile_path); |
| 465 } | 465 } |
| 466 return profile_path; | 466 return profile_path; |
| 467 } | 467 } |
| 468 | 468 |
| 469 FilePath GetTestDataFolder() { | 469 base::FilePath GetTestDataFolder() { |
| 470 FilePath test_dir; | 470 base::FilePath test_dir; |
| 471 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir); | 471 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir); |
| 472 test_dir = test_dir.Append(FILE_PATH_LITERAL("chrome_frame")) | 472 test_dir = test_dir.Append(FILE_PATH_LITERAL("chrome_frame")) |
| 473 .Append(FILE_PATH_LITERAL("test")) | 473 .Append(FILE_PATH_LITERAL("test")) |
| 474 .Append(FILE_PATH_LITERAL("data")); | 474 .Append(FILE_PATH_LITERAL("data")); |
| 475 return test_dir; | 475 return test_dir; |
| 476 } | 476 } |
| 477 | 477 |
| 478 FilePath GetSeleniumTestFolder() { | 478 base::FilePath GetSeleniumTestFolder() { |
| 479 FilePath test_dir; | 479 base::FilePath test_dir; |
| 480 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir); | 480 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir); |
| 481 test_dir = test_dir.Append(FILE_PATH_LITERAL("data")) | 481 test_dir = test_dir.Append(FILE_PATH_LITERAL("data")) |
| 482 .Append(FILE_PATH_LITERAL("selenium_core")); | 482 .Append(FILE_PATH_LITERAL("selenium_core")); |
| 483 return test_dir; | 483 return test_dir; |
| 484 } | 484 } |
| 485 | 485 |
| 486 std::wstring GetPathFromUrl(const std::wstring& url) { | 486 std::wstring GetPathFromUrl(const std::wstring& url) { |
| 487 string16 url16 = WideToUTF16(url); | 487 string16 url16 = WideToUTF16(url); |
| 488 GURL gurl = GURL(url16); | 488 GURL gurl = GURL(url16); |
| 489 if (gurl.has_query()) { | 489 if (gurl.has_query()) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 } | 595 } |
| 596 } | 596 } |
| 597 | 597 |
| 598 base::ProcessHandle StartCrashService() { | 598 base::ProcessHandle StartCrashService() { |
| 599 if (DetectRunningCrashService(kCrashServiceStartupTimeoutMs)) { | 599 if (DetectRunningCrashService(kCrashServiceStartupTimeoutMs)) { |
| 600 VLOG(1) << "crash_service.exe is already running. We will use the " | 600 VLOG(1) << "crash_service.exe is already running. We will use the " |
| 601 "existing process and leave it running after tests complete."; | 601 "existing process and leave it running after tests complete."; |
| 602 return NULL; | 602 return NULL; |
| 603 } | 603 } |
| 604 | 604 |
| 605 FilePath exe_dir; | 605 base::FilePath exe_dir; |
| 606 if (!PathService::Get(base::DIR_EXE, &exe_dir)) { | 606 if (!PathService::Get(base::DIR_EXE, &exe_dir)) { |
| 607 DCHECK(false); | 607 DCHECK(false); |
| 608 return NULL; | 608 return NULL; |
| 609 } | 609 } |
| 610 | 610 |
| 611 base::ProcessHandle crash_service = NULL; | 611 base::ProcessHandle crash_service = NULL; |
| 612 | 612 |
| 613 VLOG(1) << "Starting crash_service.exe so you know if a test crashes!"; | 613 VLOG(1) << "Starting crash_service.exe so you know if a test crashes!"; |
| 614 | 614 |
| 615 FilePath crash_service_path = exe_dir.AppendASCII("crash_service.exe"); | 615 base::FilePath crash_service_path = exe_dir.AppendASCII("crash_service.exe"); |
| 616 if (!base::LaunchProcess(crash_service_path.value(), base::LaunchOptions(), | 616 if (!base::LaunchProcess(crash_service_path.value(), base::LaunchOptions(), |
| 617 &crash_service)) { | 617 &crash_service)) { |
| 618 LOG(ERROR) << "Couldn't start crash_service.exe"; | 618 LOG(ERROR) << "Couldn't start crash_service.exe"; |
| 619 return NULL; | 619 return NULL; |
| 620 } | 620 } |
| 621 | 621 |
| 622 base::Time start = base::Time::Now(); | 622 base::Time start = base::Time::Now(); |
| 623 | 623 |
| 624 if (DetectRunningCrashService(kCrashServiceStartupTimeoutMs)) { | 624 if (DetectRunningCrashService(kCrashServiceStartupTimeoutMs)) { |
| 625 VLOG(1) << "crash_service.exe is ready for clients in " | 625 VLOG(1) << "crash_service.exe is ready for clients in " |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 | 663 |
| 664 ScopedChromeFrameRegistrar::RegistrationType GetTestBedType() { | 664 ScopedChromeFrameRegistrar::RegistrationType GetTestBedType() { |
| 665 if (GetConfigBool(false, L"PerUserTestBed")) { | 665 if (GetConfigBool(false, L"PerUserTestBed")) { |
| 666 return ScopedChromeFrameRegistrar::PER_USER; | 666 return ScopedChromeFrameRegistrar::PER_USER; |
| 667 } else { | 667 } else { |
| 668 return ScopedChromeFrameRegistrar::SYSTEM_LEVEL; | 668 return ScopedChromeFrameRegistrar::SYSTEM_LEVEL; |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 | 671 |
| 672 void ClearIESessionHistory() { | 672 void ClearIESessionHistory() { |
| 673 FilePath session_history_path; | 673 base::FilePath session_history_path; |
| 674 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, &session_history_path)) | 674 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, &session_history_path)) |
| 675 return; | 675 return; |
| 676 | 676 |
| 677 session_history_path = session_history_path.AppendASCII("Microsoft"); | 677 session_history_path = session_history_path.AppendASCII("Microsoft"); |
| 678 session_history_path = session_history_path.AppendASCII("Internet Explorer"); | 678 session_history_path = session_history_path.AppendASCII("Internet Explorer"); |
| 679 session_history_path = session_history_path.AppendASCII("Recovery"); | 679 session_history_path = session_history_path.AppendASCII("Recovery"); |
| 680 file_util::Delete(session_history_path, true); | 680 file_util::Delete(session_history_path, true); |
| 681 } | 681 } |
| 682 | 682 |
| 683 std::string GetLocalIPv4Address() { | 683 std::string GetLocalIPv4Address() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 708 if (address.empty()) { | 708 if (address.empty()) { |
| 709 LOG(ERROR) << "Failed to find a non-loopback IP_V4 address. Tests will be " | 709 LOG(ERROR) << "Failed to find a non-loopback IP_V4 address. Tests will be " |
| 710 << "run over the loopback adapter, which may result in hangs."; | 710 << "run over the loopback adapter, which may result in hangs."; |
| 711 address.assign("127.0.0.1"); | 711 address.assign("127.0.0.1"); |
| 712 } | 712 } |
| 713 | 713 |
| 714 return address; | 714 return address; |
| 715 } | 715 } |
| 716 | 716 |
| 717 } // namespace chrome_frame_test | 717 } // namespace chrome_frame_test |
| OLD | NEW |