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

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
« no previous file with comments | « chrome/installer/util/installer_state.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) 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 #include "installer_util_strings.h" // NOLINT
30
31 using base::win::RegKey;
32 using installer::InstallationState;
33 using installer::InstallerState;
34 using installer::MasterPreferences;
35
29 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys { 36 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys {
30 protected: 37 protected:
31 }; 38 };
32 39
33 // An installer state on which we can tweak the target path. 40 // An installer state on which we can tweak the target path.
34 class MockInstallerState : public installer::InstallerState { 41 class MockInstallerState : public InstallerState {
35 public: 42 public:
36 MockInstallerState() : InstallerState() { } 43 MockInstallerState() : InstallerState() { }
37 void set_target_path(const FilePath& target_path) { 44 void set_target_path(const FilePath& target_path) {
38 target_path_ = target_path; 45 target_path_ = target_path;
39 } 46 }
40 }; 47 };
41 48
42 // Simple function to dump some text into a new file. 49 // Simple function to dump some text into a new file.
43 void CreateTextFile(const std::wstring& filename, 50 void CreateTextFile(const std::wstring& filename,
44 const std::wstring& contents) { 51 const std::wstring& contents) {
45 std::ofstream file; 52 std::ofstream file;
46 file.open(filename.c_str()); 53 file.open(filename.c_str());
47 ASSERT_TRUE(file.is_open()); 54 ASSERT_TRUE(file.is_open());
48 file << contents; 55 file << contents;
49 file.close(); 56 file.close();
50 } 57 }
51 58
52 void BuildSingleChromeState(const FilePath& target_dir, 59 void BuildSingleChromeState(const FilePath& target_dir,
53 MockInstallerState* installer_state) { 60 MockInstallerState* installer_state) {
54 CommandLine cmd_line = CommandLine::FromString(L"setup.exe"); 61 CommandLine cmd_line = CommandLine::FromString(L"setup.exe");
55 installer::MasterPreferences prefs(cmd_line); 62 MasterPreferences prefs(cmd_line);
56 installer::InstallationState machine_state; 63 InstallationState machine_state;
57 machine_state.Initialize(); 64 machine_state.Initialize();
58 installer_state->Initialize(cmd_line, prefs, machine_state); 65 installer_state->Initialize(cmd_line, prefs, machine_state);
59 installer_state->set_target_path(target_dir); 66 installer_state->set_target_path(target_dir);
60 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER) 67 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER)
61 != NULL); 68 != NULL);
62 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_FRAME) 69 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_FRAME)
63 == NULL); 70 == NULL);
64 } 71 }
65 72
66 wchar_t text_content_1[] = L"delete me"; 73 wchar_t text_content_1[] = L"delete me";
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 232
226 // Tests a few basic things of the Package class. Makes sure that the path 233 // Tests a few basic things of the Package class. Makes sure that the path
227 // operations are correct 234 // operations are correct
228 TEST_F(InstallerStateTest, Basic) { 235 TEST_F(InstallerStateTest, Basic) {
229 const bool multi_install = false; 236 const bool multi_install = false;
230 const bool system_level = true; 237 const bool system_level = true;
231 CommandLine cmd_line = CommandLine::FromString( 238 CommandLine cmd_line = CommandLine::FromString(
232 std::wstring(L"setup.exe") + 239 std::wstring(L"setup.exe") +
233 (multi_install ? L" --multi-install --chrome" : L"") + 240 (multi_install ? L" --multi-install --chrome" : L"") +
234 (system_level ? L" --system-level" : L"")); 241 (system_level ? L" --system-level" : L""));
235 installer::MasterPreferences prefs(cmd_line); 242 MasterPreferences prefs(cmd_line);
236 installer::InstallationState machine_state; 243 InstallationState machine_state;
237 machine_state.Initialize(); 244 machine_state.Initialize();
238 MockInstallerState installer_state; 245 MockInstallerState installer_state;
239 installer_state.Initialize(cmd_line, prefs, machine_state); 246 installer_state.Initialize(cmd_line, prefs, machine_state);
240 installer_state.set_target_path(test_dir_.path()); 247 installer_state.set_target_path(test_dir_.path());
241 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); 248 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value());
242 EXPECT_EQ(1U, installer_state.products().size()); 249 EXPECT_EQ(1U, installer_state.products().size());
243 250
244 const char kOldVersion[] = "1.2.3.4"; 251 const char kOldVersion[] = "1.2.3.4";
245 const char kNewVersion[] = "2.3.4.5"; 252 const char kNewVersion[] = "2.3.4.5";
246 253
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 EXPECT_FALSE(file_util::PathExists(old_version_dir)); 315 EXPECT_FALSE(file_util::PathExists(old_version_dir));
309 } 316 }
310 317
311 TEST_F(InstallerStateTest, WithProduct) { 318 TEST_F(InstallerStateTest, WithProduct) {
312 const bool multi_install = false; 319 const bool multi_install = false;
313 const bool system_level = true; 320 const bool system_level = true;
314 CommandLine cmd_line = CommandLine::FromString( 321 CommandLine cmd_line = CommandLine::FromString(
315 std::wstring(L"setup.exe") + 322 std::wstring(L"setup.exe") +
316 (multi_install ? L" --multi-install --chrome" : L"") + 323 (multi_install ? L" --multi-install --chrome" : L"") +
317 (system_level ? L" --system-level" : L"")); 324 (system_level ? L" --system-level" : L""));
318 installer::MasterPreferences prefs(cmd_line); 325 MasterPreferences prefs(cmd_line);
319 installer::InstallationState machine_state; 326 InstallationState machine_state;
320 machine_state.Initialize(); 327 machine_state.Initialize();
321 MockInstallerState installer_state; 328 MockInstallerState installer_state;
322 installer_state.Initialize(cmd_line, prefs, machine_state); 329 installer_state.Initialize(cmd_line, prefs, machine_state);
323 installer_state.set_target_path(test_dir_.path()); 330 installer_state.set_target_path(test_dir_.path());
324 EXPECT_EQ(1U, installer_state.products().size()); 331 EXPECT_EQ(1U, installer_state.products().size());
325 EXPECT_EQ(system_level, installer_state.system_install()); 332 EXPECT_EQ(system_level, installer_state.system_install());
326 333
327 const char kCurrentVersion[] = "1.2.3.4"; 334 const char kCurrentVersion[] = "1.2.3.4";
328 scoped_ptr<Version> current_version( 335 scoped_ptr<Version> current_version(
329 Version::GetVersionFromString(kCurrentVersion)); 336 Version::GetVersionFromString(kCurrentVersion));
330 337
331 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 338 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
332 EXPECT_EQ(root, installer_state.root_key()); 339 EXPECT_EQ(root, installer_state.root_key());
333 { 340 {
334 TempRegKeyOverride override(root, L"root_pit"); 341 TempRegKeyOverride override(root, L"root_pit");
335 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( 342 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
336 BrowserDistribution::CHROME_BROWSER); 343 BrowserDistribution::CHROME_BROWSER);
337 base::win::RegKey chrome_key(root, dist->GetVersionKey().c_str(), 344 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS);
338 KEY_ALL_ACCESS);
339 EXPECT_TRUE(chrome_key.Valid()); 345 EXPECT_TRUE(chrome_key.Valid());
340 if (chrome_key.Valid()) { 346 if (chrome_key.Valid()) {
341 chrome_key.WriteValue(google_update::kRegVersionField, 347 chrome_key.WriteValue(google_update::kRegVersionField,
342 UTF8ToWide(current_version->GetString()).c_str()); 348 UTF8ToWide(current_version->GetString()).c_str());
343 machine_state.Initialize(); 349 machine_state.Initialize();
344 // TODO(tommi): Also test for when there exists a new_chrome.exe. 350 // TODO(tommi): Also test for when there exists a new_chrome.exe.
345 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion( 351 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion(
346 machine_state)); 352 machine_state));
347 EXPECT_TRUE(found_version.get() != NULL); 353 EXPECT_TRUE(found_version.get() != NULL);
348 if (found_version.get()) { 354 if (found_version.get()) {
349 EXPECT_TRUE(current_version->Equals(*found_version)); 355 EXPECT_TRUE(current_version->Equals(*found_version));
350 } 356 }
351 } 357 }
352 } 358 }
353 } 359 }
360
361 TEST_F(InstallerStateTest, InstallerResult) {
362 const bool system_level = true;
363 bool multi_install = false;
364 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
365
366 RegKey key;
367 std::wstring launch_cmd = L"hey diddle diddle";
368 std::wstring value;
369 DWORD dw_value;
370
371 // check results for a fresh install of single Chrome
372 {
373 TempRegKeyOverride override(root, L"root_inst_res");
374 CommandLine cmd_line = CommandLine::FromString(L"setup.exe --system-level");
375 const MasterPreferences prefs(cmd_line);
376 InstallationState machine_state;
377 machine_state.Initialize();
378 InstallerState state;
379 state.Initialize(cmd_line, prefs, machine_state);
380 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS,
381 IDS_INSTALL_OS_ERROR_BASE, &launch_cmd);
382 BrowserDistribution* distribution =
383 BrowserDistribution::GetSpecificDistribution(
384 BrowserDistribution::CHROME_BROWSER);
385 EXPECT_EQ(ERROR_SUCCESS,
386 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ));
387 EXPECT_EQ(ERROR_SUCCESS,
388 key.ReadValueDW(installer::kInstallerResult, &dw_value));
389 EXPECT_EQ(static_cast<DWORD>(0), dw_value);
390 EXPECT_EQ(ERROR_SUCCESS,
391 key.ReadValueDW(installer::kInstallerError, &dw_value));
392 EXPECT_EQ(static_cast<DWORD>(installer::FIRST_INSTALL_SUCCESS), dw_value);
393 EXPECT_EQ(ERROR_SUCCESS,
394 key.ReadValue(installer::kInstallerResultUIString, &value));
395 EXPECT_FALSE(value.empty());
396 EXPECT_EQ(ERROR_SUCCESS,
397 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value));
398 EXPECT_EQ(launch_cmd, value);
399 }
400 TempRegKeyOverride::DeleteAllTempKeys();
401
402 // check results for a fresh install of multi Chrome
403 {
404 TempRegKeyOverride override(root, L"root_inst_res");
405 CommandLine cmd_line = CommandLine::FromString(
406 L"setup.exe --system-level --multi-install --chrome");
407 const MasterPreferences prefs(cmd_line);
408 InstallationState machine_state;
409 machine_state.Initialize();
410 InstallerState state;
411 state.Initialize(cmd_line, prefs, machine_state);
412 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS, 0,
413 &launch_cmd);
414 BrowserDistribution* distribution =
415 BrowserDistribution::GetSpecificDistribution(
416 BrowserDistribution::CHROME_BROWSER);
417 BrowserDistribution* binaries =
418 BrowserDistribution::GetSpecificDistribution(
419 BrowserDistribution::CHROME_BINARIES);
420 EXPECT_EQ(ERROR_SUCCESS,
421 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ));
422 EXPECT_EQ(ERROR_SUCCESS,
423 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value));
424 EXPECT_EQ(launch_cmd, value);
425 EXPECT_EQ(ERROR_SUCCESS,
426 key.Open(root, binaries->GetStateKey().c_str(), KEY_READ));
427 EXPECT_EQ(ERROR_SUCCESS,
428 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value));
429 EXPECT_EQ(launch_cmd, value);
430 key.Close();
431 }
432 TempRegKeyOverride::DeleteAllTempKeys();
433 }
OLDNEW
« no previous file with comments | « chrome/installer/util/installer_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698