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 <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" | |
| 12 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 18 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 19 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
| 20 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 23 #include "content/browser/blob_storage/blob_url_loader_factory.h" | 22 #include "content/browser/blob_storage/blob_url_loader_factory.h" |
| 24 #include "content/browser/loader/test_url_loader_client.h" | 23 #include "content/browser/loader/test_url_loader_client.h" |
| 25 #include "content/browser/url_loader_factory_getter.h" | 24 #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" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 28 #include "mojo/common/data_pipe_utils.h" | 26 #include "mojo/common/data_pipe_utils.h" |
| 29 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 30 #include "net/base/request_priority.h" | 28 #include "net/base/request_priority.h" |
| 31 #include "net/base/test_completion_callback.h" | 29 #include "net/base/test_completion_callback.h" |
| 32 #include "net/disk_cache/disk_cache.h" | 30 #include "net/disk_cache/disk_cache.h" |
| 33 #include "net/http/http_byte_range.h" | 31 #include "net/http/http_byte_range.h" |
| 34 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
| 35 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 36 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 34 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 new net::StringIOBuffer(side_data); | 123 new net::StringIOBuffer(side_data); |
| 126 net::TestCompletionCallback callback; | 124 net::TestCompletionCallback callback; |
| 127 int rv = entry->WriteData(kTestDiskCacheSideStreamIndex, 0, iobuffer.get(), | 125 int rv = entry->WriteData(kTestDiskCacheSideStreamIndex, 0, iobuffer.get(), |
| 128 iobuffer->size(), callback.callback(), false); | 126 iobuffer->size(), callback.callback(), false); |
| 129 EXPECT_EQ(static_cast<int>(side_data.size()), callback.GetResult(rv)); | 127 EXPECT_EQ(static_cast<int>(side_data.size()), callback.GetResult(rv)); |
| 130 return entry; | 128 return entry; |
| 131 } | 129 } |
| 132 | 130 |
| 133 } // namespace | 131 } // namespace |
| 134 | 132 |
| 135 class BlobURLRequestJobTest : public testing::Test { | 133 class BlobURLRequestJobTest : public testing::TestWithParam<bool> { |
|
mmenke
2017/06/13 19:57:09
Should add a comment on what the param means. I'd
jam
2017/06/13 23:17:20
Added one here. I didn't want to add one where it'
| |
| 136 public: | 134 public: |
| 137 // A simple ProtocolHandler implementation to create BlobURLRequestJob. | 135 // A simple ProtocolHandler implementation to create BlobURLRequestJob. |
| 138 class MockProtocolHandler | 136 class MockProtocolHandler |
| 139 : public net::URLRequestJobFactory::ProtocolHandler { | 137 : public net::URLRequestJobFactory::ProtocolHandler { |
| 140 public: | 138 public: |
| 141 MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} | 139 MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} |
| 142 | 140 |
| 143 // net::URLRequestJobFactory::ProtocolHandler override. | 141 // net::URLRequestJobFactory::ProtocolHandler override. |
| 144 net::URLRequestJob* MaybeCreateJob( | 142 net::URLRequestJob* MaybeCreateJob( |
| 145 net::URLRequest* request, | 143 net::URLRequest* request, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 expected_status_code_ = expected_status_code; | 264 expected_status_code_ = expected_status_code; |
| 267 expected_response_ = ""; | 265 expected_response_ = ""; |
| 268 TestRequest("GET", net::HttpRequestHeaders()); | 266 TestRequest("GET", net::HttpRequestHeaders()); |
| 269 EXPECT_TRUE(response_metadata_.empty()); | 267 EXPECT_TRUE(response_metadata_.empty()); |
| 270 } | 268 } |
| 271 | 269 |
| 272 void TestRequest(const std::string& method, | 270 void TestRequest(const std::string& method, |
| 273 const net::HttpRequestHeaders& extra_headers) { | 271 const net::HttpRequestHeaders& extra_headers) { |
| 274 GURL url("blob:blah"); | 272 GURL url("blob:blah"); |
| 275 | 273 |
| 276 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 274 if (GetParam()) { |
| 277 switches::kEnableNetworkService)) { | |
| 278 GetHandleFromBuilder(); // To add to StorageContext. | 275 GetHandleFromBuilder(); // To add to StorageContext. |
| 279 const_cast<storage::BlobStorageRegistry&>(blob_context_.registry()) | 276 const_cast<storage::BlobStorageRegistry&>(blob_context_.registry()) |
| 280 .CreateUrlMapping(url, blob_data_->uuid()); | 277 .CreateUrlMapping(url, blob_data_->uuid()); |
| 281 ResourceRequest request; | 278 ResourceRequest request; |
| 282 request.url = url; | 279 request.url = url; |
| 283 request.method = method; | 280 request.method = method; |
| 284 if (!extra_headers.IsEmpty()) | 281 if (!extra_headers.IsEmpty()) |
| 285 request.headers = extra_headers.ToString(); | 282 request.headers = extra_headers.ToString(); |
| 286 | 283 |
| 287 mojom::URLLoaderAssociatedPtr url_loader; | 284 mojom::URLLoaderAssociatedPtr url_loader; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 net::TestDelegate url_request_delegate_; | 410 net::TestDelegate url_request_delegate_; |
| 414 std::string response_; | 411 std::string response_; |
| 415 int response_error_code_; | 412 int response_error_code_; |
| 416 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 413 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 417 std::string response_metadata_; | 414 std::string response_metadata_; |
| 418 | 415 |
| 419 int expected_status_code_; | 416 int expected_status_code_; |
| 420 std::string expected_response_; | 417 std::string expected_response_; |
| 421 }; | 418 }; |
| 422 | 419 |
| 423 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { | 420 TEST_P(BlobURLRequestJobTest, TestGetSimpleDataRequest) { |
| 424 blob_data_->AppendData(kTestData1); | 421 blob_data_->AppendData(kTestData1); |
| 425 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1); | 422 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1); |
| 426 } | 423 } |
| 427 | 424 |
| 428 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) { | 425 TEST_P(BlobURLRequestJobTest, TestGetSimpleFileRequest) { |
| 429 blob_data_->AppendFile(temp_file1_, 0, std::numeric_limits<uint64_t>::max(), | 426 blob_data_->AppendFile(temp_file1_, 0, std::numeric_limits<uint64_t>::max(), |
| 430 base::Time()); | 427 base::Time()); |
| 431 TestSuccessNonrangeRequest(kTestFileData1, arraysize(kTestFileData1) - 1); | 428 TestSuccessNonrangeRequest(kTestFileData1, arraysize(kTestFileData1) - 1); |
| 432 } | 429 } |
| 433 | 430 |
| 434 TEST_F(BlobURLRequestJobTest, TestGetLargeFileRequest) { | 431 TEST_P(BlobURLRequestJobTest, TestGetLargeFileRequest) { |
| 435 base::FilePath large_temp_file = | 432 base::FilePath large_temp_file = |
| 436 temp_dir_.GetPath().AppendASCII("LargeBlob.dat"); | 433 temp_dir_.GetPath().AppendASCII("LargeBlob.dat"); |
| 437 std::string large_data; | 434 std::string large_data; |
| 438 large_data.reserve(kBufferSize * 5); | 435 large_data.reserve(kBufferSize * 5); |
| 439 for (int i = 0; i < kBufferSize * 5; ++i) | 436 for (int i = 0; i < kBufferSize * 5; ++i) |
| 440 large_data.append(1, static_cast<char>(i % 256)); | 437 large_data.append(1, static_cast<char>(i % 256)); |
| 441 ASSERT_EQ( | 438 ASSERT_EQ( |
| 442 static_cast<int>(large_data.size()), | 439 static_cast<int>(large_data.size()), |
| 443 base::WriteFile(large_temp_file, large_data.data(), large_data.size())); | 440 base::WriteFile(large_temp_file, large_data.data(), large_data.size())); |
| 444 blob_data_->AppendFile(large_temp_file, 0, | 441 blob_data_->AppendFile(large_temp_file, 0, |
| 445 std::numeric_limits<uint64_t>::max(), base::Time()); | 442 std::numeric_limits<uint64_t>::max(), base::Time()); |
| 446 TestSuccessNonrangeRequest(large_data, large_data.size()); | 443 TestSuccessNonrangeRequest(large_data, large_data.size()); |
| 447 } | 444 } |
| 448 | 445 |
| 449 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) { | 446 TEST_P(BlobURLRequestJobTest, TestGetNonExistentFileRequest) { |
| 450 base::FilePath non_existent_file = | 447 base::FilePath non_existent_file = |
| 451 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); | 448 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); |
| 452 blob_data_->AppendFile(non_existent_file, 0, | 449 blob_data_->AppendFile(non_existent_file, 0, |
| 453 std::numeric_limits<uint64_t>::max(), base::Time()); | 450 std::numeric_limits<uint64_t>::max(), base::Time()); |
| 454 TestErrorRequest(404); | 451 TestErrorRequest(404); |
| 455 } | 452 } |
| 456 | 453 |
| 457 TEST_F(BlobURLRequestJobTest, TestGetChangedFileRequest) { | 454 TEST_P(BlobURLRequestJobTest, TestGetChangedFileRequest) { |
| 458 base::Time old_time = | 455 base::Time old_time = |
| 459 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10); | 456 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10); |
| 460 blob_data_->AppendFile(temp_file1_, 0, 3, old_time); | 457 blob_data_->AppendFile(temp_file1_, 0, 3, old_time); |
| 461 TestErrorRequest(404); | 458 TestErrorRequest(404); |
| 462 } | 459 } |
| 463 | 460 |
| 464 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileRequest) { | 461 TEST_P(BlobURLRequestJobTest, TestGetSlicedFileRequest) { |
| 465 blob_data_->AppendFile(temp_file1_, 2, 4, temp_file_modification_time1_); | 462 blob_data_->AppendFile(temp_file1_, 2, 4, temp_file_modification_time1_); |
| 466 std::string result(kTestFileData1 + 2, 4); | 463 std::string result(kTestFileData1 + 2, 4); |
| 467 TestSuccessNonrangeRequest(result, 4); | 464 TestSuccessNonrangeRequest(result, 4); |
| 468 } | 465 } |
| 469 | 466 |
| 470 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileSystemFileRequest) { | 467 TEST_P(BlobURLRequestJobTest, TestGetSimpleFileSystemFileRequest) { |
| 471 SetUpFileSystem(); | 468 SetUpFileSystem(); |
| 472 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 0, | 469 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 0, |
| 473 std::numeric_limits<uint64_t>::max(), | 470 std::numeric_limits<uint64_t>::max(), |
| 474 base::Time()); | 471 base::Time()); |
| 475 TestSuccessNonrangeRequest(kTestFileSystemFileData1, | 472 TestSuccessNonrangeRequest(kTestFileSystemFileData1, |
| 476 arraysize(kTestFileSystemFileData1) - 1); | 473 arraysize(kTestFileSystemFileData1) - 1); |
| 477 } | 474 } |
| 478 | 475 |
| 479 TEST_F(BlobURLRequestJobTest, TestGetLargeFileSystemFileRequest) { | 476 TEST_P(BlobURLRequestJobTest, TestGetLargeFileSystemFileRequest) { |
| 480 SetUpFileSystem(); | 477 SetUpFileSystem(); |
| 481 std::string large_data; | 478 std::string large_data; |
| 482 large_data.reserve(kBufferSize * 5); | 479 large_data.reserve(kBufferSize * 5); |
| 483 for (int i = 0; i < kBufferSize * 5; ++i) | 480 for (int i = 0; i < kBufferSize * 5; ++i) |
| 484 large_data.append(1, static_cast<char>(i % 256)); | 481 large_data.append(1, static_cast<char>(i % 256)); |
| 485 | 482 |
| 486 const char kFilename[] = "LargeBlob.dat"; | 483 const char kFilename[] = "LargeBlob.dat"; |
| 487 WriteFileSystemFile(kFilename, large_data.data(), large_data.size(), NULL); | 484 WriteFileSystemFile(kFilename, large_data.data(), large_data.size(), NULL); |
| 488 | 485 |
| 489 blob_data_->AppendFileSystemFile(GetFileSystemURL(kFilename), 0, | 486 blob_data_->AppendFileSystemFile(GetFileSystemURL(kFilename), 0, |
| 490 std::numeric_limits<uint64_t>::max(), | 487 std::numeric_limits<uint64_t>::max(), |
| 491 base::Time()); | 488 base::Time()); |
| 492 TestSuccessNonrangeRequest(large_data, large_data.size()); | 489 TestSuccessNonrangeRequest(large_data, large_data.size()); |
| 493 } | 490 } |
| 494 | 491 |
| 495 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileSystemFileRequest) { | 492 TEST_P(BlobURLRequestJobTest, TestGetNonExistentFileSystemFileRequest) { |
| 496 SetUpFileSystem(); | 493 SetUpFileSystem(); |
| 497 GURL non_existent_file = GetFileSystemURL("non-existent.dat"); | 494 GURL non_existent_file = GetFileSystemURL("non-existent.dat"); |
| 498 blob_data_->AppendFileSystemFile( | 495 blob_data_->AppendFileSystemFile( |
| 499 non_existent_file, 0, std::numeric_limits<uint64_t>::max(), base::Time()); | 496 non_existent_file, 0, std::numeric_limits<uint64_t>::max(), base::Time()); |
| 500 TestErrorRequest(404); | 497 TestErrorRequest(404); |
| 501 } | 498 } |
| 502 | 499 |
| 503 TEST_F(BlobURLRequestJobTest, TestGetInvalidFileSystemFileRequest) { | 500 TEST_P(BlobURLRequestJobTest, TestGetInvalidFileSystemFileRequest) { |
| 504 SetUpFileSystem(); | 501 SetUpFileSystem(); |
| 505 GURL invalid_file; | 502 GURL invalid_file; |
| 506 blob_data_->AppendFileSystemFile( | 503 blob_data_->AppendFileSystemFile( |
| 507 invalid_file, 0, std::numeric_limits<uint64_t>::max(), base::Time()); | 504 invalid_file, 0, std::numeric_limits<uint64_t>::max(), base::Time()); |
| 508 TestErrorRequest(500); | 505 TestErrorRequest(500); |
| 509 } | 506 } |
| 510 | 507 |
| 511 TEST_F(BlobURLRequestJobTest, TestGetChangedFileSystemFileRequest) { | 508 TEST_P(BlobURLRequestJobTest, TestGetChangedFileSystemFileRequest) { |
| 512 SetUpFileSystem(); | 509 SetUpFileSystem(); |
| 513 base::Time old_time = temp_file_system_file_modification_time1_ - | 510 base::Time old_time = temp_file_system_file_modification_time1_ - |
| 514 base::TimeDelta::FromSeconds(10); | 511 base::TimeDelta::FromSeconds(10); |
| 515 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 0, 3, old_time); | 512 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 0, 3, old_time); |
| 516 TestErrorRequest(404); | 513 TestErrorRequest(404); |
| 517 } | 514 } |
| 518 | 515 |
| 519 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileSystemFileRequest) { | 516 TEST_P(BlobURLRequestJobTest, TestGetSlicedFileSystemFileRequest) { |
| 520 SetUpFileSystem(); | 517 SetUpFileSystem(); |
| 521 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 2, 4, | 518 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 2, 4, |
| 522 temp_file_system_file_modification_time1_); | 519 temp_file_system_file_modification_time1_); |
| 523 std::string result(kTestFileSystemFileData1 + 2, 4); | 520 std::string result(kTestFileSystemFileData1 + 2, 4); |
| 524 TestSuccessNonrangeRequest(result, 4); | 521 TestSuccessNonrangeRequest(result, 4); |
| 525 } | 522 } |
| 526 | 523 |
| 527 TEST_F(BlobURLRequestJobTest, TestGetSimpleDiskCacheRequest) { | 524 TEST_P(BlobURLRequestJobTest, TestGetSimpleDiskCacheRequest) { |
| 528 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(), | 525 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(), |
| 529 disk_cache_entry_.get(), | 526 disk_cache_entry_.get(), |
| 530 kTestDiskCacheStreamIndex); | 527 kTestDiskCacheStreamIndex); |
| 531 TestSuccessNonrangeRequest(kTestDiskCacheData1, | 528 TestSuccessNonrangeRequest(kTestDiskCacheData1, |
| 532 arraysize(kTestDiskCacheData1) - 1); | 529 arraysize(kTestDiskCacheData1) - 1); |
| 533 } | 530 } |
| 534 | 531 |
| 535 TEST_F(BlobURLRequestJobTest, TestGetComplicatedDataFileAndDiskCacheRequest) { | 532 TEST_P(BlobURLRequestJobTest, TestGetComplicatedDataFileAndDiskCacheRequest) { |
| 536 SetUpFileSystem(); | 533 SetUpFileSystem(); |
| 537 std::string result; | 534 std::string result; |
| 538 BuildComplicatedData(&result); | 535 BuildComplicatedData(&result); |
| 539 TestSuccessNonrangeRequest(result, GetTotalBlobLength()); | 536 TestSuccessNonrangeRequest(result, GetTotalBlobLength()); |
| 540 } | 537 } |
| 541 | 538 |
| 542 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest1) { | 539 TEST_P(BlobURLRequestJobTest, TestGetRangeRequest1) { |
| 543 SetUpFileSystem(); | 540 SetUpFileSystem(); |
| 544 std::string result; | 541 std::string result; |
| 545 BuildComplicatedData(&result); | 542 BuildComplicatedData(&result); |
| 546 net::HttpRequestHeaders extra_headers; | 543 net::HttpRequestHeaders extra_headers; |
| 547 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 544 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 548 net::HttpByteRange::Bounded(5, 10).GetHeaderValue()); | 545 net::HttpByteRange::Bounded(5, 10).GetHeaderValue()); |
| 549 expected_status_code_ = 206; | 546 expected_status_code_ = 206; |
| 550 expected_response_ = result.substr(5, 10 - 5 + 1); | 547 expected_response_ = result.substr(5, 10 - 5 + 1); |
| 551 TestRequest("GET", extra_headers); | 548 TestRequest("GET", extra_headers); |
| 552 | 549 |
| 553 EXPECT_EQ(6, response_headers_->GetContentLength()); | 550 EXPECT_EQ(6, response_headers_->GetContentLength()); |
| 554 EXPECT_TRUE(response_metadata_.empty()); | 551 EXPECT_TRUE(response_metadata_.empty()); |
| 555 | 552 |
| 556 int64_t first = 0, last = 0, length = 0; | 553 int64_t first = 0, last = 0, length = 0; |
| 557 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); | 554 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
| 558 EXPECT_EQ(5, first); | 555 EXPECT_EQ(5, first); |
| 559 EXPECT_EQ(10, last); | 556 EXPECT_EQ(10, last); |
| 560 EXPECT_EQ(GetTotalBlobLength(), length); | 557 EXPECT_EQ(GetTotalBlobLength(), length); |
| 561 } | 558 } |
| 562 | 559 |
| 563 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest2) { | 560 TEST_P(BlobURLRequestJobTest, TestGetRangeRequest2) { |
| 564 SetUpFileSystem(); | 561 SetUpFileSystem(); |
| 565 std::string result; | 562 std::string result; |
| 566 BuildComplicatedData(&result); | 563 BuildComplicatedData(&result); |
| 567 net::HttpRequestHeaders extra_headers; | 564 net::HttpRequestHeaders extra_headers; |
| 568 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 565 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 569 net::HttpByteRange::Suffix(10).GetHeaderValue()); | 566 net::HttpByteRange::Suffix(10).GetHeaderValue()); |
| 570 expected_status_code_ = 206; | 567 expected_status_code_ = 206; |
| 571 expected_response_ = result.substr(result.length() - 10); | 568 expected_response_ = result.substr(result.length() - 10); |
| 572 TestRequest("GET", extra_headers); | 569 TestRequest("GET", extra_headers); |
| 573 | 570 |
| 574 EXPECT_EQ(10, response_headers_->GetContentLength()); | 571 EXPECT_EQ(10, response_headers_->GetContentLength()); |
| 575 EXPECT_TRUE(response_metadata_.empty()); | 572 EXPECT_TRUE(response_metadata_.empty()); |
| 576 | 573 |
| 577 int64_t total = GetTotalBlobLength(); | 574 int64_t total = GetTotalBlobLength(); |
| 578 int64_t first = 0, last = 0, length = 0; | 575 int64_t first = 0, last = 0, length = 0; |
| 579 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); | 576 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
| 580 EXPECT_EQ(total - 10, first); | 577 EXPECT_EQ(total - 10, first); |
| 581 EXPECT_EQ(total - 1, last); | 578 EXPECT_EQ(total - 1, last); |
| 582 EXPECT_EQ(total, length); | 579 EXPECT_EQ(total, length); |
| 583 } | 580 } |
| 584 | 581 |
| 585 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest3) { | 582 TEST_P(BlobURLRequestJobTest, TestGetRangeRequest3) { |
| 586 SetUpFileSystem(); | 583 SetUpFileSystem(); |
| 587 std::string result; | 584 std::string result; |
| 588 BuildComplicatedData(&result); | 585 BuildComplicatedData(&result); |
| 589 net::HttpRequestHeaders extra_headers; | 586 net::HttpRequestHeaders extra_headers; |
| 590 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 587 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 591 net::HttpByteRange::Bounded(0, 2).GetHeaderValue()); | 588 net::HttpByteRange::Bounded(0, 2).GetHeaderValue()); |
| 592 expected_status_code_ = 206; | 589 expected_status_code_ = 206; |
| 593 expected_response_ = result.substr(0, 3); | 590 expected_response_ = result.substr(0, 3); |
| 594 TestRequest("GET", extra_headers); | 591 TestRequest("GET", extra_headers); |
| 595 | 592 |
| 596 EXPECT_EQ(3, response_headers_->GetContentLength()); | 593 EXPECT_EQ(3, response_headers_->GetContentLength()); |
| 597 EXPECT_TRUE(response_metadata_.empty()); | 594 EXPECT_TRUE(response_metadata_.empty()); |
| 598 | 595 |
| 599 int64_t first = 0, last = 0, length = 0; | 596 int64_t first = 0, last = 0, length = 0; |
| 600 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); | 597 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
| 601 EXPECT_EQ(0, first); | 598 EXPECT_EQ(0, first); |
| 602 EXPECT_EQ(2, last); | 599 EXPECT_EQ(2, last); |
| 603 EXPECT_EQ(GetTotalBlobLength(), length); | 600 EXPECT_EQ(GetTotalBlobLength(), length); |
| 604 } | 601 } |
| 605 | 602 |
| 606 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { | 603 TEST_P(BlobURLRequestJobTest, TestExtraHeaders) { |
| 607 blob_data_->set_content_type(kTestContentType); | 604 blob_data_->set_content_type(kTestContentType); |
| 608 blob_data_->set_content_disposition(kTestContentDisposition); | 605 blob_data_->set_content_disposition(kTestContentDisposition); |
| 609 blob_data_->AppendData(kTestData1); | 606 blob_data_->AppendData(kTestData1); |
| 610 expected_status_code_ = 200; | 607 expected_status_code_ = 200; |
| 611 expected_response_ = kTestData1; | 608 expected_response_ = kTestData1; |
| 612 TestRequest("GET", net::HttpRequestHeaders()); | 609 TestRequest("GET", net::HttpRequestHeaders()); |
| 613 | 610 |
| 614 std::string content_type; | 611 std::string content_type; |
| 615 EXPECT_TRUE(response_headers_->GetMimeType(&content_type)); | 612 EXPECT_TRUE(response_headers_->GetMimeType(&content_type)); |
| 616 EXPECT_EQ(kTestContentType, content_type); | 613 EXPECT_EQ(kTestContentType, content_type); |
| 617 EXPECT_TRUE(response_metadata_.empty()); | 614 EXPECT_TRUE(response_metadata_.empty()); |
| 618 size_t iter = 0; | 615 size_t iter = 0; |
| 619 std::string content_disposition; | 616 std::string content_disposition; |
| 620 EXPECT_TRUE(response_headers_->EnumerateHeader(&iter, "Content-Disposition", | 617 EXPECT_TRUE(response_headers_->EnumerateHeader(&iter, "Content-Disposition", |
| 621 &content_disposition)); | 618 &content_disposition)); |
| 622 EXPECT_EQ(kTestContentDisposition, content_disposition); | 619 EXPECT_EQ(kTestContentDisposition, content_disposition); |
| 623 } | 620 } |
| 624 | 621 |
| 625 TEST_F(BlobURLRequestJobTest, TestSideData) { | 622 TEST_P(BlobURLRequestJobTest, TestSideData) { |
| 626 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = | 623 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = |
| 627 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), | 624 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), |
| 628 kTestDiskCacheKey2, kTestDiskCacheData2, | 625 kTestDiskCacheKey2, kTestDiskCacheData2, |
| 629 kTestDiskCacheSideData); | 626 kTestDiskCacheSideData); |
| 630 blob_data_->AppendDiskCacheEntryWithSideData( | 627 blob_data_->AppendDiskCacheEntryWithSideData( |
| 631 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), | 628 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), |
| 632 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); | 629 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); |
| 633 expected_status_code_ = 200; | 630 expected_status_code_ = 200; |
| 634 expected_response_ = kTestDiskCacheData2; | 631 expected_response_ = kTestDiskCacheData2; |
| 635 TestRequest("GET", net::HttpRequestHeaders()); | 632 TestRequest("GET", net::HttpRequestHeaders()); |
| 636 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), | 633 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), |
| 637 response_headers_->GetContentLength()); | 634 response_headers_->GetContentLength()); |
| 638 | 635 |
| 639 EXPECT_EQ(std::string(kTestDiskCacheSideData), response_metadata_); | 636 EXPECT_EQ(std::string(kTestDiskCacheSideData), response_metadata_); |
| 640 } | 637 } |
| 641 | 638 |
| 642 TEST_F(BlobURLRequestJobTest, TestZeroSizeSideData) { | 639 TEST_P(BlobURLRequestJobTest, TestZeroSizeSideData) { |
| 643 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = | 640 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = |
| 644 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), | 641 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), |
| 645 kTestDiskCacheKey2, kTestDiskCacheData2, | 642 kTestDiskCacheKey2, kTestDiskCacheData2, |
| 646 ""); | 643 ""); |
| 647 blob_data_->AppendDiskCacheEntryWithSideData( | 644 blob_data_->AppendDiskCacheEntryWithSideData( |
| 648 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), | 645 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), |
| 649 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); | 646 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); |
| 650 expected_status_code_ = 200; | 647 expected_status_code_ = 200; |
| 651 expected_response_ = kTestDiskCacheData2; | 648 expected_response_ = kTestDiskCacheData2; |
| 652 TestRequest("GET", net::HttpRequestHeaders()); | 649 TestRequest("GET", net::HttpRequestHeaders()); |
| 653 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), | 650 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), |
| 654 response_headers_->GetContentLength()); | 651 response_headers_->GetContentLength()); |
| 655 | 652 |
| 656 EXPECT_TRUE(response_metadata_.empty()); | 653 EXPECT_TRUE(response_metadata_.empty()); |
| 657 } | 654 } |
| 658 | 655 |
| 659 TEST_F(BlobURLRequestJobTest, BrokenBlob) { | 656 TEST_P(BlobURLRequestJobTest, BrokenBlob) { |
| 660 blob_handle_ = blob_context_.AddBrokenBlob( | 657 blob_handle_ = blob_context_.AddBrokenBlob( |
| 661 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); | 658 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
| 662 TestErrorRequest(500); | 659 TestErrorRequest(500); |
| 663 } | 660 } |
| 664 | 661 |
| 662 INSTANTIATE_TEST_CASE_P(BlobURLRequestJobTest, | |
| 663 BlobURLRequestJobTest, | |
| 664 ::testing::Bool()); | |
| 665 | |
| 665 } // namespace content | 666 } // namespace content |
| OLD | NEW |