| 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 "base/win/registry.h" | 7 #include "base/win/registry.h" |
| 8 #include "base/version.h" | 8 #include "base/version.h" |
| 9 #include "chrome/common/chrome_constants.h" | 9 #include "chrome/common/chrome_constants.h" |
| 10 #include "chrome/installer/setup/setup_util.h" | 10 #include "chrome/installer/setup/setup_util.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 DWORD, | 93 DWORD, |
| 94 bool)); | 94 bool)); |
| 95 MOCK_METHOD3(AddSelfRegWorkItem, WorkItem* (const std::wstring&, | 95 MOCK_METHOD3(AddSelfRegWorkItem, WorkItem* (const std::wstring&, |
| 96 bool, | 96 bool, |
| 97 bool)); | 97 bool)); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class MockProductState : public ProductState { | 100 class MockProductState : public ProductState { |
| 101 public: | 101 public: |
| 102 // Takes ownership of |version|. | 102 // Takes ownership of |version|. |
| 103 void set_version(base::Version* version) { version_.reset(version); } | 103 void set_version(Version* version) { version_.reset(version); } |
| 104 void set_multi_install(bool multi) { multi_install_ = multi; } | 104 void set_multi_install(bool multi) { multi_install_ = multi; } |
| 105 void set_brand(const std::wstring& brand) { brand_ = brand; } | 105 void set_brand(const std::wstring& brand) { brand_ = brand; } |
| 106 void set_eula_accepted(DWORD eula_accepted) { | 106 void set_eula_accepted(DWORD eula_accepted) { |
| 107 has_eula_accepted_ = true; | 107 has_eula_accepted_ = true; |
| 108 eula_accepted_ = eula_accepted; | 108 eula_accepted_ = eula_accepted; |
| 109 } | 109 } |
| 110 void clear_eula_accepted() { has_eula_accepted_ = false; } | 110 void clear_eula_accepted() { has_eula_accepted_ = false; } |
| 111 void set_usagestats(DWORD usagestats) { | 111 void set_usagestats(DWORD usagestats) { |
| 112 has_usagestats_ = true; | 112 has_usagestats_ = true; |
| 113 usagestats_ = usagestats; | 113 usagestats_ = usagestats; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 InstallerState::set_package_type(type); | 160 InstallerState::set_package_type(type); |
| 161 } | 161 } |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 // The test fixture | 164 // The test fixture |
| 165 //------------------------------------------------------------------------------ | 165 //------------------------------------------------------------------------------ |
| 166 | 166 |
| 167 class InstallWorkerTest : public testing::Test { | 167 class InstallWorkerTest : public testing::Test { |
| 168 public: | 168 public: |
| 169 virtual void SetUp() { | 169 virtual void SetUp() { |
| 170 current_version_.reset(new base::Version("1.0.0.0")); | 170 current_version_.reset(new Version("1.0.0.0")); |
| 171 new_version_.reset(new base::Version("42.0.0.0")); | 171 new_version_.reset(new Version("42.0.0.0")); |
| 172 | 172 |
| 173 // Don't bother ensuring that these paths exist. Since we're just | 173 // Don't bother ensuring that these paths exist. Since we're just |
| 174 // building the work item lists and not running them, they shouldn't | 174 // building the work item lists and not running them, they shouldn't |
| 175 // actually be touched. | 175 // actually be touched. |
| 176 archive_path_ = | 176 archive_path_ = |
| 177 base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\chrome.7z"); | 177 base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\chrome.7z"); |
| 178 // TODO(robertshield): Take this from the BrowserDistribution once that | 178 // TODO(robertshield): Take this from the BrowserDistribution once that |
| 179 // no longer depends on MasterPreferences. | 179 // no longer depends on MasterPreferences. |
| 180 installation_path_ = | 180 installation_path_ = |
| 181 base::FilePath(L"C:\\Program Files\\Google\\Chrome\\"); | 181 base::FilePath(L"C:\\Program Files\\Google\\Chrome\\"); |
| 182 src_path_ = base::FilePath( | 182 src_path_ = base::FilePath( |
| 183 L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin"); | 183 L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin"); |
| 184 setup_path_ = base::FilePath( | 184 setup_path_ = base::FilePath( |
| 185 L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe"); | 185 L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe"); |
| 186 temp_dir_ = base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123"); | 186 temp_dir_ = base::FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123"); |
| 187 } | 187 } |
| 188 | 188 |
| 189 virtual void TearDown() { | 189 virtual void TearDown() { |
| 190 } | 190 } |
| 191 | 191 |
| 192 void MaybeAddBinariesToInstallationState( | 192 void MaybeAddBinariesToInstallationState( |
| 193 bool system_level, | 193 bool system_level, |
| 194 MockInstallationState* installation_state) { | 194 MockInstallationState* installation_state) { |
| 195 if (installation_state->GetProductState( | 195 if (installation_state->GetProductState( |
| 196 system_level, BrowserDistribution::CHROME_BINARIES) == NULL) { | 196 system_level, BrowserDistribution::CHROME_BINARIES) == NULL) { |
| 197 MockProductState product_state; | 197 MockProductState product_state; |
| 198 product_state.set_version(new base::Version(*current_version_)); | 198 product_state.set_version(new Version(*current_version_)); |
| 199 product_state.set_brand(L"TEST"); | 199 product_state.set_brand(L"TEST"); |
| 200 product_state.set_multi_install(true); | 200 product_state.set_multi_install(true); |
| 201 BrowserDistribution* dist = | 201 BrowserDistribution* dist = |
| 202 BrowserDistribution::GetSpecificDistribution( | 202 BrowserDistribution::GetSpecificDistribution( |
| 203 BrowserDistribution::CHROME_BINARIES); | 203 BrowserDistribution::CHROME_BINARIES); |
| 204 base::FilePath install_path = | 204 base::FilePath install_path = |
| 205 installer::GetChromeInstallPath(system_level, dist); | 205 installer::GetChromeInstallPath(system_level, dist); |
| 206 product_state.SetUninstallProgram( | 206 product_state.SetUninstallProgram( |
| 207 install_path.AppendASCII(current_version_->GetString()) | 207 install_path.AppendASCII(current_version_->GetString()) |
| 208 .Append(installer::kInstallerDir) | 208 .Append(installer::kInstallerDir) |
| 209 .Append(installer::kSetupExe)); | 209 .Append(installer::kSetupExe)); |
| 210 product_state.AddUninstallSwitch(installer::switches::kUninstall); | 210 product_state.AddUninstallSwitch(installer::switches::kUninstall); |
| 211 product_state.AddUninstallSwitch(installer::switches::kMultiInstall); | 211 product_state.AddUninstallSwitch(installer::switches::kMultiInstall); |
| 212 if (system_level) | 212 if (system_level) |
| 213 product_state.AddUninstallSwitch(installer::switches::kSystemLevel); | 213 product_state.AddUninstallSwitch(installer::switches::kSystemLevel); |
| 214 installation_state->SetProductState(system_level, | 214 installation_state->SetProductState(system_level, |
| 215 BrowserDistribution::CHROME_BINARIES, | 215 BrowserDistribution::CHROME_BINARIES, |
| 216 product_state); | 216 product_state); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 void AddChromeToInstallationState( | 220 void AddChromeToInstallationState( |
| 221 bool system_level, | 221 bool system_level, |
| 222 bool multi_install, | 222 bool multi_install, |
| 223 MockInstallationState* installation_state) { | 223 MockInstallationState* installation_state) { |
| 224 if (multi_install) | 224 if (multi_install) |
| 225 MaybeAddBinariesToInstallationState(system_level, installation_state); | 225 MaybeAddBinariesToInstallationState(system_level, installation_state); |
| 226 MockProductState product_state; | 226 MockProductState product_state; |
| 227 product_state.set_version(new base::Version(*current_version_)); | 227 product_state.set_version(new Version(*current_version_)); |
| 228 product_state.set_multi_install(multi_install); | 228 product_state.set_multi_install(multi_install); |
| 229 product_state.set_brand(L"TEST"); | 229 product_state.set_brand(L"TEST"); |
| 230 product_state.set_eula_accepted(1); | 230 product_state.set_eula_accepted(1); |
| 231 BrowserDistribution* dist = | 231 BrowserDistribution* dist = |
| 232 BrowserDistribution::GetSpecificDistribution( | 232 BrowserDistribution::GetSpecificDistribution( |
| 233 BrowserDistribution::CHROME_BROWSER); | 233 BrowserDistribution::CHROME_BROWSER); |
| 234 base::FilePath install_path = | 234 base::FilePath install_path = |
| 235 installer::GetChromeInstallPath(system_level, dist); | 235 installer::GetChromeInstallPath(system_level, dist); |
| 236 product_state.SetUninstallProgram( | 236 product_state.SetUninstallProgram( |
| 237 install_path.AppendASCII(current_version_->GetString()) | 237 install_path.AppendASCII(current_version_->GetString()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 250 product_state); | 250 product_state); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void AddChromeFrameToInstallationState( | 253 void AddChromeFrameToInstallationState( |
| 254 bool system_level, | 254 bool system_level, |
| 255 bool multi_install, | 255 bool multi_install, |
| 256 MockInstallationState* installation_state) { | 256 MockInstallationState* installation_state) { |
| 257 if (multi_install) | 257 if (multi_install) |
| 258 MaybeAddBinariesToInstallationState(system_level, installation_state); | 258 MaybeAddBinariesToInstallationState(system_level, installation_state); |
| 259 MockProductState product_state; | 259 MockProductState product_state; |
| 260 product_state.set_version(new base::Version(*current_version_)); | 260 product_state.set_version(new Version(*current_version_)); |
| 261 product_state.set_multi_install(multi_install); | 261 product_state.set_multi_install(multi_install); |
| 262 BrowserDistribution* dist = | 262 BrowserDistribution* dist = |
| 263 BrowserDistribution::GetSpecificDistribution( | 263 BrowserDistribution::GetSpecificDistribution( |
| 264 multi_install ? BrowserDistribution::CHROME_BINARIES : | 264 multi_install ? BrowserDistribution::CHROME_BINARIES : |
| 265 BrowserDistribution::CHROME_FRAME); | 265 BrowserDistribution::CHROME_FRAME); |
| 266 base::FilePath install_path = | 266 base::FilePath install_path = |
| 267 installer::GetChromeInstallPath(system_level, dist); | 267 installer::GetChromeInstallPath(system_level, dist); |
| 268 product_state.SetUninstallProgram( | 268 product_state.SetUninstallProgram( |
| 269 install_path.AppendASCII(current_version_->GetString()) | 269 install_path.AppendASCII(current_version_->GetString()) |
| 270 .Append(installer::kInstallerDir) | 270 .Append(installer::kInstallerDir) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 scoped_ptr<MockInstallerState> installer_state( | 411 scoped_ptr<MockInstallerState> installer_state( |
| 412 BuildBasicInstallerState(system_install, multi_install, machine_state, | 412 BuildBasicInstallerState(system_install, multi_install, machine_state, |
| 413 operation)); | 413 operation)); |
| 414 if (multi_install) | 414 if (multi_install) |
| 415 AddChromeBinariesToInstallerState(machine_state, installer_state.get()); | 415 AddChromeBinariesToInstallerState(machine_state, installer_state.get()); |
| 416 AddChromeFrameToInstallerState(machine_state, installer_state.get()); | 416 AddChromeFrameToInstallerState(machine_state, installer_state.get()); |
| 417 return installer_state.release(); | 417 return installer_state.release(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 protected: | 420 protected: |
| 421 scoped_ptr<base::Version> current_version_; | 421 scoped_ptr<Version> current_version_; |
| 422 scoped_ptr<base::Version> new_version_; | 422 scoped_ptr<Version> new_version_; |
| 423 base::FilePath archive_path_; | 423 base::FilePath archive_path_; |
| 424 base::FilePath installation_path_; | 424 base::FilePath installation_path_; |
| 425 base::FilePath setup_path_; | 425 base::FilePath setup_path_; |
| 426 base::FilePath src_path_; | 426 base::FilePath src_path_; |
| 427 base::FilePath temp_dir_; | 427 base::FilePath temp_dir_; |
| 428 }; | 428 }; |
| 429 | 429 |
| 430 // Tests | 430 // Tests |
| 431 //------------------------------------------------------------------------------ | 431 //------------------------------------------------------------------------------ |
| 432 | 432 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 | 535 |
| 536 TEST_F(InstallWorkerTest, GoogleUpdateWorkItemsTest) { | 536 TEST_F(InstallWorkerTest, GoogleUpdateWorkItemsTest) { |
| 537 const bool system_level = true; | 537 const bool system_level = true; |
| 538 const bool multi_install = true; | 538 const bool multi_install = true; |
| 539 MockWorkItemList work_item_list; | 539 MockWorkItemList work_item_list; |
| 540 | 540 |
| 541 scoped_ptr<MockInstallationState> installation_state( | 541 scoped_ptr<MockInstallationState> installation_state( |
| 542 BuildChromeInstallationState(system_level, false)); | 542 BuildChromeInstallationState(system_level, false)); |
| 543 | 543 |
| 544 MockProductState cf_state; | 544 MockProductState cf_state; |
| 545 cf_state.set_version(new base::Version(*current_version_)); | 545 cf_state.set_version(new Version(*current_version_)); |
| 546 cf_state.set_multi_install(false); | 546 cf_state.set_multi_install(false); |
| 547 | 547 |
| 548 installation_state->SetProductState(system_level, | 548 installation_state->SetProductState(system_level, |
| 549 BrowserDistribution::CHROME_FRAME, cf_state); | 549 BrowserDistribution::CHROME_FRAME, cf_state); |
| 550 | 550 |
| 551 scoped_ptr<MockInstallerState> installer_state( | 551 scoped_ptr<MockInstallerState> installer_state( |
| 552 BuildChromeInstallerState(system_level, multi_install, | 552 BuildChromeInstallerState(system_level, multi_install, |
| 553 *installation_state, | 553 *installation_state, |
| 554 InstallerState::MULTI_INSTALL)); | 554 InstallerState::MULTI_INSTALL)); |
| 555 | 555 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 // Test that usagestats values are migrated properly. | 608 // Test that usagestats values are migrated properly. |
| 609 TEST_F(InstallWorkerTest, AddUsageStatsWorkItems) { | 609 TEST_F(InstallWorkerTest, AddUsageStatsWorkItems) { |
| 610 const bool system_level = true; | 610 const bool system_level = true; |
| 611 const bool multi_install = true; | 611 const bool multi_install = true; |
| 612 MockWorkItemList work_item_list; | 612 MockWorkItemList work_item_list; |
| 613 | 613 |
| 614 scoped_ptr<MockInstallationState> installation_state( | 614 scoped_ptr<MockInstallationState> installation_state( |
| 615 BuildChromeInstallationState(system_level, multi_install)); | 615 BuildChromeInstallationState(system_level, multi_install)); |
| 616 | 616 |
| 617 MockProductState chrome_state; | 617 MockProductState chrome_state; |
| 618 chrome_state.set_version(new base::Version(*current_version_)); | 618 chrome_state.set_version(new Version(*current_version_)); |
| 619 chrome_state.set_multi_install(false); | 619 chrome_state.set_multi_install(false); |
| 620 chrome_state.set_usagestats(1); | 620 chrome_state.set_usagestats(1); |
| 621 | 621 |
| 622 installation_state->SetProductState(system_level, | 622 installation_state->SetProductState(system_level, |
| 623 BrowserDistribution::CHROME_BROWSER, chrome_state); | 623 BrowserDistribution::CHROME_BROWSER, chrome_state); |
| 624 | 624 |
| 625 scoped_ptr<MockInstallerState> installer_state( | 625 scoped_ptr<MockInstallerState> installer_state( |
| 626 BuildChromeInstallerState(system_level, multi_install, | 626 BuildChromeInstallerState(system_level, multi_install, |
| 627 *installation_state, | 627 *installation_state, |
| 628 InstallerState::MULTI_INSTALL)); | 628 InstallerState::MULTI_INSTALL)); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 prod_type_list[i_type_check]); | 797 prod_type_list[i_type_check]); |
| 798 bool prod_expect = (mach_after & (1 << i_type_check)) != 0; | 798 bool prod_expect = (mach_after & (1 << i_type_check)) != 0; |
| 799 EXPECT_EQ(prod_expect, prod_res); | 799 EXPECT_EQ(prod_expect, prod_res); |
| 800 } | 800 } |
| 801 } | 801 } |
| 802 } | 802 } |
| 803 } | 803 } |
| 804 } | 804 } |
| 805 | 805 |
| 806 #endif // defined(GOOGLE_CHROME_BUILD) | 806 #endif // defined(GOOGLE_CHROME_BUILD) |
| OLD | NEW |