Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/installer/util/google_update_settings_unittest.cc

Issue 11280067: Refactor SetOmahaExperimentLabel out of gcpai and into install_util. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: grt test comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/util/google_update_settings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 #ifdef GOOGLE_CHROME_BUILD
grt (UTC plus 2) 2013/01/08 17:06:36 #if defined(GOOGLE_CHROME_BUILD)
SteveT 2013/01/08 17:53:15 Done.
120 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels(
121 install == SYSTEM_INSTALL, kTestExperimentLabel));
122
123 // Validate that something is written. Only worry about the label itself.
124 RegKey key;
125 std::wstring value;
126 BrowserDistribution* chrome =
127 BrowserDistribution::GetSpecificDistribution(
128 BrowserDistribution::CHROME_BROWSER);
129 EXPECT_TRUE(chrome->ShouldSetExperimentLabels());
130
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
142 // Now that the label is set, test the delete functionality. An empty label
143 // should result in deleting the value.
144 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels(
145 install == SYSTEM_INSTALL, string16()));
146 EXPECT_EQ(ERROR_SUCCESS,
147 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE));
148 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
149 key.ReadValue(google_update::kExperimentLabels, &value));
150 key.Close();
151 #else
152 EXPECT_FALSE(chrome->ShouldSetExperimentLabels());
grt (UTC plus 2) 2013/01/08 17:07:39 chrome -> BrowserDistribution::GetSpecificDistribu
SteveT 2013/01/08 17:53:15 Yeah... the trybots caught that error. I refactore
153 #endif // GOOGLE_CHROME_BUILD
154 }
155
115 // Creates "ap" key with the value given as parameter. Also adds work 156 // 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. 157 // 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) { 158 bool CreateApKey(WorkItemList* work_item_list, const std::wstring& value) {
118 HKEY reg_root = HKEY_CURRENT_USER; 159 HKEY reg_root = HKEY_CURRENT_USER;
119 std::wstring reg_key = GetApKeyPath(); 160 std::wstring reg_key = GetApKeyPath();
120 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key); 161 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key);
121 work_item_list->AddSetRegValueWorkItem(reg_root, reg_key, 162 work_item_list->AddSetRegValueWorkItem(reg_root, reg_key,
122 google_update::kRegApField, value.c_str(), true); 163 google_update::kRegApField, value.c_str(), true);
123 if (!work_item_list->Do()) { 164 if (!work_item_list->Do()) {
124 work_item_list->Rollback(); 165 work_item_list->Rollback();
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, 589 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
549 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(), 590 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(),
550 static_cast<DWORD>(3))); 591 static_cast<DWORD>(3)));
551 is_overridden = true; 592 is_overridden = true;
552 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, 593 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED,
553 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, 594 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
554 &is_overridden)); 595 &is_overridden));
555 EXPECT_FALSE(is_overridden); 596 EXPECT_FALSE(is_overridden);
556 } 597 }
557 598
599 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperSystem) {
600 TestExperimentsLabelHelper(SYSTEM_INSTALL);
601 }
602
603 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperUser) {
604 TestExperimentsLabelHelper(USER_INSTALL);
605 }
606
558 #endif // defined(GOOGLE_CHROME_BUILD) 607 #endif // defined(GOOGLE_CHROME_BUILD)
559 608
560 // Test GoogleUpdateSettings::GetUninstallCommandLine at system- or user-level, 609 // Test GoogleUpdateSettings::GetUninstallCommandLine at system- or user-level,
561 // according to the param. 610 // according to the param.
562 class GetUninstallCommandLine : public GoogleUpdateSettingsTest, 611 class GetUninstallCommandLine : public GoogleUpdateSettingsTest,
563 public testing::WithParamInterface<bool> { 612 public testing::WithParamInterface<bool> {
564 protected: 613 protected:
565 static const wchar_t kDummyCommand[]; 614 static const wchar_t kDummyCommand[];
566 615
567 virtual void SetUp() OVERRIDE { 616 virtual void SetUp() OVERRIDE {
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 980 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
932 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), 981 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING),
933 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 982 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
934 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), 983 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING),
935 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 984 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
936 StatsState::TRUE_SETTING, StatsState::NO_SETTING), 985 StatsState::TRUE_SETTING, StatsState::NO_SETTING),
937 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 986 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
938 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), 987 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING),
939 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 988 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
940 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); 989 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING)));
OLDNEW
« no previous file with comments | « chrome/installer/util/google_update_settings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698