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