Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium testing/gAuthors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/installer/setup/install_worker.h" | |
| 6 | |
| 7 #include "base/win/registry.h" | |
| 8 #include "base/version.h" | |
| 9 #include "chrome/installer/util/installation_state.h" | |
| 10 #include "chrome/installer/util/installer_state.h" | |
| 11 #include "chrome/installer/util/package.h" | |
| 12 #include "chrome/installer/util/package_properties.h" | |
| 13 #include "chrome/installer/util/work_item_list.h" | |
| 14 | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | |
| 17 | |
| 18 using installer::ChromiumPackageProperties; | |
| 19 using installer::InstallationState; | |
| 20 using installer::InstallerState; | |
| 21 using installer::Package; | |
| 22 using installer::PackageProperties; | |
| 23 using installer::PackagePropertiesImpl; | |
| 24 using installer::ProductState; | |
| 25 | |
| 26 using ::testing::_; | |
| 27 using ::testing::AtLeast; | |
| 28 | |
| 29 // MockClasses to help with testing | |
| 30 //------------------------------------------------------------------------------ | |
| 31 | |
| 32 class MockWorkItemList : public WorkItemList { | |
|
grt (UTC plus 2)
2011/01/12 16:18:02
Cool!
robertshield
2011/01/13 17:06:32
Thanks!
| |
| 33 public: | |
| 34 MockWorkItemList() {} | |
| 35 | |
| 36 MOCK_METHOD5(AddCopyTreeWorkItem, WorkItem*(const std::wstring&, | |
|
tommi (sloooow) - chröme
2011/01/12 19:02:49
Ah, I see :) I misunderstood the approach the othe
robertshield
2011/01/13 17:06:32
Thanks!
| |
| 37 const std::wstring&, | |
| 38 const std::wstring&, | |
| 39 CopyOverWriteOption, | |
| 40 const std::wstring&)); | |
| 41 MOCK_METHOD1(AddCreateDirWorkItem, WorkItem* (const FilePath&)); | |
| 42 MOCK_METHOD2(AddCreateRegKeyWorkItem, WorkItem* (HKEY, const std::wstring&)); | |
| 43 MOCK_METHOD2(AddDeleteRegKeyWorkItem, WorkItem* (HKEY, const std::wstring&)); | |
| 44 MOCK_METHOD4(AddDeleteRegValueWorkItem, WorkItem* (HKEY, | |
| 45 const std::wstring&, | |
| 46 const std::wstring&, | |
| 47 bool)); | |
| 48 MOCK_METHOD2(AddDeleteTreeWorkItem, WorkItem* (const FilePath&, | |
| 49 const std::vector<FilePath>&)); | |
| 50 MOCK_METHOD1(AddDeleteTreeWorkItem, WorkItem* (const FilePath&)); | |
| 51 MOCK_METHOD3(AddMoveTreeWorkItem, WorkItem* (const std::wstring&, | |
| 52 const std::wstring&, | |
| 53 const std::wstring&)); | |
| 54 MOCK_METHOD5(AddSetRegValueWorkItem, WorkItem*(HKEY, | |
| 55 const std::wstring&, | |
| 56 const std::wstring&, | |
| 57 const std::wstring&, | |
| 58 bool)); | |
| 59 MOCK_METHOD5(AddSetRegValueWorkItem, WorkItem* (HKEY, | |
| 60 const std::wstring&, | |
| 61 const std::wstring&, | |
| 62 DWORD, | |
| 63 bool)); | |
| 64 MOCK_METHOD3(AddSelfRegWorkItem, WorkItem* (const std::wstring&, | |
| 65 bool, | |
| 66 bool)); | |
| 67 }; | |
| 68 | |
| 69 // Okay, so this isn't really a mock as such, but it does add setter methods | |
| 70 // to make it easier to build custom InstallationStates. | |
| 71 class MockInstallationState : public InstallationState { | |
| 72 public: | |
| 73 // Included for testing. | |
| 74 void SetMultiPackageState(bool system_install, | |
| 75 const ProductState& package_state) { | |
| 76 ProductState& target = | |
| 77 (system_install ? system_products_ : user_products_) | |
| 78 [MULTI_PACKAGE_INDEX]; | |
| 79 target.CopyFrom(package_state); | |
| 80 } | |
| 81 | |
| 82 // Included for testing. | |
| 83 void SetProductState(bool system_install, | |
| 84 BrowserDistribution::Type type, | |
| 85 const ProductState& product_state) { | |
| 86 ProductState& target = (system_install ? system_products_ : | |
| 87 user_products_)[IndexFromDistType(type)]; | |
| 88 target.CopyFrom(product_state); | |
| 89 } | |
| 90 }; | |
| 91 | |
| 92 class MockInstallerState : public InstallerState { | |
| 93 public: | |
| 94 void set_system_install(bool system_install) { | |
| 95 system_install_ = system_install; | |
| 96 } | |
| 97 | |
| 98 void set_operation(Operation operation) { operation_ = operation; } | |
| 99 | |
| 100 void set_state_key(const std::wstring& state_key) { | |
| 101 state_key_ = state_key; | |
| 102 } | |
| 103 }; | |
| 104 | |
| 105 // The test fixture | |
| 106 //------------------------------------------------------------------------------ | |
| 107 | |
| 108 class InstallWorkerTest : public testing::Test { | |
| 109 public: | |
| 110 virtual void SetUp() { | |
| 111 new_version_.reset(Version::GetVersionFromString("42.0.0.0")); | |
| 112 current_version_.reset(Version::GetVersionFromString("1.0.0.0")); | |
| 113 | |
| 114 // Don't bother ensuring that these paths exist. Since we're just | |
| 115 // building the work item lists and not running them, they shouldn't | |
| 116 // actually be touched. | |
| 117 setup_path_ = FilePath(L"C:\\UnlikelyPath\\Temp\\CR_123.tmp\\setup.exe"); | |
| 118 archive_path_ = FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\chrome.7z"); | |
| 119 src_path_ = | |
| 120 FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123\\source\\Chrome-bin"); | |
| 121 temp_dir_ = FilePath(L"C:\\UnlikelyPath\\Temp\\chrome_123"); | |
| 122 // TODO(robertshield): Take this from the BrowserDistribution once that | |
| 123 // no longer depends on MasterPreferences. | |
| 124 installation_path_ = FilePath(L"C:\\Program Files\\Google\\Chrome\\"); | |
| 125 } | |
| 126 | |
| 127 virtual void TearDown() { | |
| 128 | |
| 129 } | |
| 130 | |
| 131 MockInstallationState* BuildChromeSingleSystemInstallationState() { | |
| 132 scoped_ptr<MockInstallationState> installation_state( | |
| 133 new MockInstallationState); | |
|
grt (UTC plus 2)
2011/01/12 16:18:02
nit: Call me old-fashioned, but I prefer new Foo()
robertshield
2011/01/13 17:06:32
You, sir, are old fashioned.
| |
| 134 | |
| 135 ProductState product_state; | |
| 136 product_state.set_version(current_version_->Clone()); | |
| 137 // Do not call SetMultiPackageState since this is a single install. | |
| 138 installation_state->SetProductState(true, | |
| 139 BrowserDistribution::CHROME_BROWSER, | |
| 140 product_state); | |
| 141 | |
| 142 return installation_state.release(); | |
| 143 } | |
| 144 | |
| 145 MockInstallerState* BuildChromeSingleSystemInstallerState() { | |
| 146 scoped_ptr<MockInstallerState> installer_state(new MockInstallerState); | |
| 147 | |
| 148 installer_state->set_system_install(true); | |
| 149 installer_state->set_operation(InstallerState::SINGLE_INSTALL_OR_UPDATE); | |
| 150 // Hope this next one isn't checked for now. | |
| 151 installer_state->set_state_key(L"PROBABLY_INVALID_REG_PATH"); | |
| 152 | |
| 153 return installer_state.release(); | |
| 154 } | |
| 155 | |
| 156 protected: | |
| 157 scoped_ptr<Version> current_version_; | |
| 158 scoped_ptr<Version> new_version_; | |
| 159 FilePath setup_path_; | |
| 160 FilePath archive_path_; | |
| 161 FilePath src_path_; | |
| 162 FilePath temp_dir_; | |
| 163 | |
|
grt (UTC plus 2)
2011/01/12 16:18:02
nit: does this blank line add something?
robertshield
2011/01/13 17:06:32
feng shui.
| |
| 164 FilePath installation_path_; | |
| 165 }; | |
| 166 | |
| 167 // Tests | |
| 168 //------------------------------------------------------------------------------ | |
| 169 | |
| 170 TEST_F(InstallWorkerTest, TestInstallChromeSingleSystem) { | |
| 171 MockWorkItemList work_item_list; | |
| 172 | |
| 173 scoped_ptr<InstallationState> installation_state( | |
| 174 BuildChromeSingleSystemInstallationState()); | |
| 175 | |
| 176 scoped_ptr<InstallerState> installer_state( | |
| 177 BuildChromeSingleSystemInstallerState()); | |
| 178 | |
| 179 // This MUST outlive the package, since the package doesn't assume ownership | |
| 180 // of it. Note: This feels like an implementation bug: | |
| 181 // The PackageProperties <-> Package relationship is 1:1 and nothing else | |
| 182 // uses the PackageProperties. I have the feeling that PackageProperties, and | |
| 183 // perhaps Package itself should not exist at all. | |
|
grt (UTC plus 2)
2011/01/12 16:18:02
this will be resolved if/when i finish my change-i
robertshield
2011/01/13 17:06:32
Then in addition to being old-fashioned, you are a
| |
| 184 scoped_ptr<PackageProperties> package_properties( | |
| 185 new ChromiumPackageProperties()); | |
| 186 | |
| 187 scoped_refptr<Package> package( | |
| 188 new Package(false, true, installation_path_, package_properties.get())); | |
| 189 | |
| 190 // Set up some expectations. | |
| 191 // TODO(robertshield): Set up some real expectations. | |
| 192 EXPECT_CALL(work_item_list, AddCopyTreeWorkItem(_,_,_,_,_)) | |
|
amit
2011/01/12 17:41:22
It will be nice if we can create a work item from
robertshield
2011/01/13 17:06:32
That sounds cool, I would like to tackle that in a
| |
| 193 .Times(AtLeast(1)); | |
| 194 | |
| 195 AddInstallWorkItems(*installation_state.get(), | |
| 196 *installer_state.get(), | |
| 197 false, | |
| 198 setup_path_, | |
| 199 archive_path_, | |
| 200 src_path_, | |
| 201 temp_dir_, | |
| 202 *new_version_.get(), | |
| 203 ¤t_version_, | |
| 204 *package.get(), | |
| 205 &work_item_list); | |
| 206 | |
|
grt (UTC plus 2)
2011/01/12 16:18:02
nit: remove extra newline.
robertshield
2011/01/13 17:06:32
Done.
| |
| 207 } | |
| OLD | NEW |