Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "components/component_updater/crx_downloader.h" | 14 #include "components/component_updater/crx_downloader.h" |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | |
| 17 #include "content/test/net/url_request_prepackaged_interceptor.h" | |
| 18 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/url_request/url_request_prepackaged_interceptor.h" | |
| 19 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 19 |
| 22 using content::BrowserThread; | |
| 23 using base::ContentsEqual; | 20 using base::ContentsEqual; |
| 24 | 21 |
| 25 namespace component_updater { | 22 namespace component_updater { |
| 26 | 23 |
| 27 namespace { | 24 namespace { |
| 28 | 25 |
| 29 // Intercepts HTTP GET requests sent to "localhost". | 26 // Intercepts HTTP GET requests sent to "localhost". |
| 30 typedef content::URLLocalHostRequestPrepackagedInterceptor GetInterceptor; | 27 typedef net::URLLocalHostRequestPrepackagedInterceptor GetInterceptor; |
| 31 | 28 |
| 32 const char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx"; | 29 const char kTestFileName[] = "jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 33 | 30 |
| 34 base::FilePath MakeTestFilePath(const char* file) { | 31 base::FilePath MakeTestFilePath(const char* file) { |
| 35 base::FilePath path; | 32 base::FilePath path; |
| 36 PathService::Get(chrome::DIR_TEST_DATA, &path); | 33 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 37 return path.AppendASCII("components").AppendASCII(file); | 34 return path.AppendASCII("components").AppendASCII(file); |
| 38 } | 35 } |
| 39 | 36 |
| 40 } // namespace | 37 } // namespace |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 52 void RunThreads(); | 49 void RunThreads(); |
| 53 void RunThreadsUntilIdle(); | 50 void RunThreadsUntilIdle(); |
| 54 | 51 |
| 55 void DownloadComplete(int crx_context, const CrxDownloader::Result& result); | 52 void DownloadComplete(int crx_context, const CrxDownloader::Result& result); |
| 56 | 53 |
| 57 void DownloadProgress(int crx_context, const CrxDownloader::Result& result); | 54 void DownloadProgress(int crx_context, const CrxDownloader::Result& result); |
| 58 | 55 |
| 59 protected: | 56 protected: |
| 60 scoped_ptr<CrxDownloader> crx_downloader_; | 57 scoped_ptr<CrxDownloader> crx_downloader_; |
| 61 | 58 |
| 59 scoped_ptr<GetInterceptor> get_interceptor_; | |
| 60 | |
| 62 CrxDownloader::DownloadCallback callback_; | 61 CrxDownloader::DownloadCallback callback_; |
| 63 CrxDownloader::ProgressCallback progress_callback_; | 62 CrxDownloader::ProgressCallback progress_callback_; |
| 64 | 63 |
| 65 int crx_context_; | 64 int crx_context_; |
| 66 | 65 |
| 67 int num_download_complete_calls_; | 66 int num_download_complete_calls_; |
| 68 CrxDownloader::Result download_complete_result_; | 67 CrxDownloader::Result download_complete_result_; |
| 69 | 68 |
| 70 // These members are updated by DownloadProgress. | 69 // These members are updated by DownloadProgress. |
| 71 int num_progress_calls_; | 70 int num_progress_calls_; |
| 72 CrxDownloader::Result download_progress_result_; | 71 CrxDownloader::Result download_progress_result_; |
| 73 | 72 |
| 74 // A magic value for the context to be used in the tests. | 73 // A magic value for the context to be used in the tests. |
| 75 static const int kExpectedContext = 0xaabb; | 74 static const int kExpectedContext = 0xaabb; |
| 76 | 75 |
| 77 private: | 76 private: |
| 78 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 77 base::MessageLoopForIO loop_; |
| 79 scoped_refptr<net::TestURLRequestContextGetter> context_; | 78 scoped_refptr<net::TestURLRequestContextGetter> context_; |
| 80 content::TestBrowserThreadBundle thread_bundle_; | |
| 81 base::Closure quit_closure_; | 79 base::Closure quit_closure_; |
| 82 }; | 80 }; |
| 83 | 81 |
| 84 const int CrxDownloaderTest::kExpectedContext; | 82 const int CrxDownloaderTest::kExpectedContext; |
| 85 | 83 |
| 86 CrxDownloaderTest::CrxDownloaderTest() | 84 CrxDownloaderTest::CrxDownloaderTest() |
| 87 : callback_(base::Bind(&CrxDownloaderTest::DownloadComplete, | 85 : callback_(base::Bind(&CrxDownloaderTest::DownloadComplete, |
| 88 base::Unretained(this), | 86 base::Unretained(this), |
| 89 kExpectedContext)), | 87 kExpectedContext)), |
| 90 progress_callback_(base::Bind(&CrxDownloaderTest::DownloadProgress, | 88 progress_callback_(base::Bind(&CrxDownloaderTest::DownloadProgress, |
| 91 base::Unretained(this), | 89 base::Unretained(this), |
| 92 kExpectedContext)), | 90 kExpectedContext)), |
| 93 crx_context_(0), | 91 crx_context_(0), |
| 94 num_download_complete_calls_(0), | 92 num_download_complete_calls_(0), |
| 95 num_progress_calls_(0), | 93 num_progress_calls_(0), |
| 96 blocking_task_runner_(BrowserThread::GetBlockingPool()-> | |
| 97 GetSequencedTaskRunnerWithShutdownBehavior( | |
| 98 BrowserThread::GetBlockingPool()->GetSequenceToken(), | |
| 99 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | |
| 100 context_(new net::TestURLRequestContextGetter( | 94 context_(new net::TestURLRequestContextGetter( |
| 101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))), | 95 base::MessageLoopProxy::current())) { |
| 102 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | |
| 103 } | 96 } |
| 104 | 97 |
| 105 CrxDownloaderTest::~CrxDownloaderTest() { | 98 CrxDownloaderTest::~CrxDownloaderTest() { |
| 106 context_ = NULL; | 99 context_ = NULL; |
| 100 | |
| 101 // The GetInterceptor requires the message loop to run to destruct correctly. | |
| 102 get_interceptor_.reset(); | |
| 103 RunThreadsUntilIdle(); | |
| 107 } | 104 } |
| 108 | 105 |
| 109 void CrxDownloaderTest::SetUp() { | 106 void CrxDownloaderTest::SetUp() { |
| 110 num_download_complete_calls_ = 0; | 107 num_download_complete_calls_ = 0; |
| 111 download_complete_result_ = CrxDownloader::Result(); | 108 download_complete_result_ = CrxDownloader::Result(); |
| 112 num_progress_calls_ = 0; | 109 num_progress_calls_ = 0; |
| 113 download_progress_result_ = CrxDownloader::Result(); | 110 download_progress_result_ = CrxDownloader::Result(); |
| 111 | |
| 114 crx_downloader_.reset(CrxDownloader::Create( | 112 crx_downloader_.reset(CrxDownloader::Create( |
| 115 false, // Do not use the background downloader in these tests. | 113 false, // Do not use the background downloader in these tests. |
| 116 context_.get(), | 114 context_.get(), |
| 117 blocking_task_runner_, | 115 base::MessageLoopProxy::current(), |
| 118 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 116 NULL /* background_task_runner */)); |
|
Sorin Jianu
2014/08/26 20:32:52
Consider not using the inline /* */.
tommycli
2014/08/26 21:06:58
Done.
| |
| 119 crx_downloader_->set_progress_callback(progress_callback_); | 117 crx_downloader_->set_progress_callback(progress_callback_); |
| 118 | |
| 119 get_interceptor_.reset(new GetInterceptor(base::MessageLoopProxy::current(), | |
| 120 base::MessageLoopProxy::current())); | |
| 120 } | 121 } |
| 121 | 122 |
| 122 void CrxDownloaderTest::TearDown() { | 123 void CrxDownloaderTest::TearDown() { |
| 123 crx_downloader_.reset(); | 124 crx_downloader_.reset(); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void CrxDownloaderTest::Quit() { | 127 void CrxDownloaderTest::Quit() { |
| 127 if (!quit_closure_.is_null()) | 128 if (!quit_closure_.is_null()) |
| 128 quit_closure_.Run(); | 129 quit_closure_.Run(); |
| 129 } | 130 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 EXPECT_EQ(-1, download_complete_result_.total_bytes); | 173 EXPECT_EQ(-1, download_complete_result_.total_bytes); |
| 173 EXPECT_EQ(0, num_progress_calls_); | 174 EXPECT_EQ(0, num_progress_calls_); |
| 174 } | 175 } |
| 175 | 176 |
| 176 // Tests that downloading from one url is successful. | 177 // Tests that downloading from one url is successful. |
| 177 TEST_F(CrxDownloaderTest, OneUrl) { | 178 TEST_F(CrxDownloaderTest, OneUrl) { |
| 178 const GURL expected_crx_url = | 179 const GURL expected_crx_url = |
| 179 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 180 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 180 | 181 |
| 181 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); | 182 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); |
| 182 GetInterceptor interceptor; | 183 get_interceptor_->SetResponse(expected_crx_url, test_file); |
| 183 interceptor.SetResponse(expected_crx_url, test_file); | |
| 184 | 184 |
| 185 crx_downloader_->StartDownloadFromUrl(expected_crx_url, callback_); | 185 crx_downloader_->StartDownloadFromUrl(expected_crx_url, callback_); |
| 186 RunThreads(); | 186 RunThreads(); |
| 187 | 187 |
| 188 EXPECT_EQ(1, interceptor.GetHitCount()); | 188 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| 189 | 189 |
| 190 EXPECT_EQ(1, num_download_complete_calls_); | 190 EXPECT_EQ(1, num_download_complete_calls_); |
| 191 EXPECT_EQ(kExpectedContext, crx_context_); | 191 EXPECT_EQ(kExpectedContext, crx_context_); |
| 192 EXPECT_EQ(0, download_complete_result_.error); | 192 EXPECT_EQ(0, download_complete_result_.error); |
| 193 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); | 193 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); |
| 194 EXPECT_EQ(1843, download_complete_result_.total_bytes); | 194 EXPECT_EQ(1843, download_complete_result_.total_bytes); |
| 195 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); | 195 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); |
| 196 | 196 |
| 197 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); | 197 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); |
| 198 | 198 |
| 199 EXPECT_LE(1, num_progress_calls_); | 199 EXPECT_LE(1, num_progress_calls_); |
| 200 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); | 200 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); |
| 201 EXPECT_EQ(1843, download_progress_result_.total_bytes); | 201 EXPECT_EQ(1843, download_progress_result_.total_bytes); |
| 202 } | 202 } |
| 203 | 203 |
| 204 // Tests that specifying from two urls has no side effects. Expect a successful | 204 // Tests that specifying from two urls has no side effects. Expect a successful |
| 205 // download, and only one download request be made. | 205 // download, and only one download request be made. |
| 206 // This test is flaky on Android. crbug.com/329883 | 206 // This test is flaky on Android. crbug.com/329883 |
| 207 #if defined(OS_ANDROID) | 207 #if defined(OS_ANDROID) |
| 208 #define MAYBE_TwoUrls DISABLED_TwoUrls | 208 #define MAYBE_TwoUrls DISABLED_TwoUrls |
| 209 #else | 209 #else |
| 210 #define MAYBE_TwoUrls TwoUrls | 210 #define MAYBE_TwoUrls TwoUrls |
| 211 #endif | 211 #endif |
| 212 TEST_F(CrxDownloaderTest, MAYBE_TwoUrls) { | 212 TEST_F(CrxDownloaderTest, MAYBE_TwoUrls) { |
| 213 const GURL expected_crx_url = | 213 const GURL expected_crx_url = |
| 214 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 214 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 215 | 215 |
| 216 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); | 216 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); |
| 217 GetInterceptor interceptor; | 217 get_interceptor_->SetResponse(expected_crx_url, test_file); |
| 218 interceptor.SetResponse(expected_crx_url, test_file); | |
| 219 | 218 |
| 220 std::vector<GURL> urls; | 219 std::vector<GURL> urls; |
| 221 urls.push_back(expected_crx_url); | 220 urls.push_back(expected_crx_url); |
| 222 urls.push_back(expected_crx_url); | 221 urls.push_back(expected_crx_url); |
| 223 | 222 |
| 224 crx_downloader_->StartDownload(urls, callback_); | 223 crx_downloader_->StartDownload(urls, callback_); |
| 225 RunThreads(); | 224 RunThreads(); |
| 226 | 225 |
| 227 EXPECT_EQ(1, interceptor.GetHitCount()); | 226 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| 228 | 227 |
| 229 EXPECT_EQ(1, num_download_complete_calls_); | 228 EXPECT_EQ(1, num_download_complete_calls_); |
| 230 EXPECT_EQ(kExpectedContext, crx_context_); | 229 EXPECT_EQ(kExpectedContext, crx_context_); |
| 231 EXPECT_EQ(0, download_complete_result_.error); | 230 EXPECT_EQ(0, download_complete_result_.error); |
| 232 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); | 231 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); |
| 233 EXPECT_EQ(1843, download_complete_result_.total_bytes); | 232 EXPECT_EQ(1843, download_complete_result_.total_bytes); |
| 234 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); | 233 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); |
| 235 | 234 |
| 236 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); | 235 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); |
| 237 | 236 |
| 238 EXPECT_LE(1, num_progress_calls_); | 237 EXPECT_LE(1, num_progress_calls_); |
| 239 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); | 238 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); |
| 240 EXPECT_EQ(1843, download_progress_result_.total_bytes); | 239 EXPECT_EQ(1843, download_progress_result_.total_bytes); |
| 241 } | 240 } |
| 242 | 241 |
| 243 // Tests that an invalid host results in a download error. | 242 // Tests that an invalid host results in a download error. |
| 244 TEST_F(CrxDownloaderTest, OneUrl_InvalidHost) { | 243 TEST_F(CrxDownloaderTest, OneUrl_InvalidHost) { |
| 245 const GURL expected_crx_url = | 244 const GURL expected_crx_url = |
| 246 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 245 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 247 | 246 |
| 248 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); | 247 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); |
| 249 GetInterceptor interceptor; | 248 get_interceptor_->SetResponse(expected_crx_url, test_file); |
| 250 interceptor.SetResponse(expected_crx_url, test_file); | |
| 251 | 249 |
| 252 crx_downloader_->StartDownloadFromUrl( | 250 crx_downloader_->StartDownloadFromUrl( |
| 253 GURL("http://no.such.host" | 251 GURL("http://no.such.host" |
| 254 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"), | 252 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx"), |
| 255 callback_); | 253 callback_); |
| 256 RunThreads(); | 254 RunThreads(); |
| 257 | 255 |
| 258 EXPECT_EQ(0, interceptor.GetHitCount()); | 256 EXPECT_EQ(0, get_interceptor_->GetHitCount()); |
| 259 | 257 |
| 260 EXPECT_EQ(1, num_download_complete_calls_); | 258 EXPECT_EQ(1, num_download_complete_calls_); |
| 261 EXPECT_EQ(kExpectedContext, crx_context_); | 259 EXPECT_EQ(kExpectedContext, crx_context_); |
| 262 EXPECT_NE(0, download_complete_result_.error); | 260 EXPECT_NE(0, download_complete_result_.error); |
| 263 EXPECT_TRUE(download_complete_result_.response.empty()); | 261 EXPECT_TRUE(download_complete_result_.response.empty()); |
| 264 } | 262 } |
| 265 | 263 |
| 266 // Tests that an invalid path results in a download error. | 264 // Tests that an invalid path results in a download error. |
| 267 TEST_F(CrxDownloaderTest, OneUrl_InvalidPath) { | 265 TEST_F(CrxDownloaderTest, OneUrl_InvalidPath) { |
| 268 const GURL expected_crx_url = | 266 const GURL expected_crx_url = |
| 269 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 267 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 270 | 268 |
| 271 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); | 269 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); |
| 272 GetInterceptor interceptor; | 270 get_interceptor_->SetResponse(expected_crx_url, test_file); |
| 273 interceptor.SetResponse(expected_crx_url, test_file); | |
| 274 | 271 |
| 275 crx_downloader_->StartDownloadFromUrl(GURL("http://localhost/no/such/file"), | 272 crx_downloader_->StartDownloadFromUrl(GURL("http://localhost/no/such/file"), |
| 276 callback_); | 273 callback_); |
| 277 RunThreads(); | 274 RunThreads(); |
| 278 | 275 |
| 279 EXPECT_EQ(0, interceptor.GetHitCount()); | 276 EXPECT_EQ(0, get_interceptor_->GetHitCount()); |
| 280 | 277 |
| 281 EXPECT_EQ(1, num_download_complete_calls_); | 278 EXPECT_EQ(1, num_download_complete_calls_); |
| 282 EXPECT_EQ(kExpectedContext, crx_context_); | 279 EXPECT_EQ(kExpectedContext, crx_context_); |
| 283 EXPECT_NE(0, download_complete_result_.error); | 280 EXPECT_NE(0, download_complete_result_.error); |
| 284 EXPECT_TRUE(download_complete_result_.response.empty()); | 281 EXPECT_TRUE(download_complete_result_.response.empty()); |
| 285 } | 282 } |
| 286 | 283 |
| 287 // Tests that the fallback to a valid url is successful. | 284 // Tests that the fallback to a valid url is successful. |
| 288 // This test is flaky on Android. crbug.com/329883 | 285 // This test is flaky on Android. crbug.com/329883 |
| 289 #if defined(OS_ANDROID) | 286 #if defined(OS_ANDROID) |
| 290 #define MAYBE_TwoUrls_FirstInvalid DISABLED_TwoUrls_FirstInvalid | 287 #define MAYBE_TwoUrls_FirstInvalid DISABLED_TwoUrls_FirstInvalid |
| 291 #else | 288 #else |
| 292 #define MAYBE_TwoUrls_FirstInvalid TwoUrls_FirstInvalid | 289 #define MAYBE_TwoUrls_FirstInvalid TwoUrls_FirstInvalid |
| 293 #endif | 290 #endif |
| 294 TEST_F(CrxDownloaderTest, MAYBE_TwoUrls_FirstInvalid) { | 291 TEST_F(CrxDownloaderTest, MAYBE_TwoUrls_FirstInvalid) { |
| 295 const GURL expected_crx_url = | 292 const GURL expected_crx_url = |
| 296 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 293 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 297 | 294 |
| 298 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); | 295 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); |
| 299 GetInterceptor interceptor; | 296 get_interceptor_->SetResponse(expected_crx_url, test_file); |
| 300 interceptor.SetResponse(expected_crx_url, test_file); | |
| 301 | 297 |
| 302 std::vector<GURL> urls; | 298 std::vector<GURL> urls; |
| 303 urls.push_back(GURL("http://localhost/no/such/file")); | 299 urls.push_back(GURL("http://localhost/no/such/file")); |
| 304 urls.push_back(expected_crx_url); | 300 urls.push_back(expected_crx_url); |
| 305 | 301 |
| 306 crx_downloader_->StartDownload(urls, callback_); | 302 crx_downloader_->StartDownload(urls, callback_); |
| 307 RunThreads(); | 303 RunThreads(); |
| 308 | 304 |
| 309 EXPECT_EQ(1, interceptor.GetHitCount()); | 305 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| 310 | 306 |
| 311 EXPECT_EQ(1, num_download_complete_calls_); | 307 EXPECT_EQ(1, num_download_complete_calls_); |
| 312 EXPECT_EQ(kExpectedContext, crx_context_); | 308 EXPECT_EQ(kExpectedContext, crx_context_); |
| 313 EXPECT_EQ(0, download_complete_result_.error); | 309 EXPECT_EQ(0, download_complete_result_.error); |
| 314 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); | 310 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); |
| 315 EXPECT_EQ(1843, download_complete_result_.total_bytes); | 311 EXPECT_EQ(1843, download_complete_result_.total_bytes); |
| 316 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); | 312 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); |
| 317 | 313 |
| 318 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); | 314 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); |
| 319 | 315 |
| 320 EXPECT_LE(1, num_progress_calls_); | 316 EXPECT_LE(1, num_progress_calls_); |
| 321 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); | 317 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); |
| 322 EXPECT_EQ(1843, download_progress_result_.total_bytes); | 318 EXPECT_EQ(1843, download_progress_result_.total_bytes); |
| 323 } | 319 } |
| 324 | 320 |
| 325 // Tests that the download succeeds if the first url is correct and the | 321 // Tests that the download succeeds if the first url is correct and the |
| 326 // second bad url does not have a side-effect. | 322 // second bad url does not have a side-effect. |
| 327 TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) { | 323 TEST_F(CrxDownloaderTest, TwoUrls_SecondInvalid) { |
| 328 const GURL expected_crx_url = | 324 const GURL expected_crx_url = |
| 329 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 325 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 330 | 326 |
| 331 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); | 327 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); |
| 332 GetInterceptor interceptor; | 328 get_interceptor_->SetResponse(expected_crx_url, test_file); |
| 333 interceptor.SetResponse(expected_crx_url, test_file); | |
| 334 | 329 |
| 335 std::vector<GURL> urls; | 330 std::vector<GURL> urls; |
| 336 urls.push_back(expected_crx_url); | 331 urls.push_back(expected_crx_url); |
| 337 urls.push_back(GURL("http://localhost/no/such/file")); | 332 urls.push_back(GURL("http://localhost/no/such/file")); |
| 338 | 333 |
| 339 crx_downloader_->StartDownload(urls, callback_); | 334 crx_downloader_->StartDownload(urls, callback_); |
| 340 RunThreads(); | 335 RunThreads(); |
| 341 | 336 |
| 342 EXPECT_EQ(1, interceptor.GetHitCount()); | 337 EXPECT_EQ(1, get_interceptor_->GetHitCount()); |
| 343 | 338 |
| 344 EXPECT_EQ(1, num_download_complete_calls_); | 339 EXPECT_EQ(1, num_download_complete_calls_); |
| 345 EXPECT_EQ(kExpectedContext, crx_context_); | 340 EXPECT_EQ(kExpectedContext, crx_context_); |
| 346 EXPECT_EQ(0, download_complete_result_.error); | 341 EXPECT_EQ(0, download_complete_result_.error); |
| 347 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); | 342 EXPECT_EQ(1843, download_complete_result_.downloaded_bytes); |
| 348 EXPECT_EQ(1843, download_complete_result_.total_bytes); | 343 EXPECT_EQ(1843, download_complete_result_.total_bytes); |
| 349 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); | 344 EXPECT_TRUE(ContentsEqual(download_complete_result_.response, test_file)); |
| 350 | 345 |
| 351 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); | 346 EXPECT_TRUE(base::DeleteFile(download_complete_result_.response, false)); |
| 352 | 347 |
| 353 EXPECT_LE(1, num_progress_calls_); | 348 EXPECT_LE(1, num_progress_calls_); |
| 354 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); | 349 EXPECT_EQ(1843, download_progress_result_.downloaded_bytes); |
| 355 EXPECT_EQ(1843, download_progress_result_.total_bytes); | 350 EXPECT_EQ(1843, download_progress_result_.total_bytes); |
| 356 } | 351 } |
| 357 | 352 |
| 358 // Tests that the download fails if both urls are bad. | 353 // Tests that the download fails if both urls are bad. |
| 359 TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) { | 354 TEST_F(CrxDownloaderTest, TwoUrls_BothInvalid) { |
| 360 const GURL expected_crx_url = | 355 const GURL expected_crx_url = |
| 361 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 356 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 362 | 357 |
| 363 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); | 358 const base::FilePath test_file(MakeTestFilePath(kTestFileName)); |
| 364 GetInterceptor interceptor; | 359 get_interceptor_->SetResponse(expected_crx_url, test_file); |
| 365 interceptor.SetResponse(expected_crx_url, test_file); | |
| 366 | 360 |
| 367 std::vector<GURL> urls; | 361 std::vector<GURL> urls; |
| 368 urls.push_back(GURL("http://localhost/no/such/file")); | 362 urls.push_back(GURL("http://localhost/no/such/file")); |
| 369 urls.push_back(GURL("http://no.such.host/" | 363 urls.push_back(GURL("http://no.such.host/" |
| 370 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx")); | 364 "/download/jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 371 | 365 |
| 372 crx_downloader_->StartDownload(urls, callback_); | 366 crx_downloader_->StartDownload(urls, callback_); |
| 373 RunThreads(); | 367 RunThreads(); |
| 374 | 368 |
| 375 EXPECT_EQ(0, interceptor.GetHitCount()); | 369 EXPECT_EQ(0, get_interceptor_->GetHitCount()); |
| 376 | 370 |
| 377 EXPECT_EQ(1, num_download_complete_calls_); | 371 EXPECT_EQ(1, num_download_complete_calls_); |
| 378 EXPECT_EQ(kExpectedContext, crx_context_); | 372 EXPECT_EQ(kExpectedContext, crx_context_); |
| 379 EXPECT_NE(0, download_complete_result_.error); | 373 EXPECT_NE(0, download_complete_result_.error); |
| 380 EXPECT_TRUE(download_complete_result_.response.empty()); | 374 EXPECT_TRUE(download_complete_result_.response.empty()); |
| 381 } | 375 } |
| 382 | 376 |
| 383 } // namespace component_updater | 377 } // namespace component_updater |
| OLD | NEW |