| OLD | NEW |
| 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 "chrome/installer/util/product_unittest.h" | 5 #include "chrome/installer/util/product_unittest.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/installer/util/chrome_frame_distribution.h" | 9 #include "chrome/installer/util/chrome_frame_distribution.h" |
| 10 #include "chrome/installer/util/google_update_constants.h" | 10 #include "chrome/installer/util/google_update_constants.h" |
| 11 #include "chrome/installer/util/installation_state.h" | 11 #include "chrome/installer/util/installation_state.h" |
| 12 #include "chrome/installer/util/package.h" | 12 #include "chrome/installer/util/installer_state.h" |
| 13 #include "chrome/installer/util/package_properties.h" | |
| 14 #include "chrome/installer/util/master_preferences.h" | 13 #include "chrome/installer/util/master_preferences.h" |
| 15 #include "chrome/installer/util/product.h" | 14 #include "chrome/installer/util/product.h" |
| 16 | 15 |
| 17 using base::win::RegKey; | 16 using base::win::RegKey; |
| 18 using installer::ChromePackageProperties; | |
| 19 using installer::ChromiumPackageProperties; | |
| 20 using installer::Package; | |
| 21 using installer::Product; | 17 using installer::Product; |
| 22 using installer::ProductPackageMapping; | |
| 23 using installer::MasterPreferences; | 18 using installer::MasterPreferences; |
| 24 | 19 |
| 25 void TestWithTempDir::SetUp() { | 20 void TestWithTempDir::SetUp() { |
| 26 // Name a subdirectory of the user temp directory. | 21 // Name a subdirectory of the user temp directory. |
| 27 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 22 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 28 } | 23 } |
| 29 | 24 |
| 30 void TestWithTempDir::TearDown() { | 25 void TestWithTempDir::TearDown() { |
| 31 logging::CloseLogFile(); | 26 logging::CloseLogFile(); |
| 32 ASSERT_TRUE(test_dir_.Delete()); | 27 ASSERT_TRUE(test_dir_.Delete()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 76 | 71 |
| 77 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { | 72 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { |
| 78 protected: | 73 protected: |
| 79 }; | 74 }; |
| 80 | 75 |
| 81 TEST_F(ProductTest, ProductInstallBasic) { | 76 TEST_F(ProductTest, ProductInstallBasic) { |
| 82 // TODO(tommi): We should mock this and use our mocked distribution. | 77 // TODO(tommi): We should mock this and use our mocked distribution. |
| 83 const bool multi_install = false; | 78 const bool multi_install = false; |
| 84 const bool system_level = true; | 79 const bool system_level = true; |
| 85 const installer::MasterPreferences& prefs = | 80 CommandLine cmd_line = CommandLine::FromString( |
| 86 installer::MasterPreferences::ForCurrentProcess(); | 81 std::wstring(L"setup.exe") + |
| 87 BrowserDistribution* distribution = | 82 (multi_install ? L" --multi-install --chrome" : L"") + |
| 88 BrowserDistribution::GetSpecificDistribution( | 83 (system_level ? L" --system-level" : L"")); |
| 89 BrowserDistribution::CHROME_BROWSER, prefs); | 84 installer::MasterPreferences prefs(cmd_line); |
| 90 ChromePackageProperties properties; | 85 installer::InstallationState machine_state; |
| 91 scoped_refptr<Package> package(new Package(multi_install, system_level, | 86 machine_state.Initialize(); |
| 92 test_dir_.path(), &properties)); | 87 installer::InstallerState installer_state; |
| 93 scoped_refptr<Product> product(new Product(distribution, package.get())); | 88 installer_state.Initialize(cmd_line, prefs, machine_state); |
| 89 |
| 90 const Product* product = installer_state.products()[0]; |
| 91 BrowserDistribution* distribution = product->distribution(); |
| 92 EXPECT_EQ(BrowserDistribution::CHROME_BROWSER, distribution->GetType()); |
| 94 | 93 |
| 95 FilePath user_data(product->GetUserDataPath()); | 94 FilePath user_data(product->GetUserDataPath()); |
| 96 EXPECT_FALSE(user_data.empty()); | 95 EXPECT_FALSE(user_data.empty()); |
| 97 EXPECT_NE(std::wstring::npos, | 96 EXPECT_NE(std::wstring::npos, |
| 98 user_data.value().find(installer::kInstallUserDataDir)); | 97 user_data.value().find(installer::kInstallUserDataDir)); |
| 99 | 98 |
| 100 FilePath program_files; | 99 FilePath program_files; |
| 101 PathService::Get(base::DIR_PROGRAM_FILES, &program_files); | 100 PathService::Get(base::DIR_PROGRAM_FILES, &program_files); |
| 102 // The User Data path should never be under program files, even though | 101 // The User Data path should never be under program files, even though |
| 103 // system_level is true. | 102 // system_level is true. |
| 104 EXPECT_EQ(std::wstring::npos, | 103 EXPECT_EQ(std::wstring::npos, |
| 105 user_data.value().find(program_files.value())); | 104 user_data.value().find(program_files.value())); |
| 106 | 105 |
| 107 // We started out with a non-msi product. | 106 // There should be no installed version in the registry. |
| 108 EXPECT_FALSE(product->IsMsi()); | 107 machine_state.Initialize(); |
| 108 EXPECT_TRUE(machine_state.GetProductState( |
| 109 system_level, distribution->GetType()) == NULL); |
| 109 | 110 |
| 110 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 111 HKEY root = installer_state.root_key(); |
| 111 { | 112 { |
| 112 TempRegKeyOverride override(root, L"root_pit"); | 113 TempRegKeyOverride override(root, L"root_pit"); |
| 113 | 114 |
| 114 // Create a make-believe client state key. | |
| 115 RegKey key; | |
| 116 std::wstring state_key_path(distribution->GetStateKey()); | |
| 117 ASSERT_EQ(ERROR_SUCCESS, | |
| 118 key.Create(root, state_key_path.c_str(), KEY_ALL_ACCESS)); | |
| 119 | |
| 120 // Set the MSI marker, delete the objects, create new ones and verify | |
| 121 // that we now see the MSI marker. | |
| 122 EXPECT_TRUE(product->SetMsiMarker(true)); | |
| 123 package = new Package(multi_install, system_level, test_dir_.path(), | |
| 124 &properties); | |
| 125 product = new Product(distribution, package.get()); | |
| 126 EXPECT_TRUE(product->IsMsi()); | |
| 127 | |
| 128 // There should be no installed version in the registry. | |
| 129 { | |
| 130 installer::InstallationState state; | |
| 131 state.Initialize(prefs); | |
| 132 EXPECT_TRUE(state.GetProductState(system_level, | |
| 133 distribution->GetType()) == NULL); | |
| 134 } | |
| 135 | |
| 136 // Let's pretend chrome is installed. | 115 // Let's pretend chrome is installed. |
| 137 RegKey version_key(root, distribution->GetVersionKey().c_str(), | 116 RegKey version_key(root, distribution->GetVersionKey().c_str(), |
| 138 KEY_ALL_ACCESS); | 117 KEY_ALL_ACCESS); |
| 139 ASSERT_TRUE(version_key.Valid()); | 118 ASSERT_TRUE(version_key.Valid()); |
| 140 | 119 |
| 141 const char kCurrentVersion[] = "1.2.3.4"; | 120 const char kCurrentVersion[] = "1.2.3.4"; |
| 142 scoped_ptr<Version> current_version( | 121 scoped_ptr<Version> current_version( |
| 143 Version::GetVersionFromString(kCurrentVersion)); | 122 Version::GetVersionFromString(kCurrentVersion)); |
| 144 version_key.WriteValue(google_update::kRegVersionField, | 123 version_key.WriteValue(google_update::kRegVersionField, |
| 145 UTF8ToWide(current_version->GetString()).c_str()); | 124 UTF8ToWide(current_version->GetString()).c_str()); |
| 146 | 125 |
| 147 { | 126 // We started out with a non-msi product. |
| 148 installer::InstallationState state; | 127 machine_state.Initialize(); |
| 149 state.Initialize(prefs); | 128 const installer::ProductState* chrome_state = |
| 150 const installer::ProductState* prod_state = | 129 machine_state.GetProductState(system_level, distribution->GetType()); |
| 151 state.GetProductState(system_level, distribution->GetType()); | 130 EXPECT_TRUE(chrome_state != NULL); |
| 152 EXPECT_TRUE(prod_state != NULL); | 131 if (chrome_state != NULL) { |
| 153 if (prod_state != NULL) { | 132 EXPECT_TRUE(chrome_state->version().Equals(*current_version.get())); |
| 154 EXPECT_TRUE(prod_state->version().Equals(*current_version.get())); | 133 EXPECT_FALSE(chrome_state->is_msi()); |
| 155 } | |
| 156 } | 134 } |
| 135 |
| 136 // Create a make-believe client state key. |
| 137 RegKey key; |
| 138 std::wstring state_key_path(distribution->GetStateKey()); |
| 139 ASSERT_EQ(ERROR_SUCCESS, |
| 140 key.Create(root, state_key_path.c_str(), KEY_ALL_ACCESS)); |
| 141 |
| 142 // Set the MSI marker, refresh, and verify that we now see the MSI marker. |
| 143 EXPECT_TRUE(product->SetMsiMarker(system_level, true)); |
| 144 machine_state.Initialize(); |
| 145 chrome_state = |
| 146 machine_state.GetProductState(system_level, distribution->GetType()); |
| 147 EXPECT_TRUE(chrome_state != NULL); |
| 148 if (chrome_state != NULL) |
| 149 EXPECT_TRUE(chrome_state->is_msi()); |
| 157 } | 150 } |
| 158 } | 151 } |
| 159 | 152 |
| 160 TEST_F(ProductTest, LaunchChrome) { | 153 TEST_F(ProductTest, LaunchChrome) { |
| 161 // TODO(tommi): Test Product::LaunchChrome and | 154 // TODO(tommi): Test Product::LaunchChrome and |
| 162 // Product::LaunchChromeAndWait. | 155 // Product::LaunchChromeAndWait. |
| 163 LOG(ERROR) << "Test not implemented."; | 156 LOG(ERROR) << "Test not implemented."; |
| 164 } | 157 } |
| 165 | |
| 166 // Overrides ChromeFrameDistribution for the sole purpose of returning | |
| 167 // the Chrome (not Chrome Frame) installation path. | |
| 168 class FakeChromeFrameDistribution : public ChromeFrameDistribution { | |
| 169 public: | |
| 170 explicit FakeChromeFrameDistribution( | |
| 171 const installer::MasterPreferences& prefs) | |
| 172 : ChromeFrameDistribution(prefs) {} | |
| 173 virtual std::wstring GetInstallSubDir() { | |
| 174 const MasterPreferences& prefs = | |
| 175 installer::MasterPreferences::ForCurrentProcess(); | |
| 176 return BrowserDistribution::GetSpecificDistribution( | |
| 177 BrowserDistribution::CHROME_BROWSER, prefs)->GetInstallSubDir(); | |
| 178 } | |
| 179 }; | |
| 180 | |
| 181 TEST_F(ProductTest, ProductInstallsBasic) { | |
| 182 const bool multi_install = true; | |
| 183 const bool system_level = true; | |
| 184 ProductPackageMapping installs(multi_install, system_level); | |
| 185 EXPECT_EQ(multi_install, installs.multi_install()); | |
| 186 EXPECT_EQ(system_level, installs.system_level()); | |
| 187 EXPECT_EQ(0U, installs.packages().size()); | |
| 188 EXPECT_EQ(0U, installs.products().size()); | |
| 189 | |
| 190 // TODO(robertshield): Include test that use mock master preferences. | |
| 191 const MasterPreferences& prefs = | |
| 192 installer::MasterPreferences::ForCurrentProcess(); | |
| 193 | |
| 194 installs.AddDistribution(BrowserDistribution::CHROME_BROWSER, prefs); | |
| 195 FakeChromeFrameDistribution fake_chrome_frame(prefs); | |
| 196 installs.AddDistribution(&fake_chrome_frame); | |
| 197 EXPECT_EQ(2U, installs.products().size()); | |
| 198 // Since our fake Chrome Frame distribution class is reporting the same | |
| 199 // installation directory as Chrome, we should have only one package object. | |
| 200 EXPECT_EQ(1U, installs.packages().size()); | |
| 201 EXPECT_EQ(multi_install, installs.packages()[0]->multi_install()); | |
| 202 } | |
| OLD | NEW |