| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 EXPECT_TRUE(update_client_->GetCrxUpdateState(id, &update_item)); | 90 EXPECT_TRUE(update_client_->GetCrxUpdateState(id, &update_item)); |
| 91 EXPECT_EQ(update_item.on_demand, expected_value_); | 91 EXPECT_EQ(update_item.on_demand, expected_value_); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 class FakePingManagerImpl : public PingManager { | 95 class FakePingManagerImpl : public PingManager { |
| 96 public: | 96 public: |
| 97 explicit FakePingManagerImpl(const scoped_refptr<Configurator>& config); | 97 explicit FakePingManagerImpl(const scoped_refptr<Configurator>& config); |
| 98 ~FakePingManagerImpl() override; | 98 ~FakePingManagerImpl() override; |
| 99 | 99 |
| 100 void SendPing(const CrxUpdateItem* item) override; | 100 bool SendPing(const CrxUpdateItem* item) override; |
| 101 | 101 |
| 102 const std::vector<CrxUpdateItem>& items() const; | 102 const std::vector<CrxUpdateItem>& items() const; |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 std::vector<CrxUpdateItem> items_; | 105 std::vector<CrxUpdateItem> items_; |
| 106 DISALLOW_COPY_AND_ASSIGN(FakePingManagerImpl); | 106 DISALLOW_COPY_AND_ASSIGN(FakePingManagerImpl); |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 FakePingManagerImpl::FakePingManagerImpl( | 109 FakePingManagerImpl::FakePingManagerImpl( |
| 110 const scoped_refptr<Configurator>& config) | 110 const scoped_refptr<Configurator>& config) |
| 111 : PingManager(config) {} | 111 : PingManager(config) {} |
| 112 | 112 |
| 113 FakePingManagerImpl::~FakePingManagerImpl() { | 113 FakePingManagerImpl::~FakePingManagerImpl() { |
| 114 } | 114 } |
| 115 | 115 |
| 116 void FakePingManagerImpl::SendPing(const CrxUpdateItem* item) { | 116 bool FakePingManagerImpl::SendPing(const CrxUpdateItem* item) { |
| 117 items_.push_back(*item); | 117 items_.push_back(*item); |
| 118 return true; |
| 118 } | 119 } |
| 119 | 120 |
| 120 const std::vector<CrxUpdateItem>& FakePingManagerImpl::items() const { | 121 const std::vector<CrxUpdateItem>& FakePingManagerImpl::items() const { |
| 121 return items_; | 122 return items_; |
| 122 } | 123 } |
| 123 | 124 |
| 124 } // namespace | 125 } // namespace |
| 125 | 126 |
| 126 using ::testing::_; | 127 using ::testing::_; |
| 127 using ::testing::AnyNumber; | 128 using ::testing::AnyNumber; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 const scoped_refptr<Configurator>& config) { | 221 const scoped_refptr<Configurator>& config) { |
| 221 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); | 222 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); |
| 222 } | 223 } |
| 223 | 224 |
| 224 bool CheckForUpdates( | 225 bool CheckForUpdates( |
| 225 const std::vector<CrxUpdateItem*>& items_to_check, | 226 const std::vector<CrxUpdateItem*>& items_to_check, |
| 226 const std::string& additional_attributes, | 227 const std::string& additional_attributes, |
| 227 const UpdateCheckCallback& update_check_callback) override { | 228 const UpdateCheckCallback& update_check_callback) override { |
| 228 base::ThreadTaskRunnerHandle::Get()->PostTask( | 229 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 229 FROM_HERE, | 230 FROM_HERE, |
| 230 base::Bind(update_check_callback, 0, UpdateResponse::Results())); | 231 base::Bind(update_check_callback, 0, UpdateResponse::Results(), 0)); |
| 231 return true; | 232 return true; |
| 232 } | 233 } |
| 233 }; | 234 }; |
| 234 | 235 |
| 235 class FakeCrxDownloader : public CrxDownloader { | 236 class FakeCrxDownloader : public CrxDownloader { |
| 236 public: | 237 public: |
| 237 static scoped_ptr<CrxDownloader> Create( | 238 static scoped_ptr<CrxDownloader> Create( |
| 238 bool is_background_download, | 239 bool is_background_download, |
| 239 net::URLRequestContextGetter* context_getter, | 240 net::URLRequestContextGetter* context_getter, |
| 240 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 241 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 362 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 362 result.crx_urls.push_back(GURL("http://localhost/download/")); | 363 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 363 result.manifest.version = "1.0"; | 364 result.manifest.version = "1.0"; |
| 364 result.manifest.browser_min_version = "11.0.1.0"; | 365 result.manifest.browser_min_version = "11.0.1.0"; |
| 365 result.manifest.packages.push_back(package); | 366 result.manifest.packages.push_back(package); |
| 366 | 367 |
| 367 UpdateResponse::Results results; | 368 UpdateResponse::Results results; |
| 368 results.list.push_back(result); | 369 results.list.push_back(result); |
| 369 | 370 |
| 370 base::ThreadTaskRunnerHandle::Get()->PostTask( | 371 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 371 FROM_HERE, base::Bind(update_check_callback, 0, results)); | 372 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); |
| 372 return true; | 373 return true; |
| 373 } | 374 } |
| 374 }; | 375 }; |
| 375 | 376 |
| 376 class FakeCrxDownloader : public CrxDownloader { | 377 class FakeCrxDownloader : public CrxDownloader { |
| 377 public: | 378 public: |
| 378 static scoped_ptr<CrxDownloader> Create( | 379 static scoped_ptr<CrxDownloader> Create( |
| 379 bool is_background_download, | 380 bool is_background_download, |
| 380 net::URLRequestContextGetter* context_getter, | 381 net::URLRequestContextGetter* context_getter, |
| 381 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 382 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 result2.crx_urls.push_back(GURL("http://localhost/download/")); | 574 result2.crx_urls.push_back(GURL("http://localhost/download/")); |
| 574 result2.manifest.version = "1.0"; | 575 result2.manifest.version = "1.0"; |
| 575 result2.manifest.browser_min_version = "11.0.1.0"; | 576 result2.manifest.browser_min_version = "11.0.1.0"; |
| 576 result2.manifest.packages.push_back(package2); | 577 result2.manifest.packages.push_back(package2); |
| 577 | 578 |
| 578 UpdateResponse::Results results; | 579 UpdateResponse::Results results; |
| 579 results.list.push_back(result1); | 580 results.list.push_back(result1); |
| 580 results.list.push_back(result2); | 581 results.list.push_back(result2); |
| 581 | 582 |
| 582 base::ThreadTaskRunnerHandle::Get()->PostTask( | 583 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 583 FROM_HERE, base::Bind(update_check_callback, 0, results)); | 584 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); |
| 584 return true; | 585 return true; |
| 585 } | 586 } |
| 586 }; | 587 }; |
| 587 | 588 |
| 588 class FakeCrxDownloader : public CrxDownloader { | 589 class FakeCrxDownloader : public CrxDownloader { |
| 589 public: | 590 public: |
| 590 static scoped_ptr<CrxDownloader> Create( | 591 static scoped_ptr<CrxDownloader> Create( |
| 591 bool is_background_download, | 592 bool is_background_download, |
| 592 net::URLRequestContextGetter* context_getter, | 593 net::URLRequestContextGetter* context_getter, |
| 593 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 594 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 result2.crx_urls.push_back(GURL("http://localhost/download/")); | 821 result2.crx_urls.push_back(GURL("http://localhost/download/")); |
| 821 result2.manifest.version = "1.0"; | 822 result2.manifest.version = "1.0"; |
| 822 result2.manifest.browser_min_version = "11.0.1.0"; | 823 result2.manifest.browser_min_version = "11.0.1.0"; |
| 823 result2.manifest.packages.push_back(package2); | 824 result2.manifest.packages.push_back(package2); |
| 824 | 825 |
| 825 UpdateResponse::Results results; | 826 UpdateResponse::Results results; |
| 826 results.list.push_back(result1); | 827 results.list.push_back(result1); |
| 827 results.list.push_back(result2); | 828 results.list.push_back(result2); |
| 828 | 829 |
| 829 base::ThreadTaskRunnerHandle::Get()->PostTask( | 830 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 830 FROM_HERE, base::Bind(update_check_callback, 0, results)); | 831 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); |
| 831 return true; | 832 return true; |
| 832 } | 833 } |
| 833 }; | 834 }; |
| 834 | 835 |
| 835 class FakeCrxDownloader : public CrxDownloader { | 836 class FakeCrxDownloader : public CrxDownloader { |
| 836 public: | 837 public: |
| 837 static scoped_ptr<CrxDownloader> Create( | 838 static scoped_ptr<CrxDownloader> Create( |
| 838 bool is_background_download, | 839 bool is_background_download, |
| 839 net::URLRequestContextGetter* context_getter, | 840 net::URLRequestContextGetter* context_getter, |
| 840 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 841 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 result.crx_diffurls.push_back(GURL("http://localhost/download/")); | 1093 result.crx_diffurls.push_back(GURL("http://localhost/download/")); |
| 1093 result.manifest.version = "2.0"; | 1094 result.manifest.version = "2.0"; |
| 1094 result.manifest.browser_min_version = "11.0.1.0"; | 1095 result.manifest.browser_min_version = "11.0.1.0"; |
| 1095 result.manifest.packages.push_back(package); | 1096 result.manifest.packages.push_back(package); |
| 1096 results.list.push_back(result); | 1097 results.list.push_back(result); |
| 1097 } else { | 1098 } else { |
| 1098 NOTREACHED(); | 1099 NOTREACHED(); |
| 1099 } | 1100 } |
| 1100 | 1101 |
| 1101 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1102 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1102 FROM_HERE, base::Bind(update_check_callback, 0, results)); | 1103 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); |
| 1103 return true; | 1104 return true; |
| 1104 } | 1105 } |
| 1105 }; | 1106 }; |
| 1106 | 1107 |
| 1107 class FakeCrxDownloader : public CrxDownloader { | 1108 class FakeCrxDownloader : public CrxDownloader { |
| 1108 public: | 1109 public: |
| 1109 static scoped_ptr<CrxDownloader> Create( | 1110 static scoped_ptr<CrxDownloader> Create( |
| 1110 bool is_background_download, | 1111 bool is_background_download, |
| 1111 net::URLRequestContextGetter* context_getter, | 1112 net::URLRequestContextGetter* context_getter, |
| 1112 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1113 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 1334 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 1334 result.crx_urls.push_back(GURL("http://localhost/download/")); | 1335 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1335 result.manifest.version = "1.0"; | 1336 result.manifest.version = "1.0"; |
| 1336 result.manifest.browser_min_version = "11.0.1.0"; | 1337 result.manifest.browser_min_version = "11.0.1.0"; |
| 1337 result.manifest.packages.push_back(package); | 1338 result.manifest.packages.push_back(package); |
| 1338 | 1339 |
| 1339 UpdateResponse::Results results; | 1340 UpdateResponse::Results results; |
| 1340 results.list.push_back(result); | 1341 results.list.push_back(result); |
| 1341 | 1342 |
| 1342 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1343 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1343 FROM_HERE, base::Bind(update_check_callback, 0, results)); | 1344 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); |
| 1344 return true; | 1345 return true; |
| 1345 } | 1346 } |
| 1346 }; | 1347 }; |
| 1347 | 1348 |
| 1348 class FakeCrxDownloader : public CrxDownloader { | 1349 class FakeCrxDownloader : public CrxDownloader { |
| 1349 public: | 1350 public: |
| 1350 static scoped_ptr<CrxDownloader> Create( | 1351 static scoped_ptr<CrxDownloader> Create( |
| 1351 bool is_background_download, | 1352 bool is_background_download, |
| 1352 net::URLRequestContextGetter* context_getter, | 1353 net::URLRequestContextGetter* context_getter, |
| 1353 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1354 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 result.crx_diffurls.push_back(GURL("http://localhost/download/")); | 1567 result.crx_diffurls.push_back(GURL("http://localhost/download/")); |
| 1567 result.manifest.version = "2.0"; | 1568 result.manifest.version = "2.0"; |
| 1568 result.manifest.browser_min_version = "11.0.1.0"; | 1569 result.manifest.browser_min_version = "11.0.1.0"; |
| 1569 result.manifest.packages.push_back(package); | 1570 result.manifest.packages.push_back(package); |
| 1570 results.list.push_back(result); | 1571 results.list.push_back(result); |
| 1571 } else { | 1572 } else { |
| 1572 NOTREACHED(); | 1573 NOTREACHED(); |
| 1573 } | 1574 } |
| 1574 | 1575 |
| 1575 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1576 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1576 FROM_HERE, base::Bind(update_check_callback, 0, results)); | 1577 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); |
| 1577 return true; | 1578 return true; |
| 1578 } | 1579 } |
| 1579 }; | 1580 }; |
| 1580 | 1581 |
| 1581 class FakeCrxDownloader : public CrxDownloader { | 1582 class FakeCrxDownloader : public CrxDownloader { |
| 1582 public: | 1583 public: |
| 1583 static scoped_ptr<CrxDownloader> Create( | 1584 static scoped_ptr<CrxDownloader> Create( |
| 1584 bool is_background_download, | 1585 bool is_background_download, |
| 1585 net::URLRequestContextGetter* context_getter, | 1586 net::URLRequestContextGetter* context_getter, |
| 1586 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1587 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 const scoped_refptr<Configurator>& config) { | 1772 const scoped_refptr<Configurator>& config) { |
| 1772 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); | 1773 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); |
| 1773 } | 1774 } |
| 1774 | 1775 |
| 1775 bool CheckForUpdates( | 1776 bool CheckForUpdates( |
| 1776 const std::vector<CrxUpdateItem*>& items_to_check, | 1777 const std::vector<CrxUpdateItem*>& items_to_check, |
| 1777 const std::string& additional_attributes, | 1778 const std::string& additional_attributes, |
| 1778 const UpdateCheckCallback& update_check_callback) override { | 1779 const UpdateCheckCallback& update_check_callback) override { |
| 1779 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1780 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1780 FROM_HERE, | 1781 FROM_HERE, |
| 1781 base::Bind(update_check_callback, 0, UpdateResponse::Results())); | 1782 base::Bind(update_check_callback, 0, UpdateResponse::Results(), 0)); |
| 1782 return true; | 1783 return true; |
| 1783 } | 1784 } |
| 1784 }; | 1785 }; |
| 1785 | 1786 |
| 1786 class FakeCrxDownloader : public CrxDownloader { | 1787 class FakeCrxDownloader : public CrxDownloader { |
| 1787 public: | 1788 public: |
| 1788 static scoped_ptr<CrxDownloader> Create( | 1789 static scoped_ptr<CrxDownloader> Create( |
| 1789 bool is_background_download, | 1790 bool is_background_download, |
| 1790 net::URLRequestContextGetter* context_getter, | 1791 net::URLRequestContextGetter* context_getter, |
| 1791 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1792 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1904 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; | 1905 result.extension_id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 1905 result.crx_urls.push_back(GURL("http://localhost/download/")); | 1906 result.crx_urls.push_back(GURL("http://localhost/download/")); |
| 1906 result.manifest.version = "1.0"; | 1907 result.manifest.version = "1.0"; |
| 1907 result.manifest.browser_min_version = "11.0.1.0"; | 1908 result.manifest.browser_min_version = "11.0.1.0"; |
| 1908 result.manifest.packages.push_back(package); | 1909 result.manifest.packages.push_back(package); |
| 1909 | 1910 |
| 1910 UpdateResponse::Results results; | 1911 UpdateResponse::Results results; |
| 1911 results.list.push_back(result); | 1912 results.list.push_back(result); |
| 1912 | 1913 |
| 1913 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1914 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1914 FROM_HERE, base::Bind(update_check_callback, 0, results)); | 1915 FROM_HERE, base::Bind(update_check_callback, 0, results, 0)); |
| 1915 return true; | 1916 return true; |
| 1916 } | 1917 } |
| 1917 }; | 1918 }; |
| 1918 | 1919 |
| 1919 class FakeCrxDownloader : public CrxDownloader { | 1920 class FakeCrxDownloader : public CrxDownloader { |
| 1920 public: | 1921 public: |
| 1921 static scoped_ptr<CrxDownloader> Create( | 1922 static scoped_ptr<CrxDownloader> Create( |
| 1922 bool is_background_download, | 1923 bool is_background_download, |
| 1923 net::URLRequestContextGetter* context_getter, | 1924 net::URLRequestContextGetter* context_getter, |
| 1924 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 1925 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 const scoped_refptr<Configurator>& config) { | 2057 const scoped_refptr<Configurator>& config) { |
| 2057 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); | 2058 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); |
| 2058 } | 2059 } |
| 2059 | 2060 |
| 2060 bool CheckForUpdates( | 2061 bool CheckForUpdates( |
| 2061 const std::vector<CrxUpdateItem*>& items_to_check, | 2062 const std::vector<CrxUpdateItem*>& items_to_check, |
| 2062 const std::string& additional_attributes, | 2063 const std::string& additional_attributes, |
| 2063 const UpdateCheckCallback& update_check_callback) override { | 2064 const UpdateCheckCallback& update_check_callback) override { |
| 2064 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2065 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2065 FROM_HERE, | 2066 FROM_HERE, |
| 2066 base::Bind(update_check_callback, 0, UpdateResponse::Results())); | 2067 base::Bind(update_check_callback, 0, UpdateResponse::Results(), 0)); |
| 2067 return true; | 2068 return true; |
| 2068 } | 2069 } |
| 2069 }; | 2070 }; |
| 2070 | 2071 |
| 2071 class FakeCrxDownloader : public CrxDownloader { | 2072 class FakeCrxDownloader : public CrxDownloader { |
| 2072 public: | 2073 public: |
| 2073 static scoped_ptr<CrxDownloader> Create( | 2074 static scoped_ptr<CrxDownloader> Create( |
| 2074 bool is_background_download, | 2075 bool is_background_download, |
| 2075 net::URLRequestContextGetter* context_getter, | 2076 net::URLRequestContextGetter* context_getter, |
| 2076 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 2077 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2236 | 2237 |
| 2237 scoped_ptr<PingManager> ping_manager(new FakePingManager(config())); | 2238 scoped_ptr<PingManager> ping_manager(new FakePingManager(config())); |
| 2238 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( | 2239 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( |
| 2239 config(), std::move(ping_manager), &FakeUpdateChecker::Create, | 2240 config(), std::move(ping_manager), &FakeUpdateChecker::Create, |
| 2240 &FakeCrxDownloader::Create)); | 2241 &FakeCrxDownloader::Create)); |
| 2241 | 2242 |
| 2242 update_client->SendUninstallPing("jebgalgnebhfojomionfpkfelancnnkf", | 2243 update_client->SendUninstallPing("jebgalgnebhfojomionfpkfelancnnkf", |
| 2243 base::Version("1.0"), 10); | 2244 base::Version("1.0"), 10); |
| 2244 } | 2245 } |
| 2245 | 2246 |
| 2247 TEST_F(UpdateClientTest, RetryAfter) { |
| 2248 class DataCallbackFake { |
| 2249 public: |
| 2250 static void Callback(const std::vector<std::string>& ids, |
| 2251 std::vector<CrxComponent>* components) { |
| 2252 CrxComponent crx; |
| 2253 crx.name = "test_jebg"; |
| 2254 crx.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 2255 crx.version = Version("0.9"); |
| 2256 crx.installer = new TestInstaller; |
| 2257 components->push_back(crx); |
| 2258 } |
| 2259 }; |
| 2260 |
| 2261 class CompletionCallbackFake { |
| 2262 public: |
| 2263 static void Callback(const base::Closure& quit_closure, int error) { |
| 2264 static int num_call = 0; |
| 2265 ++num_call; |
| 2266 |
| 2267 EXPECT_LE(num_call, 4); |
| 2268 |
| 2269 if (num_call == 1) { |
| 2270 EXPECT_EQ(0, error); |
| 2271 } else if (num_call == 2) { |
| 2272 // This request is throttled since the update engine received a |
| 2273 // positive |retry_after_sec| value in the update check response. |
| 2274 EXPECT_EQ(Error::ERROR_UPDATE_RETRY_LATER, error); |
| 2275 } else if (num_call == 3) { |
| 2276 // This request is a foreground Install, which is never throttled. |
| 2277 // The update engine received a |retry_after_sec| value of 0, which |
| 2278 // resets the throttling. |
| 2279 EXPECT_EQ(0, error); |
| 2280 } else if (num_call == 4) { |
| 2281 // This request succeeds since there is no throttling in effect. |
| 2282 EXPECT_EQ(0, error); |
| 2283 } |
| 2284 |
| 2285 quit_closure.Run(); |
| 2286 } |
| 2287 }; |
| 2288 |
| 2289 class FakeUpdateChecker : public UpdateChecker { |
| 2290 public: |
| 2291 static scoped_ptr<UpdateChecker> Create( |
| 2292 const scoped_refptr<Configurator>& config) { |
| 2293 return scoped_ptr<UpdateChecker>(new FakeUpdateChecker()); |
| 2294 } |
| 2295 |
| 2296 bool CheckForUpdates( |
| 2297 const std::vector<CrxUpdateItem*>& items_to_check, |
| 2298 const std::string& additional_attributes, |
| 2299 const UpdateCheckCallback& update_check_callback) override { |
| 2300 static int num_call = 0; |
| 2301 ++num_call; |
| 2302 |
| 2303 EXPECT_LE(num_call, 3); |
| 2304 |
| 2305 int retry_after_sec(0); |
| 2306 if (num_call == 1) { |
| 2307 // Throttle the next call. |
| 2308 retry_after_sec = 60 * 60; // 1 hour. |
| 2309 } |
| 2310 |
| 2311 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2312 FROM_HERE, base::Bind(update_check_callback, 0, |
| 2313 UpdateResponse::Results(), retry_after_sec)); |
| 2314 return true; |
| 2315 } |
| 2316 }; |
| 2317 |
| 2318 class FakeCrxDownloader : public CrxDownloader { |
| 2319 public: |
| 2320 static scoped_ptr<CrxDownloader> Create( |
| 2321 bool is_background_download, |
| 2322 net::URLRequestContextGetter* context_getter, |
| 2323 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 2324 return scoped_ptr<CrxDownloader>(new FakeCrxDownloader()); |
| 2325 } |
| 2326 |
| 2327 private: |
| 2328 FakeCrxDownloader() |
| 2329 : CrxDownloader(base::ThreadTaskRunnerHandle::Get(), nullptr) {} |
| 2330 ~FakeCrxDownloader() override {} |
| 2331 |
| 2332 void DoStartDownload(const GURL& url) override { EXPECT_TRUE(false); } |
| 2333 }; |
| 2334 |
| 2335 class FakePingManager : public FakePingManagerImpl { |
| 2336 public: |
| 2337 explicit FakePingManager(const scoped_refptr<Configurator>& config) |
| 2338 : FakePingManagerImpl(config) {} |
| 2339 ~FakePingManager() override { EXPECT_TRUE(items().empty()); } |
| 2340 }; |
| 2341 |
| 2342 scoped_ptr<PingManager> ping_manager(new FakePingManager(config())); |
| 2343 scoped_refptr<UpdateClient> update_client(new UpdateClientImpl( |
| 2344 config(), std::move(ping_manager), &FakeUpdateChecker::Create, |
| 2345 &FakeCrxDownloader::Create)); |
| 2346 |
| 2347 MockObserver observer; |
| 2348 |
| 2349 InSequence seq; |
| 2350 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2351 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2352 .Times(1); |
| 2353 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2354 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2355 .Times(1); |
| 2356 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2357 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2358 .Times(1); |
| 2359 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2360 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2361 .Times(1); |
| 2362 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_CHECKING_FOR_UPDATES, |
| 2363 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2364 .Times(1); |
| 2365 EXPECT_CALL(observer, OnEvent(Events::COMPONENT_NOT_UPDATED, |
| 2366 "jebgalgnebhfojomionfpkfelancnnkf")) |
| 2367 .Times(1); |
| 2368 |
| 2369 update_client->AddObserver(&observer); |
| 2370 |
| 2371 std::vector<std::string> ids; |
| 2372 ids.push_back(std::string("jebgalgnebhfojomionfpkfelancnnkf")); |
| 2373 |
| 2374 { |
| 2375 // The engine handles this Update call but responds with a valid |
| 2376 // |retry_after_sec|, which causes subsequent calls to fail. |
| 2377 base::RunLoop runloop; |
| 2378 update_client->Update( |
| 2379 ids, base::Bind(&DataCallbackFake::Callback), |
| 2380 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 2381 runloop.Run(); |
| 2382 } |
| 2383 |
| 2384 { |
| 2385 // This call will result in a completion callback invoked with |
| 2386 // Error::ERROR_UPDATE_RETRY_LATER. |
| 2387 base::RunLoop runloop; |
| 2388 update_client->Update( |
| 2389 ids, base::Bind(&DataCallbackFake::Callback), |
| 2390 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 2391 runloop.Run(); |
| 2392 } |
| 2393 |
| 2394 { |
| 2395 // The Install call is handled, and the throttling is reset due to |
| 2396 // the value of |retry_after_sec| in the completion callback. |
| 2397 base::RunLoop runloop; |
| 2398 update_client->Install( |
| 2399 std::string("jebgalgnebhfojomionfpkfelancnnkf"), |
| 2400 base::Bind(&DataCallbackFake::Callback), |
| 2401 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 2402 runloop.Run(); |
| 2403 } |
| 2404 |
| 2405 { |
| 2406 // This call succeeds. |
| 2407 base::RunLoop runloop; |
| 2408 update_client->Update( |
| 2409 ids, base::Bind(&DataCallbackFake::Callback), |
| 2410 base::Bind(&CompletionCallbackFake::Callback, runloop.QuitClosure())); |
| 2411 runloop.Run(); |
| 2412 } |
| 2413 |
| 2414 update_client->RemoveObserver(&observer); |
| 2415 } |
| 2416 |
| 2246 } // namespace update_client | 2417 } // namespace update_client |
| OLD | NEW |