blob: 7b1a1848ba58480c6ea0592de734cea49b006311 [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
5#include "base/bind.h"
sorin395c2ac2014-09-16 21:31:076#include "base/bind_helpers.h"
[email protected]afa378f22013-12-02 03:37:547#include "base/files/file_path.h"
thestig18dfb7a52014-08-26 10:44:048#include "base/files/file_util.h"
[email protected]afa378f22013-12-02 03:37:549#include "base/memory/ref_counted.h"
10#include "base/memory/scoped_ptr.h"
[email protected]afa378f22013-12-02 03:37:5411#include "base/path_service.h"
12#include "base/run_loop.h"
skyostilb0daa012015-06-02 19:03:4813#include "base/thread_task_runner_handle.h"
avi5dd91f82015-12-25 22:30:4614#include "build/build_config.h"
sorin52ac0882015-01-24 01:15:0015#include "components/update_client/crx_downloader.h"
[email protected]afa378f22013-12-02 03:37:5416#include "net/base/net_errors.h"
tommyclieaae5d92014-09-09 06:03:4717#include "net/url_request/test_url_request_interceptor.h"
[email protected]afa378f22013-12-02 03:37:5418#include "net/url_request/url_request_test_util.h"
19#include "testing/gtest/include/gtest/gtest.h"
20
[email protected]148dcfd32014-04-29 00:54:3021using base::ContentsEqual;
[email protected]afa378f22013-12-02 03:37:5422
sorin52ac0882015-01-24 01:15:0023namespace update_client {
[email protected]afa378f22013-12-02 03:37:5424
25namespace {
26
27// Intercepts HTTP GET requests sent to "localhost".
tommyclieaae5d92014-09-09 06:03:4728typedef net::LocalHostTestURLRequestInterceptor GetInterceptor;
[email protected]afa378f22013-12-02 03:37:5429
[email protected]148dcfd32014-04-29 00:54:3030const char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx";
31
sorin74e70672016-02-03 03:13:1032const char hash_jebg[] =
33 "6fc4b93fd11134de1300c2c0bb88c12b644a4ec0fd7c9b12cb7cc067667bde87";
34
[email protected]148dcfd32014-04-29 00:54:3035base::FilePath MakeTestFilePath(const char* file) {
[email protected]afa378f22013-12-02 03:37:5436 base::FilePath path;
tommycli0409b4df2014-08-26 23:31:3237 PathService::Get(base::DIR_SOURCE_ROOT, &path);
sorin74e70672016-02-03 03:13:1038 return path.AppendASCII("components/test/data/update_client")
sorin52ac0882015-01-24 01:15:0039 .AppendASCII(file);
[email protected]afa378f22013-12-02 03:37:5440}
41
42} // namespace
43
44class CrxDownloaderTest : public testing::Test {
45 public:
46 CrxDownloaderTest();
dcheng30a1b1542014-10-29 21:27:5047 ~CrxDownloaderTest() override;
[email protected]afa378f22013-12-02 03:37:5448
49 // Overrides from testing::Test.
dcheng30a1b1542014-10-29 21:27:5050 void SetUp() override;
51 void TearDown() override;
[email protected]afa378f22013-12-02 03:37:5452
53 void Quit();
54 void RunThreads();
55 void RunThreadsUntilIdle();
56
[email protected]3cb2a4f2013-12-07 21:54:3457 void DownloadComplete(int crx_context, const CrxDownloader::Result& result);
[email protected]afa378f22013-12-02 03:37:5458
[email protected]8a5ebd432014-05-02 00:21:2259 void DownloadProgress(int crx_context, const CrxDownloader::Result& result);
60
[email protected]afa378f22013-12-02 03:37:5461 protected:
62 scoped_ptr<CrxDownloader> crx_downloader_;
63
tommyclieaae5d92014-09-09 06:03:4764 scoped_ptr<GetInterceptor> get_interceptor_;
65
[email protected]1b6587dc52014-04-26 00:38:5566 CrxDownloader::DownloadCallback callback_;
[email protected]8a5ebd432014-05-02 00:21:2267 CrxDownloader::ProgressCallback progress_callback_;
[email protected]1b6587dc52014-04-26 00:38:5568
[email protected]afa378f22013-12-02 03:37:5469 int crx_context_;
[email protected]afa378f22013-12-02 03:37:5470
[email protected]148dcfd32014-04-29 00:54:3071 int num_download_complete_calls_;
72 CrxDownloader::Result download_complete_result_;
[email protected]afa378f22013-12-02 03:37:5473
[email protected]8a5ebd432014-05-02 00:21:2274 // These members are updated by DownloadProgress.
75 int num_progress_calls_;
76 CrxDownloader::Result download_progress_result_;
77
[email protected]afa378f22013-12-02 03:37:5478 // A magic value for the context to be used in the tests.
79 static const int kExpectedContext = 0xaabb;
80
81 private:
tommyclieaae5d92014-09-09 06:03:4782 base::MessageLoopForIO loop_;
[email protected]afa378f22013-12-02 03:37:5483 scoped_refptr<net::TestURLRequestContextGetter> context_;
[email protected]afa378f22013-12-02 03:37:5484 base::Closure quit_closure_;
85};
86
87const int CrxDownloaderTest::kExpectedContext;
88
89CrxDownloaderTest::CrxDownloaderTest()
[email protected]1b6587dc52014-04-26 00:38:5590 : callback_(base::Bind(&CrxDownloaderTest::DownloadComplete,
91 base::Unretained(this),
92 kExpectedContext)),
[email protected]8a5ebd432014-05-02 00:21:2293 progress_callback_(base::Bind(&CrxDownloaderTest::DownloadProgress,
94 base::Unretained(this),
95 kExpectedContext)),
[email protected]1b6587dc52014-04-26 00:38:5596 crx_context_(0),
[email protected]148dcfd32014-04-29 00:54:3097 num_download_complete_calls_(0),
[email protected]8a5ebd432014-05-02 00:21:2298 num_progress_calls_(0),
[email protected]afa378f22013-12-02 03:37:5499 context_(new net::TestURLRequestContextGetter(
skyostilb0daa012015-06-02 19:03:48100 base::ThreadTaskRunnerHandle::Get())) {
[email protected]afa378f22013-12-02 03:37:54101}
102
103CrxDownloaderTest::~CrxDownloaderTest() {
[email protected]3a0092d2013-12-18 03:04:35104 context_ = NULL;
tommyclieaae5d92014-09-09 06:03:47105
106 // The GetInterceptor requires the message loop to run to destruct correctly.
107 get_interceptor_.reset();
108 RunThreadsUntilIdle();
[email protected]afa378f22013-12-02 03:37:54109}
110
111void CrxDownloaderTest::SetUp() {
[email protected]148dcfd32014-04-29 00:54:30112 num_download_complete_calls_ = 0;
113 download_complete_result_ = CrxDownloader::Result();
[email protected]8a5ebd432014-05-02 00:21:22114 num_progress_calls_ = 0;
115 download_progress_result_ = CrxDownloader::Result();
tommyclieaae5d92014-09-09 06:03:47116
sorin9797aba2015-04-17 17:15:03117 // Do not use the background downloader in these tests.
skyostilb0daa012015-06-02 19:03:48118 crx_downloader_.reset(
119 CrxDownloader::Create(false, context_.get(),
sorin33012532015-10-26 21:05:54120 base::ThreadTaskRunnerHandle::Get())
121 .release());
[email protected]8a5ebd432014-05-02 00:21:22122 crx_downloader_->set_progress_callback(progress_callback_);
tommyclieaae5d92014-09-09 06:03:47123
skyostilb0daa012015-06-02 19:03:48124 get_interceptor_.reset(
125 new GetInterceptor(base::ThreadTaskRunnerHandle::Get(),
126 base::ThreadTaskRunnerHandle::Get()));
[email protected]afa378f22013-12-02 03:37:54127}
128
129void CrxDownloaderTest::TearDown() {
[email protected]8a5ebd432014-05-02 00:21:22130 crx_downloader_.reset();
[email protected]afa378f22013-12-02 03:37:54131}
132
133void CrxDownloaderTest::Quit() {
[email protected]da37c1d2013-12-19 01:04:38134 if (!quit_closure_.is_null())
135 quit_closure_.Run();
[email protected]afa378f22013-12-02 03:37:54136}
137
[email protected]148dcfd32014-04-29 00:54:30138void CrxDownloaderTest::DownloadComplete(int crx_context,
139 const CrxDownloader::Result& result) {
140 ++num_download_complete_calls_;
[email protected]afa378f22013-12-02 03:37:54141 crx_context_ = crx_context;
[email protected]148dcfd32014-04-29 00:54:30142 download_complete_result_ = result;
[email protected]afa378f22013-12-02 03:37:54143 Quit();
144}
145
[email protected]8a5ebd432014-05-02 00:21:22146void CrxDownloaderTest::DownloadProgress(int crx_context,
147 const CrxDownloader::Result& result) {
148 ++num_progress_calls_;
149 download_progress_result_ = result;
150}
151
[email protected]afa378f22013-12-02 03:37:54152void CrxDownloaderTest::RunThreads() {
153 base::RunLoop runloop;
154 quit_closure_ = runloop.QuitClosure();
155 runloop.Run();
156
157 // Since some tests need to drain currently enqueued tasks such as network
158 // intercepts on the IO thread, run the threads until they are
159 // idle. The component updater service won't loop again until the loop count
160 // is set and the service is started.
161 RunThreadsUntilIdle();
162}
163
164void CrxDownloaderTest::RunThreadsUntilIdle() {
165 base::RunLoop().RunUntilIdle();
166}
167
[email protected]da37c1d2013-12-19 01:04:38168// Tests that starting a download without a url results in an error.
169TEST_F(CrxDownloaderTest, NoUrl) {
170 std::vector<GURL> urls;
sorin74e70672016-02-03 03:13:10171 crx_downloader_->StartDownload(urls, std::string("abcd"), callback_);
[email protected]da37c1d2013-12-19 01:04:38172 RunThreadsUntilIdle();
[email protected]da37c1d2013-12-19 01:04:38173
[email protected]148dcfd32014-04-29 00:54:30174 EXPECT_EQ(1, num_download_complete_calls_);
175 EXPECT_EQ(kExpectedContext, crx_context_);
sorin74e70672016-02-03 03:13:10176 EXPECT_EQ(CrxDownloader::Error::NO_URL, download_complete_result_.error);
177 EXPECT_TRUE(download_complete_result_.response.empty());
178 EXPECT_EQ(-1, download_complete_result_.downloaded_bytes);
179 EXPECT_EQ(-1, download_complete_result_.total_bytes);
180 EXPECT_EQ(0, num_progress_calls_);
181}
182
183// Tests that starting a download without providing a hash results in an error.
184TEST_F(CrxDownloaderTest, NoHash) {
185 std::vector<GURL> urls(1, GURL("http://somehost/somefile"));
186
187 crx_downloader_->StartDownload(urls, std::string(), callback_);
188 RunThreadsUntilIdle();
189
190 EXPECT_EQ(1, num_download_complete_calls_);
191 EXPECT_EQ(kExpectedContext, crx_context_);
192 EXPECT_EQ(CrxDownloader::Error::NO_HASH, download_complete_result_.error);
[email protected]148dcfd32014-04-29 00:54:30193 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]8a5ebd432014-05-02 00:21:22194 EXPECT_EQ(-1, download_complete_result_.downloaded_bytes);
195 EXPECT_EQ(-1, download_complete_result_.total_bytes);
196 EXPECT_EQ(0, num_progress_calls_);
[email protected]da37c1d2013-12-19 01:04:38197}
198
[email protected]afa378f22013-12-02 03:37:54199// Tests that downloading from one url is successful.
200TEST_F(CrxDownloaderTest, OneUrl) {
201 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45202 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54203
[email protected]148dcfd32014-04-29 00:54:30204 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47205 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54206
sorin74e70672016-02-03 03:13:10207 crx_downloader_->StartDownloadFromUrl(expected_crx_url,
208 std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54209 RunThreads();
[email protected]afa378f22013-12-02 03:37:54210
tommyclieaae5d92014-09-09 06:03:47211 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30212
213 EXPECT_EQ(1, num_download_complete_calls_);
214 EXPECT_EQ(kExpectedContext, crx_context_);
215 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22216 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
217 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30218 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
219
220 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22221
222 EXPECT_LE(1, num_progress_calls_);
223 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
224 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54225}
226
sorin74e70672016-02-03 03:13:10227// Tests that downloading from one url fails if the actual hash of the file
228// does not match the expected hash.
229TEST_F(CrxDownloaderTest, OneUrlBadHash) {
230 const GURL expected_crx_url =
231 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
232
233 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
234 get_interceptor_->SetResponse(expected_crx_url, test_file);
235
236 crx_downloader_->StartDownloadFromUrl(
237 expected_crx_url,
238 std::string(
239 "813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"),
240 callback_);
241 RunThreads();
242
243 EXPECT_EQ(1, get_interceptor_->GetHitCount());
244
245 EXPECT_EQ(1, num_download_complete_calls_);
246 EXPECT_EQ(kExpectedContext, crx_context_);
247 EXPECT_EQ(CrxDownloader::Error::BAD_HASH, download_complete_result_.error);
248 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
249 EXPECT_EQ(1843, download_complete_result_.total_bytes);
250 EXPECT_TRUE(download_complete_result_.response.empty());
251
252 EXPECT_LE(1, num_progress_calls_);
253 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
254 EXPECT_EQ(1843, download_progress_result_.total_bytes);
255}
256
257// Tests that specifying two urls has no side effects. Expect a successful
[email protected]afa378f22013-12-02 03:37:54258// download, and only one download request be made.
[email protected]5bff685d32014-04-23 00:43:03259// This test is flaky on Android. crbug.com/329883
260#if defined(OS_ANDROID)
261#define MAYBE_TwoUrls DISABLED_TwoUrls
262#else
263#define MAYBE_TwoUrls TwoUrls
264#endif
265TEST_F(CrxDownloaderTest, MAYBE_TwoUrls) {
[email protected]afa378f22013-12-02 03:37:54266 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45267 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54268
[email protected]148dcfd32014-04-29 00:54:30269 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47270 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54271
272 std::vector<GURL> urls;
273 urls.push_back(expected_crx_url);
274 urls.push_back(expected_crx_url);
275
sorin74e70672016-02-03 03:13:10276 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54277 RunThreads();
[email protected]afa378f22013-12-02 03:37:54278
tommyclieaae5d92014-09-09 06:03:47279 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30280
281 EXPECT_EQ(1, num_download_complete_calls_);
282 EXPECT_EQ(kExpectedContext, crx_context_);
283 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22284 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
285 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30286 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
287
288 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22289
290 EXPECT_LE(1, num_progress_calls_);
291 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
292 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54293}
294
295// Tests that an invalid host results in a download error.
296TEST_F(CrxDownloaderTest, OneUrl_InvalidHost) {
297 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45298 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54299
[email protected]148dcfd32014-04-29 00:54:30300 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47301 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54302
303 crx_downloader_->StartDownloadFromUrl(
sorin74e70672016-02-03 03:13:10304 GURL("http://no.such.host"
305 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"),
306 std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54307 RunThreads();
[email protected]afa378f22013-12-02 03:37:54308
tommyclieaae5d92014-09-09 06:03:47309 EXPECT_EQ(0, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30310
311 EXPECT_EQ(1, num_download_complete_calls_);
312 EXPECT_EQ(kExpectedContext, crx_context_);
313 EXPECT_NE(0, download_complete_result_.error);
314 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]afa378f22013-12-02 03:37:54315}
316
317// Tests that an invalid path results in a download error.
318TEST_F(CrxDownloaderTest, OneUrl_InvalidPath) {
319 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45320 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54321
[email protected]148dcfd32014-04-29 00:54:30322 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47323 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54324
[email protected]d0c8b8b42014-05-06 05:11:45325 crx_downloader_->StartDownloadFromUrl(GURL("http://localhost/no/such/file"),
sorin74e70672016-02-03 03:13:10326 std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54327 RunThreads();
[email protected]afa378f22013-12-02 03:37:54328
tommyclieaae5d92014-09-09 06:03:47329 EXPECT_EQ(0, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30330
331 EXPECT_EQ(1, num_download_complete_calls_);
332 EXPECT_EQ(kExpectedContext, crx_context_);
333 EXPECT_NE(0, download_complete_result_.error);
334 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]afa378f22013-12-02 03:37:54335}
336
337// Tests that the fallback to a valid url is successful.
[email protected]5bff685d32014-04-23 00:43:03338// This test is flaky on Android. crbug.com/329883
339#if defined(OS_ANDROID)
340#define MAYBE_TwoUrls_FirstInvalid DISABLED_TwoUrls_FirstInvalid
341#else
342#define MAYBE_TwoUrls_FirstInvalid TwoUrls_FirstInvalid
343#endif
344TEST_F(CrxDownloaderTest, MAYBE_TwoUrls_FirstInvalid) {
[email protected]afa378f22013-12-02 03:37:54345 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45346 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54347
[email protected]148dcfd32014-04-29 00:54:30348 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47349 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54350
351 std::vector<GURL> urls;
352 urls.push_back(GURL("http://localhost/no/such/file"));
353 urls.push_back(expected_crx_url);
354
sorin74e70672016-02-03 03:13:10355 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54356 RunThreads();
[email protected]afa378f22013-12-02 03:37:54357
tommyclieaae5d92014-09-09 06:03:47358 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30359
360 EXPECT_EQ(1, num_download_complete_calls_);
361 EXPECT_EQ(kExpectedContext, crx_context_);
362 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22363 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
364 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30365 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
366
367 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22368
369 EXPECT_LE(1, num_progress_calls_);
370 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
371 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54372}
373
374// Tests that the download succeeds if the first url is correct and the
375// second bad url does not have a side-effect.
376TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) {
377 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45378 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54379
[email protected]148dcfd32014-04-29 00:54:30380 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47381 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54382
383 std::vector<GURL> urls;
384 urls.push_back(expected_crx_url);
385 urls.push_back(GURL("http://localhost/no/such/file"));
386
sorin74e70672016-02-03 03:13:10387 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54388 RunThreads();
[email protected]afa378f22013-12-02 03:37:54389
tommyclieaae5d92014-09-09 06:03:47390 EXPECT_EQ(1, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30391
392 EXPECT_EQ(1, num_download_complete_calls_);
393 EXPECT_EQ(kExpectedContext, crx_context_);
394 EXPECT_EQ(0, download_complete_result_.error);
[email protected]8a5ebd432014-05-02 00:21:22395 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes);
396 EXPECT_EQ(1843, download_complete_result_.total_bytes);
[email protected]148dcfd32014-04-29 00:54:30397 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file));
398
399 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false));
[email protected]8a5ebd432014-05-02 00:21:22400
401 EXPECT_LE(1, num_progress_calls_);
402 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes);
403 EXPECT_EQ(1843, download_progress_result_.total_bytes);
[email protected]afa378f22013-12-02 03:37:54404}
405
406// Tests that the download fails if both urls are bad.
407TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) {
408 const GURL expected_crx_url =
[email protected]d0c8b8b42014-05-06 05:11:45409 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
[email protected]afa378f22013-12-02 03:37:54410
[email protected]148dcfd32014-04-29 00:54:30411 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
tommyclieaae5d92014-09-09 06:03:47412 get_interceptor_->SetResponse(expected_crx_url, test_file);
[email protected]afa378f22013-12-02 03:37:54413
414 std::vector<GURL> urls;
415 urls.push_back(GURL("http://localhost/no/such/file"));
sorin52ac0882015-01-24 01:15:00416 urls.push_back(GURL(
417 "http://no.such.host/"
418 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"));
[email protected]afa378f22013-12-02 03:37:54419
sorin74e70672016-02-03 03:13:10420 crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
[email protected]afa378f22013-12-02 03:37:54421 RunThreads();
[email protected]afa378f22013-12-02 03:37:54422
tommyclieaae5d92014-09-09 06:03:47423 EXPECT_EQ(0, get_interceptor_->GetHitCount());
[email protected]148dcfd32014-04-29 00:54:30424
425 EXPECT_EQ(1, num_download_complete_calls_);
426 EXPECT_EQ(kExpectedContext, crx_context_);
427 EXPECT_NE(0, download_complete_result_.error);
428 EXPECT_TRUE(download_complete_result_.response.empty());
[email protected]afa378f22013-12-02 03:37:54429}
430
sorin52ac0882015-01-24 01:15:00431} // namespace update_client