| OLD | NEW |
| 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 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 class MockInstaller : public CrxInstaller { | 1363 class MockInstaller : public CrxInstaller { |
| 1364 public: | 1364 public: |
| 1365 MOCK_METHOD1(OnUpdateError, void(int error)); | 1365 MOCK_METHOD1(OnUpdateError, void(int error)); |
| 1366 MOCK_METHOD2(Install, | 1366 MOCK_METHOD2(Install, |
| 1367 Result(const base::DictionaryValue& manifest, | 1367 Result(const base::DictionaryValue& manifest, |
| 1368 const base::FilePath& unpack_path)); | 1368 const base::FilePath& unpack_path)); |
| 1369 MOCK_METHOD2(GetInstalledFile, | 1369 MOCK_METHOD2(GetInstalledFile, |
| 1370 bool(const std::string& file, base::FilePath* installed_file)); | 1370 bool(const std::string& file, base::FilePath* installed_file)); |
| 1371 MOCK_METHOD0(Uninstall, bool()); | 1371 MOCK_METHOD0(Uninstall, bool()); |
| 1372 | 1372 |
| 1373 static void OnInstall(const base::DictionaryValue& manifest, | 1373 void OnInstall(const base::DictionaryValue& manifest, |
| 1374 const base::FilePath& unpack_path) { | 1374 const base::FilePath& unpack_path) { |
| 1375 base::DeleteFile(unpack_path, true); | 1375 unpack_path_ = unpack_path; |
| 1376 EXPECT_TRUE(base::DirectoryExists(unpack_path_)); |
| 1376 } | 1377 } |
| 1377 | 1378 |
| 1378 protected: | 1379 protected: |
| 1379 ~MockInstaller() override {} | 1380 ~MockInstaller() override { |
| 1381 // The unpack path is deleted unconditionally by the component state code, |
| 1382 // which is driving this installer. Therefore, the unpack path must not |
| 1383 // exist when this object is destroyed. |
| 1384 if (!unpack_path_.empty()) |
| 1385 EXPECT_FALSE(base::DirectoryExists(unpack_path_)); |
| 1386 } |
| 1387 |
| 1388 private: |
| 1389 // Contains the |unpack_path| argument of the Install call. |
| 1390 base::FilePath unpack_path_; |
| 1380 }; | 1391 }; |
| 1381 | 1392 |
| 1382 class DataCallbackFake { | 1393 class DataCallbackFake { |
| 1383 public: | 1394 public: |
| 1384 static void Callback(const std::vector<std::string>& ids, | 1395 static void Callback(const std::vector<std::string>& ids, |
| 1385 std::vector<CrxComponent>* components) { | 1396 std::vector<CrxComponent>* components) { |
| 1386 scoped_refptr<MockInstaller> installer = | 1397 scoped_refptr<MockInstaller> installer = |
| 1387 base::MakeRefCounted<MockInstaller>(); | 1398 base::MakeRefCounted<MockInstaller>(); |
| 1388 | 1399 |
| 1389 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0); | 1400 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0); |
| 1390 EXPECT_CALL(*installer, Install(_, _)) | 1401 EXPECT_CALL(*installer, Install(_, _)) |
| 1391 .WillOnce( | 1402 .WillOnce( |
| 1392 DoAll(Invoke(MockInstaller::OnInstall), | 1403 DoAll(Invoke(installer.get(), &MockInstaller::OnInstall), |
| 1393 Return(CrxInstaller::Result(InstallError::GENERIC_ERROR)))); | 1404 Return(CrxInstaller::Result(InstallError::GENERIC_ERROR)))); |
| 1394 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); | 1405 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); |
| 1395 EXPECT_CALL(*installer, Uninstall()).Times(0); | 1406 EXPECT_CALL(*installer, Uninstall()).Times(0); |
| 1396 | 1407 |
| 1397 CrxComponent crx; | 1408 CrxComponent crx; |
| 1398 crx.name = "test_jebg"; | 1409 crx.name = "test_jebg"; |
| 1399 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 1410 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 1400 crx.version = base::Version("0.9"); | 1411 crx.version = base::Version("0.9"); |
| 1401 crx.installer = installer; | 1412 crx.installer = installer; |
| 1402 components->push_back(crx); | 1413 components->push_back(crx); |
| (...skipping 1582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2985 update_client->Update( | 2996 update_client->Update( |
| 2986 ids, base::Bind(&DataCallbackFake::Callback), | 2997 ids, base::Bind(&DataCallbackFake::Callback), |
| 2987 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2998 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2988 | 2999 |
| 2989 RunThreads(); | 3000 RunThreads(); |
| 2990 | 3001 |
| 2991 update_client->RemoveObserver(&observer); | 3002 update_client->RemoveObserver(&observer); |
| 2992 } | 3003 } |
| 2993 | 3004 |
| 2994 } // namespace update_client | 3005 } // namespace update_client |
| OLD | NEW |