| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/setup/install_worker.h" | 5 #include "chrome/installer/setup/install_worker.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/win/registry.h" | 9 #include "base/win/registry.h" |
| 10 #include "base/version.h" | 10 #include "base/version.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 DWORD, | 112 DWORD, |
| 113 bool)); | 113 bool)); |
| 114 MOCK_METHOD3(AddSelfRegWorkItem, WorkItem* (const std::wstring&, | 114 MOCK_METHOD3(AddSelfRegWorkItem, WorkItem* (const std::wstring&, |
| 115 bool, | 115 bool, |
| 116 bool)); | 116 bool)); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 class MockProductState : public ProductState { | 119 class MockProductState : public ProductState { |
| 120 public: | 120 public: |
| 121 // Takes ownership of |version|. | 121 // Takes ownership of |version|. |
| 122 void set_version(Version* version) { version_.reset(version); } | 122 void set_version(base::Version* version) { version_.reset(version); } |
| 123 void set_multi_install(bool multi) { multi_install_ = multi; } | 123 void set_multi_install(bool multi) { multi_install_ = multi; } |
| 124 void set_brand(const std::wstring& brand) { brand_ = brand; } | 124 void set_brand(const std::wstring& brand) { brand_ = brand; } |
| 125 void set_eula_accepted(DWORD eula_accepted) { | 125 void set_eula_accepted(DWORD eula_accepted) { |
| 126 has_eula_accepted_ = true; | 126 has_eula_accepted_ = true; |
| 127 eula_accepted_ = eula_accepted; | 127 eula_accepted_ = eula_accepted; |
| 128 } | 128 } |
| 129 void clear_eula_accepted() { has_eula_accepted_ = false; } | 129 void clear_eula_accepted() { has_eula_accepted_ = false; } |
| 130 void set_usagestats(DWORD usagestats) { | 130 void set_usagestats(DWORD usagestats) { |
| 131 has_usagestats_ = true; | 131 has_usagestats_ = true; |
| 132 usagestats_ = usagestats; | 132 usagestats_ = usagestats; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 InstallerState::set_package_type(type); | 179 InstallerState::set_package_type(type); |
| 180 } | 180 } |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 // The test fixture | 183 // The test fixture |
| 184 //------------------------------------------------------------------------------ | 184 //------------------------------------------------------------------------------ |
| 185 | 185 |
| 186 class InstallWorkerTest : public testing::Test { | 186 class InstallWorkerTest : public testing::Test { |
| 187 public: | 187 public: |
| 188 void SetUp() override { | 188 void SetUp() override { |
| 189 current_version_.reset(new Version("1.0.0.0")); | 189 current_version_.reset(new base::Version("1.0.0.0")); |
| 190 new_version_.reset(new Version("42.0.0.0")); | 190 new_version_.reset(new base::Version("42.0.0.0")); |
| 191 | 191 |
| 192 // Don't bother ensuring that these paths exist. Since we're just | 192 // Don't bother ensuring that these paths exist. Since we're just |
| 193 // building the work item lists and not running them, they shouldn't | 193 // building the work item lists and not running them, they shouldn't |
| 194 // actually be touched. | 194 // actually be touched. |
| 195 archive_path_ = | 195 archive_path_ = |
| 196 base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\chrome.7z"); | 196 base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\chrome.7z"); |
| 197 // TODO(robertshield): Take this from the BrowserDistribution once that | 197 // TODO(robertshield): Take this from the BrowserDistribution once that |
| 198 // no longer depends on MasterPreferences. | 198 // no longer depends on MasterPreferences. |
| 199 installation_path_ = | 199 installation_path_ = |
| 200 base::FilePath(L"C:\\Program Files\\Google\\Chrome\\"); | 200 base::FilePath(L"C:\\Program Files\\Google\\Chrome\\"); |
| 201 src_path_ = base::FilePath( | 201 src_path_ = base::FilePath( |
| 202 L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin"); | 202 L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin"); |
| 203 setup_path_ = base::FilePath( | 203 setup_path_ = base::FilePath( |
| 204 L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe"); | 204 L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe"); |
| 205 temp_dir_ = base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123"); | 205 temp_dir_ = base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123"); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void TearDown() override {} | 208 void TearDown() override {} |
| 209 | 209 |
| 210 void MaybeAddBinariesToInstallationState( | 210 void MaybeAddBinariesToInstallationState( |
| 211 bool system_level, | 211 bool system_level, |
| 212 MockInstallationState* installation_state) { | 212 MockInstallationState* installation_state) { |
| 213 if (installation_state->GetProductState( | 213 if (installation_state->GetProductState( |
| 214 system_level, BrowserDistribution::CHROME_BINARIES) == NULL) { | 214 system_level, BrowserDistribution::CHROME_BINARIES) == NULL) { |
| 215 MockProductState product_state; | 215 MockProductState product_state; |
| 216 product_state.set_version(new Version(*current_version_)); | 216 product_state.set_version(new base::Version(*current_version_)); |
| 217 product_state.set_brand(L"TEST"); | 217 product_state.set_brand(L"TEST"); |
| 218 product_state.set_multi_install(true); | 218 product_state.set_multi_install(true); |
| 219 BrowserDistribution* dist = | 219 BrowserDistribution* dist = |
| 220 BrowserDistribution::GetSpecificDistribution( | 220 BrowserDistribution::GetSpecificDistribution( |
| 221 BrowserDistribution::CHROME_BINARIES); | 221 BrowserDistribution::CHROME_BINARIES); |
| 222 base::FilePath install_path = | 222 base::FilePath install_path = |
| 223 installer::GetChromeInstallPath(system_level, dist); | 223 installer::GetChromeInstallPath(system_level, dist); |
| 224 product_state.SetUninstallProgram( | 224 product_state.SetUninstallProgram( |
| 225 install_path.AppendASCII(current_version_->GetString()) | 225 install_path.AppendASCII(current_version_->GetString()) |
| 226 .Append(installer::kInstallerDir) | 226 .Append(installer::kInstallerDir) |
| 227 .Append(installer::kSetupExe)); | 227 .Append(installer::kSetupExe)); |
| 228 product_state.AddUninstallSwitch(installer::switches::kUninstall); | 228 product_state.AddUninstallSwitch(installer::switches::kUninstall); |
| 229 product_state.AddUninstallSwitch(installer::switches::kMultiInstall); | 229 product_state.AddUninstallSwitch(installer::switches::kMultiInstall); |
| 230 if (system_level) | 230 if (system_level) |
| 231 product_state.AddUninstallSwitch(installer::switches::kSystemLevel); | 231 product_state.AddUninstallSwitch(installer::switches::kSystemLevel); |
| 232 installation_state->SetProductState(system_level, | 232 installation_state->SetProductState(system_level, |
| 233 BrowserDistribution::CHROME_BINARIES, | 233 BrowserDistribution::CHROME_BINARIES, |
| 234 product_state); | 234 product_state); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 void AddChromeToInstallationState( | 238 void AddChromeToInstallationState( |
| 239 bool system_level, | 239 bool system_level, |
| 240 bool multi_install, | 240 bool multi_install, |
| 241 MockInstallationState* installation_state) { | 241 MockInstallationState* installation_state) { |
| 242 if (multi_install) | 242 if (multi_install) |
| 243 MaybeAddBinariesToInstallationState(system_level, installation_state); | 243 MaybeAddBinariesToInstallationState(system_level, installation_state); |
| 244 MockProductState product_state; | 244 MockProductState product_state; |
| 245 product_state.set_version(new Version(*current_version_)); | 245 product_state.set_version(new base::Version(*current_version_)); |
| 246 product_state.set_multi_install(multi_install); | 246 product_state.set_multi_install(multi_install); |
| 247 product_state.set_brand(L"TEST"); | 247 product_state.set_brand(L"TEST"); |
| 248 product_state.set_eula_accepted(1); | 248 product_state.set_eula_accepted(1); |
| 249 BrowserDistribution* dist = | 249 BrowserDistribution* dist = |
| 250 BrowserDistribution::GetSpecificDistribution( | 250 BrowserDistribution::GetSpecificDistribution( |
| 251 BrowserDistribution::CHROME_BROWSER); | 251 BrowserDistribution::CHROME_BROWSER); |
| 252 base::FilePath install_path = | 252 base::FilePath install_path = |
| 253 installer::GetChromeInstallPath(system_level, dist); | 253 installer::GetChromeInstallPath(system_level, dist); |
| 254 product_state.SetUninstallProgram( | 254 product_state.SetUninstallProgram( |
| 255 install_path.AppendASCII(current_version_->GetString()) | 255 install_path.AppendASCII(current_version_->GetString()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 268 product_state); | 268 product_state); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void AddChromeFrameToInstallationState( | 271 void AddChromeFrameToInstallationState( |
| 272 bool system_level, | 272 bool system_level, |
| 273 bool multi_install, | 273 bool multi_install, |
| 274 MockInstallationState* installation_state) { | 274 MockInstallationState* installation_state) { |
| 275 if (multi_install) | 275 if (multi_install) |
| 276 MaybeAddBinariesToInstallationState(system_level, installation_state); | 276 MaybeAddBinariesToInstallationState(system_level, installation_state); |
| 277 MockProductState product_state; | 277 MockProductState product_state; |
| 278 product_state.set_version(new Version(*current_version_)); | 278 product_state.set_version(new base::Version(*current_version_)); |
| 279 product_state.set_multi_install(multi_install); | 279 product_state.set_multi_install(multi_install); |
| 280 BrowserDistribution* dist = | 280 BrowserDistribution* dist = |
| 281 BrowserDistribution::GetSpecificDistribution( | 281 BrowserDistribution::GetSpecificDistribution( |
| 282 multi_install ? BrowserDistribution::CHROME_BINARIES : | 282 multi_install ? BrowserDistribution::CHROME_BINARIES : |
| 283 BrowserDistribution::CHROME_FRAME); | 283 BrowserDistribution::CHROME_FRAME); |
| 284 base::FilePath install_path = | 284 base::FilePath install_path = |
| 285 installer::GetChromeInstallPath(system_level, dist); | 285 installer::GetChromeInstallPath(system_level, dist); |
| 286 product_state.SetUninstallProgram( | 286 product_state.SetUninstallProgram( |
| 287 install_path.AppendASCII(current_version_->GetString()) | 287 install_path.AppendASCII(current_version_->GetString()) |
| 288 .Append(installer::kInstallerDir) | 288 .Append(installer::kInstallerDir) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 scoped_ptr<MockInstallerState> installer_state( | 429 scoped_ptr<MockInstallerState> installer_state( |
| 430 BuildBasicInstallerState(system_install, multi_install, machine_state, | 430 BuildBasicInstallerState(system_install, multi_install, machine_state, |
| 431 operation)); | 431 operation)); |
| 432 if (multi_install) | 432 if (multi_install) |
| 433 AddChromeBinariesToInstallerState(machine_state, installer_state.get()); | 433 AddChromeBinariesToInstallerState(machine_state, installer_state.get()); |
| 434 AddChromeFrameToInstallerState(machine_state, installer_state.get()); | 434 AddChromeFrameToInstallerState(machine_state, installer_state.get()); |
| 435 return installer_state.release(); | 435 return installer_state.release(); |
| 436 } | 436 } |
| 437 | 437 |
| 438 protected: | 438 protected: |
| 439 scoped_ptr<Version> current_version_; | 439 scoped_ptr<base::Version> current_version_; |
| 440 scoped_ptr<Version> new_version_; | 440 scoped_ptr<base::Version> new_version_; |
| 441 base::FilePath archive_path_; | 441 base::FilePath archive_path_; |
| 442 base::FilePath installation_path_; | 442 base::FilePath installation_path_; |
| 443 base::FilePath setup_path_; | 443 base::FilePath setup_path_; |
| 444 base::FilePath src_path_; | 444 base::FilePath src_path_; |
| 445 base::FilePath temp_dir_; | 445 base::FilePath temp_dir_; |
| 446 }; | 446 }; |
| 447 | 447 |
| 448 // Tests | 448 // Tests |
| 449 //------------------------------------------------------------------------------ | 449 //------------------------------------------------------------------------------ |
| 450 | 450 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 TEST_F(InstallWorkerTest, GoogleUpdateWorkItemsTest) { | 562 TEST_F(InstallWorkerTest, GoogleUpdateWorkItemsTest) { |
| 563 const bool system_level = true; | 563 const bool system_level = true; |
| 564 const bool multi_install = true; | 564 const bool multi_install = true; |
| 565 MockWorkItemList work_item_list; | 565 MockWorkItemList work_item_list; |
| 566 | 566 |
| 567 // Per-machine single-install Chrome is installed. | 567 // Per-machine single-install Chrome is installed. |
| 568 scoped_ptr<MockInstallationState> installation_state( | 568 scoped_ptr<MockInstallationState> installation_state( |
| 569 BuildChromeInstallationState(system_level, false)); | 569 BuildChromeInstallationState(system_level, false)); |
| 570 | 570 |
| 571 MockProductState cf_state; | 571 MockProductState cf_state; |
| 572 cf_state.set_version(new Version(*current_version_)); | 572 cf_state.set_version(new base::Version(*current_version_)); |
| 573 cf_state.set_multi_install(false); | 573 cf_state.set_multi_install(false); |
| 574 | 574 |
| 575 // Per-machine single-install Chrome Frame is installed. | 575 // Per-machine single-install Chrome Frame is installed. |
| 576 installation_state->SetProductState(system_level, | 576 installation_state->SetProductState(system_level, |
| 577 BrowserDistribution::CHROME_FRAME, cf_state); | 577 BrowserDistribution::CHROME_FRAME, cf_state); |
| 578 | 578 |
| 579 // Prepare per-machine multi-install Chrome for installation. | 579 // Prepare per-machine multi-install Chrome for installation. |
| 580 scoped_ptr<MockInstallerState> installer_state( | 580 scoped_ptr<MockInstallerState> installer_state( |
| 581 BuildChromeInstallerState(system_level, multi_install, | 581 BuildChromeInstallerState(system_level, multi_install, |
| 582 *installation_state, | 582 *installation_state, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 // Test that usagestats values are migrated properly. | 634 // Test that usagestats values are migrated properly. |
| 635 TEST_F(InstallWorkerTest, AddUsageStatsWorkItems) { | 635 TEST_F(InstallWorkerTest, AddUsageStatsWorkItems) { |
| 636 const bool system_level = true; | 636 const bool system_level = true; |
| 637 const bool multi_install = true; | 637 const bool multi_install = true; |
| 638 MockWorkItemList work_item_list; | 638 MockWorkItemList work_item_list; |
| 639 | 639 |
| 640 scoped_ptr<MockInstallationState> installation_state( | 640 scoped_ptr<MockInstallationState> installation_state( |
| 641 BuildChromeInstallationState(system_level, multi_install)); | 641 BuildChromeInstallationState(system_level, multi_install)); |
| 642 | 642 |
| 643 MockProductState chrome_state; | 643 MockProductState chrome_state; |
| 644 chrome_state.set_version(new Version(*current_version_)); | 644 chrome_state.set_version(new base::Version(*current_version_)); |
| 645 chrome_state.set_multi_install(false); | 645 chrome_state.set_multi_install(false); |
| 646 chrome_state.set_usagestats(1); | 646 chrome_state.set_usagestats(1); |
| 647 | 647 |
| 648 installation_state->SetProductState(system_level, | 648 installation_state->SetProductState(system_level, |
| 649 BrowserDistribution::CHROME_BROWSER, chrome_state); | 649 BrowserDistribution::CHROME_BROWSER, chrome_state); |
| 650 | 650 |
| 651 scoped_ptr<MockInstallerState> installer_state( | 651 scoped_ptr<MockInstallerState> installer_state( |
| 652 BuildChromeInstallerState(system_level, multi_install, | 652 BuildChromeInstallerState(system_level, multi_install, |
| 653 *installation_state, | 653 *installation_state, |
| 654 InstallerState::MULTI_INSTALL)); | 654 InstallerState::MULTI_INSTALL)); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 prod_type_list[i_type_check]); | 828 prod_type_list[i_type_check]); |
| 829 bool prod_expect = (mach_after & (1 << i_type_check)) != 0; | 829 bool prod_expect = (mach_after & (1 << i_type_check)) != 0; |
| 830 EXPECT_EQ(prod_expect, prod_res); | 830 EXPECT_EQ(prod_expect, prod_res); |
| 831 } | 831 } |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 } | 834 } |
| 835 } | 835 } |
| 836 | 836 |
| 837 #endif // defined(GOOGLE_CHROME_BUILD) | 837 #endif // defined(GOOGLE_CHROME_BUILD) |
| OLD | NEW |