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

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

Issue 2725007: Reverting this as it caused installer_unit_tests to fail. Please fix and rela... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 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/util/google_update_settings.cc ('k') | chrome/installer/util/install_util.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 6
7 #include "base/registry.h" 7 #include "base/registry.h"
8 #include "base/scoped_ptr.h"
9 #include "chrome/installer/util/browser_distribution.h" 8 #include "chrome/installer/util/browser_distribution.h"
10 #include "chrome/installer/util/google_update_constants.h"
11 #include "chrome/installer/util/google_update_settings.h" 9 #include "chrome/installer/util/google_update_settings.h"
12 #include "chrome/installer/util/work_item_list.h"
13 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
14 11
15 namespace { 12 namespace {
16 const wchar_t* kHKCUReplacement = 13 const wchar_t* kHKCUReplacement =
17 L"Software\\Google\\InstallUtilUnittest\\HKCU"; 14 L"Software\\Google\\InstallUtilUnittest\\HKCU";
18 const wchar_t* kHKLMReplacement = 15 const wchar_t* kHKLMReplacement =
19 L"Software\\Google\\InstallUtilUnittest\\HKLM"; 16 L"Software\\Google\\InstallUtilUnittest\\HKLM";
20 17
21 const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}";
22
23 // This test fixture redirects the HKLM and HKCU registry hives for 18 // This test fixture redirects the HKLM and HKCU registry hives for
24 // the duration of the test to make it independent of the machine 19 // the duration of the test to make it independent of the machine
25 // and user settings. 20 // and user settings.
26 class GoogleUpdateSettingsTest: public testing::Test { 21 class GoogleUpdateSettingsTest: public testing::Test {
27 protected: 22 protected:
28 virtual void SetUp() { 23 virtual void SetUp() {
29 // Wipe the keys we redirect to. 24 // Wipe the keys we redirect to.
30 // This gives us a stable run, even in the presence of previous 25 // This gives us a stable run, even in the presence of previous
31 // crashes or failures. 26 // crashes or failures.
32 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kHKCUReplacement); 27 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kHKCUReplacement);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannel(is_system, 110 EXPECT_TRUE(GoogleUpdateSettings::GetChromeChannel(is_system,
116 &ret_channel)); 111 &ret_channel));
117 EXPECT_STREQ(channel, ret_channel.c_str()) 112 EXPECT_STREQ(channel, ret_channel.c_str())
118 << "Expecting channel \"" << channel 113 << "Expecting channel \"" << channel
119 << "\" for ap=\"" << ap << "\""; 114 << "\" for ap=\"" << ap << "\"";
120 } 115 }
121 } 116 }
122 } 117 }
123 } 118 }
124 119
125 // Creates "ap" key with the value given as parameter. Also adds work
126 // items to work_item_list given so that they can be rolled back later.
127 bool CreateApKey(WorkItemList* work_item_list, const std::wstring& value) {
128 HKEY reg_root = HKEY_CURRENT_USER;
129 std::wstring reg_key = GetApKeyPath();
130 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key);
131 work_item_list->AddSetRegValueWorkItem(reg_root, reg_key,
132 google_update::kRegApField, value.c_str(), true);
133 if (!work_item_list->Do()) {
134 work_item_list->Rollback();
135 return false;
136 }
137 return true;
138 }
139
140 // Returns the key path of "ap" key, e.g.:
141 // Google\Update\ClientState\<kTestProductGuid>
142 std::wstring GetApKeyPath() {
143 std::wstring reg_key(google_update::kRegPathClientState);
144 reg_key.append(L"\\");
145 reg_key.append(kTestProductGuid);
146 return reg_key;
147 }
148
149 // Utility method to read "ap" key value
150 std::wstring ReadApKeyValue() {
151 RegKey key;
152 std::wstring ap_key_value;
153 std::wstring reg_key = GetApKeyPath();
154 if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) &&
155 key.ReadValue(google_update::kRegApField, &ap_key_value)) {
156 return ap_key_value;
157 }
158 return std::wstring();
159 }
160
161 RegKey hkcu_; 120 RegKey hkcu_;
162 RegKey hklm_; 121 RegKey hklm_;
163 }; 122 };
164 123
165 } // namespace 124 } // namespace
166 125
167 // Verify that we return failure on no registration, 126 // Verify that we return failure on no registration,
168 // whether per-system or per-user install. 127 // whether per-system or per-user install.
169 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) { 128 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelAbsent) {
170 // Per-system first. 129 // Per-system first.
(...skipping 28 matching lines...) Expand all
199 EXPECT_STREQ(L"", channel.c_str()); 158 EXPECT_STREQ(L"", channel.c_str());
200 } 159 }
201 160
202 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) { 161 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesSystem) {
203 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL); 162 TestCurrentChromeChannelWithVariousApValues(SYSTEM_INSTALL);
204 } 163 }
205 164
206 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) { 165 TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) {
207 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL); 166 TestCurrentChromeChannelWithVariousApValues(USER_INSTALL);
208 } 167 }
209
210 TEST_F(GoogleUpdateSettingsTest, GetNewGoogleUpdateApKeyTest) {
211 installer_util::InstallStatus s = installer_util::FIRST_INSTALL_SUCCESS;
212 installer_util::InstallStatus f = installer_util::INSTALL_FAILED;
213
214 // Incremental Installer that worked.
215 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L""), L"");
216 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1"),
217 L"1.1");
218 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1-dev"),
219 L"1.1-dev");
220 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"-full"),
221 L"");
222 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1-full"),
223 L"1.1");
224 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s,
225 L"1.1-dev-full"),
226 L"1.1-dev");
227
228 // Incremental Installer that failed.
229 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L""),
230 L"-full");
231 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1"),
232 L"1.1-full");
233 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1-dev"),
234 L"1.1-dev-full");
235 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"-full"),
236 L"-full");
237 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1-full"),
238 L"1.1-full");
239 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f,
240 L"1.1-dev-full"),
241 L"1.1-dev-full");
242
243 // Full Installer that worked.
244 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L""), L"");
245 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"1.1"),
246 L"1.1");
247 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"1.1-dev"),
248 L"1.1-dev");
249 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"-full"),
250 L"");
251 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s,
252 L"1.1-full"),
253 L"1.1");
254 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s,
255 L"1.1-dev-full"),
256 L"1.1-dev");
257
258 // Full Installer that failed.
259 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L""), L"");
260 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"1.1"),
261 L"1.1");
262 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"1.1-dev"),
263 L"1.1-dev");
264 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"-full"),
265 L"");
266 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f,
267 L"1.1-full"),
268 L"1.1");
269 EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f,
270 L"1.1-dev-full"),
271 L"1.1-dev");
272 }
273
274 TEST_F(GoogleUpdateSettingsTest, UpdateDiffInstallStatusTest) {
275 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
276 // Test incremental install failure
277 ASSERT_TRUE(CreateApKey(work_item_list.get(), L""))
278 << "Failed to create ap key.";
279 GoogleUpdateSettings::UpdateDiffInstallStatus(false, true,
280 installer_util::INSTALL_FAILED,
281 kTestProductGuid);
282 EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full");
283 work_item_list->Rollback();
284
285 work_item_list.reset(WorkItem::CreateWorkItemList());
286 // Test incremental install success
287 ASSERT_TRUE(CreateApKey(work_item_list.get(), L""))
288 << "Failed to create ap key.";
289 GoogleUpdateSettings::UpdateDiffInstallStatus(false, true,
290 installer_util::FIRST_INSTALL_SUCCESS,
291 kTestProductGuid);
292 EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
293 work_item_list->Rollback();
294
295 work_item_list.reset(WorkItem::CreateWorkItemList());
296 // Test full install failure
297 ASSERT_TRUE(CreateApKey(work_item_list.get(), L"-full"))
298 << "Failed to create ap key.";
299 GoogleUpdateSettings::UpdateDiffInstallStatus(false, false,
300 installer_util::INSTALL_FAILED,
301 kTestProductGuid);
302 EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
303 work_item_list->Rollback();
304
305 work_item_list.reset(WorkItem::CreateWorkItemList());
306 // Test full install success
307 ASSERT_TRUE(CreateApKey(work_item_list.get(), L"-full"))
308 << "Failed to create ap key.";
309 GoogleUpdateSettings::UpdateDiffInstallStatus(false, false,
310 installer_util::FIRST_INSTALL_SUCCESS,
311 kTestProductGuid);
312 EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
313 work_item_list->Rollback();
314
315 work_item_list.reset(WorkItem::CreateWorkItemList());
316 // Test the case of when "ap" key doesnt exist at all
317 std::wstring ap_key_value = ReadApKeyValue();
318 std::wstring reg_key = GetApKeyPath();
319 HKEY reg_root = HKEY_CURRENT_USER;
320 bool ap_key_deleted = false;
321 RegKey key;
322 if (!key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS)) {
323 work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key);
324 ASSERT_TRUE(work_item_list->Do()) << "Failed to create ClientState key.";
325 } else if (key.DeleteValue(google_update::kRegApField)) {
326 ap_key_deleted = true;
327 }
328 // try differential installer
329 GoogleUpdateSettings::UpdateDiffInstallStatus(false, true,
330 installer_util::INSTALL_FAILED,
331 kTestProductGuid);
332 EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full");
333 // try full installer now
334 GoogleUpdateSettings::UpdateDiffInstallStatus(false, false,
335 installer_util::INSTALL_FAILED,
336 kTestProductGuid);
337 EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
338 // Now cleanup to leave the system in unchanged state.
339 // - Diff installer creates an ap key if it didnt exist, so delete this ap key
340 // - If we created any reg key path for ap, roll it back
341 // - Finally restore the original value of ap key.
342 key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS);
343 key.DeleteValue(google_update::kRegApField);
344 work_item_list->Rollback();
345 if (ap_key_deleted) {
346 work_item_list.reset(WorkItem::CreateWorkItemList());
347 ASSERT_TRUE(CreateApKey(work_item_list.get(), ap_key_value))
348 << "Failed to restore ap key.";
349 }
350 }
OLDNEW
« no previous file with comments | « chrome/installer/util/google_update_settings.cc ('k') | chrome/installer/util/install_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698