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

Side by Side Diff: chrome/installer/gcapi/gcapi_reactivation_test.cc

Issue 9465013: Mike's change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing Roger's feedback. Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/gcapi/gcapi_reactivation.cc ('k') | chrome/installer/gcapi/gcapi_test.cc » ('j') | 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/test/test_reg_util_win.h" 10 #include "base/test/test_reg_util_win.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 path += L"\\"; 71 path += L"\\";
72 path += google_update::kChromeUpgradeCode; 72 path += google_update::kChromeUpgradeCode;
73 73
74 RegKey client_state(hive, path.c_str(), KEY_SET_VALUE); 74 RegKey client_state(hive, path.c_str(), KEY_SET_VALUE);
75 return (client_state.Valid() && 75 return (client_state.Valid() &&
76 client_state.WriteValue( 76 client_state.WriteValue(
77 google_update::kRegLastRunTimeField, 77 google_update::kRegLastRunTimeField,
78 last_run_time_string.c_str()) == ERROR_SUCCESS); 78 last_run_time_string.c_str()) == ERROR_SUCCESS);
79 } 79 }
80 80
81 bool HasExperimentLabels() { 81 bool HasExperimentLabels(HKEY hive) {
82 int label_count = 0; 82 int label_count = 0;
83 for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) { 83 for (int i = 0; i < arraysize(kExperimentAppGuids); ++i) {
84 string16 client_state_path(google_update::kRegPathClientState); 84 string16 client_state_path(google_update::kRegPathClientState);
85 client_state_path += L"\\"; 85 client_state_path += L"\\";
86 client_state_path += kExperimentAppGuids[i]; 86 client_state_path += kExperimentAppGuids[i];
87 87
88 RegKey client_state_key(HKEY_LOCAL_MACHINE, 88 RegKey client_state_key(hive,
89 client_state_path.c_str(), 89 client_state_path.c_str(),
90 KEY_QUERY_VALUE); 90 KEY_QUERY_VALUE);
91 if (client_state_key.Valid() && 91 if (client_state_key.Valid() &&
92 client_state_key.HasValue(kExperimentLabels)) { 92 client_state_key.HasValue(kExperimentLabels)) {
93 label_count++; 93 label_count++;
94 } 94 }
95 } 95 }
96 return label_count == arraysize(kExperimentAppGuids); 96 return label_count == arraysize(kExperimentAppGuids);
97 } 97 }
98 98
(...skipping 16 matching lines...) Expand all
115 } 115 }
116 116
117 return L"ERROR"; 117 return L"ERROR";
118 } 118 }
119 119
120 private: 120 private:
121 registry_util::RegistryOverrideManager override_manager_; 121 registry_util::RegistryOverrideManager override_manager_;
122 }; 122 };
123 123
124 TEST_F(GCAPIReactivationTest, CheckSetReactivationBrandCode) { 124 TEST_F(GCAPIReactivationTest, CheckSetReactivationBrandCode) {
125 EXPECT_TRUE(SetReactivationBrandCode(L"GAGA")); 125 EXPECT_TRUE(SetReactivationBrandCode(L"GAGA", GCAPI_INVOKED_STANDARD_SHELL));
126 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); 126 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER));
127 127
128 std::vector<std::wstring> check_codes; 128 std::vector<std::wstring> check_codes;
129 check_codes.push_back(L"GAGA"); 129 check_codes.push_back(L"GAGA");
130 EXPECT_TRUE(HasBeenReactivatedByBrandCodes(check_codes)); 130 EXPECT_TRUE(HasBeenReactivatedByBrandCodes(check_codes));
131 131
132 check_codes.push_back(L"GOOGOO"); 132 check_codes.push_back(L"GOOGOO");
133 EXPECT_TRUE(HasBeenReactivatedByBrandCodes(check_codes)); 133 EXPECT_TRUE(HasBeenReactivatedByBrandCodes(check_codes));
134 134
135 check_codes.erase(check_codes.begin()); 135 check_codes.erase(check_codes.begin());
136 EXPECT_FALSE(HasBeenReactivatedByBrandCodes(check_codes)); 136 EXPECT_FALSE(HasBeenReactivatedByBrandCodes(check_codes));
137 } 137 }
138 138
139 TEST_F(GCAPIReactivationTest, CanOfferReactivation_Basic) { 139 TEST_F(GCAPIReactivationTest, CanOfferReactivation_Basic) {
140 const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"}; 140 const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"};
141 DWORD error; 141 DWORD error;
142 142
143 // We're not installed yet. Make sure CanOfferReactivation fails. 143 // We're not installed yet. Make sure CanOfferReactivation fails.
144 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands), 144 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
145 previous_brands, &error)); 145 previous_brands,
146 GCAPI_INVOKED_STANDARD_SHELL,
147 &error));
146 EXPECT_EQ(REACTIVATE_ERROR_NOTINSTALLED, error); 148 EXPECT_EQ(REACTIVATE_ERROR_NOTINSTALLED, error);
147 149
148 // Now pretend to be installed. CanOfferReactivation should pass. 150 // Now pretend to be installed. CanOfferReactivation should pass.
149 EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER)); 151 EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER));
150 EXPECT_TRUE(CanOfferReactivation(L"GAGA", arraysize(previous_brands), 152 EXPECT_TRUE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
151 previous_brands, &error)); 153 previous_brands,
154 GCAPI_INVOKED_STANDARD_SHELL,
155 &error));
152 156
153 // Now set a recent last_run value. CanOfferReactivation should fail again. 157 // Now set a recent last_run value. CanOfferReactivation should fail again.
154 Time hkcu_last_run = Time::NowFromSystemTime() - TimeDelta::FromDays(20); 158 Time hkcu_last_run = Time::NowFromSystemTime() - TimeDelta::FromDays(20);
155 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, 159 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
156 hkcu_last_run.ToInternalValue())); 160 hkcu_last_run.ToInternalValue()));
157 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands), 161 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
158 previous_brands, &error)); 162 previous_brands,
163 GCAPI_INVOKED_STANDARD_SHELL,
164 &error));
159 EXPECT_EQ(REACTIVATE_ERROR_NOTDORMANT, error); 165 EXPECT_EQ(REACTIVATE_ERROR_NOTDORMANT, error);
160 166
161 // Now set a last_run value that exceeds the threshold. 167 // Now set a last_run value that exceeds the threshold.
162 hkcu_last_run = Time::NowFromSystemTime() - 168 hkcu_last_run = Time::NowFromSystemTime() -
163 TimeDelta::FromDays(kReactivationMinDaysDormant); 169 TimeDelta::FromDays(kReactivationMinDaysDormant);
164 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, 170 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
165 hkcu_last_run.ToInternalValue())); 171 hkcu_last_run.ToInternalValue()));
166 EXPECT_TRUE(CanOfferReactivation(L"GAGA", arraysize(previous_brands), 172 EXPECT_TRUE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
167 previous_brands, &error)); 173 previous_brands,
174 GCAPI_INVOKED_STANDARD_SHELL,
175 &error));
168 176
169 // Test some invalid inputs 177 // Test some invalid inputs
170 EXPECT_FALSE(CanOfferReactivation(NULL, arraysize(previous_brands), 178 EXPECT_FALSE(CanOfferReactivation(NULL, arraysize(previous_brands),
171 previous_brands, &error)); 179 previous_brands,
180 GCAPI_INVOKED_STANDARD_SHELL,
181 &error));
172 EXPECT_EQ(REACTIVATE_ERROR_INVALID_INPUT, error); 182 EXPECT_EQ(REACTIVATE_ERROR_INVALID_INPUT, error);
173 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands), 183 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
174 NULL, &error)); 184 NULL, GCAPI_INVOKED_STANDARD_SHELL,
185 &error));
175 EXPECT_EQ(REACTIVATE_ERROR_INVALID_INPUT, error); 186 EXPECT_EQ(REACTIVATE_ERROR_INVALID_INPUT, error);
176 187
177 // One more valid one 188 // One more valid one
178 EXPECT_TRUE(CanOfferReactivation(L"GAGA", 0, NULL, &error)); 189 EXPECT_TRUE(CanOfferReactivation(L"GAGA", 0, NULL,
190 GCAPI_INVOKED_STANDARD_SHELL,
191 &error));
179 192
180 // Check that the previous brands check works: 193 // Check that the previous brands check works:
181 EXPECT_TRUE(SetReactivationBrandCode(L"GOOGOO")); 194 EXPECT_TRUE(SetReactivationBrandCode(L"GOOGOO",
195 GCAPI_INVOKED_STANDARD_SHELL));
182 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands), 196 EXPECT_FALSE(CanOfferReactivation(L"GAGA", arraysize(previous_brands),
183 previous_brands, &error)); 197 previous_brands,
198 GCAPI_INVOKED_STANDARD_SHELL,
199 &error));
184 EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error); 200 EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error);
185 } 201 }
186 202
187 TEST_F(GCAPIReactivationTest, Reactivation_Flow) { 203 TEST_F(GCAPIReactivationTest, Reactivation_Flow) {
188 const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"}; 204 const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"};
189 DWORD error; 205 DWORD error;
190 206
191 // Set us up as a candidate for reactivation. 207 // Set us up as a candidate for reactivation.
192 EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER)); 208 EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER));
193 209
194 Time hkcu_last_run = Time::NowFromSystemTime() - 210 Time hkcu_last_run = Time::NowFromSystemTime() -
195 TimeDelta::FromDays(kReactivationMinDaysDormant); 211 TimeDelta::FromDays(kReactivationMinDaysDormant);
196 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, 212 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
197 hkcu_last_run.ToInternalValue())); 213 hkcu_last_run.ToInternalValue()));
198 214
199 EXPECT_TRUE(ReactivateChrome(L"GAGA", arraysize(previous_brands), 215 EXPECT_TRUE(ReactivateChrome(L"GAGA", arraysize(previous_brands),
200 previous_brands, &error)); 216 previous_brands, GCAPI_INVOKED_STANDARD_SHELL,
217 &error));
201 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); 218 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER));
202 219
203 // Make sure we can't reactivate again: 220 // Make sure we can't reactivate again:
204 EXPECT_FALSE(ReactivateChrome(L"GAGA", arraysize(previous_brands), 221 EXPECT_FALSE(ReactivateChrome(L"GAGA", arraysize(previous_brands),
205 previous_brands, &error)); 222 previous_brands, GCAPI_INVOKED_STANDARD_SHELL,
223 &error));
206 EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error); 224 EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error);
207 225
208 // Should still be able to reactivate under other brands: 226 // Should still be able to reactivate under other brands:
209 EXPECT_TRUE(ReactivateChrome(L"MAMA", arraysize(previous_brands), 227 EXPECT_TRUE(ReactivateChrome(L"MAMA", arraysize(previous_brands),
210 previous_brands, &error)); 228 previous_brands, GCAPI_INVOKED_STANDARD_SHELL,
229 &error));
211 EXPECT_EQ(L"MAMA", GetReactivationString(HKEY_CURRENT_USER)); 230 EXPECT_EQ(L"MAMA", GetReactivationString(HKEY_CURRENT_USER));
212 231
213 // Validate that previous_brands are rejected: 232 // Validate that previous_brands are rejected:
214 EXPECT_FALSE(ReactivateChrome(L"PFFT", arraysize(previous_brands), 233 EXPECT_FALSE(ReactivateChrome(L"PFFT", arraysize(previous_brands),
215 previous_brands, &error)); 234 previous_brands, GCAPI_INVOKED_STANDARD_SHELL,
235 &error));
216 EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error); 236 EXPECT_EQ(REACTIVATE_ERROR_ALREADY_REACTIVATED, error);
217 EXPECT_EQ(L"MAMA", GetReactivationString(HKEY_CURRENT_USER)); 237 EXPECT_EQ(L"MAMA", GetReactivationString(HKEY_CURRENT_USER));
218 } 238 }
219 239
220 TEST_F(GCAPIReactivationTest, ExperimentLabelCheck) { 240 TEST_F(GCAPIReactivationTest, ExperimentLabelCheck) {
221 const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"}; 241 const wchar_t* previous_brands[] = {L"GOOGOO", L"MAMA", L"DADA"};
222 DWORD error; 242 DWORD error;
223 243
224 // Set us up as a candidate for reactivation. 244 // Set us up as a candidate for reactivation.
225 EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER)); 245 EXPECT_TRUE(SetChromeInstallMarker(HKEY_CURRENT_USER));
226 246
227 Time hkcu_last_run = Time::NowFromSystemTime() - 247 Time hkcu_last_run = Time::NowFromSystemTime() -
228 TimeDelta::FromDays(kReactivationMinDaysDormant); 248 TimeDelta::FromDays(kReactivationMinDaysDormant);
229 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER, 249 EXPECT_TRUE(SetLastRunTime(HKEY_CURRENT_USER,
230 hkcu_last_run.ToInternalValue())); 250 hkcu_last_run.ToInternalValue()));
231 251
232 EXPECT_TRUE(ReactivateChrome(L"GAGA", arraysize(previous_brands), 252 EXPECT_TRUE(ReactivateChrome(L"GAGA", arraysize(previous_brands),
233 previous_brands, &error)); 253 previous_brands, GCAPI_INVOKED_STANDARD_SHELL,
254 &error));
234 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER)); 255 EXPECT_EQ(L"GAGA", GetReactivationString(HKEY_CURRENT_USER));
235 256
236 EXPECT_TRUE(HasExperimentLabels()); 257 EXPECT_TRUE(HasExperimentLabels(HKEY_CURRENT_USER));
237 } 258 }
OLDNEW
« no previous file with comments | « chrome/installer/gcapi/gcapi_reactivation.cc ('k') | chrome/installer/gcapi/gcapi_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698