blob: a0560fd1ba7c6554d6f4172ed9abb2cdd39e6240 [file] [log] [blame]
[email protected]afa378f22013-12-02 03:37:541// Copyright 2013 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
dchengd0fc6aa92016-04-22 18:03:125#include "components/update_client/crx_downloader.h"
6
7#include <memory>
8
[email protected]afa378f22013-12-02 03:37:549#include "base/bind.h"
sorin395c2ac2014-09-16 21:31:0710#include "base/bind_helpers.h"
[email protected]afa378f22013-12-02 03:37:5411#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:0412#include "base/files/file_util.h"
[email protected]afa378f22013-12-02 03:37:5413#include "base/memory/ref_counted.h"
[email protected]afa378f22013-12-02 03:37:5414#include "base/path_service.h"
15#include "base/run_loop.h"
skyostilb0daa012015-06-02 19:03:4816#include "base/thread_task_runner_handle.h"
avi5dd91f82015-12-25 22:30:4617#include "build/build_config.h"
[email protected]afa378f22013-12-02 03:37:5418#include "net/base/net_errors.h"
tommyclieaae5d92014-09-09 06:03:4719#include "net/url_request/test_url_request_interceptor.h"
[email protected]afa378f22013-12-02 03:37:5420#include "net/url_request/url_request_test_util.h"
21#include "testing/gtest/include/gtest/gtest.h"
22
[email protected]148dcfd32014-04-29 00:54:3023using base::ContentsEqual;
[email protected]afa378f22013-12-02 03:37:5424
sorin52ac0882015-01-24 01:15:0025namespace update_client {
[email protected]afa378f22013-12-02 03:37:5426
27namespace {
28
29// Intercepts HTTP GET requests sent to "localhost".
tommyclieaae5d92014-09-09 06:03:4730typedef net::LocalHostTestURLRequestInterceptor GetInterceptor;
[email protected]afa378f22013-12-02 03:37:5431
[email protected]148dcfd32014-04-29 00:54:3032const char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx";
33
sorin74e70672016-02-03 03:13:1034const char hash_jebg[] =
35 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87";
36
[email protected]148dcfd32014-04-29 00:54:3037base::FilePath MakeTestFilePath(const char* file) {
[email protected]afa378f22013-12-02 03:37:5438 base::FilePath path;
tommycli0409b4df2014-08-26 23:31:3239 PathService::Get(base::DIR_SOURCE_ROOT, &path);
sorin74e70672016-02-03 03:13:1040 return path.AppendASCII("components/test/data/update_client")
sorin52ac0882015-01-24 01:15:0041 .AppendASCII(file);
[email protected]afa378f22013-12-02 03:37:5442}
43
44} // namespace
45
46class CrxDownloaderTest : public testing::Test {
47 public:
48 CrxDownloaderTest();
dcheng30a1b1542014-10-29 21:27:5049 ~CrxDownloaderTest() override;
[email protected]afa378f22013-12-02 03:37:5450
51 // Overrides from testing::Test.
dcheng30a1b1542014-10-29 21:27:5052 void SetUp() override;
53 void TearDown() override;
[email protected]afa378f22013-12-02 03:37:5454
55 void Quit();
56 void RunThreads();
57 void RunThreadsUntilIdle();
58
[email protected]3cb2a4f2013-12-07 21:54:3459 void DownloadComplete(int crx_context, const CrxDownloader::Result& result);
[email protected]afa378f22013-12-02 03:37:5460
[email protected]8a5ebd432014-05-02 00:21:2261 void DownloadProgress(int crx_context, const CrxDownloader::Result& result);
62
[email protected]afa378f22013-12-02 03:37:5463 protected:
dchengd0fc6aa92016-04-22 18:03:1264 std::unique_ptr<CrxDownloader> crx_downloader_;
[email protected]afa378f22013-12-02 03:37:5465
dchengd0fc6aa92016-04-22 18:03:1266 std::unique_ptr<GetInterceptor> get_interceptor_;
tommyclieaae5d92014-09-09 06:03:4767
[email protected]1b6587dc52014-04-26 00:38:5568 CrxDownloader::DownloadCallback callback_;
[email protected]8a5ebd432014-05-02 00:21:2269 CrxDownloader::ProgressCallback progress_callback_;
[email protected]1b6587dc52014-04-26 00:38:5570
[email protected]afa378f22013-12-02 03:37:5471 int crx_context_;
[email protected]afa378f22013-12-02 03:37:5472
[email protected]148dcfd32014-04-29 00:54:3073 int num_download_complete_calls_;
74 CrxDownloader::Result download_complete_result_;
[email protected]afa378f22013-12-02 03:37:5475
[email protected]8a5ebd432014-05-02 00:21:2276 // These members are updated by DownloadProgress.
77 int num_progress_calls_;
78 CrxDownloader::Result download_progress_result_;
79
[email protected]afa378f22013-12-02 03:37:5480 // A magic value for the context to be used in the tests.
81 static const int kExpectedContext = 0xaabb;
82
83 private:
tommyclieaae5d92014-09-09 06:03:4784 base::MessageLoopForIO loop_;
[email protected]afa378f22013-12-02 03:37:5485 scoped_refptr<net::TestURLRequestContextGetter> context_;
[email protected]afa378f22013-12-02 03:37:5486 base::Closure quit_closure_;
87};
88
89const int CrxDownloaderTest::kExpectedContext;
90
91CrxDownloaderTest::CrxDownloaderTest()
[email protected]1b6587dc52014-04-26 00:38:5592 : callback_(base::Bind(&CrxDownloaderTest::DownloadComplete,
93 base::Unretained(this),
94 kExpectedContext)),
[email protected]8a5ebd432014-05-02 00:21:2295 progress_callback_(base::Bind(&CrxDownloaderTest::DownloadProgress,
96 base::Unretained(this),
97 kExpectedContext)),
[email protected]1b6587dc52014-04-26 00:38:5598 crx_context_(0),
[email protected]148dcfd32014-04-29 00:54:3099 num_download_complete_calls_(0),
[email protected]8a5ebd432014-05-02 00:21:22100 num_progress_calls_(0),
[email protected]afa378f22013-12-02 03:37:54101 context_(new net::TestURLRequestContextGetter(
skyostilb0daa012015-06-02 19:03:48102 base::ThreadTaskRunnerHandle::Get())) {
[email protected]afa378f22013-12-02 03:37:54103}
104
105CrxDownloaderTest::~CrxDownloaderTest() {
[email protected]3a0092d2013-12-18 03:04:35106 context_ = NULL;
tommyclieaae5d92014-09-09 06:03:47107
108 // The GetInterceptor requires the message loop to run to destruct correctly.
109 get_interceptor_.reset();
110 RunThreadsUntilIdle();
[email protected]afa378f22013-12-02 03:37:54111}
112
113void CrxDownloaderTest::SetUp() {
[email protected]148dcfd32014-04-29 00:54:30114 num_download_complete_calls_ = 0;
115 download_complete_result_ = CrxDownloader::Result();
[email protected]8a5ebd432014-05-02 00:21:22116 num_progress_calls_ = 0;
117 download_progress_result_ = CrxDownloader::Result();
tommyclieaae5d92014-09-09 06:03:47118
sorin9797aba2015-04-17 17:15:03119 // Do not use the background downloader in these tests.
skyostilb0daa012015-06-02 19:03:48120 crx_downloader_.reset(
121 CrxDownloader::Create(false, context_.get(),
sorin33012532015-10-26 21:05:54122 base::ThreadTaskRunnerHandle::Get())
123 .release());
[email protected]8a5ebd432014-05-02 00:21:22124 crx_downloader_->set_progress_callback(progress_callback_);
tommyclieaae5d92014-09-09 06:03:47125
skyostilb0daa012015-06-02 19:03:48126 get_interceptor_.reset(
127 new GetInterceptor(base::ThreadTaskRunnerHandle::Get(),
128 base::ThreadTaskRunnerHandle::Get()));
[email protected]afa378f22013-12-02 03:37:54129}
130
131void CrxDownloaderTest::TearDown() {
[email protected]8a5ebd432014-05-02 00:21:22132 crx_downloader_.reset();
[email protected]afa378f22013-12-02 03:37:54133}
134
135void CrxDownloaderTest::Quit() {
[email protected]da37c1d2013-12-19 01:04:38136 if (!quit_closure_.is_null())
137 quit_closure_.Run();
[email protected]afa378f22013-12-02 03:37:54138}
139
[email protected]148dcfd32014-04-29 00:54:30140void CrxDownloaderTest::DownloadComplete(int crx_context,
141 const CrxDownloader::Result& result) {
142 ++num_download_complete_calls_;
[email protected]afa378f22013-12-02 03:37:54143 crx_context_ = crx_context;
[email protected]148dcfd32014-04-29 00:54:30144 download_complete_result_ = result;
[email protected]afa378f22013-12-02 03:37:54145 Quit();
146}
147
[email protected]8a5ebd432014-05-02 00:21:22148void CrxDownloaderTest::DownloadProgress(int crx_context,
149 const CrxDownloader::Result& result) {
150 ++num_progress_calls_;
151 download_progress_result_ = result;
152}
153
[email protected]afa378f22013-12-02 03:37:54154void CrxDownloaderTest::RunThreads() {
155 base::RunLoop runloop;
156 quit_closure_ = runloop.QuitClosure();
157 runloop.Run();
158
159 // Since some tests need to drain currently enqueued tasks such as network
160 // intercepts on the IO thread, run the threads until they are
161 // idle. The component updater service won't loop again until the loop count
162 // is set and the service is started.
163 RunThreadsUntilIdle();
164}
165
166void CrxDownloaderTest::RunThreadsUntilIdle() {
167 base::RunLoop().RunUntilIdle();
168}
169
[email protected]da37c1d2013-12-19 01:04:38170// Tests that starting a download without a url results in an error.
171TEST_F(CrxDownloaderTest, NoUrl) {
172 std::vector<GURL> urls;
sorin74e70672016-02-03 03:13:10173 crx_downloader_->StartDownload(urls, std::string("abcd"), callback_);
[email protected]da37c1d2013-12-19 01:04:38174 RunThreadsUntilIdle();
[email protected]da37c1d2013-12-19 01:04:38175
[email protected]148dcfd32014-04-29 00:54:30176 EXPECT_EQ(1, num_download_complete_calls_);
177 EXPECT_EQ(kExpectedContext, crx_context_);
sorin74e70672016-02-03 03:13:10178 EXPECT_EQ(CrxDownloader::Error::NO_URL, download_complete_result_.error);
179 EXPECT_TRUE(download_complete_result_.response.empty());
180 EXPECT_EQ(-1, download_complete_result_.downloaded_bytes);
181 EXPECT_EQ(-1, download_complete_result_.total_bytes);
182 EXPECT_EQ(0, num_progress_calls_);
183}
184
185// Tests that starting a download without providing a hash results in an error.
186TEST_F(CrxDownloaderTest, NoHash) {
187 std::vector<GURL> urls(1, GURL("http://somehost/somefile"));
188
189 crx_downloader_->StartDownload(urls, std::string(), callback_);
190 RunThreadsUntilIdle();
191
192 EXPECT_EQ(1, num_download_complete_calls_);
193 EXPECT_EQ(kExpectedContext, crx_context_);
194 EXPECT_EQ(CrxDownloader::Error::NO_HASH, download_complete_result_.error);
[email protected]148dcfd32014-04-29 00:54:30195 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]8a5ebd432014-05-02 00:21:22196 EXPECT_EQ(-1, download_complete_result_.downloaded_bytes);
197 EXPECT_EQ(-1, download_complete_result_.total_bytes);
198 EXPECT_EQ(0, num_progress_calls_);
[email protected]da37c1d2013-12-19 01:04:38199}
200
[email protected]afa378f22013-12-02 03:37:54201// Tests that downloading from one url is successful.
202TEST_F(CrxDownloaderTest, OneUrl) {
203 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45204 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54205
[email protected]148dcfd32014-04-29 00:54:30206 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47207 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54208
sorin74e70672016-02-03 03:13:10209 crx_downloader_->StartDownloadFromUrl(expected_crx_url,
210 std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54211 RunThreads();
[email protected]afa378f22013-12-02 03:37:54212
tommyclieaae5d92014-09-09 06:03:47213 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30214
215 EXPECT_EQ(1, num_download_complete_calls_);
216 EXPECT_EQ(kExpectedContext, crx_context_);
217 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22218 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
219 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30220 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
221
222 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22223
224 EXPECT_LE(1, num_progress_calls_);
225 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
226 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54227}
228
sorin74e70672016-02-03 03:13:10229// Tests that downloading from one url fails if the actual hash of the file
230// does not match the expected hash.
231TEST_F(CrxDownloaderTest, OneUrlBadHash) {
232 const GURL expected_crx_url =
233 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
234
235 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
236 get_interceptor_->SetResponse(expected_crx_url, test_file);
237
238 crx_downloader_->StartDownloadFromUrl(
239 expected_crx_url,
240 std::string(
241 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"),
242 callback_);
243 RunThreads();
244
245 EXPECT_EQ(1, get_interceptor_->GetHitCount());
246
247 EXPECT_EQ(1, num_download_complete_calls_);
248 EXPECT_EQ(kExpectedContext, crx_context_);
249 EXPECT_EQ(CrxDownloader::Error::BAD_HASH, download_complete_result_.error);
250 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
251 EXPECT_EQ(1843, download_complete_result_.total_bytes);
252 EXPECT_TRUE(download_complete_result_.response.empty());
253
254 EXPECT_LE(1, num_progress_calls_);
255 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
256 EXPECT_EQ(1843, download_progress_result_.total_bytes);
257}
258
259// Tests that specifying two urls has no side effects. Expect a successful
[email protected]afa378f22013-12-02 03:37:54260// download, and only one download request be made.
[email protected]5bff685d32014-04-23 00:43:03261// This test is flaky on Android. crbug.com/329883
262#if defined(OS_ANDROID)
263#define MAYBE_TwoUrls DISABLED_TwoUrls
264#else
265#define MAYBE_TwoUrls TwoUrls
266#endif
267TEST_F(CrxDownloaderTest, MAYBE_TwoUrls) {
[email protected]afa378f22013-12-02 03:37:54268 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45269 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54270
[email protected]148dcfd32014-04-29 00:54:30271 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47272 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54273
274 std::vector<GURL> urls;
275 urls.push_back(expected_crx_url);
276 urls.push_back(expected_crx_url);
277
sorin74e70672016-02-03 03:13:10278 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54279 RunThreads();
[email protected]afa378f22013-12-02 03:37:54280
tommyclieaae5d92014-09-09 06:03:47281 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30282
283 EXPECT_EQ(1, num_download_complete_calls_);
284 EXPECT_EQ(kExpectedContext, crx_context_);
285 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22286 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
287 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30288 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
289
290 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22291
292 EXPECT_LE(1, num_progress_calls_);
293 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
294 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54295}
296
297// Tests that an invalid host results in a download error.
298TEST_F(CrxDownloaderTest, OneUrl_InvalidHost) {
299 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45300 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54301
[email protected]148dcfd32014-04-29 00:54:30302 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47303 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54304
305 crx_downloader_->StartDownloadFromUrl(
sorin74e70672016-02-03 03:13:10306 GURL("http://no.such.host"
307 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"),
308 std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54309 RunThreads();
[email protected]afa378f22013-12-02 03:37:54310
tommyclieaae5d92014-09-09 06:03:47311 EXPECT_EQ(0, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30312
313 EXPECT_EQ(1, num_download_complete_calls_);
314 EXPECT_EQ(kExpectedContext, crx_context_);
315 EXPECT_NE(0, download_complete_result_.error);
316 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]afa378f22013-12-02 03:37:54317}
318
319// Tests that an invalid path results in a download error.
320TEST_F(CrxDownloaderTest, OneUrl_InvalidPath) {
321 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45322 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54323
[email protected]148dcfd32014-04-29 00:54:30324 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47325 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54326
[email protected]d0c8b8b42014-05-06 05:11:45327 crx_downloader_->StartDownloadFromUrl(GURL("http://localhost/no/such/file"),
sorin74e70672016-02-03 03:13:10328 std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54329 RunThreads();
[email protected]afa378f22013-12-02 03:37:54330
tommyclieaae5d92014-09-09 06:03:47331 EXPECT_EQ(0, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30332
333 EXPECT_EQ(1, num_download_complete_calls_);
334 EXPECT_EQ(kExpectedContext, crx_context_);
335 EXPECT_NE(0, download_complete_result_.error);
336 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]afa378f22013-12-02 03:37:54337}
338
339// Tests that the fallback to a valid url is successful.
[email protected]5bff685d32014-04-23 00:43:03340// This test is flaky on Android. crbug.com/329883
341#if defined(OS_ANDROID)
342#define MAYBE_TwoUrls_FirstInvalid DISABLED_TwoUrls_FirstInvalid
343#else
344#define MAYBE_TwoUrls_FirstInvalid TwoUrls_FirstInvalid
345#endif
346TEST_F(CrxDownloaderTest, MAYBE_TwoUrls_FirstInvalid) {
[email protected]afa378f22013-12-02 03:37:54347 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45348 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54349
[email protected]148dcfd32014-04-29 00:54:30350 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47351 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54352
353 std::vector<GURL> urls;
354 urls.push_back(GURL("http://localhost/no/such/file"));
355 urls.push_back(expected_crx_url);
356
sorin74e70672016-02-03 03:13:10357 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54358 RunThreads();
[email protected]afa378f22013-12-02 03:37:54359
tommyclieaae5d92014-09-09 06:03:47360 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30361
362 EXPECT_EQ(1, num_download_complete_calls_);
363 EXPECT_EQ(kExpectedContext, crx_context_);
364 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22365 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
366 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30367 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
368
369 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22370
371 EXPECT_LE(1, num_progress_calls_);
372 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
373 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54374}
375
376// Tests that the download succeeds if the first url is correct and the
377// second bad url does not have a side-effect.
378TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) {
379 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45380 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54381
[email protected]148dcfd32014-04-29 00:54:30382 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47383 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54384
385 std::vector<GURL> urls;
386 urls.push_back(expected_crx_url);
387 urls.push_back(GURL("http://localhost/no/such/file"));
388
sorin74e70672016-02-03 03:13:10389 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54390 RunThreads();
[email protected]afa378f22013-12-02 03:37:54391
tommyclieaae5d92014-09-09 06:03:47392 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30393
394 EXPECT_EQ(1, num_download_complete_calls_);
395 EXPECT_EQ(kExpectedContext, crx_context_);
396 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22397 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
398 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30399 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
400
401 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22402
403 EXPECT_LE(1, num_progress_calls_);
404 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
405 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54406}
407
408// Tests that the download fails if both urls are bad.
409TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) {
410 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45411 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54412
[email protected]148dcfd32014-04-29 00:54:30413 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47414 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54415
416 std::vector<GURL> urls;
417 urls.push_back(GURL("http://localhost/no/such/file"));
sorin52ac0882015-01-24 01:15:00418 urls.push_back(GURL(
419 "http://no.such.host/"
420 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"));
[email protected]afa378f22013-12-02 03:37:54421
sorin74e70672016-02-03 03:13:10422 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54423 RunThreads();
[email protected]afa378f22013-12-02 03:37:54424
tommyclieaae5d92014-09-09 06:03:47425 EXPECT_EQ(0, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30426
427 EXPECT_EQ(1, num_download_complete_calls_);
428 EXPECT_EQ(kExpectedContext, crx_context_);
429 EXPECT_NE(0, download_complete_result_.error);
430 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]afa378f22013-12-02 03:37:54431}
432
sorin52ac0882015-01-24 01:15:00433} // namespace update_client