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

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

Issue 7036017: Write installer results in all relevant registry keys so that we're sure that Google Update will ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <fstream> 7 #include <fstream>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/memory/scoped_temp_dir.h" 12 #include "base/memory/scoped_temp_dir.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/version.h" 17 #include "base/version.h"
18 #include "base/win/registry.h" 18 #include "base/win/registry.h"
19 #include "base/win/scoped_handle.h" 19 #include "base/win/scoped_handle.h"
20 #include "chrome/installer/util/google_update_constants.h" 20 #include "chrome/installer/util/google_update_constants.h"
21 #include "chrome/installer/util/helper.h" 21 #include "chrome/installer/util/helper.h"
22 #include "chrome/installer/util/installation_state.h" 22 #include "chrome/installer/util/installation_state.h"
23 #include "chrome/installer/util/installer_state.h" 23 #include "chrome/installer/util/installer_state.h"
24 #include "chrome/installer/util/master_preferences.h" 24 #include "chrome/installer/util/master_preferences.h"
25 #include "chrome/installer/util/product_unittest.h" 25 #include "chrome/installer/util/product_unittest.h"
26 #include "chrome/installer/util/work_item.h" 26 #include "chrome/installer/util/work_item.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 using base::win::RegKey;
30 using installer::InstallationState;
31 using installer::InstallerState;
32 using installer::MasterPreferences;
33
29 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys { 34 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys {
30 protected: 35 protected:
31 }; 36 };
32 37
33 // An installer state on which we can tweak the target path. 38 // An installer state on which we can tweak the target path.
34 class MockInstallerState : public installer::InstallerState { 39 class MockInstallerState : public InstallerState {
35 public: 40 public:
36 MockInstallerState() : InstallerState() { } 41 MockInstallerState() : InstallerState() { }
37 void set_target_path(const FilePath& target_path) { 42 void set_target_path(const FilePath& target_path) {
38 target_path_ = target_path; 43 target_path_ = target_path;
39 } 44 }
40 }; 45 };
41 46
42 // Simple function to dump some text into a new file. 47 // Simple function to dump some text into a new file.
43 void CreateTextFile(const std::wstring& filename, 48 void CreateTextFile(const std::wstring& filename,
44 const std::wstring& contents) { 49 const std::wstring& contents) {
45 std::ofstream file; 50 std::ofstream file;
46 file.open(filename.c_str()); 51 file.open(filename.c_str());
47 ASSERT_TRUE(file.is_open()); 52 ASSERT_TRUE(file.is_open());
48 file << contents; 53 file << contents;
49 file.close(); 54 file.close();
50 } 55 }
51 56
52 void BuildSingleChromeState(const FilePath& target_dir, 57 void BuildSingleChromeState(const FilePath& target_dir,
53 MockInstallerState* installer_state) { 58 MockInstallerState* installer_state) {
54 CommandLine cmd_line = CommandLine::FromString(L"setup.exe"); 59 CommandLine cmd_line = CommandLine::FromString(L"setup.exe");
55 installer::MasterPreferences prefs(cmd_line); 60 MasterPreferences prefs(cmd_line);
56 installer::InstallationState machine_state; 61 InstallationState machine_state;
57 machine_state.Initialize(); 62 machine_state.Initialize();
58 installer_state->Initialize(cmd_line, prefs, machine_state); 63 installer_state->Initialize(cmd_line, prefs, machine_state);
59 installer_state->set_target_path(target_dir); 64 installer_state->set_target_path(target_dir);
60 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER) 65 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER)
61 != NULL); 66 != NULL);
62 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_FRAME) 67 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_FRAME)
63 == NULL); 68 == NULL);
64 } 69 }
65 70
66 wchar_t text_content_1[] = L"delete me"; 71 wchar_t text_content_1[] = L"delete me";
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 230
226 // Tests a few basic things of the Package class. Makes sure that the path 231 // Tests a few basic things of the Package class. Makes sure that the path
227 // operations are correct 232 // operations are correct
228 TEST_F(InstallerStateTest, Basic) { 233 TEST_F(InstallerStateTest, Basic) {
229 const bool multi_install = false; 234 const bool multi_install = false;
230 const bool system_level = true; 235 const bool system_level = true;
231 CommandLine cmd_line = CommandLine::FromString( 236 CommandLine cmd_line = CommandLine::FromString(
232 std::wstring(L"setup.exe") + 237 std::wstring(L"setup.exe") +
233 (multi_install ? L" --multi-install --chrome" : L"") + 238 (multi_install ? L" --multi-install --chrome" : L"") +
234 (system_level ? L" --system-level" : L"")); 239 (system_level ? L" --system-level" : L""));
235 installer::MasterPreferences prefs(cmd_line); 240 MasterPreferences prefs(cmd_line);
236 installer::InstallationState machine_state; 241 InstallationState machine_state;
237 machine_state.Initialize(); 242 machine_state.Initialize();
238 MockInstallerState installer_state; 243 MockInstallerState installer_state;
239 installer_state.Initialize(cmd_line, prefs, machine_state); 244 installer_state.Initialize(cmd_line, prefs, machine_state);
240 installer_state.set_target_path(test_dir_.path()); 245 installer_state.set_target_path(test_dir_.path());
241 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); 246 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value());
242 EXPECT_EQ(1U, installer_state.products().size()); 247 EXPECT_EQ(1U, installer_state.products().size());
243 248
244 const char kOldVersion[] = "1.2.3.4"; 249 const char kOldVersion[] = "1.2.3.4";
245 const char kNewVersion[] = "2.3.4.5"; 250 const char kNewVersion[] = "2.3.4.5";
246 251
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 EXPECT_FALSE(file_util::PathExists(old_version_dir)); 313 EXPECT_FALSE(file_util::PathExists(old_version_dir));
309 } 314 }
310 315
311 TEST_F(InstallerStateTest, WithProduct) { 316 TEST_F(InstallerStateTest, WithProduct) {
312 const bool multi_install = false; 317 const bool multi_install = false;
313 const bool system_level = true; 318 const bool system_level = true;
314 CommandLine cmd_line = CommandLine::FromString( 319 CommandLine cmd_line = CommandLine::FromString(
315 std::wstring(L"setup.exe") + 320 std::wstring(L"setup.exe") +
316 (multi_install ? L" --multi-install --chrome" : L"") + 321 (multi_install ? L" --multi-install --chrome" : L"") +
317 (system_level ? L" --system-level" : L"")); 322 (system_level ? L" --system-level" : L""));
318 installer::MasterPreferences prefs(cmd_line); 323 MasterPreferences prefs(cmd_line);
319 installer::InstallationState machine_state; 324 InstallationState machine_state;
320 machine_state.Initialize(); 325 machine_state.Initialize();
321 MockInstallerState installer_state; 326 MockInstallerState installer_state;
322 installer_state.Initialize(cmd_line, prefs, machine_state); 327 installer_state.Initialize(cmd_line, prefs, machine_state);
323 installer_state.set_target_path(test_dir_.path()); 328 installer_state.set_target_path(test_dir_.path());
324 EXPECT_EQ(1U, installer_state.products().size()); 329 EXPECT_EQ(1U, installer_state.products().size());
325 EXPECT_EQ(system_level, installer_state.system_install()); 330 EXPECT_EQ(system_level, installer_state.system_install());
326 331
327 const char kCurrentVersion[] = "1.2.3.4"; 332 const char kCurrentVersion[] = "1.2.3.4";
328 scoped_ptr<Version> current_version( 333 scoped_ptr<Version> current_version(
329 Version::GetVersionFromString(kCurrentVersion)); 334 Version::GetVersionFromString(kCurrentVersion));
330 335
331 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 336 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
332 EXPECT_EQ(root, installer_state.root_key()); 337 EXPECT_EQ(root, installer_state.root_key());
333 { 338 {
334 TempRegKeyOverride override(root, L"root_pit"); 339 TempRegKeyOverride override(root, L"root_pit");
335 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( 340 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
336 BrowserDistribution::CHROME_BROWSER); 341 BrowserDistribution::CHROME_BROWSER);
337 base::win::RegKey chrome_key(root, dist->GetVersionKey().c_str(), 342 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS);
338 KEY_ALL_ACCESS);
339 EXPECT_TRUE(chrome_key.Valid()); 343 EXPECT_TRUE(chrome_key.Valid());
340 if (chrome_key.Valid()) { 344 if (chrome_key.Valid()) {
341 chrome_key.WriteValue(google_update::kRegVersionField, 345 chrome_key.WriteValue(google_update::kRegVersionField,
342 UTF8ToWide(current_version->GetString()).c_str()); 346 UTF8ToWide(current_version->GetString()).c_str());
343 machine_state.Initialize(); 347 machine_state.Initialize();
344 // TODO(tommi): Also test for when there exists a new_chrome.exe. 348 // TODO(tommi): Also test for when there exists a new_chrome.exe.
345 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion( 349 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion(
346 machine_state)); 350 machine_state));
347 EXPECT_TRUE(found_version.get() != NULL); 351 EXPECT_TRUE(found_version.get() != NULL);
348 if (found_version.get()) { 352 if (found_version.get()) {
349 EXPECT_TRUE(current_version->Equals(*found_version)); 353 EXPECT_TRUE(current_version->Equals(*found_version));
350 } 354 }
351 } 355 }
352 } 356 }
353 } 357 }
358
359 TEST_F(InstallerStateTest, InstallerResult) {
360 const bool system_level = true;
361 bool multi_install = false;
362 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
363
364 RegKey key;
365 std::wstring launch_cmd = L"hey diddle diddle";
366 std::wstring value;
367
368 // check results for a fresh install of single Chrome
369 {
370 TempRegKeyOverride override(root, L"root_inst_res");
371 CommandLine cmd_line = CommandLine::FromString(L"setup.exe --system-level");
372 const MasterPreferences prefs(cmd_line);
373 InstallationState machine_state;
374 machine_state.Initialize();
375 InstallerState state;
376 state.Initialize(cmd_line, prefs, machine_state);
377 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS, 0,
378 &launch_cmd);
379 BrowserDistribution* distribution =
380 BrowserDistribution::GetSpecificDistribution(
381 BrowserDistribution::CHROME_BROWSER);
382 EXPECT_EQ(ERROR_SUCCESS,
383 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ));
384 EXPECT_EQ(ERROR_SUCCESS,
385 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value));
386 EXPECT_EQ(launch_cmd, value);
387 }
388 TempRegKeyOverride::DeleteAllTempKeys();
389
390 // check results for a fresh install of multi Chrome
391 {
392 TempRegKeyOverride override(root, L"root_inst_res");
393 CommandLine cmd_line = CommandLine::FromString(
394 L"setup.exe --system-level --multi-install --chrome");
395 const MasterPreferences prefs(cmd_line);
396 InstallationState machine_state;
397 machine_state.Initialize();
398 InstallerState state;
399 state.Initialize(cmd_line, prefs, machine_state);
400 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS, 0,
401 &launch_cmd);
402 BrowserDistribution* distribution =
403 BrowserDistribution::GetSpecificDistribution(
404 BrowserDistribution::CHROME_BROWSER);
405 BrowserDistribution* binaries =
406 BrowserDistribution::GetSpecificDistribution(
407 BrowserDistribution::CHROME_BINARIES);
408 EXPECT_EQ(ERROR_SUCCESS,
409 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ));
410 EXPECT_EQ(ERROR_SUCCESS,
411 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value));
412 EXPECT_EQ(launch_cmd, value);
413 EXPECT_EQ(ERROR_SUCCESS,
414 key.Open(root, binaries->GetStateKey().c_str(), KEY_READ));
415 EXPECT_EQ(ERROR_SUCCESS,
416 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value));
417 EXPECT_EQ(launch_cmd, value);
418 key.Close();
419 }
420 TempRegKeyOverride::DeleteAllTempKeys();
robertshield 2011/05/18 12:28:40 should also test the error field and the UI string
grt (UTC plus 2) 2011/05/18 13:39:30 Done.
421 }
OLDNEW
« chrome/installer/util/install_util.h ('K') | « chrome/installer/util/installer_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698