Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/update_client/update_client_unittest.cc

Issue 2479633003: Makes the component installers return a Result instead of a bool. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/update_client/update_client_errors.h ('k') | components/update_client/utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 update_client->RemoveObserver(&observer); 1268 update_client->RemoveObserver(&observer);
1269 } 1269 }
1270 1270
1271 // Tests the update scenario for one CRX where the CRX installer returns 1271 // Tests the update scenario for one CRX where the CRX installer returns
1272 // an error. 1272 // an error.
1273 TEST_F(UpdateClientTest, OneCrxInstallError) { 1273 TEST_F(UpdateClientTest, OneCrxInstallError) {
1274 class MockInstaller : public CrxInstaller { 1274 class MockInstaller : public CrxInstaller {
1275 public: 1275 public:
1276 MOCK_METHOD1(OnUpdateError, void(int error)); 1276 MOCK_METHOD1(OnUpdateError, void(int error));
1277 MOCK_METHOD2(Install, 1277 MOCK_METHOD2(Install,
1278 bool(const base::DictionaryValue& manifest, 1278 Result(const base::DictionaryValue& manifest,
1279 const base::FilePath& unpack_path)); 1279 const base::FilePath& unpack_path));
1280 MOCK_METHOD2(GetInstalledFile, 1280 MOCK_METHOD2(GetInstalledFile,
1281 bool(const std::string& file, base::FilePath* installed_file)); 1281 bool(const std::string& file, base::FilePath* installed_file));
1282 MOCK_METHOD0(Uninstall, bool()); 1282 MOCK_METHOD0(Uninstall, bool());
1283 1283
1284 static void OnInstall(const base::DictionaryValue& manifest, 1284 static void OnInstall(const base::DictionaryValue& manifest,
1285 const base::FilePath& unpack_path) { 1285 const base::FilePath& unpack_path) {
1286 base::DeleteFile(unpack_path, true); 1286 base::DeleteFile(unpack_path, true);
1287 } 1287 }
1288 1288
1289 protected: 1289 protected:
1290 ~MockInstaller() override {} 1290 ~MockInstaller() override {}
1291 }; 1291 };
1292 1292
1293 class DataCallbackFake { 1293 class DataCallbackFake {
1294 public: 1294 public:
1295 static void Callback(const std::vector<std::string>& ids, 1295 static void Callback(const std::vector<std::string>& ids,
1296 std::vector<CrxComponent>* components) { 1296 std::vector<CrxComponent>* components) {
1297 scoped_refptr<MockInstaller> installer(new MockInstaller()); 1297 scoped_refptr<MockInstaller> installer(new MockInstaller());
1298 1298
1299 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0); 1299 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0);
1300 EXPECT_CALL(*installer, Install(_, _)) 1300 EXPECT_CALL(*installer, Install(_, _))
1301 .WillOnce(DoAll(Invoke(MockInstaller::OnInstall), Return(false))); 1301 .WillOnce(
1302 DoAll(Invoke(MockInstaller::OnInstall),
1303 Return(CrxInstaller::Result(InstallError::GENERIC_ERROR))));
1302 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); 1304 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0);
1303 EXPECT_CALL(*installer, Uninstall()).Times(0); 1305 EXPECT_CALL(*installer, Uninstall()).Times(0);
1304 1306
1305 CrxComponent crx; 1307 CrxComponent crx;
1306 crx.name = "test_jebg"; 1308 crx.name = "test_jebg";
1307 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); 1309 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
1308 crx.version = base::Version("0.9"); 1310 crx.version = base::Version("0.9");
1309 crx.installer = installer; 1311 crx.installer = installer;
1310 components->push_back(crx); 1312 components->push_back(crx);
1311 } 1313 }
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 update_client->Update( 2708 update_client->Update(
2707 ids, base::Bind(&DataCallbackFake::Callback), 2709 ids, base::Bind(&DataCallbackFake::Callback),
2708 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); 2710 base::Bind(&CompletionCallbackFake::Callback, quit_closure()));
2709 2711
2710 RunThreads(); 2712 RunThreads();
2711 2713
2712 update_client->RemoveObserver(&observer); 2714 update_client->RemoveObserver(&observer);
2713 } 2715 }
2714 2716
2715 } // namespace update_client 2717 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/update_client_errors.h ('k') | components/update_client/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698