| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_handle.h" | 8 #include "base/scoped_handle.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/master_preferences.h" | 11 #include "chrome/installer/util/master_preferences.h" |
| 12 #include "chrome/installer/util/product.h" | 12 #include "chrome/installer/util/product.h" |
| 13 | 13 |
| 14 using base::win::RegKey; | 14 using base::win::RegKey; |
| 15 using base::win::ScopedHandle; | 15 using base::win::ScopedHandle; |
| 16 using installer::Package; | 16 using installer::Package; |
| 17 using installer::Product; | 17 using installer::Product; |
| 18 using installer::ProductPackageMapping; | 18 using installer::ProductPackageMapping; |
| 19 using installer::Version; | 19 using installer::Version; |
| 20 using installer::MasterPreferences; | 20 using installer_util::MasterPreferences; |
| 21 | 21 |
| 22 void TestWithTempDir::SetUp() { | 22 void TestWithTempDir::SetUp() { |
| 23 // Name a subdirectory of the user temp directory. | 23 // Name a subdirectory of the user temp directory. |
| 24 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); | 24 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void TestWithTempDir::TearDown() { | 27 void TestWithTempDir::TearDown() { |
| 28 logging::CloseLogFile(); | 28 logging::CloseLogFile(); |
| 29 ASSERT_TRUE(test_dir_.Delete()); | 29 ASSERT_TRUE(test_dir_.Delete()); |
| 30 } | 30 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 73 | 73 |
| 74 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { | 74 class ProductTest : public TestWithTempDirAndDeleteTempOverrideKeys { |
| 75 protected: | 75 protected: |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 TEST_F(ProductTest, ProductInstallBasic) { | 78 TEST_F(ProductTest, ProductInstallBasic) { |
| 79 // TODO(tommi): We should mock this and use our mocked distribution. | 79 // TODO(tommi): We should mock this and use our mocked distribution. |
| 80 const bool system_level = true; | 80 const bool system_level = true; |
| 81 const installer::MasterPreferences& prefs = | 81 const installer_util::MasterPreferences& prefs = |
| 82 installer::MasterPreferences::ForCurrentProcess(); | 82 installer_util::MasterPreferences::ForCurrentProcess(); |
| 83 BrowserDistribution* distribution = | 83 BrowserDistribution* distribution = |
| 84 BrowserDistribution::GetSpecificDistribution( | 84 BrowserDistribution::GetSpecificDistribution( |
| 85 BrowserDistribution::CHROME_BROWSER, prefs); | 85 BrowserDistribution::CHROME_BROWSER, prefs); |
| 86 scoped_refptr<Package> package(new Package(test_dir_.path())); | 86 scoped_refptr<Package> package(new Package(test_dir_.path())); |
| 87 scoped_refptr<Product> product(new Product(distribution, system_level, | 87 scoped_refptr<Product> product(new Product(distribution, system_level, |
| 88 package.get())); | 88 package.get())); |
| 89 | 89 |
| 90 EXPECT_EQ(system_level, product->system_level()); | 90 EXPECT_EQ(system_level, product->system_level()); |
| 91 FilePath user_data(product->GetUserDataPath()); | 91 FilePath user_data(product->GetUserDataPath()); |
| 92 EXPECT_FALSE(user_data.empty()); | 92 EXPECT_FALSE(user_data.empty()); |
| 93 EXPECT_NE(std::wstring::npos, | 93 EXPECT_NE(std::wstring::npos, |
| 94 user_data.value().find(installer::kInstallUserDataDir)); | 94 user_data.value().find(installer_util::kInstallUserDataDir)); |
| 95 | 95 |
| 96 FilePath program_files; | 96 FilePath program_files; |
| 97 PathService::Get(base::DIR_PROGRAM_FILES, &program_files); | 97 PathService::Get(base::DIR_PROGRAM_FILES, &program_files); |
| 98 // The User Data path should never be under program files, even though | 98 // The User Data path should never be under program files, even though |
| 99 // system_level is true. | 99 // system_level is true. |
| 100 EXPECT_EQ(std::wstring::npos, | 100 EXPECT_EQ(std::wstring::npos, |
| 101 user_data.value().find(program_files.value())); | 101 user_data.value().find(program_files.value())); |
| 102 | 102 |
| 103 // We started out with a non-msi product. | 103 // We started out with a non-msi product. |
| 104 EXPECT_FALSE(product->IsMsi()); | 104 EXPECT_FALSE(product->IsMsi()); |
| 105 | 105 |
| 106 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 106 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 107 { | 107 { |
| 108 TempRegKeyOverride override(root, L"root_pit"); | 108 TempRegKeyOverride override(root, L"root_pit"); |
| 109 | 109 |
| 110 // Create a make-believe client state key. | 110 // Create a make-believe client state key. |
| 111 RegKey key; | 111 RegKey key; |
| 112 std::wstring state_key_path(distribution->GetStateKey()); | 112 std::wstring state_key_path(distribution->GetStateKey()); |
| 113 ASSERT_TRUE(key.Create(root, state_key_path.c_str(), KEY_ALL_ACCESS)); | 113 ASSERT_TRUE(key.Create(root, state_key_path.c_str(), KEY_ALL_ACCESS)); |
| 114 | 114 |
| 115 // Set the MSI marker, delete the objects, create new ones and verify | 115 // Set the MSI marker, delete the objects, create new ones and verify |
| 116 // that we now see the MSI marker. | 116 // that we now see the MSI marker. |
| 117 EXPECT_TRUE(product->SetMsiMarker(true)); | 117 EXPECT_TRUE(product->SetMsiMarker(true)); |
| 118 package = new Package(test_dir_.path()); | 118 package = new Package(test_dir_.path()); |
| 119 product = new Product(distribution, system_level, package.get()); | 119 product = new Product(distribution, system_level, package.get()); |
| 120 EXPECT_TRUE(product->IsMsi()); | 120 EXPECT_TRUE(product->IsMsi()); |
| 121 | 121 |
| 122 // See if WriteInstallerResult writes anything. | 122 // See if WriteInstallerResult writes anything. |
| 123 std::wstring launch_cmd(L"chrome.exe --this-is-a-test"); | 123 std::wstring launch_cmd(L"chrome.exe --this-is-a-test"); |
| 124 product->WriteInstallerResult(installer::TEMP_DIR_FAILED, | 124 product->WriteInstallerResult(installer_util::TEMP_DIR_FAILED, |
| 125 0, &launch_cmd); | 125 0, &launch_cmd); |
| 126 std::wstring found_launch_cmd; | 126 std::wstring found_launch_cmd; |
| 127 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, | 127 key.ReadValue(installer_util::kInstallerSuccessLaunchCmdLine, |
| 128 &found_launch_cmd); | 128 &found_launch_cmd); |
| 129 EXPECT_EQ(launch_cmd, found_launch_cmd); | 129 EXPECT_EQ(launch_cmd, found_launch_cmd); |
| 130 | 130 |
| 131 // There should be no installed version in the registry. | 131 // There should be no installed version in the registry. |
| 132 EXPECT_TRUE(product->GetInstalledVersion() == NULL); | 132 EXPECT_TRUE(product->GetInstalledVersion() == NULL); |
| 133 | 133 |
| 134 // Let's pretend chrome is installed. | 134 // Let's pretend chrome is installed. |
| 135 RegKey version_key(root, distribution->GetVersionKey().c_str(), | 135 RegKey version_key(root, distribution->GetVersionKey().c_str(), |
| 136 KEY_ALL_ACCESS); | 136 KEY_ALL_ACCESS); |
| 137 ASSERT_TRUE(version_key.Valid()); | 137 ASSERT_TRUE(version_key.Valid()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 154 // TODO(tommi): Test Product::LaunchChrome and | 154 // TODO(tommi): Test Product::LaunchChrome and |
| 155 // Product::LaunchChromeAndWait. | 155 // Product::LaunchChromeAndWait. |
| 156 LOG(ERROR) << "Test not implemented."; | 156 LOG(ERROR) << "Test not implemented."; |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Overrides ChromeFrameDistribution for the sole purpose of returning | 159 // Overrides ChromeFrameDistribution for the sole purpose of returning |
| 160 // the Chrome (not Chrome Frame) installation path. | 160 // the Chrome (not Chrome Frame) installation path. |
| 161 class FakeChromeFrameDistribution : public ChromeFrameDistribution { | 161 class FakeChromeFrameDistribution : public ChromeFrameDistribution { |
| 162 public: | 162 public: |
| 163 explicit FakeChromeFrameDistribution( | 163 explicit FakeChromeFrameDistribution( |
| 164 const installer::MasterPreferences& prefs) | 164 const installer_util::MasterPreferences& prefs) |
| 165 : ChromeFrameDistribution(prefs) {} | 165 : ChromeFrameDistribution(prefs) {} |
| 166 virtual std::wstring GetInstallSubDir() { | 166 virtual std::wstring GetInstallSubDir() { |
| 167 const MasterPreferences& prefs = | 167 const MasterPreferences& prefs = |
| 168 installer::MasterPreferences::ForCurrentProcess(); | 168 installer_util::MasterPreferences::ForCurrentProcess(); |
| 169 return BrowserDistribution::GetSpecificDistribution( | 169 return BrowserDistribution::GetSpecificDistribution( |
| 170 BrowserDistribution::CHROME_BROWSER, prefs)->GetInstallSubDir(); | 170 BrowserDistribution::CHROME_BROWSER, prefs)->GetInstallSubDir(); |
| 171 } | 171 } |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 TEST_F(ProductTest, ProductInstallsBasic) { | 174 TEST_F(ProductTest, ProductInstallsBasic) { |
| 175 const bool system_level = true; | 175 const bool system_level = true; |
| 176 ProductPackageMapping installs(system_level); | 176 ProductPackageMapping installs(system_level); |
| 177 EXPECT_EQ(system_level, installs.system_level()); | 177 EXPECT_EQ(system_level, installs.system_level()); |
| 178 EXPECT_EQ(0U, installs.packages().size()); | 178 EXPECT_EQ(0U, installs.packages().size()); |
| 179 EXPECT_EQ(0U, installs.products().size()); | 179 EXPECT_EQ(0U, installs.products().size()); |
| 180 | 180 |
| 181 // TODO(robertshield): Include test that use mock master preferences. | 181 // TODO(robertshield): Include test that use mock master preferences. |
| 182 const MasterPreferences& prefs = | 182 const MasterPreferences& prefs = |
| 183 installer::MasterPreferences::ForCurrentProcess(); | 183 installer_util::MasterPreferences::ForCurrentProcess(); |
| 184 | 184 |
| 185 installs.AddDistribution(BrowserDistribution::CHROME_BROWSER, prefs); | 185 installs.AddDistribution(BrowserDistribution::CHROME_BROWSER, prefs); |
| 186 FakeChromeFrameDistribution fake_chrome_frame(prefs); | 186 FakeChromeFrameDistribution fake_chrome_frame(prefs); |
| 187 installs.AddDistribution(&fake_chrome_frame); | 187 installs.AddDistribution(&fake_chrome_frame); |
| 188 EXPECT_EQ(2U, installs.products().size()); | 188 EXPECT_EQ(2U, installs.products().size()); |
| 189 // Since our fake Chrome Frame distribution class is reporting the same | 189 // Since our fake Chrome Frame distribution class is reporting the same |
| 190 // installation directory as Chrome, we should have only one package object. | 190 // installation directory as Chrome, we should have only one package object. |
| 191 EXPECT_EQ(1U, installs.packages().size()); | 191 EXPECT_EQ(1U, installs.packages().size()); |
| 192 } | 192 } |
| OLD | NEW |