Chromium Code Reviews| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shlwapi.h> // For SHDeleteKey. | 6 #include <shlwapi.h> // For SHDeleteKey. |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/test_reg_util_win.h" | 10 #include "base/test/test_reg_util_win.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 HKEY root = is_system == SYSTEM_INSTALL ? | 47 HKEY root = is_system == SYSTEM_INSTALL ? |
| 48 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 48 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 49 | 49 |
| 50 RegKey update_key; | 50 RegKey update_key; |
| 51 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 51 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 52 std::wstring path = dist->GetStateKey(); | 52 std::wstring path = dist->GetStateKey(); |
| 53 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), KEY_WRITE)); | 53 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), KEY_WRITE)); |
| 54 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); | 54 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Sets the "ap" field for a multi-install product (both the product and | |
| 58 // the binaries). | |
| 59 void SetMultiApField(SystemUserInstall is_system, const wchar_t* value) { | |
| 60 // Caller must specify a multi-install ap value. | |
| 61 ASSERT_NE(std::wstring::npos, std::wstring(value).find(L"-multi")); | |
| 62 HKEY root = is_system == SYSTEM_INSTALL ? | |
| 63 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
| 64 RegKey update_key; | |
| 65 | |
| 66 // Write the ap value for both the product and the binaries. | |
| 67 BrowserDistribution* const kDists[] = { | |
| 68 BrowserDistribution::GetDistribution(), | |
| 69 BrowserDistribution::GetSpecificDistribution( | |
| 70 BrowserDistribution::CHROME_BINARIES) | |
| 71 }; | |
| 72 for (size_t i = 0; i < arraysize(kDists); ++i) { | |
| 73 std::wstring path = kDists[i]->GetStateKey(); | |
| 74 ASSERT_EQ(ERROR_SUCCESS, update_key.Create(root, path.c_str(), | |
| 75 KEY_WRITE)); | |
| 76 ASSERT_EQ(ERROR_SUCCESS, update_key.WriteValue(L"ap", value)); | |
| 77 } | |
| 78 | |
| 79 // Make the product technically multi-install. | |
| 80 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 81 ASSERT_EQ(ERROR_SUCCESS, | |
| 82 update_key.Create(root, dist->GetStateKey().c_str(), KEY_WRITE)); | |
| 83 ASSERT_EQ(ERROR_SUCCESS, | |
| 84 update_key.WriteValue(installer::kUninstallArgumentsField, | |
| 85 L"--multi-install")); | |
| 86 } | |
| 87 | |
| 57 // Tests setting the ap= value to various combinations of values with | 88 // Tests setting the ap= value to various combinations of values with |
| 58 // prefixes and suffixes, while asserting on the correct channel value. | 89 // prefixes and suffixes, while asserting on the correct channel value. |
| 59 // 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}.*" |
| 60 // will return the "unknown" channel. | 91 // will return the "unknown" channel. |
| 61 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { | 92 void TestCurrentChromeChannelWithVariousApValues(SystemUserInstall install) { |
| 62 static struct Expectations { | 93 static struct Expectations { |
| 63 const wchar_t* ap_value; | 94 const wchar_t* ap_value; |
| 64 const wchar_t* channel; | 95 const wchar_t* channel; |
| 65 } expectations[] = { | 96 } expectations[] = { |
| 66 { L"dev", installer::kChromeChannelDev }, | 97 { L"dev", installer::kChromeChannelDev }, |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, | 334 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(true, |
| 304 &channel)); | 335 &channel)); |
| 305 EXPECT_STREQ(L"", channel.c_str()); | 336 EXPECT_STREQ(L"", channel.c_str()); |
| 306 | 337 |
| 307 // Per-user lookup should succeed. | 338 // Per-user lookup should succeed. |
| 308 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | 339 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, |
| 309 &channel)); | 340 &channel)); |
| 310 EXPECT_STREQ(L"", channel.c_str()); | 341 EXPECT_STREQ(L"", channel.c_str()); |
| 311 } | 342 } |
| 312 | 343 |
| 344 // Test that the channel is pulled from the binaries for multi-install products. | |
| 345 TEST_F(GoogleUpdateSettingsTest, MultiInstallChannelFromBinaries) { | |
| 346 SetMultiApField(USER_INSTALL, L"2.0-dev-multi"); | |
| 347 base::string16 channel; | |
| 348 | |
| 349 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | |
| 350 &channel)); | |
| 351 EXPECT_STREQ(L"dev-m", channel.c_str()); | |
| 352 | |
| 353 // See if the same happens if the product's ap is cleared. | |
| 354 SetApField(USER_INSTALL, L""); | |
| 355 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, | |
| 356 &channel)); | |
| 357 EXPECT_STREQ(L"dev-m", channel.c_str()); | |
|
robertshield
2014/06/04 21:10:14
optional: test also that a non-empty value for the
grt (UTC plus 2)
2014/06/04 21:15:36
Done.
| |
| 358 } | |
| 359 | |
| 313 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { | 360 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { |
| 314 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); | 361 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); |
| 315 } | 362 } |
| 316 | 363 |
| 317 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { | 364 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { |
| 318 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); | 365 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); |
| 319 } | 366 } |
| 320 | 367 |
| 321 // Run through all combinations of diff vs. full install, single vs. multi | 368 // Run through all combinations of diff vs. full install, single vs. multi |
| 322 // install, success and failure results, and a fistful of initial "ap" values | 369 // install, success and failure results, and a fistful of initial "ap" values |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1216 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1170 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 1217 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), |
| 1171 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1218 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1172 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 1219 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), |
| 1173 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1220 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1174 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 1221 StatsState::TRUE_SETTING, StatsState::NO_SETTING), |
| 1175 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1222 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1176 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 1223 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), |
| 1177 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1224 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
| 1178 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | 1225 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); |
| OLD | NEW |