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

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: robertshield nits 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 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels(
grt (UTC plus 2) 2013/01/08 04:34:06 i think you need to make this test brand-aware. d
SteveT 2013/01/08 16:33:04 Done. It's a bit odd using ifdefs in a unit test
grt (UTC plus 2) 2013/01/08 17:06:36 The normal case on the trybots, CQ, etc is Chromiu
120 install == SYSTEM_INSTALL, kTestExperimentLabel));
121
122 // Validate that something is written. Only worry about the label itself.
123 RegKey key;
124 std::wstring value;
125 BrowserDistribution* chrome =
126 BrowserDistribution::GetSpecificDistribution(
127 BrowserDistribution::CHROME_BROWSER);
128
129 HKEY root = install == SYSTEM_INSTALL ?
130 HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
131 string16 state_key = install == SYSTEM_INSTALL ?
132 chrome->GetStateMediumKey() : chrome->GetStateKey();
133
134 EXPECT_EQ(ERROR_SUCCESS,
135 key.Open(root, state_key.c_str(), KEY_QUERY_VALUE));
136 EXPECT_EQ(ERROR_SUCCESS,
137 key.ReadValue(google_update::kExperimentLabels, &value));
138 EXPECT_EQ(kTestExperimentLabel, value);
139 key.Close();
140
141 // Now that the label is set, test the delete functionality. An empty label
142 // should result in deleting the value.
143 RegKey key2;
grt (UTC plus 2) 2013/01/08 04:34:06 you could re-use |key| on lines 147 and 149 rather
SteveT 2013/01/08 16:33:04 Done. Okay great. I thought you might have to clo
grt (UTC plus 2) 2013/01/08 17:06:36 2013/01/08 16:33:04, SteveT wrote:
SteveT 2013/01/08 17:53:15 Done. Kept the second Close.
144 EXPECT_TRUE(GoogleUpdateSettings::SetExperimentLabels(
145 install == SYSTEM_INSTALL, string16()));
146 EXPECT_EQ(ERROR_SUCCESS,
147 key2.Open(root, state_key.c_str(), KEY_QUERY_VALUE));
148 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
149 key2.ReadValue(google_update::kExperimentLabels, &value));
150 key2.Close();
151 }
152
115 // Creates "ap" key with the value given as parameter. Also adds work 153 // 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. 154 // 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) { 155 bool CreateApKey(WorkItemList* work_item_list, const std::wstring& value) {
118 HKEY reg_root = HKEY_CURRENT_USER; 156 HKEY reg_root = HKEY_CURRENT_USER;
119 std::wstring reg_key = GetApKeyPath(); 157 std::wstring reg_key = GetApKeyPath();
120 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key); 158 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key);
121 work_item_list->AddSetRegValueWorkItem(reg_root, reg_key, 159 work_item_list->AddSetRegValueWorkItem(reg_root, reg_key,
122 google_update::kRegApField, value.c_str(), true); 160 google_update::kRegApField, value.c_str(), true);
123 if (!work_item_list->Do()) { 161 if (!work_item_list->Do()) {
124 work_item_list->Rollback(); 162 work_item_list->Rollback();
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey, 586 RegKey(HKEY_LOCAL_MACHINE, kGoogleUpdatePoliciesKey,
549 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(), 587 KEY_SET_VALUE).WriteValue(app_policy_value.c_str(),
550 static_cast<DWORD>(3))); 588 static_cast<DWORD>(3)));
551 is_overridden = true; 589 is_overridden = true;
552 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, 590 EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED,
553 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid, 591 GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
554 &is_overridden)); 592 &is_overridden));
555 EXPECT_FALSE(is_overridden); 593 EXPECT_FALSE(is_overridden);
556 } 594 }
557 595
596 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperSystem) {
597 TestExperimentsLabelHelper(SYSTEM_INSTALL);
598 }
599
600 TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperUser) {
601 TestExperimentsLabelHelper(USER_INSTALL);
602 }
603
558 #endif // defined(GOOGLE_CHROME_BUILD) 604 #endif // defined(GOOGLE_CHROME_BUILD)
559 605
560 // Test GoogleUpdateSettings::GetUninstallCommandLine at system- or user-level, 606 // Test GoogleUpdateSettings::GetUninstallCommandLine at system- or user-level,
561 // according to the param. 607 // according to the param.
562 class GetUninstallCommandLine : public GoogleUpdateSettingsTest, 608 class GetUninstallCommandLine : public GoogleUpdateSettingsTest,
563 public testing::WithParamInterface<bool> { 609 public testing::WithParamInterface<bool> {
564 protected: 610 protected:
565 static const wchar_t kDummyCommand[]; 611 static const wchar_t kDummyCommand[];
566 612
567 virtual void SetUp() OVERRIDE { 613 virtual void SetUp() OVERRIDE {
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 977 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
932 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING), 978 StatsState::FALSE_SETTING, StatsState::FALSE_SETTING),
933 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 979 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
934 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING), 980 StatsState::FALSE_SETTING, StatsState::TRUE_SETTING),
935 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 981 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
936 StatsState::TRUE_SETTING, StatsState::NO_SETTING), 982 StatsState::TRUE_SETTING, StatsState::NO_SETTING),
937 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 983 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
938 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING), 984 StatsState::TRUE_SETTING, StatsState::FALSE_SETTING),
939 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL, 985 StatsState(StatsState::kSystemLevel, StatsState::MULTI_INSTALL,
940 StatsState::TRUE_SETTING, StatsState::TRUE_SETTING))); 986 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