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 blob_context_.AsWeakPtr(), file_system_context_); |
| 291 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader), 0, 0, |
| 292 mojom::kURLLoadOptionNone, request, |
| 293 url_loader_client.CreateInterfacePtr()); |
| 294 url_loader_client.RunUntilComplete(); |
| 295 |
| 296 if (url_loader_client.response_body().is_valid()) { |
| 297 EXPECT_TRUE(mojo::common::BlockingCopyToString( |
| 298 url_loader_client.response_body_release(), &response_)); |
| 299 } |
| 300 response_headers_ = url_loader_client.response_head().headers; |
| 301 response_metadata_ = url_loader_client.cached_metadata(); |
| 302 response_error_code_ = url_loader_client.completion_status().error_code; |
| 303 } else { |
| 304 std::unique_ptr<net::URLRequest> request = |
| 305 url_request_context_.CreateRequest(url, net::DEFAULT_PRIORITY, |
| 306 &url_request_delegate_, |
| 307 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 308 request->set_method(method); |
| 309 if (!extra_headers.IsEmpty()) |
| 310 request->SetExtraRequestHeaders(extra_headers); |
| 311 request->Start(); |
| 312 |
| 313 base::RunLoop().Run(); |
| 314 response_ = url_request_delegate_.data_received(); |
| 315 response_headers_ = request->response_headers(); |
| 316 if (request->response_info().metadata) { |
| 317 response_metadata_ = |
| 318 std::string(request->response_info().metadata->data(), |
| 319 request->response_info().metadata->size()); |
| 320 } |
| 321 |
| 322 response_error_code_ = url_request_delegate_.request_status(); |
| 323 } |
275 | 324 |
276 // Verify response. | 325 // Verify response. |
277 EXPECT_EQ(net::OK, url_request_delegate_.request_status()); | 326 EXPECT_EQ(net::OK, response_error_code_); |
278 EXPECT_EQ(expected_status_code_, | 327 EXPECT_EQ(expected_status_code_, response_headers_->response_code()); |
279 request_->response_headers()->response_code()); | 328 EXPECT_EQ(expected_response_, response_); |
280 EXPECT_EQ(expected_response_, url_request_delegate_.data_received()); | |
281 } | 329 } |
282 | 330 |
283 void BuildComplicatedData(std::string* expected_result) { | 331 void BuildComplicatedData(std::string* expected_result) { |
284 blob_data_->AppendData(kTestData1 + 1, 2); | 332 blob_data_->AppendData(kTestData1 + 1, 2); |
285 *expected_result = std::string(kTestData1 + 1, 2); | 333 *expected_result = std::string(kTestData1 + 1, 2); |
286 | 334 |
287 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); | 335 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); |
288 *expected_result += std::string(kTestFileData1 + 2, 3); | 336 *expected_result += std::string(kTestFileData1 + 2, 3); |
289 | 337 |
290 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(), | 338 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 base::Time temp_file_modification_time2_; | 385 base::Time temp_file_modification_time2_; |
338 GURL file_system_root_url_; | 386 GURL file_system_root_url_; |
339 GURL temp_file_system_file1_; | 387 GURL temp_file_system_file1_; |
340 GURL temp_file_system_file2_; | 388 GURL temp_file_system_file2_; |
341 base::Time temp_file_system_file_modification_time1_; | 389 base::Time temp_file_system_file_modification_time1_; |
342 base::Time temp_file_system_file_modification_time2_; | 390 base::Time temp_file_system_file_modification_time2_; |
343 | 391 |
344 std::unique_ptr<disk_cache::Backend> disk_cache_backend_; | 392 std::unique_ptr<disk_cache::Backend> disk_cache_backend_; |
345 disk_cache::ScopedEntryPtr disk_cache_entry_; | 393 disk_cache::ScopedEntryPtr disk_cache_entry_; |
346 | 394 |
347 base::MessageLoopForIO message_loop_; | 395 TestBrowserThreadBundle thread_bundle_; |
348 scoped_refptr<storage::FileSystemContext> file_system_context_; | 396 scoped_refptr<storage::FileSystemContext> file_system_context_; |
349 | 397 |
350 storage::BlobStorageContext blob_context_; | 398 storage::BlobStorageContext blob_context_; |
351 std::unique_ptr<storage::BlobDataHandle> blob_handle_; | 399 std::unique_ptr<storage::BlobDataHandle> blob_handle_; |
352 std::unique_ptr<BlobDataBuilder> blob_data_; | 400 std::unique_ptr<BlobDataBuilder> blob_data_; |
353 std::unique_ptr<BlobDataSnapshot> blob_data_snapshot_; | 401 std::unique_ptr<BlobDataSnapshot> blob_data_snapshot_; |
354 net::URLRequestJobFactoryImpl url_request_job_factory_; | 402 net::URLRequestJobFactoryImpl url_request_job_factory_; |
355 net::URLRequestContext url_request_context_; | 403 net::URLRequestContext url_request_context_; |
356 net::TestDelegate url_request_delegate_; | 404 net::TestDelegate url_request_delegate_; |
357 std::unique_ptr<net::URLRequest> request_; | 405 std::string response_; |
| 406 int response_error_code_; |
| 407 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 408 std::string response_metadata_; |
358 | 409 |
359 int expected_status_code_; | 410 int expected_status_code_; |
360 std::string expected_response_; | 411 std::string expected_response_; |
361 }; | 412 }; |
362 | 413 |
363 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { | 414 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { |
364 blob_data_->AppendData(kTestData1); | 415 blob_data_->AppendData(kTestData1); |
365 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1); | 416 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1); |
366 } | 417 } |
367 | 418 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 SetUpFileSystem(); | 534 SetUpFileSystem(); |
484 std::string result; | 535 std::string result; |
485 BuildComplicatedData(&result); | 536 BuildComplicatedData(&result); |
486 net::HttpRequestHeaders extra_headers; | 537 net::HttpRequestHeaders extra_headers; |
487 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 538 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
488 net::HttpByteRange::Bounded(5, 10).GetHeaderValue()); | 539 net::HttpByteRange::Bounded(5, 10).GetHeaderValue()); |
489 expected_status_code_ = 206; | 540 expected_status_code_ = 206; |
490 expected_response_ = result.substr(5, 10 - 5 + 1); | 541 expected_response_ = result.substr(5, 10 - 5 + 1); |
491 TestRequest("GET", extra_headers); | 542 TestRequest("GET", extra_headers); |
492 | 543 |
493 EXPECT_EQ(6, request_->response_headers()->GetContentLength()); | 544 EXPECT_EQ(6, response_headers_->GetContentLength()); |
494 EXPECT_FALSE(request_->response_info().metadata); | 545 EXPECT_TRUE(response_metadata_.empty()); |
495 | 546 |
496 int64_t first = 0, last = 0, length = 0; | 547 int64_t first = 0, last = 0, length = 0; |
497 EXPECT_TRUE(request_->response_headers()->GetContentRangeFor206(&first, &last, | 548 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
498 &length)); | |
499 EXPECT_EQ(5, first); | 549 EXPECT_EQ(5, first); |
500 EXPECT_EQ(10, last); | 550 EXPECT_EQ(10, last); |
501 EXPECT_EQ(GetTotalBlobLength(), length); | 551 EXPECT_EQ(GetTotalBlobLength(), length); |
502 } | 552 } |
503 | 553 |
504 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest2) { | 554 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest2) { |
505 SetUpFileSystem(); | 555 SetUpFileSystem(); |
506 std::string result; | 556 std::string result; |
507 BuildComplicatedData(&result); | 557 BuildComplicatedData(&result); |
508 net::HttpRequestHeaders extra_headers; | 558 net::HttpRequestHeaders extra_headers; |
509 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 559 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
510 net::HttpByteRange::Suffix(10).GetHeaderValue()); | 560 net::HttpByteRange::Suffix(10).GetHeaderValue()); |
511 expected_status_code_ = 206; | 561 expected_status_code_ = 206; |
512 expected_response_ = result.substr(result.length() - 10); | 562 expected_response_ = result.substr(result.length() - 10); |
513 TestRequest("GET", extra_headers); | 563 TestRequest("GET", extra_headers); |
514 | 564 |
515 EXPECT_EQ(10, request_->response_headers()->GetContentLength()); | 565 EXPECT_EQ(10, response_headers_->GetContentLength()); |
516 EXPECT_FALSE(request_->response_info().metadata); | 566 EXPECT_TRUE(response_metadata_.empty()); |
517 | 567 |
518 int64_t total = GetTotalBlobLength(); | 568 int64_t total = GetTotalBlobLength(); |
519 int64_t first = 0, last = 0, length = 0; | 569 int64_t first = 0, last = 0, length = 0; |
520 EXPECT_TRUE(request_->response_headers()->GetContentRangeFor206(&first, &last, | 570 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
521 &length)); | |
522 EXPECT_EQ(total - 10, first); | 571 EXPECT_EQ(total - 10, first); |
523 EXPECT_EQ(total - 1, last); | 572 EXPECT_EQ(total - 1, last); |
524 EXPECT_EQ(total, length); | 573 EXPECT_EQ(total, length); |
525 } | 574 } |
526 | 575 |
527 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest3) { | 576 TEST_F(BlobURLRequestJobTest, TestGetRangeRequest3) { |
528 SetUpFileSystem(); | 577 SetUpFileSystem(); |
529 std::string result; | 578 std::string result; |
530 BuildComplicatedData(&result); | 579 BuildComplicatedData(&result); |
531 net::HttpRequestHeaders extra_headers; | 580 net::HttpRequestHeaders extra_headers; |
532 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, | 581 extra_headers.SetHeader(net::HttpRequestHeaders::kRange, |
533 net::HttpByteRange::Bounded(0, 2).GetHeaderValue()); | 582 net::HttpByteRange::Bounded(0, 2).GetHeaderValue()); |
534 expected_status_code_ = 206; | 583 expected_status_code_ = 206; |
535 expected_response_ = result.substr(0, 3); | 584 expected_response_ = result.substr(0, 3); |
536 TestRequest("GET", extra_headers); | 585 TestRequest("GET", extra_headers); |
537 | 586 |
538 EXPECT_EQ(3, request_->response_headers()->GetContentLength()); | 587 EXPECT_EQ(3, response_headers_->GetContentLength()); |
539 EXPECT_FALSE(request_->response_info().metadata); | 588 EXPECT_TRUE(response_metadata_.empty()); |
540 | 589 |
541 int64_t first = 0, last = 0, length = 0; | 590 int64_t first = 0, last = 0, length = 0; |
542 EXPECT_TRUE(request_->response_headers()->GetContentRangeFor206(&first, &last, | 591 EXPECT_TRUE(response_headers_->GetContentRangeFor206(&first, &last, &length)); |
543 &length)); | |
544 EXPECT_EQ(0, first); | 592 EXPECT_EQ(0, first); |
545 EXPECT_EQ(2, last); | 593 EXPECT_EQ(2, last); |
546 EXPECT_EQ(GetTotalBlobLength(), length); | 594 EXPECT_EQ(GetTotalBlobLength(), length); |
547 } | 595 } |
548 | 596 |
549 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { | 597 TEST_F(BlobURLRequestJobTest, TestExtraHeaders) { |
550 blob_data_->set_content_type(kTestContentType); | 598 blob_data_->set_content_type(kTestContentType); |
551 blob_data_->set_content_disposition(kTestContentDisposition); | 599 blob_data_->set_content_disposition(kTestContentDisposition); |
552 blob_data_->AppendData(kTestData1); | 600 blob_data_->AppendData(kTestData1); |
553 expected_status_code_ = 200; | 601 expected_status_code_ = 200; |
554 expected_response_ = kTestData1; | 602 expected_response_ = kTestData1; |
555 TestRequest("GET", net::HttpRequestHeaders()); | 603 TestRequest("GET", net::HttpRequestHeaders()); |
556 | 604 |
557 std::string content_type; | 605 std::string content_type; |
558 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); | 606 EXPECT_TRUE(response_headers_->GetMimeType(&content_type)); |
559 EXPECT_EQ(kTestContentType, content_type); | 607 EXPECT_EQ(kTestContentType, content_type); |
560 EXPECT_FALSE(request_->response_info().metadata); | 608 EXPECT_TRUE(response_metadata_.empty()); |
561 size_t iter = 0; | 609 size_t iter = 0; |
562 std::string content_disposition; | 610 std::string content_disposition; |
563 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( | 611 EXPECT_TRUE(response_headers_->EnumerateHeader(&iter, "Content-Disposition", |
564 &iter, "Content-Disposition", &content_disposition)); | 612 &content_disposition)); |
565 EXPECT_EQ(kTestContentDisposition, content_disposition); | 613 EXPECT_EQ(kTestContentDisposition, content_disposition); |
566 } | 614 } |
567 | 615 |
568 TEST_F(BlobURLRequestJobTest, TestSideData) { | 616 TEST_F(BlobURLRequestJobTest, TestSideData) { |
569 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = | 617 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = |
570 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), | 618 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), |
571 kTestDiskCacheKey2, kTestDiskCacheData2, | 619 kTestDiskCacheKey2, kTestDiskCacheData2, |
572 kTestDiskCacheSideData); | 620 kTestDiskCacheSideData); |
573 blob_data_->AppendDiskCacheEntryWithSideData( | 621 blob_data_->AppendDiskCacheEntryWithSideData( |
574 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), | 622 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), |
575 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); | 623 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); |
576 expected_status_code_ = 200; | 624 expected_status_code_ = 200; |
577 expected_response_ = kTestDiskCacheData2; | 625 expected_response_ = kTestDiskCacheData2; |
578 TestRequest("GET", net::HttpRequestHeaders()); | 626 TestRequest("GET", net::HttpRequestHeaders()); |
579 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), | 627 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), |
580 request_->response_headers()->GetContentLength()); | 628 response_headers_->GetContentLength()); |
581 | 629 |
582 ASSERT_TRUE(request_->response_info().metadata); | 630 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 } | 631 } |
587 | 632 |
588 TEST_F(BlobURLRequestJobTest, TestZeroSizeSideData) { | 633 TEST_F(BlobURLRequestJobTest, TestZeroSizeSideData) { |
589 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = | 634 disk_cache::ScopedEntryPtr disk_cache_entry_with_side_data = |
590 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), | 635 CreateDiskCacheEntryWithSideData(disk_cache_backend_.get(), |
591 kTestDiskCacheKey2, kTestDiskCacheData2, | 636 kTestDiskCacheKey2, kTestDiskCacheData2, |
592 ""); | 637 ""); |
593 blob_data_->AppendDiskCacheEntryWithSideData( | 638 blob_data_->AppendDiskCacheEntryWithSideData( |
594 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), | 639 new EmptyDataHandle(), disk_cache_entry_with_side_data.get(), |
595 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); | 640 kTestDiskCacheStreamIndex, kTestDiskCacheSideStreamIndex); |
596 expected_status_code_ = 200; | 641 expected_status_code_ = 200; |
597 expected_response_ = kTestDiskCacheData2; | 642 expected_response_ = kTestDiskCacheData2; |
598 TestRequest("GET", net::HttpRequestHeaders()); | 643 TestRequest("GET", net::HttpRequestHeaders()); |
599 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), | 644 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), |
600 request_->response_headers()->GetContentLength()); | 645 response_headers_->GetContentLength()); |
601 | 646 |
602 EXPECT_FALSE(request_->response_info().metadata); | 647 EXPECT_TRUE(response_metadata_.empty()); |
603 } | 648 } |
604 | 649 |
605 TEST_F(BlobURLRequestJobTest, BrokenBlob) { | 650 TEST_F(BlobURLRequestJobTest, BrokenBlob) { |
606 blob_handle_ = blob_context_.AddBrokenBlob( | 651 blob_handle_ = blob_context_.AddBrokenBlob( |
607 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); | 652 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); |
608 TestErrorRequest(500); | 653 TestErrorRequest(500); |
609 } | 654 } |
610 | 655 |
611 } // namespace content | 656 } // namespace content |
OLD | NEW |