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