| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "storage/browser/blob/blob_data_builder.h" | 30 #include "storage/browser/blob/blob_data_builder.h" |
| 31 #include "storage/browser/blob/blob_data_handle.h" | 31 #include "storage/browser/blob/blob_data_handle.h" |
| 32 #include "storage/browser/blob/blob_data_snapshot.h" | 32 #include "storage/browser/blob/blob_data_snapshot.h" |
| 33 #include "storage/browser/blob/blob_storage_context.h" | 33 #include "storage/browser/blob/blob_storage_context.h" |
| 34 #include "storage/browser/blob/blob_url_request_job.h" | 34 #include "storage/browser/blob/blob_url_request_job.h" |
| 35 #include "storage/browser/fileapi/file_system_context.h" | 35 #include "storage/browser/fileapi/file_system_context.h" |
| 36 #include "storage/browser/fileapi/file_system_operation_context.h" | 36 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 37 #include "storage/browser/fileapi/file_system_url.h" | 37 #include "storage/browser/fileapi/file_system_url.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 39 |
| 40 using storage::BlobDataBuilder; |
| 41 using storage::BlobDataHandle; |
| 40 using storage::BlobDataSnapshot; | 42 using storage::BlobDataSnapshot; |
| 41 using storage::BlobDataBuilder; | |
| 42 using storage::BlobURLRequestJob; | 43 using storage::BlobURLRequestJob; |
| 43 | 44 |
| 44 namespace content { | 45 namespace content { |
| 45 | 46 |
| 46 namespace { | 47 namespace { |
| 47 | 48 |
| 48 const int kBufferSize = 1024; | 49 const int kBufferSize = 1024; |
| 49 const char kTestData1[] = "Hello"; | 50 const char kTestData1[] = "Hello"; |
| 50 const char kTestData2[] = "Here it is data."; | 51 const char kTestData2[] = "Here it is data."; |
| 51 const char kTestFileData1[] = "0123456789"; | 52 const char kTestFileData1[] = "0123456789"; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 102 } |
| 102 | 103 |
| 103 } // namespace | 104 } // namespace |
| 104 | 105 |
| 105 class BlobURLRequestJobTest : public testing::Test { | 106 class BlobURLRequestJobTest : public testing::Test { |
| 106 public: | 107 public: |
| 107 // A simple ProtocolHandler implementation to create BlobURLRequestJob. | 108 // A simple ProtocolHandler implementation to create BlobURLRequestJob. |
| 108 class MockProtocolHandler : | 109 class MockProtocolHandler : |
| 109 public net::URLRequestJobFactory::ProtocolHandler { | 110 public net::URLRequestJobFactory::ProtocolHandler { |
| 110 public: | 111 public: |
| 111 MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} | 112 explicit MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} |
| 112 | 113 |
| 113 // net::URLRequestJobFactory::ProtocolHandler override. | 114 // net::URLRequestJobFactory::ProtocolHandler override. |
| 114 net::URLRequestJob* MaybeCreateJob( | 115 net::URLRequestJob* MaybeCreateJob( |
| 115 net::URLRequest* request, | 116 net::URLRequest* request, |
| 116 net::NetworkDelegate* network_delegate) const override { | 117 net::NetworkDelegate* network_delegate) const override { |
| 117 return new BlobURLRequestJob(request, network_delegate, | 118 return new BlobURLRequestJob(request, network_delegate, |
| 118 test_->GetHandleFromBuilder(), | 119 test_->GetHandleFromBuilder(), |
| 119 test_->file_system_context_.get(), | 120 test_->file_system_context_.get(), |
| 120 base::ThreadTaskRunnerHandle::Get().get()); | 121 base::ThreadTaskRunnerHandle::Get().get()); |
| 121 } | 122 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 *expected_result += std::string(kTestData2 + 4, 5); | 277 *expected_result += std::string(kTestData2 + 4, 5); |
| 277 | 278 |
| 278 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_); | 279 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_); |
| 279 *expected_result += std::string(kTestFileData2 + 5, 6); | 280 *expected_result += std::string(kTestFileData2 + 5, 6); |
| 280 | 281 |
| 281 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7, | 282 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7, |
| 282 temp_file_system_file_modification_time2_); | 283 temp_file_system_file_modification_time2_); |
| 283 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); | 284 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); |
| 284 } | 285 } |
| 285 | 286 |
| 286 storage::BlobDataHandle* GetHandleFromBuilder() { | 287 BlobDataHandle* GetHandleFromBuilder() { |
| 287 if (!blob_handle_) { | 288 if (!blob_handle_) { |
| 288 blob_handle_ = blob_context_.AddFinishedBlob(blob_data_.get()).Pass(); | 289 blob_handle_ = blob_context_.AddFinishedBlob(blob_data_.get()).Pass(); |
| 289 } | 290 } |
| 290 return blob_handle_.get(); | 291 return blob_handle_.get(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 // This only works if all the Blob items have a definite pre-computed length. | 294 // This only works if all the Blob items have a definite pre-computed length. |
| 294 // Otherwise, this will fail a CHECK. | 295 // Otherwise, this will fail a CHECK. |
| 295 int64 GetTotalBlobLength() { | 296 int64 GetTotalBlobLength() { |
| 296 int64 total = 0; | 297 int64 total = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 317 base::Time temp_file_system_file_modification_time1_; | 318 base::Time temp_file_system_file_modification_time1_; |
| 318 base::Time temp_file_system_file_modification_time2_; | 319 base::Time temp_file_system_file_modification_time2_; |
| 319 | 320 |
| 320 scoped_ptr<disk_cache::Backend> disk_cache_backend_; | 321 scoped_ptr<disk_cache::Backend> disk_cache_backend_; |
| 321 disk_cache::ScopedEntryPtr disk_cache_entry_; | 322 disk_cache::ScopedEntryPtr disk_cache_entry_; |
| 322 | 323 |
| 323 base::MessageLoopForIO message_loop_; | 324 base::MessageLoopForIO message_loop_; |
| 324 scoped_refptr<storage::FileSystemContext> file_system_context_; | 325 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 325 | 326 |
| 326 storage::BlobStorageContext blob_context_; | 327 storage::BlobStorageContext blob_context_; |
| 327 scoped_ptr<storage::BlobDataHandle> blob_handle_; | 328 scoped_ptr<BlobDataHandle> blob_handle_; |
| 328 scoped_ptr<BlobDataBuilder> blob_data_; | 329 scoped_ptr<BlobDataBuilder> blob_data_; |
| 329 scoped_ptr<BlobDataSnapshot> blob_data_snapshot_; | 330 scoped_ptr<BlobDataSnapshot> blob_data_snapshot_; |
| 330 net::URLRequestJobFactoryImpl url_request_job_factory_; | 331 net::URLRequestJobFactoryImpl url_request_job_factory_; |
| 331 net::URLRequestContext url_request_context_; | 332 net::URLRequestContext url_request_context_; |
| 332 MockURLRequestDelegate url_request_delegate_; | 333 MockURLRequestDelegate url_request_delegate_; |
| 333 scoped_ptr<net::URLRequest> request_; | 334 scoped_ptr<net::URLRequest> request_; |
| 334 | 335 |
| 335 int expected_status_code_; | 336 int expected_status_code_; |
| 336 std::string expected_response_; | 337 std::string expected_response_; |
| 337 }; | 338 }; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); | 527 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); |
| 527 EXPECT_EQ(kTestContentType, content_type); | 528 EXPECT_EQ(kTestContentType, content_type); |
| 528 void* iter = NULL; | 529 void* iter = NULL; |
| 529 std::string content_disposition; | 530 std::string content_disposition; |
| 530 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( | 531 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( |
| 531 &iter, "Content-Disposition", &content_disposition)); | 532 &iter, "Content-Disposition", &content_disposition)); |
| 532 EXPECT_EQ(kTestContentDisposition, content_disposition); | 533 EXPECT_EQ(kTestContentDisposition, content_disposition); |
| 533 } | 534 } |
| 534 | 535 |
| 535 } // namespace content | 536 } // namespace content |
| OLD | NEW |