| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 class MockProtocolHandler : | 108 class MockProtocolHandler : |
| 109 public net::URLRequestJobFactory::ProtocolHandler { | 109 public net::URLRequestJobFactory::ProtocolHandler { |
| 110 public: | 110 public: |
| 111 MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} | 111 MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} |
| 112 | 112 |
| 113 // net::URLRequestJobFactory::ProtocolHandler override. | 113 // net::URLRequestJobFactory::ProtocolHandler override. |
| 114 net::URLRequestJob* MaybeCreateJob( | 114 net::URLRequestJob* MaybeCreateJob( |
| 115 net::URLRequest* request, | 115 net::URLRequest* request, |
| 116 net::NetworkDelegate* network_delegate) const override { | 116 net::NetworkDelegate* network_delegate) const override { |
| 117 return new BlobURLRequestJob(request, network_delegate, | 117 return new BlobURLRequestJob(request, network_delegate, |
| 118 test_->GetSnapshotFromBuilder(), | 118 test_->GetHandleFromBuilder(), |
| 119 test_->file_system_context_.get(), | 119 test_->file_system_context_.get(), |
| 120 base::ThreadTaskRunnerHandle::Get().get()); | 120 base::ThreadTaskRunnerHandle::Get().get()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 BlobURLRequestJobTest* test_; | 124 BlobURLRequestJobTest* test_; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 BlobURLRequestJobTest() | 127 BlobURLRequestJobTest() |
| 128 : blob_data_(new BlobDataBuilder("uuid")), expected_status_code_(0) {} | 128 : blob_data_(new BlobDataBuilder("uuid")), expected_status_code_(0) {} |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 *expected_result += std::string(kTestData2 + 4, 5); | 275 *expected_result += std::string(kTestData2 + 4, 5); |
| 276 | 276 |
| 277 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_); | 277 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_); |
| 278 *expected_result += std::string(kTestFileData2 + 5, 6); | 278 *expected_result += std::string(kTestFileData2 + 5, 6); |
| 279 | 279 |
| 280 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7, | 280 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7, |
| 281 temp_file_system_file_modification_time2_); | 281 temp_file_system_file_modification_time2_); |
| 282 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); | 282 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); |
| 283 } | 283 } |
| 284 | 284 |
| 285 scoped_ptr<BlobDataSnapshot> GetSnapshotFromBuilder() { | 285 storage::BlobDataHandle* GetHandleFromBuilder() { |
| 286 if (!blob_handle_) { | 286 if (!blob_handle_) { |
| 287 blob_handle_ = blob_context_.AddFinishedBlob(blob_data_.get()).Pass(); | 287 blob_handle_ = blob_context_.AddFinishedBlob(blob_data_.get()).Pass(); |
| 288 } | 288 } |
| 289 return blob_handle_->CreateSnapshot().Pass(); | 289 return blob_handle_.get(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // This only works if all the Blob items have a definite pre-computed length. | 292 // This only works if all the Blob items have a definite pre-computed length. |
| 293 // Otherwise, this will fail a CHECK. | 293 // Otherwise, this will fail a CHECK. |
| 294 int64 GetTotalBlobLength() { | 294 int64 GetTotalBlobLength() { |
| 295 int64 total = 0; | 295 int64 total = 0; |
| 296 scoped_ptr<BlobDataSnapshot> data = GetSnapshotFromBuilder(); | 296 scoped_ptr<BlobDataSnapshot> data = |
| 297 GetHandleFromBuilder()->CreateSnapshot(); |
| 297 const auto& items = data->items(); | 298 const auto& items = data->items(); |
| 298 for (const auto& item : items) { | 299 for (const auto& item : items) { |
| 299 int64 length = base::checked_cast<int64>(item->length()); | 300 int64 length = base::checked_cast<int64>(item->length()); |
| 300 CHECK(length <= kint64max - total); | 301 CHECK(length <= kint64max - total); |
| 301 total += length; | 302 total += length; |
| 302 } | 303 } |
| 303 return total; | 304 return total; |
| 304 } | 305 } |
| 305 | 306 |
| 306 protected: | 307 protected: |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); | 504 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); |
| 504 EXPECT_EQ(kTestContentType, content_type); | 505 EXPECT_EQ(kTestContentType, content_type); |
| 505 void* iter = NULL; | 506 void* iter = NULL; |
| 506 std::string content_disposition; | 507 std::string content_disposition; |
| 507 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( | 508 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( |
| 508 &iter, "Content-Disposition", &content_disposition)); | 509 &iter, "Content-Disposition", &content_disposition)); |
| 509 EXPECT_EQ(kTestContentDisposition, content_disposition); | 510 EXPECT_EQ(kTestContentDisposition, content_disposition); |
| 510 } | 511 } |
| 511 | 512 |
| 512 } // namespace content | 513 } // namespace content |
| OLD | NEW |