| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "sync/internal_api/public/attachments/attachment_downloader_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_downloader_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return base::Bind(&AttachmentDownloaderImplTest::DownloadDone, | 179 return base::Bind(&AttachmentDownloaderImplTest::DownloadDone, |
| 180 base::Unretained(this), | 180 base::Unretained(this), |
| 181 id); | 181 id); |
| 182 } | 182 } |
| 183 | 183 |
| 184 // Respond with |response_code| and hash header of type |hash_header_type|. | 184 // Respond with |response_code| and hash header of type |hash_header_type|. |
| 185 void CompleteDownload(int response_code, HashHeaderType hash_header_type); | 185 void CompleteDownload(int response_code, HashHeaderType hash_header_type); |
| 186 | 186 |
| 187 void DownloadDone(const AttachmentId& attachment_id, | 187 void DownloadDone(const AttachmentId& attachment_id, |
| 188 const AttachmentDownloader::DownloadResult& result, | 188 const AttachmentDownloader::DownloadResult& result, |
| 189 scoped_ptr<Attachment> attachment); | 189 std::unique_ptr<Attachment> attachment); |
| 190 | 190 |
| 191 void VerifyDownloadResult(const AttachmentId& attachment_id, | 191 void VerifyDownloadResult(const AttachmentId& attachment_id, |
| 192 const AttachmentDownloader::DownloadResult& result); | 192 const AttachmentDownloader::DownloadResult& result); |
| 193 | 193 |
| 194 void RunMessageLoop(); | 194 void RunMessageLoop(); |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 static void AddHashHeader(HashHeaderType hash_header_type, | 197 static void AddHashHeader(HashHeaderType hash_header_type, |
| 198 net::TestURLFetcher* fetcher); | 198 net::TestURLFetcher* fetcher); |
| 199 | 199 |
| 200 base::MessageLoopForIO message_loop_; | 200 base::MessageLoopForIO message_loop_; |
| 201 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 201 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 202 net::TestURLFetcherFactory url_fetcher_factory_; | 202 net::TestURLFetcherFactory url_fetcher_factory_; |
| 203 scoped_ptr<MockOAuth2TokenService> token_service_; | 203 std::unique_ptr<MockOAuth2TokenService> token_service_; |
| 204 scoped_ptr<AttachmentDownloader> attachment_downloader_; | 204 std::unique_ptr<AttachmentDownloader> attachment_downloader_; |
| 205 ResultsMap download_results_; | 205 ResultsMap download_results_; |
| 206 int num_completed_downloads_; | 206 int num_completed_downloads_; |
| 207 const AttachmentId attachment_id_; | 207 const AttachmentId attachment_id_; |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 void AttachmentDownloaderImplTest::SetUp() { | 210 void AttachmentDownloaderImplTest::SetUp() { |
| 211 url_request_context_getter_ = | 211 url_request_context_getter_ = |
| 212 new net::TestURLRequestContextGetter(message_loop_.task_runner()); | 212 new net::TestURLRequestContextGetter(message_loop_.task_runner()); |
| 213 url_fetcher_factory_.set_remove_fetcher_on_delete(true); | 213 url_fetcher_factory_.set_remove_fetcher_on_delete(true); |
| 214 token_service_.reset(new MockOAuth2TokenService()); | 214 token_service_.reset(new MockOAuth2TokenService()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 delegate->OnURLFetchComplete(fetcher); | 246 delegate->OnURLFetchComplete(fetcher); |
| 247 RunMessageLoop(); | 247 RunMessageLoop(); |
| 248 // Once result is processed URLFetcher should be deleted. | 248 // Once result is processed URLFetcher should be deleted. |
| 249 fetcher = url_fetcher_factory_.GetFetcherByID(0); | 249 fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 250 EXPECT_TRUE(fetcher == NULL); | 250 EXPECT_TRUE(fetcher == NULL); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void AttachmentDownloaderImplTest::DownloadDone( | 253 void AttachmentDownloaderImplTest::DownloadDone( |
| 254 const AttachmentId& attachment_id, | 254 const AttachmentId& attachment_id, |
| 255 const AttachmentDownloader::DownloadResult& result, | 255 const AttachmentDownloader::DownloadResult& result, |
| 256 scoped_ptr<Attachment> attachment) { | 256 std::unique_ptr<Attachment> attachment) { |
| 257 download_results_.insert(std::make_pair(attachment_id, result)); | 257 download_results_.insert(std::make_pair(attachment_id, result)); |
| 258 if (result == AttachmentDownloader::DOWNLOAD_SUCCESS) { | 258 if (result == AttachmentDownloader::DOWNLOAD_SUCCESS) { |
| 259 // Successful download should be accompanied by valid attachment with | 259 // Successful download should be accompanied by valid attachment with |
| 260 // matching id and valid data. | 260 // matching id and valid data. |
| 261 EXPECT_TRUE(attachment != NULL); | 261 EXPECT_TRUE(attachment != NULL); |
| 262 EXPECT_EQ(attachment_id, attachment->GetId()); | 262 EXPECT_EQ(attachment_id, attachment->GetId()); |
| 263 | 263 |
| 264 scoped_refptr<base::RefCountedMemory> data = attachment->GetData(); | 264 scoped_refptr<base::RefCountedMemory> data = attachment->GetData(); |
| 265 std::string data_as_string(data->front_as<char>(), data->size()); | 265 std::string data_as_string(data->front_as<char>(), data->size()); |
| 266 EXPECT_EQ(data_as_string, kAttachmentContent); | 266 EXPECT_EQ(data_as_string, kAttachmentContent); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 raw += "\n"; | 532 raw += "\n"; |
| 533 std::replace(raw.begin(), raw.end(), '\n', '\0'); | 533 std::replace(raw.begin(), raw.end(), '\n', '\0'); |
| 534 scoped_refptr<net::HttpResponseHeaders> headers( | 534 scoped_refptr<net::HttpResponseHeaders> headers( |
| 535 new net::HttpResponseHeaders(raw)); | 535 new net::HttpResponseHeaders(raw)); |
| 536 uint32_t extracted; | 536 uint32_t extracted; |
| 537 ASSERT_FALSE( | 537 ASSERT_FALSE( |
| 538 AttachmentDownloaderImpl::ExtractCrc32c(headers.get(), &extracted)); | 538 AttachmentDownloaderImpl::ExtractCrc32c(headers.get(), &extracted)); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace syncer | 541 } // namespace syncer |
| OLD | NEW |