| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shlwapi.h> // For SHDeleteKey. | 6 #include <shlwapi.h> // For SHDeleteKey. |
| 7 | 7 |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 virtual void SetUp() { | 38 virtual void SetUp() { |
| 39 // Wipe the keys we redirect to. | 39 // Wipe the keys we redirect to. |
| 40 // This gives us a stable run, even in the presence of previous | 40 // This gives us a stable run, even in the presence of previous |
| 41 // crashes or failures. | 41 // crashes or failures. |
| 42 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kHKCUReplacement); | 42 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kHKCUReplacement); |
| 43 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); | 43 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); |
| 44 err = SHDeleteKey(HKEY_CURRENT_USER, kHKLMReplacement); | 44 err = SHDeleteKey(HKEY_CURRENT_USER, kHKLMReplacement); |
| 45 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); | 45 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); |
| 46 | 46 |
| 47 // Create the keys we're redirecting HKCU and HKLM to. | 47 // Create the keys we're redirecting HKCU and HKLM to. |
| 48 ASSERT_TRUE(hkcu_.Create(HKEY_CURRENT_USER, kHKCUReplacement, KEY_READ)); | 48 ASSERT_EQ(ERROR_SUCCESS, |
| 49 ASSERT_TRUE(hklm_.Create(HKEY_CURRENT_USER, kHKLMReplacement, KEY_READ)); | 49 hkcu_.Create(HKEY_CURRENT_USER, kHKCUReplacement, KEY_READ)); |
| 50 ASSERT_EQ(ERROR_SUCCESS, |
| 51 hklm_.Create(HKEY_CURRENT_USER, kHKLMReplacement, KEY_READ)); |
| 50 | 52 |
| 51 // And do the switcharoo. | 53 // And do the switcharoo. |
| 52 ASSERT_EQ(ERROR_SUCCESS, | 54 ASSERT_EQ(ERROR_SUCCESS, |
| 53 ::RegOverridePredefKey(HKEY_CURRENT_USER, hkcu_.Handle())); | 55 ::RegOverridePredefKey(HKEY_CURRENT_USER, hkcu_.Handle())); |
| 54 ASSERT_EQ(ERROR_SUCCESS, | 56 ASSERT_EQ(ERROR_SUCCESS, |
| 55 ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, hklm_.Handle())); | 57 ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, hklm_.Handle())); |
| 56 } | 58 } |
| 57 | 59 |
| 58 virtual void TearDown() { | 60 virtual void TearDown() { |
| 59 // Undo the redirection. | 61 // Undo the redirection. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 72 USER_INSTALL, | 74 USER_INSTALL, |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 void SetApField(SystemUserInstall is_system, const wchar_t* value) { | 77 void SetApField(SystemUserInstall is_system, const wchar_t* value) { |
| 76 HKEY root = is_system == SYSTEM_INSTALL ? | 78 HKEY root = is_system == SYSTEM_INSTALL ? |
| 77 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 79 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 78 | 80 |
| 79 RegKey update_key; | 81 RegKey update_key; |
| 80 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 82 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 81 std::wstring path = dist->GetStateKey(); | 83 std::wstring path = dist->GetStateKey(); |
| 82 ASSERT_TRUE(update_key.Create(root, path.c_str(), KEY_WRITE)); | 84 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), KEY_WRITE)); |
| 83 ASSERT_TRUE(update_key.WriteValue(L"ap", value)); | 85 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); |
| 84 } | 86 } |
| 85 | 87 |
| 86 // Tests setting the ap= value to various combinations of values with | 88 // Tests setting the ap= value to various combinations of values with |
| 87 // prefixes and suffixes, while asserting on the correct channel value. | 89 // prefixes and suffixes, while asserting on the correct channel value. |
| 88 // Note that any non-empty ap= value that doesn't match ".*-{dev|beta}.*" | 90 // Note that any non-empty ap= value that doesn't match ".*-{dev|beta}.*" |
| 89 // will return the "unknown" channel. | 91 // will return the "unknown" channel. |
| 90 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { | 92 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { |
| 91 static struct Expectations { | 93 static struct Expectations { |
| 92 const wchar_t* ap_value; | 94 const wchar_t* ap_value; |
| 93 const wchar_t* channel; | 95 const wchar_t* channel; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 reg_key.append(L"\\"); | 156 reg_key.append(L"\\"); |
| 155 reg_key.append(kTestProductGuid); | 157 reg_key.append(kTestProductGuid); |
| 156 return reg_key; | 158 return reg_key; |
| 157 } | 159 } |
| 158 | 160 |
| 159 // Utility method to read "ap" key value | 161 // Utility method to read "ap" key value |
| 160 std::wstring ReadApKeyValue() { | 162 std::wstring ReadApKeyValue() { |
| 161 RegKey key; | 163 RegKey key; |
| 162 std::wstring ap_key_value; | 164 std::wstring ap_key_value; |
| 163 std::wstring reg_key = GetApKeyPath(); | 165 std::wstring reg_key = GetApKeyPath(); |
| 164 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) && | 166 LONG result = key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS); |
| 165 key.ReadValue(google_update::kRegApField, &ap_key_value)) { | 167 if (result == ERROR_SUCCESS) { |
| 166 return ap_key_value; | 168 key.ReadValue(google_update::kRegApField, &ap_key_value); |
| 167 } | 169 } |
| 168 return std::wstring(); | 170 |
| 171 return ap_key_value; |
| 169 } | 172 } |
| 170 | 173 |
| 171 RegKey hkcu_; | 174 RegKey hkcu_; |
| 172 RegKey hklm_; | 175 RegKey hklm_; |
| 173 }; | 176 }; |
| 174 | 177 |
| 175 } // namespace | 178 } // namespace |
| 176 | 179 |
| 177 // Verify that we return failure on no registration, | 180 // Verify that we return failure on no registration, |
| 178 // whether per-system or per-user install. | 181 // whether per-system or per-user install. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_STREQ(ReadApKeyValue().c_str(), L""); | 367 EXPECT_STREQ(ReadApKeyValue().c_str(), L""); |
| 365 work_item_list->Rollback(); | 368 work_item_list->Rollback(); |
| 366 | 369 |
| 367 work_item_list.reset(WorkItem::CreateWorkItemList()); | 370 work_item_list.reset(WorkItem::CreateWorkItemList()); |
| 368 // Test the case of when "ap" key doesnt exist at all | 371 // Test the case of when "ap" key doesnt exist at all |
| 369 std::wstring ap_key_value = ReadApKeyValue(); | 372 std::wstring ap_key_value = ReadApKeyValue(); |
| 370 std::wstring reg_key = GetApKeyPath(); | 373 std::wstring reg_key = GetApKeyPath(); |
| 371 HKEY reg_root = HKEY_CURRENT_USER; | 374 HKEY reg_root = HKEY_CURRENT_USER; |
| 372 bool ap_key_deleted = false; | 375 bool ap_key_deleted = false; |
| 373 RegKey key; | 376 RegKey key; |
| 374 if (!key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS)) { | 377 LONG result = key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS); |
| 378 if (result != ERROR_SUCCESS) { |
| 375 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key); | 379 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key); |
| 376 ASSERT_TRUE(work_item_list->Do()) << "Failed to create ClientState key."; | 380 ASSERT_TRUE(work_item_list->Do()) << "Failed to create ClientState key."; |
| 377 } else if (key.DeleteValue(google_update::kRegApField)) { | 381 } else if (key.DeleteValue(google_update::kRegApField) == ERROR_SUCCESS) { |
| 378 ap_key_deleted = true; | 382 ap_key_deleted = true; |
| 379 } | 383 } |
| 380 // try differential installer | 384 // try differential installer |
| 381 GoogleUpdateSettings::UpdateDiffInstallStatus(false, true, | 385 GoogleUpdateSettings::UpdateDiffInstallStatus(false, true, |
| 382 installer::INSTALL_FAILED, | 386 installer::INSTALL_FAILED, |
| 383 kTestProductGuid); | 387 kTestProductGuid); |
| 384 EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full"); | 388 EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full"); |
| 385 // try full installer now | 389 // try full installer now |
| 386 GoogleUpdateSettings::UpdateDiffInstallStatus(false, false, | 390 GoogleUpdateSettings::UpdateDiffInstallStatus(false, false, |
| 387 installer::INSTALL_FAILED, | 391 installer::INSTALL_FAILED, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 415 scoped_refptr<installer::Package> package( | 419 scoped_refptr<installer::Package> package( |
| 416 new installer::Package(multi_install, system_level, FilePath(), | 420 new installer::Package(multi_install, system_level, FilePath(), |
| 417 &properties)); | 421 &properties)); |
| 418 scoped_refptr<installer::Product> product( | 422 scoped_refptr<installer::Product> product( |
| 419 new installer::Product(distribution, package.get())); | 423 new installer::Product(distribution, package.get())); |
| 420 RegKey key; | 424 RegKey key; |
| 421 DWORD value; | 425 DWORD value; |
| 422 | 426 |
| 423 // By default, eulaconsent ends up on the package. | 427 // By default, eulaconsent ends up on the package. |
| 424 EXPECT_TRUE(GoogleUpdateSettings::SetEULAConsent(*package.get(), true)); | 428 EXPECT_TRUE(GoogleUpdateSettings::SetEULAConsent(*package.get(), true)); |
| 425 EXPECT_TRUE(key.Open(HKEY_LOCAL_MACHINE, | 429 EXPECT_EQ(ERROR_SUCCESS, |
| 426 properties.GetStateMediumKey().c_str(), | 430 key.Open(HKEY_LOCAL_MACHINE, properties.GetStateMediumKey().c_str(), |
| 427 KEY_QUERY_VALUE | KEY_SET_VALUE)); | 431 KEY_QUERY_VALUE | KEY_SET_VALUE)); |
| 428 EXPECT_TRUE(key.ReadValueDW(google_update::kRegEULAAceptedField, &value)); | 432 EXPECT_EQ(ERROR_SUCCESS, |
| 433 key.ReadValueDW(google_update::kRegEULAAceptedField, &value)); |
| 429 EXPECT_EQ(1U, value); | 434 EXPECT_EQ(1U, value); |
| 430 EXPECT_TRUE(key.DeleteValue(google_update::kRegEULAAceptedField)); | 435 EXPECT_EQ(ERROR_SUCCESS, |
| 436 key.DeleteValue(google_update::kRegEULAAceptedField)); |
| 431 | 437 |
| 432 // But it will end up on the product if needed | 438 // But it will end up on the product if needed |
| 433 EXPECT_TRUE(key.Create(HKEY_LOCAL_MACHINE, | 439 EXPECT_EQ(ERROR_SUCCESS, |
| 434 distribution->GetStateKey().c_str(), KEY_SET_VALUE)); | 440 key.Create(HKEY_LOCAL_MACHINE, distribution->GetStateKey().c_str(), |
| 435 EXPECT_TRUE(key.WriteValue(google_update::kRegEULAAceptedField, | 441 KEY_SET_VALUE)); |
| 436 static_cast<DWORD>(0))); | 442 EXPECT_EQ(ERROR_SUCCESS, |
| 443 key.WriteValue(google_update::kRegEULAAceptedField, |
| 444 static_cast<DWORD>(0))); |
| 437 EXPECT_TRUE(GoogleUpdateSettings::SetEULAConsent(*package.get(), true)); | 445 EXPECT_TRUE(GoogleUpdateSettings::SetEULAConsent(*package.get(), true)); |
| 438 EXPECT_TRUE(key.Open(HKEY_LOCAL_MACHINE, | 446 EXPECT_EQ(ERROR_SUCCESS, |
| 439 distribution->GetStateMediumKey().c_str(), | 447 key.Open(HKEY_LOCAL_MACHINE, distribution->GetStateMediumKey().c_str(), |
| 440 KEY_QUERY_VALUE | KEY_SET_VALUE)); | 448 KEY_QUERY_VALUE | KEY_SET_VALUE)); |
| 441 EXPECT_TRUE(key.ReadValueDW(google_update::kRegEULAAceptedField, &value)); | 449 EXPECT_EQ(ERROR_SUCCESS, |
| 450 key.ReadValueDW(google_update::kRegEULAAceptedField, &value)); |
| 442 EXPECT_EQ(1U, value); | 451 EXPECT_EQ(1U, value); |
| 443 } | 452 } |
| OLD | NEW |