Android: Get rid of extra dup()s on launching child processes
[chromium-blink-merge.git] / chrome / installer / util / product_unittest.cc
blobd499548046a0d3e1e7d1c744a8b290ca1e722312
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_unittest.h"
7 #include "base/logging.h"
8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/test_reg_util_win.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/installer/util/chrome_frame_distribution.h"
13 #include "chrome/installer/util/google_update_constants.h"
14 #include "chrome/installer/util/installation_state.h"
15 #include "chrome/installer/util/installer_state.h"
16 #include "chrome/installer/util/master_preferences.h"
17 #include "chrome/installer/util/product.h"
19 using base::win::RegKey;
20 using installer::Product;
21 using installer::MasterPreferences;
22 using registry_util::RegistryOverrideManager;
24 void TestWithTempDir::SetUp() {
25 // Name a subdirectory of the user temp directory.
26 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
29 void TestWithTempDir::TearDown() {
30 logging::CloseLogFile();
31 ASSERT_TRUE(test_dir_.Delete());
34 ////////////////////////////////////////////////////////////////////////////////
36 void TestWithTempDirAndDeleteTempOverrideKeys::SetUp() {
37 TestWithTempDir::SetUp();
40 void TestWithTempDirAndDeleteTempOverrideKeys::TearDown() {
41 TestWithTempDir::TearDown();
44 ////////////////////////////////////////////////////////////////////////////////
46 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys {
47 protected:
50 TEST_F(ProductTest, ProductInstallBasic) {
51 // TODO(tommi): We should mock this and use our mocked distribution.
52 const bool multi_install = false;
53 const bool system_level = true;
54 base::CommandLine cmd_line = base::CommandLine::FromString(
55 std::wstring(L"setup.exe") +
56 (multi_install ? L" --multi-install --chrome" : L"") +
57 (system_level ? L" --system-level" : L""));
58 installer::MasterPreferences prefs(cmd_line);
59 installer::InstallationState machine_state;
60 machine_state.Initialize();
61 installer::InstallerState installer_state;
62 installer_state.Initialize(cmd_line, prefs, machine_state);
64 const Product* product = installer_state.products()[0];
65 BrowserDistribution* distribution = product->distribution();
66 EXPECT_EQ(BrowserDistribution::CHROME_BROWSER, distribution->GetType());
68 base::FilePath user_data_dir;
69 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
70 EXPECT_FALSE(user_data_dir.empty());
72 base::FilePath program_files;
73 ASSERT_TRUE(PathService::Get(base::DIR_PROGRAM_FILES, &program_files));
74 // The User Data path should never be under program files, even though
75 // system_level is true.
76 EXPECT_EQ(std::wstring::npos,
77 user_data_dir.value().find(program_files.value()));
79 HKEY root = installer_state.root_key();
81 RegistryOverrideManager override_manager;
82 override_manager.OverrideRegistry(root);
84 // There should be no installed version in the registry.
85 machine_state.Initialize();
86 EXPECT_TRUE(machine_state.GetProductState(
87 system_level, distribution->GetType()) == NULL);
89 // Let's pretend chrome is installed.
90 RegKey version_key(root, distribution->GetVersionKey().c_str(),
91 KEY_ALL_ACCESS);
92 ASSERT_TRUE(version_key.Valid());
94 const char kCurrentVersion[] = "1.2.3.4";
95 Version current_version(kCurrentVersion);
96 version_key.WriteValue(google_update::kRegVersionField,
97 base::UTF8ToWide(
98 current_version.GetString()).c_str());
100 // We started out with a non-msi product.
101 machine_state.Initialize();
102 const installer::ProductState* chrome_state =
103 machine_state.GetProductState(system_level, distribution->GetType());
104 EXPECT_TRUE(chrome_state != NULL);
105 if (chrome_state != NULL) {
106 EXPECT_TRUE(chrome_state->version().Equals(current_version));
107 EXPECT_FALSE(chrome_state->is_msi());
110 // Create a make-believe client state key.
111 RegKey key;
112 std::wstring state_key_path(distribution->GetStateKey());
113 ASSERT_EQ(ERROR_SUCCESS,
114 key.Create(root, state_key_path.c_str(), KEY_ALL_ACCESS));
116 // Set the MSI marker, refresh, and verify that we now see the MSI marker.
117 EXPECT_TRUE(product->SetMsiMarker(system_level, true));
118 machine_state.Initialize();
119 chrome_state =
120 machine_state.GetProductState(system_level, distribution->GetType());
121 EXPECT_TRUE(chrome_state != NULL);
122 if (chrome_state != NULL)
123 EXPECT_TRUE(chrome_state->is_msi());
127 TEST_F(ProductTest, LaunchChrome) {
128 // TODO(tommi): Test Product::LaunchChrome and
129 // Product::LaunchChromeAndWait.
130 LOG(ERROR) << "Test not implemented.";