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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // Tests the scenario where one update check is done for one CRX. The CRX | 195 // Tests the scenario where one update check is done for one CRX. The CRX |
196 // has no update. | 196 // has no update. |
197 TEST_F(UpdateClientTest, OneCrxNoUpdate) { | 197 TEST_F(UpdateClientTest, OneCrxNoUpdate) { |
198 class DataCallbackFake { | 198 class DataCallbackFake { |
199 public: | 199 public: |
200 static void Callback(const std::vector<std::string>& ids, | 200 static void Callback(const std::vector<std::string>& ids, |
201 std::vector<CrxComponent>* components) { | 201 std::vector<CrxComponent>* components) { |
202 CrxComponent crx; | 202 CrxComponent crx; |
203 crx.name = "test_jebg"; | 203 crx.name = "test_jebg"; |
204 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 204 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
205 crx.version = Version("0.9"); | 205 crx.version = base::Version("0.9"); |
206 crx.installer = new TestInstaller; | 206 crx.installer = new TestInstaller; |
207 components->push_back(crx); | 207 components->push_back(crx); |
208 } | 208 } |
209 }; | 209 }; |
210 | 210 |
211 class CompletionCallbackFake { | 211 class CompletionCallbackFake { |
212 public: | 212 public: |
213 static void Callback(const base::Closure& quit_closure, int error) { | 213 static void Callback(const base::Closure& quit_closure, int error) { |
214 EXPECT_EQ(0, error); | 214 EXPECT_EQ(0, error); |
215 quit_closure.Run(); | 215 quit_closure.Run(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // Tests the scenario where two CRXs are checked for updates. On CRX has | 295 // Tests the scenario where two CRXs are checked for updates. On CRX has |
296 // an update, the other CRX does not. | 296 // an update, the other CRX does not. |
297 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { | 297 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { |
298 class DataCallbackFake { | 298 class DataCallbackFake { |
299 public: | 299 public: |
300 static void Callback(const std::vector<std::string>& ids, | 300 static void Callback(const std::vector<std::string>& ids, |
301 std::vector<CrxComponent>* components) { | 301 std::vector<CrxComponent>* components) { |
302 CrxComponent crx1; | 302 CrxComponent crx1; |
303 crx1.name = "test_jebg"; | 303 crx1.name = "test_jebg"; |
304 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 304 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
305 crx1.version = Version("0.9"); | 305 crx1.version = base::Version("0.9"); |
306 crx1.installer = new TestInstaller; | 306 crx1.installer = new TestInstaller; |
307 | 307 |
308 CrxComponent crx2; | 308 CrxComponent crx2; |
309 crx2.name = "test_abag"; | 309 crx2.name = "test_abag"; |
310 crx2.pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); | 310 crx2.pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); |
311 crx2.version = Version("2.2"); | 311 crx2.version = base::Version("2.2"); |
312 crx2.installer = new TestInstaller; | 312 crx2.installer = new TestInstaller; |
313 | 313 |
314 components->push_back(crx1); | 314 components->push_back(crx1); |
315 components->push_back(crx2); | 315 components->push_back(crx2); |
316 } | 316 } |
317 }; | 317 }; |
318 | 318 |
319 class CompletionCallbackFake { | 319 class CompletionCallbackFake { |
320 public: | 320 public: |
321 static void Callback(const base::Closure& quit_closure, int error) { | 321 static void Callback(const base::Closure& quit_closure, int error) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 478 |
479 // Tests the update check for two CRXs scenario. Both CRXs have updates. | 479 // Tests the update check for two CRXs scenario. Both CRXs have updates. |
480 TEST_F(UpdateClientTest, TwoCrxUpdate) { | 480 TEST_F(UpdateClientTest, TwoCrxUpdate) { |
481 class DataCallbackFake { | 481 class DataCallbackFake { |
482 public: | 482 public: |
483 static void Callback(const std::vector<std::string>& ids, | 483 static void Callback(const std::vector<std::string>& ids, |
484 std::vector<CrxComponent>* components) { | 484 std::vector<CrxComponent>* components) { |
485 CrxComponent crx1; | 485 CrxComponent crx1; |
486 crx1.name = "test_jebg"; | 486 crx1.name = "test_jebg"; |
487 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 487 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
488 crx1.version = Version("0.9"); | 488 crx1.version = base::Version("0.9"); |
489 crx1.installer = new TestInstaller; | 489 crx1.installer = new TestInstaller; |
490 | 490 |
491 CrxComponent crx2; | 491 CrxComponent crx2; |
492 crx2.name = "test_ihfo"; | 492 crx2.name = "test_ihfo"; |
493 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 493 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
494 crx2.version = Version("0.8"); | 494 crx2.version = base::Version("0.8"); |
495 crx2.installer = new TestInstaller; | 495 crx2.installer = new TestInstaller; |
496 | 496 |
497 components->push_back(crx1); | 497 components->push_back(crx1); |
498 components->push_back(crx2); | 498 components->push_back(crx2); |
499 } | 499 } |
500 }; | 500 }; |
501 | 501 |
502 class CompletionCallbackFake { | 502 class CompletionCallbackFake { |
503 public: | 503 public: |
504 static void Callback(const base::Closure& quit_closure, int error) { | 504 static void Callback(const base::Closure& quit_closure, int error) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 // CRX. The update for the first CRX fails. The update client waits before | 719 // CRX. The update for the first CRX fails. The update client waits before |
720 // attempting the update for the second CRX. This update succeeds. | 720 // attempting the update for the second CRX. This update succeeds. |
721 TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { | 721 TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { |
722 class DataCallbackFake { | 722 class DataCallbackFake { |
723 public: | 723 public: |
724 static void Callback(const std::vector<std::string>& ids, | 724 static void Callback(const std::vector<std::string>& ids, |
725 std::vector<CrxComponent>* components) { | 725 std::vector<CrxComponent>* components) { |
726 CrxComponent crx1; | 726 CrxComponent crx1; |
727 crx1.name = "test_jebg"; | 727 crx1.name = "test_jebg"; |
728 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 728 crx1.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
729 crx1.version = Version("0.9"); | 729 crx1.version = base::Version("0.9"); |
730 crx1.installer = new TestInstaller; | 730 crx1.installer = new TestInstaller; |
731 | 731 |
732 CrxComponent crx2; | 732 CrxComponent crx2; |
733 crx2.name = "test_ihfo"; | 733 crx2.name = "test_ihfo"; |
734 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 734 crx2.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
735 crx2.version = Version("0.8"); | 735 crx2.version = base::Version("0.8"); |
736 crx2.installer = new TestInstaller; | 736 crx2.installer = new TestInstaller; |
737 | 737 |
738 components->push_back(crx1); | 738 components->push_back(crx1); |
739 components->push_back(crx2); | 739 components->push_back(crx2); |
740 } | 740 } |
741 }; | 741 }; |
742 | 742 |
743 class CompletionCallbackFake { | 743 class CompletionCallbackFake { |
744 public: | 744 public: |
745 static void Callback(const base::Closure& quit_closure, int error) { | 745 static void Callback(const base::Closure& quit_closure, int error) { |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 static scoped_refptr<CrxInstaller> installer( | 966 static scoped_refptr<CrxInstaller> installer( |
967 new VersionedTestInstaller()); | 967 new VersionedTestInstaller()); |
968 | 968 |
969 ++num_calls; | 969 ++num_calls; |
970 | 970 |
971 CrxComponent crx; | 971 CrxComponent crx; |
972 crx.name = "test_ihfo"; | 972 crx.name = "test_ihfo"; |
973 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 973 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
974 crx.installer = installer; | 974 crx.installer = installer; |
975 if (num_calls == 1) { | 975 if (num_calls == 1) { |
976 crx.version = Version("0.8"); | 976 crx.version = base::Version("0.8"); |
977 } else if (num_calls == 2) { | 977 } else if (num_calls == 2) { |
978 crx.version = Version("1.0"); | 978 crx.version = base::Version("1.0"); |
979 } else { | 979 } else { |
980 NOTREACHED(); | 980 NOTREACHED(); |
981 } | 981 } |
982 | 982 |
983 components->push_back(crx); | 983 components->push_back(crx); |
984 } | 984 } |
985 }; | 985 }; |
986 | 986 |
987 class CompletionCallbackFake { | 987 class CompletionCallbackFake { |
988 public: | 988 public: |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 | 1251 |
1252 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0); | 1252 EXPECT_CALL(*installer, OnUpdateError(_)).Times(0); |
1253 EXPECT_CALL(*installer, Install(_, _)) | 1253 EXPECT_CALL(*installer, Install(_, _)) |
1254 .WillOnce(DoAll(Invoke(MockInstaller::OnInstall), Return(false))); | 1254 .WillOnce(DoAll(Invoke(MockInstaller::OnInstall), Return(false))); |
1255 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); | 1255 EXPECT_CALL(*installer, GetInstalledFile(_, _)).Times(0); |
1256 EXPECT_CALL(*installer, Uninstall()).Times(0); | 1256 EXPECT_CALL(*installer, Uninstall()).Times(0); |
1257 | 1257 |
1258 CrxComponent crx; | 1258 CrxComponent crx; |
1259 crx.name = "test_jebg"; | 1259 crx.name = "test_jebg"; |
1260 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 1260 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
1261 crx.version = Version("0.9"); | 1261 crx.version = base::Version("0.9"); |
1262 crx.installer = installer; | 1262 crx.installer = installer; |
1263 components->push_back(crx); | 1263 components->push_back(crx); |
1264 } | 1264 } |
1265 }; | 1265 }; |
1266 | 1266 |
1267 class CompletionCallbackFake { | 1267 class CompletionCallbackFake { |
1268 public: | 1268 public: |
1269 static void Callback(const base::Closure& quit_closure, int error) { | 1269 static void Callback(const base::Closure& quit_closure, int error) { |
1270 EXPECT_EQ(0, error); | 1270 EXPECT_EQ(0, error); |
1271 quit_closure.Run(); | 1271 quit_closure.Run(); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 static scoped_refptr<CrxInstaller> installer( | 1428 static scoped_refptr<CrxInstaller> installer( |
1429 new VersionedTestInstaller()); | 1429 new VersionedTestInstaller()); |
1430 | 1430 |
1431 ++num_calls; | 1431 ++num_calls; |
1432 | 1432 |
1433 CrxComponent crx; | 1433 CrxComponent crx; |
1434 crx.name = "test_ihfo"; | 1434 crx.name = "test_ihfo"; |
1435 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 1435 crx.pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
1436 crx.installer = installer; | 1436 crx.installer = installer; |
1437 if (num_calls == 1) { | 1437 if (num_calls == 1) { |
1438 crx.version = Version("0.8"); | 1438 crx.version = base::Version("0.8"); |
1439 } else if (num_calls == 2) { | 1439 } else if (num_calls == 2) { |
1440 crx.version = Version("1.0"); | 1440 crx.version = base::Version("1.0"); |
1441 } else { | 1441 } else { |
1442 NOTREACHED(); | 1442 NOTREACHED(); |
1443 } | 1443 } |
1444 | 1444 |
1445 components->push_back(crx); | 1445 components->push_back(crx); |
1446 } | 1446 } |
1447 }; | 1447 }; |
1448 | 1448 |
1449 class CompletionCallbackFake { | 1449 class CompletionCallbackFake { |
1450 public: | 1450 public: |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 // done for one CRX. The second update check call is queued up and will run | 1706 // done for one CRX. The second update check call is queued up and will run |
1707 // after the first check has completed. The CRX has no updates. | 1707 // after the first check has completed. The CRX has no updates. |
1708 TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { | 1708 TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { |
1709 class DataCallbackFake { | 1709 class DataCallbackFake { |
1710 public: | 1710 public: |
1711 static void Callback(const std::vector<std::string>& ids, | 1711 static void Callback(const std::vector<std::string>& ids, |
1712 std::vector<CrxComponent>* components) { | 1712 std::vector<CrxComponent>* components) { |
1713 CrxComponent crx; | 1713 CrxComponent crx; |
1714 crx.name = "test_jebg"; | 1714 crx.name = "test_jebg"; |
1715 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 1715 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
1716 crx.version = Version("0.9"); | 1716 crx.version = base::Version("0.9"); |
1717 crx.installer = new TestInstaller; | 1717 crx.installer = new TestInstaller; |
1718 components->push_back(crx); | 1718 components->push_back(crx); |
1719 } | 1719 } |
1720 }; | 1720 }; |
1721 | 1721 |
1722 class CompletionCallbackFake { | 1722 class CompletionCallbackFake { |
1723 public: | 1723 public: |
1724 static void Callback(const base::Closure& quit_closure, int error) { | 1724 static void Callback(const base::Closure& quit_closure, int error) { |
1725 static int num_call = 0; | 1725 static int num_call = 0; |
1726 ++num_call; | 1726 ++num_call; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 | 1811 |
1812 // Tests the install of one CRX. | 1812 // Tests the install of one CRX. |
1813 TEST_F(UpdateClientTest, OneCrxInstall) { | 1813 TEST_F(UpdateClientTest, OneCrxInstall) { |
1814 class DataCallbackFake { | 1814 class DataCallbackFake { |
1815 public: | 1815 public: |
1816 static void Callback(const std::vector<std::string>& ids, | 1816 static void Callback(const std::vector<std::string>& ids, |
1817 std::vector<CrxComponent>* components) { | 1817 std::vector<CrxComponent>* components) { |
1818 CrxComponent crx; | 1818 CrxComponent crx; |
1819 crx.name = "test_jebg"; | 1819 crx.name = "test_jebg"; |
1820 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 1820 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
1821 crx.version = Version("0.0"); | 1821 crx.version = base::Version("0.0"); |
1822 crx.installer = new TestInstaller; | 1822 crx.installer = new TestInstaller; |
1823 | 1823 |
1824 components->push_back(crx); | 1824 components->push_back(crx); |
1825 } | 1825 } |
1826 }; | 1826 }; |
1827 | 1827 |
1828 class CompletionCallbackFake { | 1828 class CompletionCallbackFake { |
1829 public: | 1829 public: |
1830 static void Callback(const base::Closure& quit_closure, int error) { | 1830 static void Callback(const base::Closure& quit_closure, int error) { |
1831 EXPECT_EQ(0, error); | 1831 EXPECT_EQ(0, error); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1977 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
1978 | 1978 |
1979 RunThreads(); | 1979 RunThreads(); |
1980 | 1980 |
1981 update_client->RemoveObserver(&observer); | 1981 update_client->RemoveObserver(&observer); |
1982 | 1982 |
1983 StopWorkerPool(); | 1983 StopWorkerPool(); |
1984 } | 1984 } |
1985 | 1985 |
1986 } // namespace update_client | 1986 } // namespace update_client |
OLD | NEW |