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
5 #include "components/update_client/test_configurator.h"
6
7 #include <utility>
8
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/net/network_chromium.h"
16 #include "components/update_client/patch/patch_impl.h"
17 #include "components/update_client/patcher.h"
18 #include "components/update_client/protocol_handler.h"
19 #include "components/update_client/unzip/unzip_impl.h"
20 #include "components/update_client/unzipper.h"
21 #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
22 #include "url/gurl.h"
23
24 namespace update_client {
25
26 namespace {
27
MakeDefaultUrls()28 std::vector<GURL> MakeDefaultUrls() {
29 std::vector<GURL> urls;
30 urls.push_back(GURL(POST_INTERCEPT_SCHEME
31 "://" POST_INTERCEPT_HOSTNAME POST_INTERCEPT_PATH));
32 return urls;
33 }
34
35 } // namespace
36
TestConfigurator(PrefService * pref_service)37 TestConfigurator::TestConfigurator(PrefService* pref_service)
38 : brand_("TEST"),
39 initial_time_(0),
40 ondemand_time_(0),
41 enabled_cup_signing_(false),
42 enabled_component_updates_(true),
43 pref_service_(pref_service),
44 unzip_factory_(base::MakeRefCounted<update_client::UnzipChromiumFactory>(
45 base::BindRepeating(&unzip::LaunchInProcessUnzipper))),
46 patch_factory_(base::MakeRefCounted<update_client::PatchChromiumFactory>(
47 base::BindRepeating(&patch::LaunchInProcessFilePatcher))),
48 test_shared_loader_factory_(
49 base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
50 &test_url_loader_factory_)),
51 network_fetcher_factory_(
52 base::MakeRefCounted<NetworkFetcherChromiumFactory>(
53 test_shared_loader_factory_,
54 base::BindRepeating([](const GURL& url) { return false; }))) {}
55
56 TestConfigurator::~TestConfigurator() = default;
57
InitialDelay() const58 int TestConfigurator::InitialDelay() const {
59 return initial_time_;
60 }
61
NextCheckDelay() const62 int TestConfigurator::NextCheckDelay() const {
63 return 1;
64 }
65
OnDemandDelay() const66 int TestConfigurator::OnDemandDelay() const {
67 return ondemand_time_;
68 }
69
UpdateDelay() const70 int TestConfigurator::UpdateDelay() const {
71 return 1;
72 }
73
UpdateUrl() const74 std::vector<GURL> TestConfigurator::UpdateUrl() const {
75 if (!update_check_url_.is_empty())
76 return std::vector<GURL>(1, update_check_url_);
77
78 return MakeDefaultUrls();
79 }
80
PingUrl() const81 std::vector<GURL> TestConfigurator::PingUrl() const {
82 if (!ping_url_.is_empty())
83 return std::vector<GURL>(1, ping_url_);
84
85 return UpdateUrl();
86 }
87
GetProdId() const88 std::string TestConfigurator::GetProdId() const {
89 return "fake_prodid";
90 }
91
GetBrowserVersion() const92 base::Version TestConfigurator::GetBrowserVersion() const {
93 // Needs to be larger than the required version in tested component manifests.
94 return base::Version("30.0");
95 }
96
GetChannel() const97 std::string TestConfigurator::GetChannel() const {
98 return "fake_channel_string";
99 }
100
GetBrand() const101 std::string TestConfigurator::GetBrand() const {
102 return brand_;
103 }
104
GetLang() const105 std::string TestConfigurator::GetLang() const {
106 return "fake_lang";
107 }
108
GetOSLongName() const109 std::string TestConfigurator::GetOSLongName() const {
110 return "Fake Operating System";
111 }
112
ExtraRequestParams() const113 base::flat_map<std::string, std::string> TestConfigurator::ExtraRequestParams()
114 const {
115 return {{"extra", "foo"}};
116 }
117
GetDownloadPreference() const118 std::string TestConfigurator::GetDownloadPreference() const {
119 return download_preference_;
120 }
121
122 scoped_refptr<NetworkFetcherFactory>
GetNetworkFetcherFactory()123 TestConfigurator::GetNetworkFetcherFactory() {
124 return network_fetcher_factory_;
125 }
126
GetUnzipperFactory()127 scoped_refptr<UnzipperFactory> TestConfigurator::GetUnzipperFactory() {
128 return unzip_factory_;
129 }
130
GetPatcherFactory()131 scoped_refptr<PatcherFactory> TestConfigurator::GetPatcherFactory() {
132 return patch_factory_;
133 }
134
EnabledDeltas() const135 bool TestConfigurator::EnabledDeltas() const {
136 return true;
137 }
138
EnabledComponentUpdates() const139 bool TestConfigurator::EnabledComponentUpdates() const {
140 return enabled_component_updates_;
141 }
142
EnabledBackgroundDownloader() const143 bool TestConfigurator::EnabledBackgroundDownloader() const {
144 return false;
145 }
146
EnabledCupSigning() const147 bool TestConfigurator::EnabledCupSigning() const {
148 return enabled_cup_signing_;
149 }
150
SetBrand(const std::string & brand)151 void TestConfigurator::SetBrand(const std::string& brand) {
152 brand_ = brand;
153 }
154
SetOnDemandTime(int seconds)155 void TestConfigurator::SetOnDemandTime(int seconds) {
156 ondemand_time_ = seconds;
157 }
158
SetInitialDelay(int seconds)159 void TestConfigurator::SetInitialDelay(int seconds) {
160 initial_time_ = seconds;
161 }
162
SetEnabledCupSigning(bool enabled_cup_signing)163 void TestConfigurator::SetEnabledCupSigning(bool enabled_cup_signing) {
164 enabled_cup_signing_ = enabled_cup_signing;
165 }
166
SetEnabledComponentUpdates(bool enabled_component_updates)167 void TestConfigurator::SetEnabledComponentUpdates(
168 bool enabled_component_updates) {
169 enabled_component_updates_ = enabled_component_updates;
170 }
171
SetDownloadPreference(const std::string & download_preference)172 void TestConfigurator::SetDownloadPreference(
173 const std::string& download_preference) {
174 download_preference_ = download_preference;
175 }
176
SetUpdateCheckUrl(const GURL & url)177 void TestConfigurator::SetUpdateCheckUrl(const GURL& url) {
178 update_check_url_ = url;
179 }
180
SetPingUrl(const GURL & url)181 void TestConfigurator::SetPingUrl(const GURL& url) {
182 ping_url_ = url;
183 }
184
GetPrefService() const185 PrefService* TestConfigurator::GetPrefService() const {
186 return pref_service_;
187 }
188
GetActivityDataService() const189 ActivityDataService* TestConfigurator::GetActivityDataService() const {
190 return nullptr;
191 }
192
IsPerUserInstall() const193 bool TestConfigurator::IsPerUserInstall() const {
194 return true;
195 }
196
197 std::unique_ptr<ProtocolHandlerFactory>
GetProtocolHandlerFactory() const198 TestConfigurator::GetProtocolHandlerFactory() const {
199 return std::make_unique<ProtocolHandlerFactoryJSON>();
200 }
201
202 } // namespace update_client
203