Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: components/update_client/test/crx_downloader_unittest.cc

Issue 808773005: Move most of the component updater artifacts to update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "components/component_updater/crx_downloader.h" 14 #include "components/update_client/crx_downloader.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/url_request/test_url_request_interceptor.h" 16 #include "net/url_request/test_url_request_interceptor.h"
17 #include "net/url_request/url_request_test_util.h" 17 #include "net/url_request/url_request_test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using base::ContentsEqual; 20 using base::ContentsEqual;
21 21
22 namespace component_updater { 22 namespace update_client {
23 23
24 namespace { 24 namespace {
25 25
26 // Intercepts HTTP GET requests sent to "localhost". 26 // Intercepts HTTP GET requests sent to "localhost".
27 typedef net::LocalHostTestURLRequestInterceptor GetInterceptor; 27 typedef net::LocalHostTestURLRequestInterceptor GetInterceptor;
28 28
29 const char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx"; 29 const char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx";
30 30
31 base::FilePath MakeTestFilePath(const char* file) { 31 base::FilePath MakeTestFilePath(const char* file) {
32 base::FilePath path; 32 base::FilePath path;
33 PathService::Get(base::DIR_SOURCE_ROOT, &path); 33 PathService::Get(base::DIR_SOURCE_ROOT, &path);
34 return path.AppendASCII("components").AppendASCII("test").AppendASCII("data") 34 return path.AppendASCII("components")
35 .AppendASCII("component_updater").AppendASCII(file); 35 .AppendASCII("test")
36 .AppendASCII("data")
37 .AppendASCII("update_client")
38 .AppendASCII(file);
36 } 39 }
37 40
38 } // namespace 41 } // namespace
39 42
40 class CrxDownloaderTest : public testing::Test { 43 class CrxDownloaderTest : public testing::Test {
41 public: 44 public:
42 CrxDownloaderTest(); 45 CrxDownloaderTest();
43 ~CrxDownloaderTest() override; 46 ~CrxDownloaderTest() override;
44 47
45 // Overrides from testing::Test. 48 // Overrides from testing::Test.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 108 }
106 109
107 void CrxDownloaderTest::SetUp() { 110 void CrxDownloaderTest::SetUp() {
108 num_download_complete_calls_ = 0; 111 num_download_complete_calls_ = 0;
109 download_complete_result_ = CrxDownloader::Result(); 112 download_complete_result_ = CrxDownloader::Result();
110 num_progress_calls_ = 0; 113 num_progress_calls_ = 0;
111 download_progress_result_ = CrxDownloader::Result(); 114 download_progress_result_ = CrxDownloader::Result();
112 115
113 crx_downloader_.reset(CrxDownloader::Create( 116 crx_downloader_.reset(CrxDownloader::Create(
114 false, // Do not use the background downloader in these tests. 117 false, // Do not use the background downloader in these tests.
115 context_.get(), 118 context_.get(), base::MessageLoopProxy::current(),
116 base::MessageLoopProxy::current(),
117 NULL)); // No |background_task_runner| because no background downloader. 119 NULL)); // No |background_task_runner| because no background downloader.
118 crx_downloader_->set_progress_callback(progress_callback_); 120 crx_downloader_->set_progress_callback(progress_callback_);
119 121
120 get_interceptor_.reset(new GetInterceptor(base::MessageLoopProxy::current(), 122 get_interceptor_.reset(new GetInterceptor(base::MessageLoopProxy::current(),
121 base::MessageLoopProxy::current())); 123 base::MessageLoopProxy::current()));
122 } 124 }
123 125
124 void CrxDownloaderTest::TearDown() { 126 void CrxDownloaderTest::TearDown() {
125 crx_downloader_.reset(); 127 crx_downloader_.reset();
126 } 128 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 244
243 // Tests that an invalid host results in a download error. 245 // Tests that an invalid host results in a download error.
244 TEST_F(CrxDownloaderTest, OneUrl_InvalidHost) { 246 TEST_F(CrxDownloaderTest, OneUrl_InvalidHost) {
245 const GURL expected_crx_url = 247 const GURL expected_crx_url =
246 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); 248 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
247 249
248 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); 250 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
249 get_interceptor_->SetResponse(expected_crx_url, test_file); 251 get_interceptor_->SetResponse(expected_crx_url, test_file);
250 252
251 crx_downloader_->StartDownloadFromUrl( 253 crx_downloader_->StartDownloadFromUrl(
252 GURL("http://no.such.host" 254 GURL(
253 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"), 255 "http://no.such.host"
256 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"),
254 callback_); 257 callback_);
255 RunThreads(); 258 RunThreads();
256 259
257 EXPECT_EQ(0, get_interceptor_->GetHitCount()); 260 EXPECT_EQ(0, get_interceptor_->GetHitCount());
258 261
259 EXPECT_EQ(1, num_download_complete_calls_); 262 EXPECT_EQ(1, num_download_complete_calls_);
260 EXPECT_EQ(kExpectedContext, crx_context_); 263 EXPECT_EQ(kExpectedContext, crx_context_);
261 EXPECT_NE(0, download_complete_result_.error); 264 EXPECT_NE(0, download_complete_result_.error);
262 EXPECT_TRUE(download_complete_result_.response.empty()); 265 EXPECT_TRUE(download_complete_result_.response.empty());
263 } 266 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // Tests that the download fails if both urls are bad. 357 // Tests that the download fails if both urls are bad.
355 TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) { 358 TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) {
356 const GURL expected_crx_url = 359 const GURL expected_crx_url =
357 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); 360 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx");
358 361
359 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); 362 const base::FilePath test_file(MakeTestFilePath(kTestFileName));
360 get_interceptor_->SetResponse(expected_crx_url, test_file); 363 get_interceptor_->SetResponse(expected_crx_url, test_file);
361 364
362 std::vector<GURL> urls; 365 std::vector<GURL> urls;
363 urls.push_back(GURL("http://localhost/no/such/file")); 366 urls.push_back(GURL("http://localhost/no/such/file"));
364 urls.push_back(GURL("http://no.such.host/" 367 urls.push_back(GURL(
365 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx")); 368 "http://no.such.host/"
369 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"));
366 370
367 crx_downloader_->StartDownload(urls, callback_); 371 crx_downloader_->StartDownload(urls, callback_);
368 RunThreads(); 372 RunThreads();
369 373
370 EXPECT_EQ(0, get_interceptor_->GetHitCount()); 374 EXPECT_EQ(0, get_interceptor_->GetHitCount());
371 375
372 EXPECT_EQ(1, num_download_complete_calls_); 376 EXPECT_EQ(1, num_download_complete_calls_);
373 EXPECT_EQ(kExpectedContext, crx_context_); 377 EXPECT_EQ(kExpectedContext, crx_context_);
374 EXPECT_NE(0, download_complete_result_.error); 378 EXPECT_NE(0, download_complete_result_.error);
375 EXPECT_TRUE(download_complete_result_.response.empty()); 379 EXPECT_TRUE(download_complete_result_.response.empty());
376 } 380 }
377 381
378 } // namespace component_updater 382 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698