| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 18 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 19 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "content/browser/blob_storage/blob_url_loader_factory.h" |
| 24 #include "content/browser/loader/test_url_loader_client.h" |
| 25 #include "content/browser/url_loader_factory_getter.h" |
| 26 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 28 #include "mojo/common/data_pipe_utils.h" |
| 22 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 23 #include "net/base/request_priority.h" | 30 #include "net/base/request_priority.h" |
| 24 #include "net/base/test_completion_callback.h" | 31 #include "net/base/test_completion_callback.h" |
| 25 #include "net/disk_cache/disk_cache.h" | 32 #include "net/disk_cache/disk_cache.h" |
| 26 #include "net/http/http_byte_range.h" | 33 #include "net/http/http_byte_range.h" |
| 27 #include "net/http/http_request_headers.h" | 34 #include "net/http/http_request_headers.h" |
| 28 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
| 29 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 36 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 30 #include "net/url_request/url_request.h" | 37 #include "net/url_request/url_request.h" |
| 31 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 test_->GetHandleFromBuilder(), | 148 test_->GetHandleFromBuilder(), |
| 142 test_->file_system_context_.get(), | 149 test_->file_system_context_.get(), |
| 143 base::ThreadTaskRunnerHandle::Get().get()); | 150 base::ThreadTaskRunnerHandle::Get().get()); |
| 144 } | 151 } |
| 145 | 152 |
| 146 private: | 153 private: |
| 147 BlobURLRequestJobTest* test_; | 154 BlobURLRequestJobTest* test_; |
| 148 }; | 155 }; |
| 149 | 156 |
| 150 BlobURLRequestJobTest() | 157 BlobURLRequestJobTest() |
| 151 : blob_data_(new BlobDataBuilder("uuid")), expected_status_code_(0) {} | 158 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 159 blob_data_(new BlobDataBuilder("uuid")), |
| 160 response_error_code_(net::OK), |
| 161 expected_status_code_(0) {} |
| 152 | 162 |
| 153 void SetUp() override { | 163 void SetUp() override { |
| 154 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 164 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 155 | 165 |
| 156 temp_file1_ = temp_dir_.GetPath().AppendASCII("BlobFile1.dat"); | 166 temp_file1_ = temp_dir_.GetPath().AppendASCII("BlobFile1.dat"); |
| 157 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), | 167 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), |
| 158 base::WriteFile(temp_file1_, kTestFileData1, | 168 base::WriteFile(temp_file1_, kTestFileData1, |
| 159 arraysize(kTestFileData1) - 1)); | 169 arraysize(kTestFileData1) - 1)); |
| 160 base::File::Info file_info1; | 170 base::File::Info file_info1; |
| 161 base::GetFileInfo(temp_file1_, &file_info1); | 171 base::GetFileInfo(temp_file1_, &file_info1); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 173 disk_cache_entry_ = CreateDiskCacheEntry( | 183 disk_cache_entry_ = CreateDiskCacheEntry( |
| 174 disk_cache_backend_.get(), kTestDiskCacheKey1, kTestDiskCacheData1); | 184 disk_cache_backend_.get(), kTestDiskCacheKey1, kTestDiskCacheData1); |
| 175 | 185 |
| 176 url_request_job_factory_.SetProtocolHandler( | 186 url_request_job_factory_.SetProtocolHandler( |
| 177 "blob", base::MakeUnique<MockProtocolHandler>(this)); | 187 "blob", base::MakeUnique<MockProtocolHandler>(this)); |
| 178 url_request_context_.set_job_factory(&url_request_job_factory_); | 188 url_request_context_.set_job_factory(&url_request_job_factory_); |
| 179 } | 189 } |
| 180 | 190 |
| 181 void TearDown() override { | 191 void TearDown() override { |
| 182 blob_handle_.reset(); | 192 blob_handle_.reset(); |
| 183 request_.reset(); | |
| 184 // Clean up for ASAN | 193 // Clean up for ASAN |
| 185 base::RunLoop run_loop; | 194 base::RunLoop run_loop; |
| 186 run_loop.RunUntilIdle(); | 195 run_loop.RunUntilIdle(); |
| 187 } | 196 } |
| 188 | 197 |
| 189 void SetUpFileSystem() { | 198 void SetUpFileSystem() { |
| 190 // Prepare file system. | 199 // Prepare file system. |
| 191 file_system_context_ = | 200 file_system_context_ = |
| 192 CreateFileSystemContextForTesting(NULL, temp_dir_.GetPath()); | 201 CreateFileSystemContextForTesting(NULL, temp_dir_.GetPath()); |
| 193 | 202 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ASSERT_EQ(base::File::FILE_OK, result); | 252 ASSERT_EQ(base::File::FILE_OK, result); |
| 244 ASSERT_TRUE(root.is_valid()); | 253 ASSERT_TRUE(root.is_valid()); |
| 245 file_system_root_url_ = root; | 254 file_system_root_url_ = root; |
| 246 } | 255 } |
| 247 | 256 |
| 248 void TestSuccessNonrangeRequest(const std::string& expected_response, | 257 void TestSuccessNonrangeRequest(const std::string& expected_response, |
| 249 int64_t expected_content_length) { | 258 int64_t expected_content_length) { |
| 250 expected_status_code_ = 200; | 259 expected_status_code_ = 200; |
| 251 expected_response_ = expected_response; | 260 expected_response_ = expected_response; |
| 252 TestRequest("GET", net::HttpRequestHeaders()); | 261 TestRequest("GET", net::HttpRequestHeaders()); |
| 253 EXPECT_EQ(expected_content_length, | 262 EXPECT_EQ(expected_content_length, response_headers_->GetContentLength()); |
| 254 request_->response_headers()->GetContentLength()); | |
| 255 } | 263 } |
| 256 | 264 |
| 257 void TestErrorRequest(int expected_status_code) { | 265 void TestErrorRequest(int expected_status_code) { |
| 258 expected_status_code_ = expected_status_code; | 266 expected_status_code_ = expected_status_code; |
| 259 expected_response_ = ""; | 267 expected_response_ = ""; |
| 260 TestRequest("GET", net::HttpRequestHeaders()); | 268 TestRequest("GET", net::HttpRequestHeaders()); |
| 261 EXPECT_FALSE(request_->response_info().metadata); | 269 EXPECT_TRUE(response_metadata_.empty()); |
| 262 } | 270 } |
| 263 | 271 |
| 264 void TestRequest(const std::string& method, | 272 void TestRequest(const std::string& method, |
| 265 const net::HttpRequestHeaders& extra_headers) { | 273 const net::HttpRequestHeaders& extra_headers) { |
| 266 request_ = url_request_context_.CreateRequest( | 274 GURL url("blob:blah"); |
| 267 GURL("blob:blah"), net::DEFAULT_PRIORITY, &url_request_delegate_, | |
| 268 TRAFFIC_ANNOTATION_FOR_TESTS); | |
| 269 request_->set_method(method); | |
| 270 if (!extra_headers.IsEmpty()) | |
| 271 request_->SetExtraRequestHeaders(extra_headers); | |
| 272 request_->Start(); | |
| 273 | 275 |
| 274 base::RunLoop().Run(); | 276 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 277 switches::kEnableNetworkService)) { |
| 278 GetHandleFromBuilder(); // To add to StorageContext. |
| 279 const_cast<storage::BlobStorageRegistry&>(blob_context_.registry()) |
| 280 .CreateUrlMapping(url, blob_data_->uuid()); |
| 281 ResourceRequest request; |
| 282 request.url = url; |
| 283 request.method = method; |
| 284 if (!extra_headers.IsEmpty()) |
| 285 request.headers = extra_headers.ToString(); |
| 286 |
| 287 mojom::URLLoaderAssociatedPtr url_loader; |
| 288 TestURLLoaderClient url_loader_client; |
| 289 scoped_refptr<BlobURLLoaderFactory> factory = new BlobURLLoaderFactory( |
| 290 base::Bind(&BlobURLRequestJobTest::GetStorageContext, |
| 291 base::Unretained(this)), |
| 292 file_system_context_); |
| 293 base::RunLoop().RunUntilIdle(); |
| 294 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader), 0, 0, |
| 295 mojom::kURLLoadOptionNone, request, |
| 296 url_loader_client.CreateInterfacePtr()); |
| 297 url_loader_client.RunUntilComplete(); |
| 298 |
| 299 if (url_loader_client.response_body().is_valid()) { |
| 300 EXPECT_TRUE(mojo::common::BlockingCopyToString( |
| 301 url_loader_client.response_body_release(), &response_)); |
| 302 } |
| 303 response_headers_ = url_loader_client.response_head().headers; |
| 304 response_metadata_ = url_loader_client.cached_metadata(); |
| 305 response_error_code_ = url_loader_client.completion_status().error_code; |
| 306 } else { |
| 307 std::unique_ptr<net::URLRequest> request = |
| 308 url_request_context_.CreateRequest(url, net::DEFAULT_PRIORITY, |
| 309 &url_request_delegate_, |
| 310 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 311 request->set_method(method); |
| 312 if (!extra_headers.IsEmpty()) |
| 313 request->SetExtraRequestHeaders(extra_headers); |
| 314 request->Start(); |
| 315 |
| 316 base::RunLoop().Run(); |
| 317 response_ = url_request_delegate_.data_received(); |
| 318 response_headers_ = request->response_headers(); |
| 319 if (request->response_info().metadata) { |
| 320 response_metadata_ = |
| 321 std::string(request->response_info().metadata->data(), |
| 322 request->response_info().metadata->size()); |
| 323 } |
| 324 |
| 325 response_error_code_ = url_request_delegate_.request_status(); |
| 326 } |
| 275 | 327 |
| 276 // Verify response. | 328 // Verify response. |
| 277 EXPECT_EQ(net::OK, url_request_delegate_.request_status()); | 329 EXPECT_EQ(net::OK, response_error_code_); |
| 278 EXPECT_EQ(expected_status_code_, | 330 EXPECT_EQ(expected_status_code_, response_headers_->response_code()); |
| 279 request_->response_headers()->response_code()); | 331 EXPECT_EQ(expected_response_, response_); |
| 280 EXPECT_EQ(expected_response_, url_request_delegate_.data_received()); | |
| 281 } | 332 } |
| 282 | 333 |
| 283 void BuildComplicatedData(std::string* expected_result) { | 334 void BuildComplicatedData(std::string* expected_result) { |
| 284 blob_data_->AppendData(kTestData1 + 1, 2); | 335 blob_data_->AppendData(kTestData1 + 1, 2); |
| 285 *expected_result = std::string(kTestData1 + 1, 2); | 336 *expected_result = std::string(kTestData1 + 1, 2); |
| 286 | 337 |
| 287 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); | 338 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); |
| 288 *expected_result += std::string(kTestFileData1 + 2, 3); | 339 *expected_result += std::string(kTestFileData1 + 2, 3); |
| 289 | 340 |
| 290 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(), | 341 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 const auto& items = data->items(); | 374 const auto& items = data->items(); |
| 324 for (const auto& item : items) { | 375 for (const auto& item : items) { |
| 325 int64_t length = base::checked_cast<int64_t>(item->length()); | 376 int64_t length = base::checked_cast<int64_t>(item->length()); |
| 326 CHECK(length <= std::numeric_limits<int64_t>::max() - total); | 377 CHECK(length <= std::numeric_limits<int64_t>::max() - total); |
| 327 total += length; | 378 total += length; |
| 328 } | 379 } |
| 329 return total; | 380 return total; |
| 330 } | 381 } |
| 331 | 382 |
| 332 protected: | 383 protected: |
| 384 base::WeakPtr<storage::BlobStorageContext> GetStorageContext() { |
| 385 return blob_context_.AsWeakPtr(); |
| 386 } |
| 387 |
| 333 base::ScopedTempDir temp_dir_; | 388 base::ScopedTempDir temp_dir_; |
| 334 base::FilePath temp_file1_; | 389 base::FilePath temp_file1_; |
| 335 base::FilePath temp_file2_; | 390 base::FilePath temp_file2_; |
| 336 base::Time temp_file_modification_time1_; | 391 base::Time temp_file_modification_time1_; |
| 337 base::Time temp_file_modification_time2_; | 392 base::Time temp_file_modification_time2_; |
| 338 GURL file_system_root_url_; | 393 GURL file_system_root_url_; |
| 339 GURL temp_file_system_file1_; | 394 GURL temp_file_system_file1_; |
| 340 GURL temp_file_system_file2_; | 395 GURL temp_file_system_file2_; |
| 341 base::Time temp_file_system_file_modification_time1_; | 396 base::Time temp_file_system_file_modification_time1_; |
| 342 base::Time temp_file_system_file_modification_time2_; | 397 base::Time temp_file_system_file_modification_time2_; |
| 343 | 398 |
| 344 std::unique_ptr<disk_cache::Backend> disk_cache_backend_; | 399 std::unique_ptr<disk_cache::Backend> disk_cache_backend_; |
| 345 disk_cache::ScopedEntryPtr disk_cache_entry_; | 400 disk_cache::ScopedEntryPtr disk_cache_entry_; |
| 346 | 401 |
| 347 base::MessageLoopForIO message_loop_; | 402 TestBrowserThreadBundle thread_bundle_; |
| 348 scoped_refptr<storage::FileSystemContext> file_system_context_; | 403 scoped_refptr<storage::FileSystemContext> file_system_context_; |
| 349 | 404 |
| 350 storage::BlobStorageContext blob_context_; | 405 storage::BlobStorageContext blob_context_; |
| 351 std::unique_ptr<storage::BlobDataHandle> blob_handle_; | 406 std::unique_ptr<storage::BlobDataHandle> blob_handle_; |
| 352 std::unique_ptr<BlobDataBuilder> blob_data_; | 407 std::unique_ptr<BlobDataBuilder> blob_data_; |
| 353 std::unique_ptr<BlobDataSnapshot> blob_data_snapshot_; | 408 std::unique_ptr<BlobDataSnapshot> blob_data_snapshot_; |
| 354 net::URLRequestJobFactoryImpl url_request_job_factory_; | 409 net::URLRequestJobFactoryImpl url_request_job_factory_; |
| 355 net::URLRequestContext url_request_context_; | 410 net::URLRequestContext url_request_context_; |
| 356 net::TestDelegate url_request_delegate_; | 411 net::TestDelegate url_request_delegate_; |
| 357 std::unique_ptr<net::URLRequest> request_; | 412 std::string response_; |
| 413 int response_error_code_; |
| 414 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 415 std::string response_metadata_; |
| 358 | 416 |
| 359 int expected_status_code_; | 417 int expected_status_code_; |
| 360 std::string expected_response_; | 418 std::string expected_response_; |
| 361 }; | 419 }; |
| 362 | 420 |
| 363 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { | 421 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { |
| 364 blob_data_->AppendData(kTestData1); | 422 blob_data_->AppendData(kTestData1); |
| 365 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1); | 423 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1); |
| 366 } | 424 } |
| 367 | 425 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 SetUpFileSystem(); | 541 SetUpFileSystem(); |
| 484 std::string result; | 542 std::string result; |
| 485 BuildComplicatedData(&result); | 543 BuildComplicatedData(&result); |
| 486 net::HttpRequestHeaders extra_headers; | 544 net::HttpRequestHeaders extra_headers; |
| 487 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 545 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 488 net::HttpByteRange::Bounded(5, 10).GetHeaderValue()); | 546 net::HttpByteRange::Bounded(5, 10).GetHeaderValue()); |
| 489 expected_status_code_ = 206; | 547 expected_status_code_ = 206; |
| 490 expected_response_ = result.substr(5, 10 - 5 + 1); | 548 expected_response_ = result.substr(5, 10 - 5 + 1); |
| 491 TestRequest("GET", extra_headers); | 549 TestRequest("GET", extra_headers); |
| 492 | 550 |
| 493 EXPECT_EQ(6, request_->response_headers()->GetContentLength()); | 551 EXPECT_EQ(6, response_headers_->GetContentLength()); |
| 494 EXPECT_FALSE(request_->response_info().metadata); | 552 EXPECT_TRUE(response_metadata_.empty()); |
| 495 | 553 |
| 496 int64_t first = 0, last = 0, length = 0; | 554 int64_t first = 0, last = 0, length = 0; |
| 497 EXPECT_TRUE(request_->response_headers()->GetContentRangeFor206(&first, &last, | 555 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
| 498 &length)); | |
| 499 EXPECT_EQ(5, first); | 556 EXPECT_EQ(5, first); |
| 500 EXPECT_EQ(10, last); | 557 EXPECT_EQ(10, last); |
| 501 EXPECT_EQ(GetTotalBlobLength(), length); | 558 EXPECT_EQ(GetTotalBlobLength(), length); |
| 502 } | 559 } |
| 503 | 560 |
| 504 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest2) { | 561 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest2) { |
| 505 SetUpFileSystem(); | 562 SetUpFileSystem(); |
| 506 std::string result; | 563 std::string result; |
| 507 BuildComplicatedData(&result); | 564 BuildComplicatedData(&result); |
| 508 net::HttpRequestHeaders extra_headers; | 565 net::HttpRequestHeaders extra_headers; |
| 509 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 566 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 510 net::HttpByteRange::Suffix(10).GetHeaderValue()); | 567 net::HttpByteRange::Suffix(10).GetHeaderValue()); |
| 511 expected_status_code_ = 206; | 568 expected_status_code_ = 206; |
| 512 expected_response_ = result.substr(result.length() - 10); | 569 expected_response_ = result.substr(result.length() - 10); |
| 513 TestRequest("GET", extra_headers); | 570 TestRequest("GET", extra_headers); |
| 514 | 571 |
| 515 EXPECT_EQ(10, request_->response_headers()->GetContentLength()); | 572 EXPECT_EQ(10, response_headers_->GetContentLength()); |
| 516 EXPECT_FALSE(request_->response_info().metadata); | 573 EXPECT_TRUE(response_metadata_.empty()); |
| 517 | 574 |
| 518 int64_t total = GetTotalBlobLength(); | 575 int64_t total = GetTotalBlobLength(); |
| 519 int64_t first = 0, last = 0, length = 0; | 576 int64_t first = 0, last = 0, length = 0; |
| 520 EXPECT_TRUE(request_->response_headers()->GetContentRangeFor206(&first, &last, | 577 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
| 521 &length)); | |
| 522 EXPECT_EQ(total - 10, first); | 578 EXPECT_EQ(total - 10, first); |
| 523 EXPECT_EQ(total - 1, last); | 579 EXPECT_EQ(total - 1, last); |
| 524 EXPECT_EQ(total, length); | 580 EXPECT_EQ(total, length); |
| 525 } | 581 } |
| 526 | 582 |
| 527 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest3) { | 583 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest3) { |
| 528 SetUpFileSystem(); | 584 SetUpFileSystem(); |
| 529 std::string result; | 585 std::string result; |
| 530 BuildComplicatedData(&result); | 586 BuildComplicatedData(&result); |
| 531 net::HttpRequestHeaders extra_headers; | 587 net::HttpRequestHeaders extra_headers; |
| 532 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 588 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 533 net::HttpByteRange::Bounded(0, 2).GetHeaderValue()); | 589 net::HttpByteRange::Bounded(0, 2).GetHeaderValue()); |
| 534 expected_status_code_ = 206; | 590 expected_status_code_ = 206; |
| 535 expected_response_ = result.substr(0, 3); | 591 expected_response_ = result.substr(0, 3); |
| 536 TestRequest("GET", extra_headers); | 592 TestRequest("GET", extra_headers); |
| 537 | 593 |
| 538 EXPECT_EQ(3, request_->response_headers()->GetContentLength()); | 594 EXPECT_EQ(3, response_headers_->GetContentLength()); |
| 539 EXPECT_FALSE(request_->response_info().metadata); | 595 EXPECT_TRUE(response_metadata_.empty()); |
| 540 | 596 |
| 541 int64_t first = 0, last = 0, length = 0; | 597 int64_t first = 0, last = 0, length = 0; |
| 542 EXPECT_TRUE(request_->response_headers()->GetContentRangeFor206(&first, &last, | 598 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
| 543 &length)); | |
| 544 EXPECT_EQ(0, first); | 599 EXPECT_EQ(0, first); |
| 545 EXPECT_EQ(2, last); | 600 EXPECT_EQ(2, last); |
| 546 EXPECT_EQ(GetTotalBlobLength(), length); | 601 EXPECT_EQ(GetTotalBlobLength(), length); |
| 547 } | 602 } |
| 548 | 603 |
| 549 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { | 604 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { |
| 550 blob_data_->set_content_type(kTestContentType); | 605 blob_data_->set_content_type(kTestContentType); |
| 551 blob_data_->set_content_disposition(kTestContentDisposition); | 606 blob_data_->set_content_disposition(kTestContentDisposition); |
| 552 blob_data_->AppendData(kTestData1); | 607 blob_data_->AppendData(kTestData1); |
| 553 expected_status_code_ = 200; | 608 expected_status_code_ = 200; |
| 554 expected_response_ = kTestData1; | 609 expected_response_ = kTestData1; |
| 555 TestRequest("GET", net::HttpRequestHeaders()); | 610 TestRequest("GET", net::HttpRequestHeaders()); |
| 556 | 611 |
| 557 std::string content_type; | 612 std::string content_type; |
| 558 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); | 613 EXPECT_TRUE(response_headers_->GetMimeType(&content_type)); |
| 559 EXPECT_EQ(kTestContentType, content_type); | 614 EXPECT_EQ(kTestContentType, content_type); |
| 560 EXPECT_FALSE(request_->response_info().metadata); | 615 EXPECT_TRUE(response_metadata_.empty()); |
| 561 size_t iter = 0; | 616 size_t iter = 0; |
| 562 std::string content_disposition; | 617 std::string content_disposition; |
| 563 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( | 618 EXPECT_TRUE(response_headers_->EnumerateHeader(&iter, "Content-Disposition", |
| 564 &iter, "Content-Disposition", &content_disposition)); | 619 &content_disposition)); |
| 565 EXPECT_EQ(kTestContentDisposition, content_disposition); | 620 EXPECT_EQ(kTestContentDisposition, content_disposition); |
| 566 } | 621 } |
| 567 | 622 |
| 568 TEST_F(BlobURLRequestJobTest, TestSideData) { | 623 TEST_F(BlobURLRequestJobTest, TestSideData) { |
| 569 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = | 624 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = |
| 570 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), | 625 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), |
| 571 kTestDiskCacheKey2, kTestDiskCacheData2, | 626 kTestDiskCacheKey2, kTestDiskCacheData2, |
| 572 kTestDiskCacheSideData); | 627 kTestDiskCacheSideData); |
| 573 blob_data_->AppendDiskCacheEntryWithSideData( | 628 blob_data_->AppendDiskCacheEntryWithSideData( |
| 574 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), | 629 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), |
| 575 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); | 630 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); |
| 576 expected_status_code_ = 200; | 631 expected_status_code_ = 200; |
| 577 expected_response_ = kTestDiskCacheData2; | 632 expected_response_ = kTestDiskCacheData2; |
| 578 TestRequest("GET", net::HttpRequestHeaders()); | 633 TestRequest("GET", net::HttpRequestHeaders()); |
| 579 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), | 634 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), |
| 580 request_->response_headers()->GetContentLength()); | 635 response_headers_->GetContentLength()); |
| 581 | 636 |
| 582 ASSERT_TRUE(request_->response_info().metadata); | 637 EXPECT_EQ(std::string(kTestDiskCacheSideData), response_metadata_); |
| 583 std::string metadata(request_->response_info().metadata->data(), | |
| 584 request_->response_info().metadata->size()); | |
| 585 EXPECT_EQ(std::string(kTestDiskCacheSideData), metadata); | |
| 586 } | 638 } |
| 587 | 639 |
| 588 TEST_F(BlobURLRequestJobTest, TestZeroSizeSideData) { | 640 TEST_F(BlobURLRequestJobTest, TestZeroSizeSideData) { |
| 589 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = | 641 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = |
| 590 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), | 642 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), |
| 591 kTestDiskCacheKey2, kTestDiskCacheData2, | 643 kTestDiskCacheKey2, kTestDiskCacheData2, |
| 592 ""); | 644 ""); |
| 593 blob_data_->AppendDiskCacheEntryWithSideData( | 645 blob_data_->AppendDiskCacheEntryWithSideData( |
| 594 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), | 646 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), |
| 595 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); | 647 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); |
| 596 expected_status_code_ = 200; | 648 expected_status_code_ = 200; |
| 597 expected_response_ = kTestDiskCacheData2; | 649 expected_response_ = kTestDiskCacheData2; |
| 598 TestRequest("GET", net::HttpRequestHeaders()); | 650 TestRequest("GET", net::HttpRequestHeaders()); |
| 599 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), | 651 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), |
| 600 request_->response_headers()->GetContentLength()); | 652 response_headers_->GetContentLength()); |
| 601 | 653 |
| 602 EXPECT_FALSE(request_->response_info().metadata); | 654 EXPECT_TRUE(response_metadata_.empty()); |
| 603 } | 655 } |
| 604 | 656 |
| 605 TEST_F(BlobURLRequestJobTest, BrokenBlob) { | 657 TEST_F(BlobURLRequestJobTest, BrokenBlob) { |
| 606 blob_handle_ = blob_context_.AddBrokenBlob( | 658 blob_handle_ = blob_context_.AddBrokenBlob( |
| 607 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); | 659 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 608 TestErrorRequest(500); | 660 TestErrorRequest(500); |
| 609 } | 661 } |
| 610 | 662 |
| 611 } // namespace content | 663 } // namespace content |
| OLD | NEW |