sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. 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 <iterator> |
| 6 | #include <string> |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 7 | #include <utility> |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 10 | #include "base/bind.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 11 | #include "base/callback.h" |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
| 13 | #include "base/files/file_util.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 14 | #include "base/macros.h" |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 15 | #include "base/memory/ptr_util.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 17 | #include "base/path_service.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 18 | #include "base/run_loop.h" |
fdoray | b26583c | 2017-05-16 18:47:01 | [diff] [blame] | 19 | #include "base/task_scheduler/post_task.h" |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 20 | #include "base/test/scoped_path_override.h" |
fdoray | b26583c | 2017-05-16 18:47:01 | [diff] [blame] | 21 | #include "base/test/scoped_task_environment.h" |
| 22 | #include "base/threading/thread_task_runner_handle.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 23 | #include "base/version.h" |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 24 | #include "components/component_updater/component_installer.h" |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 25 | #include "components/component_updater/component_updater_paths.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 26 | #include "components/component_updater/component_updater_service.h" |
| 27 | #include "components/component_updater/component_updater_service_internal.h" |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 28 | #include "components/update_client/component_unpacker.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 29 | #include "components/update_client/crx_update_item.h" |
| 30 | #include "components/update_client/test_configurator.h" |
| 31 | #include "components/update_client/update_client.h" |
sorin | 7b865052 | 2016-11-02 18:23:41 | [diff] [blame] | 32 | #include "components/update_client/update_client_errors.h" |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 33 | #include "testing/gmock/include/gmock/gmock.h" |
| 34 | #include "testing/gtest/include/gtest/gtest.h" |
| 35 | |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 36 | using ComponentUnpacker = update_client::ComponentUnpacker; |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 37 | using Configurator = update_client::Configurator; |
| 38 | using CrxUpdateItem = update_client::CrxUpdateItem; |
| 39 | using TestConfigurator = update_client::TestConfigurator; |
| 40 | using UpdateClient = update_client::UpdateClient; |
| 41 | |
| 42 | using ::testing::_; |
| 43 | using ::testing::Invoke; |
| 44 | |
| 45 | namespace component_updater { |
| 46 | |
| 47 | namespace { |
| 48 | |
| 49 | // This hash corresponds to jebgalgnebhfojomionfpkfelancnnkf.crx. |
| 50 | const uint8_t kSha256Hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, |
| 51 | 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5, |
| 52 | 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4, |
| 53 | 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; |
| 54 | |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 55 | constexpr base::FilePath::CharType relative_install_dir[] = |
| 56 | FILE_PATH_LITERAL("fake"); |
| 57 | |
| 58 | base::FilePath test_file(const char* file) { |
| 59 | base::FilePath path; |
| 60 | PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 61 | return path.AppendASCII("components") |
| 62 | .AppendASCII("test") |
| 63 | .AppendASCII("data") |
| 64 | .AppendASCII("update_client") |
| 65 | .AppendASCII(file); |
| 66 | } |
| 67 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 68 | class MockUpdateClient : public UpdateClient { |
| 69 | public: |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 70 | MockUpdateClient() {} |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 71 | |
| 72 | void Install(const std::string& id, |
| 73 | const CrxDataCallback& crx_data_callback, |
| 74 | Callback callback) { |
| 75 | DoInstall(id, crx_data_callback); |
| 76 | std::move(callback).Run(update_client::Error::NONE); |
| 77 | } |
| 78 | |
| 79 | void Update(const std::vector<std::string>& ids, |
| 80 | const CrxDataCallback& crx_data_callback, |
| 81 | Callback callback) { |
| 82 | DoUpdate(ids, crx_data_callback); |
| 83 | std::move(callback).Run(update_client::Error::NONE); |
| 84 | } |
| 85 | |
| 86 | void SendUninstallPing(const std::string& id, |
| 87 | const base::Version& version, |
| 88 | int reason, |
| 89 | Callback callback) { |
| 90 | DoSendUninstallPing(id, version, reason); |
| 91 | std::move(callback).Run(update_client::Error::NONE); |
| 92 | } |
| 93 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 94 | MOCK_METHOD1(AddObserver, void(Observer* observer)); |
| 95 | MOCK_METHOD1(RemoveObserver, void(Observer* observer)); |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 96 | MOCK_METHOD2(DoInstall, |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 97 | void(const std::string& id, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 98 | const CrxDataCallback& crx_data_callback)); |
| 99 | MOCK_METHOD2(DoUpdate, |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 100 | void(const std::vector<std::string>& ids, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 101 | const CrxDataCallback& crx_data_callback)); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 102 | MOCK_CONST_METHOD2(GetCrxUpdateState, |
| 103 | bool(const std::string& id, CrxUpdateItem* update_item)); |
| 104 | MOCK_CONST_METHOD1(IsUpdating, bool(const std::string& id)); |
| 105 | MOCK_METHOD0(Stop, void()); |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 106 | MOCK_METHOD3(DoSendUninstallPing, |
sorin | 8037ac8c | 2017-04-19 16:28:00 | [diff] [blame] | 107 | void(const std::string& id, |
| 108 | const base::Version& version, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 109 | int reason)); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 110 | |
| 111 | private: |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 112 | ~MockUpdateClient() override {} |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 113 | }; |
| 114 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 115 | class FakeInstallerPolicy : public ComponentInstallerPolicy { |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 116 | public: |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 117 | FakeInstallerPolicy() {} |
| 118 | ~FakeInstallerPolicy() override {} |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 119 | |
| 120 | bool VerifyInstallation(const base::DictionaryValue& manifest, |
| 121 | const base::FilePath& dir) const override { |
| 122 | return true; |
| 123 | } |
| 124 | |
sorin | 3574ef9 | 2016-08-03 16:46:01 | [diff] [blame] | 125 | bool SupportsGroupPolicyEnabledComponentUpdates() const override { |
sorin | 098a4a7 | 2016-08-30 04:43:24 | [diff] [blame] | 126 | return true; |
sorin | 3574ef9 | 2016-08-03 16:46:01 | [diff] [blame] | 127 | } |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 128 | |
| 129 | bool RequiresNetworkEncryption() const override { return true; } |
| 130 | |
sorin | 2892f721 | 2016-11-07 18:59:43 | [diff] [blame] | 131 | update_client::CrxInstaller::Result OnCustomInstall( |
| 132 | const base::DictionaryValue& manifest, |
| 133 | const base::FilePath& install_dir) override { |
| 134 | return update_client::CrxInstaller::Result(0); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void ComponentReady( |
| 138 | const base::Version& version, |
| 139 | const base::FilePath& install_dir, |
| 140 | std::unique_ptr<base::DictionaryValue> manifest) override {} |
| 141 | |
| 142 | base::FilePath GetRelativeInstallDir() const override { |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 143 | return base::FilePath(relative_install_dir); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void GetHash(std::vector<uint8_t>* hash) const override { GetPkHash(hash); } |
| 147 | |
| 148 | std::string GetName() const override { return "fake name"; } |
| 149 | |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 150 | update_client::InstallerAttributes GetInstallerAttributes() const override { |
| 151 | update_client::InstallerAttributes installer_attributes; |
| 152 | installer_attributes["ap"] = "fake-ap"; |
| 153 | installer_attributes["is-enterprise"] = "1"; |
| 154 | return installer_attributes; |
| 155 | } |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 156 | |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 157 | std::vector<std::string> GetMimeTypes() const override { |
| 158 | return std::vector<std::string>(); |
| 159 | } |
| 160 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 161 | private: |
| 162 | static void GetPkHash(std::vector<uint8_t>* hash) { |
| 163 | hash->assign(std::begin(kSha256Hash), std::end(kSha256Hash)); |
| 164 | } |
| 165 | }; |
| 166 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 167 | class ComponentInstallerTest : public testing::Test { |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 168 | public: |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 169 | ComponentInstallerTest(); |
| 170 | ~ComponentInstallerTest() override; |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 171 | |
| 172 | MockUpdateClient& update_client() { return *update_client_; } |
| 173 | ComponentUpdateService* component_updater() { |
| 174 | return component_updater_.get(); |
| 175 | } |
| 176 | scoped_refptr<TestConfigurator> configurator() const { return config_; } |
| 177 | base::Closure quit_closure() const { return quit_closure_; } |
| 178 | |
| 179 | protected: |
| 180 | void RunThreads(); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 181 | void Unpack(const base::FilePath& crx_path); |
| 182 | ComponentUnpacker::Result result() const { return result_; } |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 183 | |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 184 | base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 185 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 186 | private: |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 187 | void UnpackComplete(const ComponentUnpacker::Result& result); |
| 188 | |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 189 | const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_ = |
| 190 | base::ThreadTaskRunnerHandle::Get(); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 191 | base::RunLoop runloop_; |
Sorin Jianu | cc048f89 | 2017-07-26 02:05:54 | [diff] [blame] | 192 | base::Closure quit_closure_ = runloop_.QuitClosure(); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 193 | |
Sorin Jianu | cc048f89 | 2017-07-26 02:05:54 | [diff] [blame] | 194 | scoped_refptr<TestConfigurator> config_ = |
| 195 | base::MakeRefCounted<TestConfigurator>(); |
| 196 | scoped_refptr<MockUpdateClient> update_client_ = |
| 197 | base::MakeRefCounted<MockUpdateClient>(); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 198 | std::unique_ptr<ComponentUpdateService> component_updater_; |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 199 | ComponentUnpacker::Result result_; |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 200 | }; |
| 201 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 202 | ComponentInstallerTest::ComponentInstallerTest() { |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 203 | EXPECT_CALL(update_client(), AddObserver(_)).Times(1); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 204 | component_updater_ = |
| 205 | base::MakeUnique<CrxUpdateService>(config_, update_client_); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 206 | } |
| 207 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 208 | ComponentInstallerTest::~ComponentInstallerTest() { |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 209 | EXPECT_CALL(update_client(), RemoveObserver(_)).Times(1); |
| 210 | component_updater_.reset(); |
| 211 | } |
| 212 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 213 | void ComponentInstallerTest::RunThreads() { |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 214 | runloop_.Run(); |
| 215 | } |
| 216 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 217 | void ComponentInstallerTest::Unpack(const base::FilePath& crx_path) { |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 218 | auto component_unpacker = base::MakeRefCounted<ComponentUnpacker>( |
| 219 | std::vector<uint8_t>(std::begin(kSha256Hash), std::end(kSha256Hash)), |
Sorin Jianu | ebd65246 | 2017-07-23 02:00:58 | [diff] [blame] | 220 | crx_path, nullptr, nullptr); |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 221 | component_unpacker->Unpack(base::Bind(&ComponentInstallerTest::UnpackComplete, |
| 222 | base::Unretained(this))); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 223 | RunThreads(); |
| 224 | } |
| 225 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 226 | void ComponentInstallerTest::UnpackComplete( |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 227 | const ComponentUnpacker::Result& result) { |
| 228 | result_ = result; |
| 229 | |
| 230 | EXPECT_EQ(update_client::UnpackerError::kNone, result_.error); |
| 231 | EXPECT_EQ(0, result_.extended_error); |
| 232 | |
| 233 | main_thread_task_runner_->PostTask(FROM_HERE, quit_closure_); |
| 234 | } |
| 235 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 236 | } // namespace |
| 237 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 238 | // Tests that the component metadata is propagated from the component installer |
| 239 | // and its component policy, through the instance of the CrxComponent, to the |
| 240 | // component updater service. |
| 241 | TEST_F(ComponentInstallerTest, RegisterComponent) { |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 242 | class LoopHandler { |
| 243 | public: |
| 244 | LoopHandler(int max_cnt, const base::Closure& quit_closure) |
| 245 | : max_cnt_(max_cnt), quit_closure_(quit_closure) {} |
| 246 | |
| 247 | void OnUpdate(const std::vector<std::string>& ids, |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 248 | const UpdateClient::CrxDataCallback& crx_data_callback) { |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 249 | static int cnt = 0; |
| 250 | ++cnt; |
| 251 | if (cnt >= max_cnt_) |
| 252 | quit_closure_.Run(); |
| 253 | } |
| 254 | |
| 255 | private: |
| 256 | const int max_cnt_; |
| 257 | base::Closure quit_closure_; |
| 258 | }; |
| 259 | |
Sorin Jianu | 0bf4bd3f | 2017-06-01 23:42:32 | [diff] [blame] | 260 | base::ScopedPathOverride scoped_path_override(DIR_COMPONENT_USER); |
| 261 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 262 | const std::string id("jebgalgnebhfojomionfpkfelancnnkf"); |
| 263 | |
| 264 | // Quit after one update check has been fired. |
| 265 | LoopHandler loop_handler(1, quit_closure()); |
Vladislav Kuzkokov | 12eca79 | 2017-10-20 12:45:38 | [diff] [blame^] | 266 | EXPECT_CALL(update_client(), DoUpdate(_, _)) |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 267 | .WillRepeatedly(Invoke(&loop_handler, &LoopHandler::OnUpdate)); |
| 268 | |
| 269 | EXPECT_CALL(update_client(), GetCrxUpdateState(id, _)).Times(1); |
| 270 | EXPECT_CALL(update_client(), Stop()).Times(1); |
| 271 | |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 272 | auto installer = base::MakeRefCounted<ComponentInstaller>( |
| 273 | base::MakeUnique<FakeInstallerPolicy>()); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 274 | installer->Register(component_updater(), base::Closure()); |
| 275 | |
| 276 | RunThreads(); |
| 277 | |
| 278 | CrxUpdateItem item; |
| 279 | EXPECT_TRUE(component_updater()->GetComponentDetails(id, &item)); |
| 280 | const CrxComponent& component(item.component); |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 281 | |
| 282 | update_client::InstallerAttributes expected_attrs; |
| 283 | expected_attrs["ap"] = "fake-ap"; |
| 284 | expected_attrs["is-enterprise"] = "1"; |
| 285 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 286 | EXPECT_EQ( |
| 287 | std::vector<uint8_t>(std::begin(kSha256Hash), std::end(kSha256Hash)), |
| 288 | component.pk_hash); |
| 289 | EXPECT_EQ(base::Version("0.0.0.0"), component.version); |
| 290 | EXPECT_TRUE(component.fingerprint.empty()); |
| 291 | EXPECT_STREQ("fake name", component.name.c_str()); |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 292 | EXPECT_EQ(expected_attrs, component.installer_attributes); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 293 | EXPECT_TRUE(component.requires_network_encryption); |
sorin | 098a4a7 | 2016-08-30 04:43:24 | [diff] [blame] | 294 | EXPECT_TRUE(component.supports_group_policy_enable_component_updates); |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 295 | } |
| 296 | |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 297 | // Tests that the unpack path is removed when the install succeeded. |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 298 | TEST_F(ComponentInstallerTest, UnpackPathInstallSuccess) { |
| 299 | auto installer = base::MakeRefCounted<ComponentInstaller>( |
| 300 | base::MakeUnique<FakeInstallerPolicy>()); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 301 | |
| 302 | Unpack(test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 303 | |
| 304 | const auto unpack_path = result().unpack_path; |
| 305 | EXPECT_TRUE(base::DirectoryExists(unpack_path)); |
Minh X. Nguyen | aafd763 | 2017-10-19 21:12:35 | [diff] [blame] | 306 | EXPECT_EQ(update_client::jebg_public_key, result().public_key); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 307 | |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 308 | base::ScopedPathOverride scoped_path_override(DIR_COMPONENT_USER); |
| 309 | base::FilePath base_dir; |
| 310 | EXPECT_TRUE(PathService::Get(DIR_COMPONENT_USER, &base_dir)); |
| 311 | base_dir = base_dir.Append(relative_install_dir); |
| 312 | EXPECT_TRUE(base::CreateDirectory(base_dir)); |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 313 | installer->Install( |
Sorin Jianu | 7aa6d1f | 2017-10-13 20:29:29 | [diff] [blame] | 314 | unpack_path, |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 315 | base::Bind([](const update_client::CrxInstaller::Result& result) { |
| 316 | EXPECT_EQ(0, result.error); |
| 317 | })); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 318 | |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 319 | scoped_task_environment_.RunUntilIdle(); |
| 320 | |
| 321 | EXPECT_FALSE(base::PathExists(unpack_path)); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 322 | EXPECT_CALL(update_client(), Stop()).Times(1); |
| 323 | } |
| 324 | |
| 325 | // Tests that the unpack path is removed when the install failed. |
Sorin Jianu | 08f92b3c | 2017-09-25 16:17:12 | [diff] [blame] | 326 | TEST_F(ComponentInstallerTest, UnpackPathInstallError) { |
| 327 | auto installer = base::MakeRefCounted<ComponentInstaller>( |
| 328 | base::MakeUnique<FakeInstallerPolicy>()); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 329 | |
| 330 | Unpack(test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 331 | |
| 332 | const auto unpack_path = result().unpack_path; |
| 333 | EXPECT_TRUE(base::DirectoryExists(unpack_path)); |
| 334 | |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 335 | // Test the precondition that DIR_COMPONENT_USER is not registered with |
| 336 | // the path service. |
| 337 | base::FilePath base_dir; |
| 338 | EXPECT_FALSE(PathService::Get(DIR_COMPONENT_USER, &base_dir)); |
| 339 | |
| 340 | // Calling |Install| fails since DIR_COMPONENT_USER does not exist. |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 341 | installer->Install( |
Sorin Jianu | 7aa6d1f | 2017-10-13 20:29:29 | [diff] [blame] | 342 | unpack_path, |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 343 | base::Bind([](const update_client::CrxInstaller::Result& result) { |
| 344 | EXPECT_EQ(static_cast<int>( |
| 345 | update_client::InstallError::NO_DIR_COMPONENT_USER), |
| 346 | result.error); |
| 347 | })); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 348 | |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 349 | scoped_task_environment_.RunUntilIdle(); |
| 350 | |
| 351 | EXPECT_FALSE(base::PathExists(unpack_path)); |
Sorin Jianu | 316232a | 2017-05-26 20:22:30 | [diff] [blame] | 352 | EXPECT_CALL(update_client(), Stop()).Times(1); |
| 353 | } |
| 354 | |
sorin | 6a57db9 | 2016-06-27 22:28:15 | [diff] [blame] | 355 | } // namespace component_updater |