| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 13 matching lines...) Expand all Loading... |
| 24 #include "base/win/scoped_handle.h" | 24 #include "base/win/scoped_handle.h" |
| 25 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
| 26 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_paths_internal.h" | 27 #include "chrome/common/chrome_paths_internal.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome_frame/utils.h" | 29 #include "chrome_frame/utils.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "ui/base/clipboard/clipboard.h" | 31 #include "ui/base/clipboard/clipboard.h" |
| 32 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 32 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 33 | 33 |
| 34 using registry_util::ScopedRegistryKeyOverride; |
| 35 |
| 34 namespace chrome_frame_test { | 36 namespace chrome_frame_test { |
| 35 | 37 |
| 36 const wchar_t kCrashServicePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; | 38 const wchar_t kCrashServicePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; |
| 37 | 39 |
| 38 const DWORD kCrashServicePipeDesiredAccess = FILE_READ_DATA | | 40 const DWORD kCrashServicePipeDesiredAccess = FILE_READ_DATA | |
| 39 FILE_WRITE_DATA | | 41 FILE_WRITE_DATA | |
| 40 FILE_WRITE_ATTRIBUTES; | 42 FILE_WRITE_ATTRIBUTES; |
| 41 | 43 |
| 42 const DWORD kCrashServicePipeFlagsAndAttributes = SECURITY_IDENTIFICATION | | 44 const DWORD kCrashServicePipeFlagsAndAttributes = SECURITY_IDENTIFICATION | |
| 43 SECURITY_SQOS_PRESENT; | 45 SECURITY_SQOS_PRESENT; |
| 44 const int kCrashServiceStartupTimeoutMs = 500; | 46 const int kCrashServiceStartupTimeoutMs = 500; |
| 45 | 47 |
| 46 const wchar_t kIEImageName[] = L"iexplore.exe"; | 48 const wchar_t kIEImageName[] = L"iexplore.exe"; |
| 47 const wchar_t kIEBrokerImageName[] = L"ieuser.exe"; | 49 const wchar_t kIEBrokerImageName[] = L"ieuser.exe"; |
| 48 const char kChromeImageName[] = "chrome.exe"; | 50 const char kChromeImageName[] = "chrome.exe"; |
| 49 const wchar_t kIEProfileName[] = L"iexplore"; | 51 const wchar_t kIEProfileName[] = L"iexplore"; |
| 50 const wchar_t kChromeLauncher[] = L"chrome_launcher.exe"; | 52 const wchar_t kChromeLauncher[] = L"chrome_launcher.exe"; |
| 51 const int kChromeFrameLongNavigationTimeoutInSeconds = 10; | 53 const int kChromeFrameLongNavigationTimeoutInSeconds = 10; |
| 52 const int kChromeFrameVeryLongNavigationTimeoutInSeconds = 30; | 54 const int kChromeFrameVeryLongNavigationTimeoutInSeconds = 30; |
| 53 | 55 |
| 54 const wchar_t TempRegKeyOverride::kTempTestKeyPath[] = | |
| 55 L"Software\\Chromium\\TempTestKeys"; | |
| 56 | |
| 57 // Callback function for EnumThreadWindows. | 56 // Callback function for EnumThreadWindows. |
| 58 BOOL CALLBACK CloseWindowsThreadCallback(HWND hwnd, LPARAM param) { | 57 BOOL CALLBACK CloseWindowsThreadCallback(HWND hwnd, LPARAM param) { |
| 59 int& count = *reinterpret_cast<int*>(param); | 58 int& count = *reinterpret_cast<int*>(param); |
| 60 if (IsWindowVisible(hwnd)) { | 59 if (IsWindowVisible(hwnd)) { |
| 61 if (IsWindowEnabled(hwnd)) { | 60 if (IsWindowEnabled(hwnd)) { |
| 62 DWORD results = 0; | 61 DWORD results = 0; |
| 63 if (!::SendMessageTimeout(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0, SMTO_BLOCK, | 62 if (!::SendMessageTimeout(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0, SMTO_BLOCK, |
| 64 10000, &results)) { | 63 10000, &results)) { |
| 65 LOG(WARNING) << "Window hung: " << base::StringPrintf(L"%08X", hwnd); | 64 LOG(WARNING) << "Window hung: " << base::StringPrintf(L"%08X", hwnd); |
| 66 } | 65 } |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 608 |
| 610 // First check to see if it's even still running just to minimize the | 609 // First check to see if it's even still running just to minimize the |
| 611 // likelihood of spurious error messages from KillProcess. | 610 // likelihood of spurious error messages from KillProcess. |
| 612 if (WAIT_OBJECT_0 != ::WaitForSingleObject(crash_service, 0)) { | 611 if (WAIT_OBJECT_0 != ::WaitForSingleObject(crash_service, 0)) { |
| 613 base::KillProcess(crash_service, 0, false); | 612 base::KillProcess(crash_service, 0, false); |
| 614 } | 613 } |
| 615 return NULL; | 614 return NULL; |
| 616 } | 615 } |
| 617 } | 616 } |
| 618 | 617 |
| 619 TempRegKeyOverride::TempRegKeyOverride(HKEY override, const wchar_t* temp_name) | |
| 620 : override_(override), temp_name_(temp_name) { | |
| 621 DCHECK(temp_name && lstrlenW(temp_name)); | |
| 622 std::wstring key_path(kTempTestKeyPath); | |
| 623 key_path += L"\\" + temp_name_; | |
| 624 EXPECT_EQ(ERROR_SUCCESS, temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(), | |
| 625 KEY_ALL_ACCESS)); | |
| 626 EXPECT_EQ(ERROR_SUCCESS, | |
| 627 ::RegOverridePredefKey(override_, temp_key_.Handle())); | |
| 628 } | |
| 629 | |
| 630 TempRegKeyOverride::~TempRegKeyOverride() { | |
| 631 ::RegOverridePredefKey(override_, NULL); | |
| 632 // The temp key will be deleted via a call to DeleteAllTempKeys(). | |
| 633 } | |
| 634 | |
| 635 // static | |
| 636 void TempRegKeyOverride::DeleteAllTempKeys() { | |
| 637 base::win::RegKey key; | |
| 638 if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS) == ERROR_SUCCESS) { | |
| 639 key.DeleteKey(kTempTestKeyPath); | |
| 640 } | |
| 641 } | |
| 642 | |
| 643 ScopedVirtualizeHklmAndHkcu::ScopedVirtualizeHklmAndHkcu() { | 618 ScopedVirtualizeHklmAndHkcu::ScopedVirtualizeHklmAndHkcu() { |
| 644 TempRegKeyOverride::DeleteAllTempKeys(); | 619 ScopedRegistryKeyOverride::DeleteAllTempKeys(); |
| 645 hklm_.reset(new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_fake")); | 620 hklm_.reset(new ScopedRegistryKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_fake")); |
| 646 hkcu_.reset(new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_fake")); | 621 hkcu_.reset(new ScopedRegistryKeyOverride(HKEY_CURRENT_USER, L"hkcu_fake")); |
| 647 } | 622 } |
| 648 | 623 |
| 649 ScopedVirtualizeHklmAndHkcu::~ScopedVirtualizeHklmAndHkcu() { | 624 ScopedVirtualizeHklmAndHkcu::~ScopedVirtualizeHklmAndHkcu() { |
| 650 hkcu_.reset(NULL); | 625 hkcu_.reset(NULL); |
| 651 hklm_.reset(NULL); | 626 hklm_.reset(NULL); |
| 652 TempRegKeyOverride::DeleteAllTempKeys(); | 627 ScopedRegistryKeyOverride::DeleteAllTempKeys(); |
| 653 } | 628 } |
| 654 | 629 |
| 655 bool KillProcesses(const std::wstring& executable_name, int exit_code, | 630 bool KillProcesses(const std::wstring& executable_name, int exit_code, |
| 656 bool wait) { | 631 bool wait) { |
| 657 bool result = true; | 632 bool result = true; |
| 658 base::NamedProcessIterator iter(executable_name, NULL); | 633 base::NamedProcessIterator iter(executable_name, NULL); |
| 659 while (const base::ProcessEntry* entry = iter.NextProcessEntry()) { | 634 while (const base::ProcessEntry* entry = iter.NextProcessEntry()) { |
| 660 result &= base::KillProcessById(entry->pid(), exit_code, wait); | 635 result &= base::KillProcessById(entry->pid(), exit_code, wait); |
| 661 } | 636 } |
| 662 return result; | 637 return result; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 674 wchar_t local_app_data_path[MAX_PATH + 1] = {0}; | 649 wchar_t local_app_data_path[MAX_PATH + 1] = {0}; |
| 675 SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, | 650 SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, |
| 676 local_app_data_path); | 651 local_app_data_path); |
| 677 | 652 |
| 678 std::wstring session_history_path = local_app_data_path; | 653 std::wstring session_history_path = local_app_data_path; |
| 679 session_history_path += L"\\Microsoft\\Internet Explorer\\Recovery"; | 654 session_history_path += L"\\Microsoft\\Internet Explorer\\Recovery"; |
| 680 file_util::Delete(session_history_path, true); | 655 file_util::Delete(session_history_path, true); |
| 681 } | 656 } |
| 682 | 657 |
| 683 } // namespace chrome_frame_test | 658 } // namespace chrome_frame_test |
| OLD | NEW |