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/test/test_reg_util_win.h" | 9 #include "base/test/test_reg_util_win.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const wchar_t kGoogleUpdateUpdateDefault[] = L"UpdateDefault"; | 29 const wchar_t kGoogleUpdateUpdateDefault[] = L"UpdateDefault"; |
30 const wchar_t kGoogleUpdateUpdatePrefix[] = L"Update"; | 30 const wchar_t kGoogleUpdateUpdatePrefix[] = L"Update"; |
31 const GoogleUpdateSettings::UpdatePolicy kDefaultUpdatePolicy = | 31 const GoogleUpdateSettings::UpdatePolicy kDefaultUpdatePolicy = |
32 #if defined(GOOGLE_CHROME_BUILD) | 32 #if defined(GOOGLE_CHROME_BUILD) |
33 GoogleUpdateSettings::AUTOMATIC_UPDATES; | 33 GoogleUpdateSettings::AUTOMATIC_UPDATES; |
34 #else | 34 #else |
35 GoogleUpdateSettings::UPDATES_DISABLED; | 35 GoogleUpdateSettings::UPDATES_DISABLED; |
36 #endif | 36 #endif |
37 | 37 |
38 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; | 38 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}"; |
| 39 const wchar_t kTestExperimentLabel[] = L"test_label_value"; |
39 | 40 |
40 // This test fixture redirects the HKLM and HKCU registry hives for | 41 // This test fixture redirects the HKLM and HKCU registry hives for |
41 // the duration of the test to make it independent of the machine | 42 // the duration of the test to make it independent of the machine |
42 // and user settings. | 43 // and user settings. |
43 class GoogleUpdateSettingsTest: public testing::Test { | 44 class GoogleUpdateSettingsTest : public testing::Test { |
44 protected: | 45 protected: |
45 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
46 registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE, L"HKLM_pit"); | 47 registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE, L"HKLM_pit"); |
47 registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER, L"HKCU_pit"); | 48 registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER, L"HKCU_pit"); |
48 } | 49 } |
49 | 50 |
50 enum SystemUserInstall { | 51 enum SystemUserInstall { |
51 SYSTEM_INSTALL, | 52 SYSTEM_INSTALL, |
52 USER_INSTALL, | 53 USER_INSTALL, |
53 }; | 54 }; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( | 106 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannelAndModifiers( |
106 is_system, &ret_channel)); | 107 is_system, &ret_channel)); |
107 EXPECT_STREQ(channel, ret_channel.c_str()) | 108 EXPECT_STREQ(channel, ret_channel.c_str()) |
108 << "Expecting channel \"" << channel | 109 << "Expecting channel \"" << channel |
109 << "\" for ap=\"" << ap << "\""; | 110 << "\" for ap=\"" << ap << "\""; |
110 } | 111 } |
111 } | 112 } |
112 } | 113 } |
113 } | 114 } |
114 | 115 |
| 116 // Test the writing and deleting functionality of the experiments label |
| 117 // helper. |
| 118 void TestExperimentsLabelHelper(SystemUserInstall install) { |
| 119 BrowserDistribution* chrome = |
| 120 BrowserDistribution::GetSpecificDistribution( |
| 121 BrowserDistribution::CHROME_BROWSER); |
| 122 #if defined(GOOGLE_CHROME_BUILD) |
| 123 EXPECT_TRUE(chrome->ShouldSetExperimentLabels()); |
| 124 |
| 125 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( |
| 126 install == SYSTEM_INSTALL, kTestExperimentLabel)); |
| 127 |
| 128 // Validate that something is written. Only worry about the label itself. |
| 129 RegKey key; |
| 130 std::wstring value; |
| 131 HKEY root = install == SYSTEM_INSTALL ? |
| 132 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 133 string16 state_key = install == SYSTEM_INSTALL ? |
| 134 chrome->GetStateMediumKey() : chrome->GetStateKey(); |
| 135 |
| 136 EXPECT_EQ(ERROR_SUCCESS, |
| 137 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); |
| 138 EXPECT_EQ(ERROR_SUCCESS, |
| 139 key.ReadValue(google_update::kExperimentLabels, &value)); |
| 140 EXPECT_EQ(kTestExperimentLabel, value); |
| 141 key.Close(); |
| 142 |
| 143 // Now that the label is set, test the delete functionality. An empty label |
| 144 // should result in deleting the value. |
| 145 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels( |
| 146 install == SYSTEM_INSTALL, string16())); |
| 147 EXPECT_EQ(ERROR_SUCCESS, |
| 148 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE)); |
| 149 EXPECT_EQ(ERROR_FILE_NOT_FOUND, |
| 150 key.ReadValue(google_update::kExperimentLabels, &value)); |
| 151 key.Close(); |
| 152 #else |
| 153 EXPECT_FALSE(chrome->ShouldSetExperimentLabels()); |
| 154 #endif // GOOGLE_CHROME_BUILD |
| 155 } |
| 156 |
115 // Creates "ap" key with the value given as parameter. Also adds work | 157 // Creates "ap" key with the value given as parameter. Also adds work |
116 // items to work_item_list given so that they can be rolled back later. | 158 // items to work_item_list given so that they can be rolled back later. |
117 bool CreateApKey(WorkItemList* work_item_list, const std::wstring& value) { | 159 bool CreateApKey(WorkItemList* work_item_list, const std::wstring& value) { |
118 HKEY reg_root = HKEY_CURRENT_USER; | 160 HKEY reg_root = HKEY_CURRENT_USER; |
119 std::wstring reg_key = GetApKeyPath(); | 161 std::wstring reg_key = GetApKeyPath(); |
120 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key); | 162 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key); |
121 work_item_list->AddSetRegValueWorkItem(reg_root, reg_key, | 163 work_item_list->AddSetRegValueWorkItem(reg_root, reg_key, |
122 google_update::kRegApField, value.c_str(), true); | 164 google_update::kRegApField, value.c_str(), true); |
123 if (!work_item_list->Do()) { | 165 if (!work_item_list->Do()) { |
124 work_item_list->Rollback(); | 166 work_item_list->Rollback(); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, | 590 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, |
549 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(), | 591 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(), |
550 static_cast<DWORD>(3))); | 592 static_cast<DWORD>(3))); |
551 is_overridden = true; | 593 is_overridden = true; |
552 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, | 594 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, |
553 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, | 595 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, |
554 &is_overridden)); | 596 &is_overridden)); |
555 EXPECT_FALSE(is_overridden); | 597 EXPECT_FALSE(is_overridden); |
556 } | 598 } |
557 | 599 |
| 600 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperSystem) { |
| 601 TestExperimentsLabelHelper(SYSTEM_INSTALL); |
| 602 } |
| 603 |
| 604 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperUser) { |
| 605 TestExperimentsLabelHelper(USER_INSTALL); |
| 606 } |
| 607 |
558 #endif // defined(GOOGLE_CHROME_BUILD) | 608 #endif // defined(GOOGLE_CHROME_BUILD) |
559 | 609 |
560 // Test GoogleUpdateSettings::GetUninstallCommandLine at system- or user-level, | 610 // Test GoogleUpdateSettings::GetUninstallCommandLine at system- or user-level, |
561 // according to the param. | 611 // according to the param. |
562 class GetUninstallCommandLine : public GoogleUpdateSettingsTest, | 612 class GetUninstallCommandLine : public GoogleUpdateSettingsTest, |
563 public testing::WithParamInterface<bool> { | 613 public testing::WithParamInterface<bool> { |
564 protected: | 614 protected: |
565 static const wchar_t kDummyCommand[]; | 615 static const wchar_t kDummyCommand[]; |
566 | 616 |
567 virtual void SetUp() OVERRIDE { | 617 virtual void SetUp() OVERRIDE { |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 981 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
932 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), | 982 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), |
933 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 983 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
934 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), | 984 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), |
935 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 985 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
936 StatsState::TRUE_SETTING, StatsState::NO_SETTING), | 986 StatsState::TRUE_SETTING, StatsState::NO_SETTING), |
937 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 987 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
938 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), | 988 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), |
939 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, | 989 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, |
940 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); | 990 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); |
OLD | NEW |