test_configurator.cc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/update_client/test_configurator.h"
  5. #include <string>
  6. #include <utility>
  7. #include "base/bind.h"
  8. #include "base/containers/flat_map.h"
  9. #include "base/threading/thread_task_runner_handle.h"
  10. #include "base/version.h"
  11. #include "components/prefs/pref_service.h"
  12. #include "components/services/patch/in_process_file_patcher.h"
  13. #include "components/services/unzip/in_process_unzipper.h"
  14. #include "components/update_client/activity_data_service.h"
  15. #include "components/update_client/crx_downloader_factory.h"
  16. #include "components/update_client/net/network_chromium.h"
  17. #include "components/update_client/patch/patch_impl.h"
  18. #include "components/update_client/patcher.h"
  19. #include "components/update_client/protocol_handler.h"
  20. #include "components/update_client/unzip/unzip_impl.h"
  21. #include "components/update_client/unzipper.h"
  22. #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
  23. #include "third_party/abseil-cpp/absl/types/optional.h"
  24. #include "url/gurl.h"
  25. namespace update_client {
  26. namespace {
  27. std::vector<GURL> MakeDefaultUrls() {
  28. std::vector<GURL> urls;
  29. urls.push_back(GURL(POST_INTERCEPT_SCHEME
  30. "://" POST_INTERCEPT_HOSTNAME POST_INTERCEPT_PATH));
  31. return urls;
  32. }
  33. } // namespace
  34. TestConfigurator::TestConfigurator(PrefService* pref_service)
  35. : enabled_cup_signing_(false),
  36. pref_service_(pref_service),
  37. unzip_factory_(base::MakeRefCounted<update_client::UnzipChromiumFactory>(
  38. base::BindRepeating(&unzip::LaunchInProcessUnzipper))),
  39. patch_factory_(base::MakeRefCounted<update_client::PatchChromiumFactory>(
  40. base::BindRepeating(&patch::LaunchInProcessFilePatcher))),
  41. test_shared_loader_factory_(
  42. base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
  43. &test_url_loader_factory_)),
  44. network_fetcher_factory_(
  45. base::MakeRefCounted<NetworkFetcherChromiumFactory>(
  46. test_shared_loader_factory_,
  47. base::BindRepeating([](const GURL& url) { return false; }))),
  48. updater_state_provider_(base::BindRepeating(
  49. [](bool /*is_machine*/) { return UpdaterStateAttributes(); })) {}
  50. TestConfigurator::~TestConfigurator() = default;
  51. double TestConfigurator::InitialDelay() const {
  52. return initial_time_;
  53. }
  54. int TestConfigurator::NextCheckDelay() const {
  55. return 1;
  56. }
  57. int TestConfigurator::OnDemandDelay() const {
  58. return ondemand_time_;
  59. }
  60. int TestConfigurator::UpdateDelay() const {
  61. return 1;
  62. }
  63. std::vector<GURL> TestConfigurator::UpdateUrl() const {
  64. if (!update_check_urls_.empty())
  65. return update_check_urls_;
  66. return MakeDefaultUrls();
  67. }
  68. std::vector<GURL> TestConfigurator::PingUrl() const {
  69. if (!ping_url_.is_empty())
  70. return std::vector<GURL>(1, ping_url_);
  71. return UpdateUrl();
  72. }
  73. std::string TestConfigurator::GetProdId() const {
  74. return "fake_prodid";
  75. }
  76. base::Version TestConfigurator::GetBrowserVersion() const {
  77. // Needs to be larger than the required version in tested component manifests.
  78. return base::Version("30.0");
  79. }
  80. std::string TestConfigurator::GetChannel() const {
  81. return "fake_channel_string";
  82. }
  83. std::string TestConfigurator::GetLang() const {
  84. return "fake_lang";
  85. }
  86. std::string TestConfigurator::GetOSLongName() const {
  87. return "Fake Operating System";
  88. }
  89. base::flat_map<std::string, std::string> TestConfigurator::ExtraRequestParams()
  90. const {
  91. return {{"extra", "foo"}};
  92. }
  93. std::string TestConfigurator::GetDownloadPreference() const {
  94. return download_preference_;
  95. }
  96. scoped_refptr<NetworkFetcherFactory>
  97. TestConfigurator::GetNetworkFetcherFactory() {
  98. return network_fetcher_factory_;
  99. }
  100. scoped_refptr<CrxDownloaderFactory>
  101. TestConfigurator::GetCrxDownloaderFactory() {
  102. return crx_downloader_factory_;
  103. }
  104. scoped_refptr<UnzipperFactory> TestConfigurator::GetUnzipperFactory() {
  105. return unzip_factory_;
  106. }
  107. scoped_refptr<PatcherFactory> TestConfigurator::GetPatcherFactory() {
  108. return patch_factory_;
  109. }
  110. bool TestConfigurator::EnabledDeltas() const {
  111. return true;
  112. }
  113. bool TestConfigurator::EnabledBackgroundDownloader() const {
  114. return false;
  115. }
  116. bool TestConfigurator::EnabledCupSigning() const {
  117. return enabled_cup_signing_;
  118. }
  119. PrefService* TestConfigurator::GetPrefService() const {
  120. return pref_service_;
  121. }
  122. ActivityDataService* TestConfigurator::GetActivityDataService() const {
  123. return nullptr;
  124. }
  125. bool TestConfigurator::IsPerUserInstall() const {
  126. return true;
  127. }
  128. std::unique_ptr<ProtocolHandlerFactory>
  129. TestConfigurator::GetProtocolHandlerFactory() const {
  130. return std::make_unique<ProtocolHandlerFactoryJSON>();
  131. }
  132. absl::optional<bool> TestConfigurator::IsMachineExternallyManaged() const {
  133. return is_machine_externally_managed_;
  134. }
  135. UpdaterStateProvider TestConfigurator::GetUpdaterStateProvider() const {
  136. return updater_state_provider_;
  137. }
  138. void TestConfigurator::SetOnDemandTime(int seconds) {
  139. ondemand_time_ = seconds;
  140. }
  141. void TestConfigurator::SetInitialDelay(double seconds) {
  142. initial_time_ = seconds;
  143. }
  144. void TestConfigurator::SetEnabledCupSigning(bool enabled_cup_signing) {
  145. enabled_cup_signing_ = enabled_cup_signing;
  146. }
  147. void TestConfigurator::SetDownloadPreference(
  148. const std::string& download_preference) {
  149. download_preference_ = download_preference;
  150. }
  151. void TestConfigurator::SetUpdateCheckUrl(const GURL& url) {
  152. update_check_urls_ = {url};
  153. }
  154. void TestConfigurator::SetUpdateCheckUrls(const std::vector<GURL>& urls) {
  155. update_check_urls_ = urls;
  156. }
  157. void TestConfigurator::SetPingUrl(const GURL& url) {
  158. ping_url_ = url;
  159. }
  160. void TestConfigurator::SetCrxDownloaderFactory(
  161. scoped_refptr<CrxDownloaderFactory> crx_downloader_factory) {
  162. crx_downloader_factory_ = crx_downloader_factory;
  163. }
  164. void TestConfigurator::SetIsMachineExternallyManaged(
  165. absl::optional<bool> is_machine_externally_managed) {
  166. is_machine_externally_managed_ = is_machine_externally_managed;
  167. }
  168. void TestConfigurator::SetUpdaterStateProvider(
  169. UpdaterStateProvider update_state_provider) {
  170. updater_state_provider_ = update_state_provider;
  171. }
  172. } // namespace update_client