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
3 // found in the LICENSE file.
5 #include "chrome/installer/util/product.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/test_reg_util_win.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/installer/util/chrome_frame_distribution.h"
14 #include "chrome/installer/util/google_update_constants.h"
15 #include "chrome/installer/util/installation_state.h"
16 #include "chrome/installer/util/installer_state.h"
17 #include "chrome/installer/util/master_preferences.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 using base::win::RegKey
;
21 using installer::Product
;
22 using installer::MasterPreferences
;
23 using registry_util::RegistryOverrideManager
;
25 TEST(ProductTest
, ProductInstallBasic
) {
26 // TODO(tommi): We should mock this and use our mocked distribution.
27 const bool multi_install
= false;
28 const bool system_level
= true;
29 base::CommandLine cmd_line
= base::CommandLine::FromString(
30 std::wstring(L
"setup.exe") +
31 (multi_install
? L
" --multi-install --chrome" : L
"") +
32 (system_level
? L
" --system-level" : L
""));
33 installer::MasterPreferences
prefs(cmd_line
);
34 installer::InstallationState machine_state
;
35 machine_state
.Initialize();
36 installer::InstallerState installer_state
;
37 installer_state
.Initialize(cmd_line
, prefs
, machine_state
);
39 const Product
* product
= installer_state
.products()[0];
40 BrowserDistribution
* distribution
= product
->distribution();
41 EXPECT_EQ(BrowserDistribution::CHROME_BROWSER
, distribution
->GetType());
43 base::FilePath user_data_dir
;
44 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA
, &user_data_dir
));
45 EXPECT_FALSE(user_data_dir
.empty());
47 base::FilePath program_files
;
48 ASSERT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES
, &program_files
));
49 // The User Data path should never be under program files, even though
50 // system_level is true.
51 EXPECT_EQ(std::wstring::npos
,
52 user_data_dir
.value().find(program_files
.value()));
54 HKEY root
= installer_state
.root_key();
56 RegistryOverrideManager override_manager
;
57 override_manager
.OverrideRegistry(root
);
59 // There should be no installed version in the registry.
60 machine_state
.Initialize();
61 EXPECT_TRUE(machine_state
.GetProductState(
62 system_level
, distribution
->GetType()) == NULL
);
64 // Let's pretend chrome is installed.
65 RegKey
version_key(root
, distribution
->GetVersionKey().c_str(),
67 ASSERT_TRUE(version_key
.Valid());
69 const char kCurrentVersion
[] = "1.2.3.4";
70 Version
current_version(kCurrentVersion
);
71 version_key
.WriteValue(google_update::kRegVersionField
,
73 current_version
.GetString()).c_str());
75 // We started out with a non-msi product.
76 machine_state
.Initialize();
77 const installer::ProductState
* chrome_state
=
78 machine_state
.GetProductState(system_level
, distribution
->GetType());
79 EXPECT_TRUE(chrome_state
!= NULL
);
80 if (chrome_state
!= NULL
) {
81 EXPECT_TRUE(chrome_state
->version().Equals(current_version
));
82 EXPECT_FALSE(chrome_state
->is_msi());
85 // Create a make-believe client state key.
87 std::wstring
state_key_path(distribution
->GetStateKey());
88 ASSERT_EQ(ERROR_SUCCESS
,
89 key
.Create(root
, state_key_path
.c_str(), KEY_ALL_ACCESS
));
91 // Set the MSI marker, refresh, and verify that we now see the MSI marker.
92 EXPECT_TRUE(product
->SetMsiMarker(system_level
, true));
93 machine_state
.Initialize();
95 machine_state
.GetProductState(system_level
, distribution
->GetType());
96 EXPECT_TRUE(chrome_state
!= NULL
);
97 if (chrome_state
!= NULL
)
98 EXPECT_TRUE(chrome_state
->is_msi());
102 TEST(ProductTest
, LaunchChrome
) {
103 // TODO(tommi): Test Product::LaunchChrome and
104 // Product::LaunchChromeAndWait.