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-chrome"); |
| 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()); |
| 358 |
| 359 // Test the converse (binaries are stable, Chrome is other). |
| 360 SetMultiApField(USER_INSTALL, L"-multi-chrome"); |
| 361 SetApField(USER_INSTALL, L"2.0-dev-multi-chrome"); |
| 362 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers(false, |
| 363 &channel)); |
| 364 EXPECT_STREQ(L"m", channel.c_str()); |
| 365 } |
| 366 |
313 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { | 367 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { |
314 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); | 368 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); |
315 } | 369 } |
316 | 370 |
317 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { | 371 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { |
318 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); | 372 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); |
319 } | 373 } |
320 | 374 |
321 // Run through all combinations of diff vs. full install, single vs. multi | 375 // 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 | 376 // 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, | 1223 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1170 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 1224 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), |
1171 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1225 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1172 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 1226 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), |
1173 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1227 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1174 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 1228 StatsState::TRUE_SETTING, StatsState::NO_SETTING), |
1175 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1229 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1176 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 1230 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), |
1177 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 1231 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
1178 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | 1232 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); |
OLD | NEW |