| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 using std::string; | 131 using std::string; |
| 132 | 132 |
| 133 class UpdateClientTest : public testing::Test { | 133 class UpdateClientTest : public testing::Test { |
| 134 public: | 134 public: |
| 135 UpdateClientTest(); | 135 UpdateClientTest(); |
| 136 ~UpdateClientTest() override; | 136 ~UpdateClientTest() override; |
| 137 | 137 |
| 138 protected: | 138 protected: |
| 139 void RunThreads(); | 139 void RunThreads(); |
| 140 void StopWorkerPool(); |
| 140 | 141 |
| 141 // Returns the full path to a test file. | 142 // Returns the full path to a test file. |
| 142 static base::FilePath TestFilePath(const char* file); | 143 static base::FilePath TestFilePath(const char* file); |
| 143 | 144 |
| 144 scoped_refptr<update_client::Configurator> config() { return config_; } | 145 scoped_refptr<update_client::Configurator> config() { return config_; } |
| 145 | 146 |
| 146 base::Closure quit_closure() { return quit_closure_; } | 147 base::Closure quit_closure() { return quit_closure_; } |
| 147 | 148 |
| 148 private: | 149 private: |
| 149 static const int kNumWorkerThreads_ = 2; | 150 static const int kNumWorkerThreads_ = 2; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 170 message_loop_.task_runner()); | 171 message_loop_.task_runner()); |
| 171 } | 172 } |
| 172 | 173 |
| 173 UpdateClientTest::~UpdateClientTest() { | 174 UpdateClientTest::~UpdateClientTest() { |
| 174 } | 175 } |
| 175 | 176 |
| 176 void UpdateClientTest::RunThreads() { | 177 void UpdateClientTest::RunThreads() { |
| 177 runloop_.Run(); | 178 runloop_.Run(); |
| 178 } | 179 } |
| 179 | 180 |
| 181 void UpdateClientTest::StopWorkerPool() { |
| 182 worker_pool_->pool()->Shutdown(); |
| 183 } |
| 184 |
| 180 base::FilePath UpdateClientTest::TestFilePath(const char* file) { | 185 base::FilePath UpdateClientTest::TestFilePath(const char* file) { |
| 181 base::FilePath path; | 186 base::FilePath path; |
| 182 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 187 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 183 return path.AppendASCII("components") | 188 return path.AppendASCII("components") |
| 184 .AppendASCII("test") | 189 .AppendASCII("test") |
| 185 .AppendASCII("data") | 190 .AppendASCII("data") |
| 186 .AppendASCII("update_client") | 191 .AppendASCII("update_client") |
| 187 .AppendASCII(file); | 192 .AppendASCII(file); |
| 188 } | 193 } |
| 189 | 194 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 std::vector<std::string> ids; | 280 std::vector<std::string> ids; |
| 276 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 281 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); |
| 277 | 282 |
| 278 update_client->Update( | 283 update_client->Update( |
| 279 ids, base::Bind(&DataCallbackFake::Callback), | 284 ids, base::Bind(&DataCallbackFake::Callback), |
| 280 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 285 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 281 | 286 |
| 282 RunThreads(); | 287 RunThreads(); |
| 283 | 288 |
| 284 update_client->RemoveObserver(&observer); | 289 update_client->RemoveObserver(&observer); |
| 290 |
| 291 StopWorkerPool(); |
| 285 } | 292 } |
| 286 | 293 |
| 287 // Tests the scenario where two CRXs are checked for updates. On CRX has | 294 // Tests the scenario where two CRXs are checked for updates. On CRX has |
| 288 // an update, the other CRX does not. | 295 // an update, the other CRX does not. |
| 289 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { | 296 TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { |
| 290 class DataCallbackFake { | 297 class DataCallbackFake { |
| 291 public: | 298 public: |
| 292 static void Callback(const std::vector<std::string>& ids, | 299 static void Callback(const std::vector<std::string>& ids, |
| 293 std::vector<CrxComponent>* components) { | 300 std::vector<CrxComponent>* components) { |
| 294 CrxComponent crx1; | 301 CrxComponent crx1; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 463 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); |
| 457 ids.push_back(std::string("abagagagagagagagagagagagagagagag")); | 464 ids.push_back(std::string("abagagagagagagagagagagagagagagag")); |
| 458 | 465 |
| 459 update_client->Update( | 466 update_client->Update( |
| 460 ids, base::Bind(&DataCallbackFake::Callback), | 467 ids, base::Bind(&DataCallbackFake::Callback), |
| 461 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 468 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 462 | 469 |
| 463 RunThreads(); | 470 RunThreads(); |
| 464 | 471 |
| 465 update_client->RemoveObserver(&observer); | 472 update_client->RemoveObserver(&observer); |
| 473 |
| 474 StopWorkerPool(); |
| 466 } | 475 } |
| 467 | 476 |
| 468 // Tests the update check for two CRXs scenario. Both CRXs have updates. | 477 // Tests the update check for two CRXs scenario. Both CRXs have updates. |
| 469 TEST_F(UpdateClientTest, TwoCrxUpdate) { | 478 TEST_F(UpdateClientTest, TwoCrxUpdate) { |
| 470 class DataCallbackFake { | 479 class DataCallbackFake { |
| 471 public: | 480 public: |
| 472 static void Callback(const std::vector<std::string>& ids, | 481 static void Callback(const std::vector<std::string>& ids, |
| 473 std::vector<CrxComponent>* components) { | 482 std::vector<CrxComponent>* components) { |
| 474 CrxComponent crx1; | 483 CrxComponent crx1; |
| 475 crx1.name = "test_jebg"; | 484 crx1.name = "test_jebg"; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 701 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); |
| 693 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); | 702 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); |
| 694 | 703 |
| 695 update_client->Update( | 704 update_client->Update( |
| 696 ids, base::Bind(&DataCallbackFake::Callback), | 705 ids, base::Bind(&DataCallbackFake::Callback), |
| 697 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 706 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 698 | 707 |
| 699 RunThreads(); | 708 RunThreads(); |
| 700 | 709 |
| 701 update_client->RemoveObserver(&observer); | 710 update_client->RemoveObserver(&observer); |
| 711 |
| 712 StopWorkerPool(); |
| 702 } | 713 } |
| 703 | 714 |
| 704 // Tests the scenario where there is a download timeout for the first | 715 // Tests the scenario where there is a download timeout for the first |
| 705 // CRX. The update for the first CRX fails. The update client waits before | 716 // CRX. The update for the first CRX fails. The update client waits before |
| 706 // attempting the update for the second CRX. This update succeeds. | 717 // attempting the update for the second CRX. This update succeeds. |
| 707 TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { | 718 TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { |
| 708 class DataCallbackFake { | 719 class DataCallbackFake { |
| 709 public: | 720 public: |
| 710 static void Callback(const std::vector<std::string>& ids, | 721 static void Callback(const std::vector<std::string>& ids, |
| 711 std::vector<CrxComponent>* components) { | 722 std::vector<CrxComponent>* components) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 939 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); |
| 929 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); | 940 ids.push_back(std::string("ihfokbkgjpifnbbojhneepfflplebdkc")); |
| 930 | 941 |
| 931 update_client->Update( | 942 update_client->Update( |
| 932 ids, base::Bind(&DataCallbackFake::Callback), | 943 ids, base::Bind(&DataCallbackFake::Callback), |
| 933 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 944 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 934 | 945 |
| 935 RunThreads(); | 946 RunThreads(); |
| 936 | 947 |
| 937 update_client->RemoveObserver(&observer); | 948 update_client->RemoveObserver(&observer); |
| 949 |
| 950 StopWorkerPool(); |
| 938 } | 951 } |
| 939 | 952 |
| 940 // Tests the differential update scenario for one CRX. | 953 // Tests the differential update scenario for one CRX. |
| 941 TEST_F(UpdateClientTest, OneCrxDiffUpdate) { | 954 TEST_F(UpdateClientTest, OneCrxDiffUpdate) { |
| 942 class DataCallbackFake { | 955 class DataCallbackFake { |
| 943 public: | 956 public: |
| 944 static void Callback(const std::vector<std::string>& ids, | 957 static void Callback(const std::vector<std::string>& ids, |
| 945 std::vector<CrxComponent>* components) { | 958 std::vector<CrxComponent>* components) { |
| 946 static int num_calls = 0; | 959 static int num_calls = 0; |
| 947 | 960 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 | 1205 |
| 1193 { | 1206 { |
| 1194 base::RunLoop runloop; | 1207 base::RunLoop runloop; |
| 1195 update_client->Update( | 1208 update_client->Update( |
| 1196 ids, base::Bind(&DataCallbackFake::Callback), | 1209 ids, base::Bind(&DataCallbackFake::Callback), |
| 1197 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 1210 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 1198 runloop.Run(); | 1211 runloop.Run(); |
| 1199 } | 1212 } |
| 1200 | 1213 |
| 1201 update_client->RemoveObserver(&observer); | 1214 update_client->RemoveObserver(&observer); |
| 1215 |
| 1216 StopWorkerPool(); |
| 1202 } | 1217 } |
| 1203 | 1218 |
| 1204 // Tests the update scenario for one CRX where the CRX installer returns | 1219 // Tests the update scenario for one CRX where the CRX installer returns |
| 1205 // an error. | 1220 // an error. |
| 1206 TEST_F(UpdateClientTest, OneCrxInstallError) { | 1221 TEST_F(UpdateClientTest, OneCrxInstallError) { |
| 1207 class MockInstaller : public CrxInstaller { | 1222 class MockInstaller : public CrxInstaller { |
| 1208 public: | 1223 public: |
| 1209 MOCK_METHOD1(OnUpdateError, void(int error)); | 1224 MOCK_METHOD1(OnUpdateError, void(int error)); |
| 1210 MOCK_METHOD2(Install, | 1225 MOCK_METHOD2(Install, |
| 1211 bool(const base::DictionaryValue& manifest, | 1226 bool(const base::DictionaryValue& manifest, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 std::vector<std::string> ids; | 1399 std::vector<std::string> ids; |
| 1385 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); | 1400 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); |
| 1386 | 1401 |
| 1387 update_client->Update( | 1402 update_client->Update( |
| 1388 ids, base::Bind(&DataCallbackFake::Callback), | 1403 ids, base::Bind(&DataCallbackFake::Callback), |
| 1389 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1404 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 1390 | 1405 |
| 1391 RunThreads(); | 1406 RunThreads(); |
| 1392 | 1407 |
| 1393 update_client->RemoveObserver(&observer); | 1408 update_client->RemoveObserver(&observer); |
| 1409 |
| 1410 StopWorkerPool(); |
| 1394 } | 1411 } |
| 1395 | 1412 |
| 1396 // Tests the fallback from differential to full update scenario for one CRX. | 1413 // Tests the fallback from differential to full update scenario for one CRX. |
| 1397 TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { | 1414 TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { |
| 1398 class DataCallbackFake { | 1415 class DataCallbackFake { |
| 1399 public: | 1416 public: |
| 1400 static void Callback(const std::vector<std::string>& ids, | 1417 static void Callback(const std::vector<std::string>& ids, |
| 1401 std::vector<CrxComponent>* components) { | 1418 std::vector<CrxComponent>* components) { |
| 1402 static int num_calls = 0; | 1419 static int num_calls = 0; |
| 1403 | 1420 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 | 1684 |
| 1668 { | 1685 { |
| 1669 base::RunLoop runloop; | 1686 base::RunLoop runloop; |
| 1670 update_client->Update( | 1687 update_client->Update( |
| 1671 ids, base::Bind(&DataCallbackFake::Callback), | 1688 ids, base::Bind(&DataCallbackFake::Callback), |
| 1672 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 1689 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 1673 runloop.Run(); | 1690 runloop.Run(); |
| 1674 } | 1691 } |
| 1675 | 1692 |
| 1676 update_client->RemoveObserver(&observer); | 1693 update_client->RemoveObserver(&observer); |
| 1694 |
| 1695 StopWorkerPool(); |
| 1677 } | 1696 } |
| 1678 | 1697 |
| 1679 // Tests the queuing of update checks. In this scenario, two update checks are | 1698 // Tests the queuing of update checks. In this scenario, two update checks are |
| 1680 // done for one CRX. The second update check call is queued up and will run | 1699 // done for one CRX. The second update check call is queued up and will run |
| 1681 // after the first check has completed. The CRX has no updates. | 1700 // after the first check has completed. The CRX has no updates. |
| 1682 TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { | 1701 TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { |
| 1683 class DataCallbackFake { | 1702 class DataCallbackFake { |
| 1684 public: | 1703 public: |
| 1685 static void Callback(const std::vector<std::string>& ids, | 1704 static void Callback(const std::vector<std::string>& ids, |
| 1686 std::vector<CrxComponent>* components) { | 1705 std::vector<CrxComponent>* components) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 update_client->Update( | 1790 update_client->Update( |
| 1772 ids, base::Bind(&DataCallbackFake::Callback), | 1791 ids, base::Bind(&DataCallbackFake::Callback), |
| 1773 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1792 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 1774 update_client->Update( | 1793 update_client->Update( |
| 1775 ids, base::Bind(&DataCallbackFake::Callback), | 1794 ids, base::Bind(&DataCallbackFake::Callback), |
| 1776 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1795 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 1777 | 1796 |
| 1778 RunThreads(); | 1797 RunThreads(); |
| 1779 | 1798 |
| 1780 update_client->RemoveObserver(&observer); | 1799 update_client->RemoveObserver(&observer); |
| 1800 |
| 1801 StopWorkerPool(); |
| 1781 } | 1802 } |
| 1782 | 1803 |
| 1783 // Tests the install of one CRX. | 1804 // Tests the install of one CRX. |
| 1784 TEST_F(UpdateClientTest, OneCrxInstall) { | 1805 TEST_F(UpdateClientTest, OneCrxInstall) { |
| 1785 class DataCallbackFake { | 1806 class DataCallbackFake { |
| 1786 public: | 1807 public: |
| 1787 static void Callback(const std::vector<std::string>& ids, | 1808 static void Callback(const std::vector<std::string>& ids, |
| 1788 std::vector<CrxComponent>* components) { | 1809 std::vector<CrxComponent>* components) { |
| 1789 CrxComponent crx; | 1810 CrxComponent crx; |
| 1790 crx.name = "test_jebg"; | 1811 crx.name = "test_jebg"; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 update_client->AddObserver(&observer); | 1963 update_client->AddObserver(&observer); |
| 1943 | 1964 |
| 1944 update_client->Install( | 1965 update_client->Install( |
| 1945 std::string("jebgalgnebhfojomionfpkfelancnnkf"), | 1966 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 1946 base::Bind(&DataCallbackFake::Callback), | 1967 base::Bind(&DataCallbackFake::Callback), |
| 1947 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 1968 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 1948 | 1969 |
| 1949 RunThreads(); | 1970 RunThreads(); |
| 1950 | 1971 |
| 1951 update_client->RemoveObserver(&observer); | 1972 update_client->RemoveObserver(&observer); |
| 1973 |
| 1974 StopWorkerPool(); |
| 1952 } | 1975 } |
| 1953 | 1976 |
| 1954 // Tests that overlapping installs of the same CRX result in an error. | 1977 // Tests that overlapping installs of the same CRX result in an error. |
| 1955 TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { | 1978 TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { |
| 1956 class DataCallbackFake { | 1979 class DataCallbackFake { |
| 1957 public: | 1980 public: |
| 1958 static void Callback(const std::vector<std::string>& ids, | 1981 static void Callback(const std::vector<std::string>& ids, |
| 1959 std::vector<CrxComponent>* components) { | 1982 std::vector<CrxComponent>* components) { |
| 1960 CrxComponent crx; | 1983 CrxComponent crx; |
| 1961 crx.name = "test_jebg"; | 1984 crx.name = "test_jebg"; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2054 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2077 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2055 | 2078 |
| 2056 update_client->Install( | 2079 update_client->Install( |
| 2057 std::string("jebgalgnebhfojomionfpkfelancnnkf"), | 2080 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 2058 base::Bind(&DataCallbackFake::Callback), | 2081 base::Bind(&DataCallbackFake::Callback), |
| 2059 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); | 2082 base::Bind(&CompletionCallbackFake::Callback, quit_closure())); |
| 2060 | 2083 |
| 2061 RunThreads(); | 2084 RunThreads(); |
| 2062 | 2085 |
| 2063 update_client->RemoveObserver(&observer); | 2086 update_client->RemoveObserver(&observer); |
| 2087 |
| 2088 StopWorkerPool(); |
| 2064 } | 2089 } |
| 2065 | 2090 |
| 2066 // Make sure that we don't get any crashes when trying to update an empty list | 2091 // Make sure that we don't get any crashes when trying to update an empty list |
| 2067 // of ids. | 2092 // of ids. |
| 2068 TEST_F(UpdateClientTest, EmptyIdList) { | 2093 TEST_F(UpdateClientTest, EmptyIdList) { |
| 2069 class DataCallbackFake { | 2094 class DataCallbackFake { |
| 2070 public: | 2095 public: |
| 2071 static void Callback(const std::vector<std::string>& ids, | 2096 static void Callback(const std::vector<std::string>& ids, |
| 2072 std::vector<CrxComponent>* components) {} | 2097 std::vector<CrxComponent>* components) {} |
| 2073 }; | 2098 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2112 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2137 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( |
| 2113 config(), make_scoped_ptr(new FakePingManagerImpl(*config())), | 2138 config(), make_scoped_ptr(new FakePingManagerImpl(*config())), |
| 2114 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); | 2139 &FakeUpdateChecker::Create, &FakeCrxDownloader::Create)); |
| 2115 | 2140 |
| 2116 std::vector<std::string> empty_id_list; | 2141 std::vector<std::string> empty_id_list; |
| 2117 base::RunLoop runloop; | 2142 base::RunLoop runloop; |
| 2118 update_client->Update( | 2143 update_client->Update( |
| 2119 empty_id_list, base::Bind(&DataCallbackFake::Callback), | 2144 empty_id_list, base::Bind(&DataCallbackFake::Callback), |
| 2120 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); | 2145 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 2121 runloop.Run(); | 2146 runloop.Run(); |
| 2147 |
| 2148 StopWorkerPool(); |
| 2122 } | 2149 } |
| 2123 | 2150 |
| 2124 } // namespace update_client | 2151 } // namespace update_client |
| OLD | NEW |