Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1562)

Side by Side Diff: content/browser/blob_storage/blob_url_unittest.cc

Issue 2940553003: Failure in reading Blob URL should results in network error
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 private: 153 private:
154 BlobURLRequestJobTest* test_; 154 BlobURLRequestJobTest* test_;
155 }; 155 };
156 156
157 BlobURLRequestJobTest() 157 BlobURLRequestJobTest()
158 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 158 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
159 blob_data_(new BlobDataBuilder("uuid")), 159 blob_data_(new BlobDataBuilder("uuid")),
160 response_error_code_(net::OK), 160 response_error_code_(net::OK),
161 expected_error_code_(net::OK),
161 expected_status_code_(0) {} 162 expected_status_code_(0) {}
162 163
163 void SetUp() override { 164 void SetUp() override {
164 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 165 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
165 166
166 temp_file1_ = temp_dir_.GetPath().AppendASCII("BlobFile1.dat"); 167 temp_file1_ = temp_dir_.GetPath().AppendASCII("BlobFile1.dat");
167 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), 168 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1),
168 base::WriteFile(temp_file1_, kTestFileData1, 169 base::WriteFile(temp_file1_, kTestFileData1,
169 arraysize(kTestFileData1) - 1)); 170 arraysize(kTestFileData1) - 1));
170 base::File::Info file_info1; 171 base::File::Info file_info1;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 void OnValidateFileSystem(const GURL& root, 250 void OnValidateFileSystem(const GURL& root,
250 const std::string& name, 251 const std::string& name,
251 base::File::Error result) { 252 base::File::Error result) {
252 ASSERT_EQ(base::File::FILE_OK, result); 253 ASSERT_EQ(base::File::FILE_OK, result);
253 ASSERT_TRUE(root.is_valid()); 254 ASSERT_TRUE(root.is_valid());
254 file_system_root_url_ = root; 255 file_system_root_url_ = root;
255 } 256 }
256 257
257 void TestSuccessNonrangeRequest(const std::string& expected_response, 258 void TestSuccessNonrangeRequest(const std::string& expected_response,
258 int64_t expected_content_length) { 259 int64_t expected_content_length) {
260 expected_error_code_ = net::OK;
259 expected_status_code_ = 200; 261 expected_status_code_ = 200;
260 expected_response_ = expected_response; 262 expected_response_ = expected_response;
261 TestRequest("GET", net::HttpRequestHeaders()); 263 TestRequest("GET", net::HttpRequestHeaders());
262 EXPECT_EQ(expected_content_length, response_headers_->GetContentLength()); 264 EXPECT_EQ(expected_content_length, response_headers_->GetContentLength());
263 } 265 }
264 266
265 void TestErrorRequest(int expected_status_code) { 267 void TestErrorRequest(int expected_error_code) {
266 expected_status_code_ = expected_status_code; 268 expected_error_code_ = expected_error_code;
267 expected_response_ = ""; 269 expected_response_ = "";
268 TestRequest("GET", net::HttpRequestHeaders()); 270 TestRequest("GET", net::HttpRequestHeaders());
269 EXPECT_TRUE(response_metadata_.empty()); 271 EXPECT_TRUE(response_metadata_.empty());
270 } 272 }
271 273
272 void TestRequest(const std::string& method, 274 void TestRequest(const std::string& method,
273 const net::HttpRequestHeaders& extra_headers) { 275 const net::HttpRequestHeaders& extra_headers) {
274 GURL url("blob:blah"); 276 GURL url("blob:blah");
275 277
276 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 278 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if (request->response_info().metadata) { 321 if (request->response_info().metadata) {
320 response_metadata_ = 322 response_metadata_ =
321 std::string(request->response_info().metadata->data(), 323 std::string(request->response_info().metadata->data(),
322 request->response_info().metadata->size()); 324 request->response_info().metadata->size());
323 } 325 }
324 326
325 response_error_code_ = url_request_delegate_.request_status(); 327 response_error_code_ = url_request_delegate_.request_status();
326 } 328 }
327 329
328 // Verify response. 330 // Verify response.
329 EXPECT_EQ(net::OK, response_error_code_); 331 EXPECT_EQ(expected_error_code_, response_error_code_);
330 EXPECT_EQ(expected_status_code_, response_headers_->response_code()); 332 if (response_error_code_ == net::OK) {
331 EXPECT_EQ(expected_response_, response_); 333 EXPECT_EQ(expected_status_code_, response_headers_->response_code());
334 EXPECT_EQ(expected_response_, response_);
335 }
332 } 336 }
333 337
334 void BuildComplicatedData(std::string* expected_result) { 338 void BuildComplicatedData(std::string* expected_result) {
335 blob_data_->AppendData(kTestData1 + 1, 2); 339 blob_data_->AppendData(kTestData1 + 1, 2);
336 *expected_result = std::string(kTestData1 + 1, 2); 340 *expected_result = std::string(kTestData1 + 1, 2);
337 341
338 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); 342 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_);
339 *expected_result += std::string(kTestFileData1 + 2, 3); 343 *expected_result += std::string(kTestFileData1 + 2, 3);
340 344
341 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(), 345 blob_data_->AppendDiskCacheEntry(new EmptyDataHandle(),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 std::unique_ptr<BlobDataBuilder> blob_data_; 411 std::unique_ptr<BlobDataBuilder> blob_data_;
408 std::unique_ptr<BlobDataSnapshot> blob_data_snapshot_; 412 std::unique_ptr<BlobDataSnapshot> blob_data_snapshot_;
409 net::URLRequestJobFactoryImpl url_request_job_factory_; 413 net::URLRequestJobFactoryImpl url_request_job_factory_;
410 net::URLRequestContext url_request_context_; 414 net::URLRequestContext url_request_context_;
411 net::TestDelegate url_request_delegate_; 415 net::TestDelegate url_request_delegate_;
412 std::string response_; 416 std::string response_;
413 int response_error_code_; 417 int response_error_code_;
414 scoped_refptr<net::HttpResponseHeaders> response_headers_; 418 scoped_refptr<net::HttpResponseHeaders> response_headers_;
415 std::string response_metadata_; 419 std::string response_metadata_;
416 420
421 int expected_error_code_;
417 int expected_status_code_; 422 int expected_status_code_;
418 std::string expected_response_; 423 std::string expected_response_;
419 }; 424 };
420 425
421 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { 426 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) {
422 blob_data_->AppendData(kTestData1); 427 blob_data_->AppendData(kTestData1);
423 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1); 428 TestSuccessNonrangeRequest(kTestData1, arraysize(kTestData1) - 1);
424 } 429 }
425 430
426 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) { 431 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) {
(...skipping 15 matching lines...) Expand all
442 blob_data_->AppendFile(large_temp_file, 0, 447 blob_data_->AppendFile(large_temp_file, 0,
443 std::numeric_limits<uint64_t>::max(), base::Time()); 448 std::numeric_limits<uint64_t>::max(), base::Time());
444 TestSuccessNonrangeRequest(large_data, large_data.size()); 449 TestSuccessNonrangeRequest(large_data, large_data.size());
445 } 450 }
446 451
447 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) { 452 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) {
448 base::FilePath non_existent_file = 453 base::FilePath non_existent_file =
449 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); 454 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na"));
450 blob_data_->AppendFile(non_existent_file, 0, 455 blob_data_->AppendFile(non_existent_file, 0,
451 std::numeric_limits<uint64_t>::max(), base::Time()); 456 std::numeric_limits<uint64_t>::max(), base::Time());
452 TestErrorRequest(404); 457 TestErrorRequest(net::ERR_FILE_NOT_FOUND);
453 } 458 }
454 459
455 TEST_F(BlobURLRequestJobTest, TestGetChangedFileRequest) { 460 TEST_F(BlobURLRequestJobTest, TestGetChangedFileRequest) {
456 base::Time old_time = 461 base::Time old_time =
457 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10); 462 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10);
458 blob_data_->AppendFile(temp_file1_, 0, 3, old_time); 463 blob_data_->AppendFile(temp_file1_, 0, 3, old_time);
459 TestErrorRequest(404); 464 TestErrorRequest(net::ERR_FILE_NOT_FOUND);
460 } 465 }
461 466
462 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileRequest) { 467 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileRequest) {
463 blob_data_->AppendFile(temp_file1_, 2, 4, temp_file_modification_time1_); 468 blob_data_->AppendFile(temp_file1_, 2, 4, temp_file_modification_time1_);
464 std::string result(kTestFileData1 + 2, 4); 469 std::string result(kTestFileData1 + 2, 4);
465 TestSuccessNonrangeRequest(result, 4); 470 TestSuccessNonrangeRequest(result, 4);
466 } 471 }
467 472
468 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileSystemFileRequest) { 473 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileSystemFileRequest) {
469 SetUpFileSystem(); 474 SetUpFileSystem();
(...skipping 18 matching lines...) Expand all
488 std::numeric_limits<uint64_t>::max(), 493 std::numeric_limits<uint64_t>::max(),
489 base::Time()); 494 base::Time());
490 TestSuccessNonrangeRequest(large_data, large_data.size()); 495 TestSuccessNonrangeRequest(large_data, large_data.size());
491 } 496 }
492 497
493 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileSystemFileRequest) { 498 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileSystemFileRequest) {
494 SetUpFileSystem(); 499 SetUpFileSystem();
495 GURL non_existent_file = GetFileSystemURL("non-existent.dat"); 500 GURL non_existent_file = GetFileSystemURL("non-existent.dat");
496 blob_data_->AppendFileSystemFile( 501 blob_data_->AppendFileSystemFile(
497 non_existent_file, 0, std::numeric_limits<uint64_t>::max(), base::Time()); 502 non_existent_file, 0, std::numeric_limits<uint64_t>::max(), base::Time());
498 TestErrorRequest(404); 503 TestErrorRequest(net::ERR_FILE_NOT_FOUND);
499 } 504 }
500 505
501 TEST_F(BlobURLRequestJobTest, TestGetInvalidFileSystemFileRequest) { 506 TEST_F(BlobURLRequestJobTest, TestGetInvalidFileSystemFileRequest) {
502 SetUpFileSystem(); 507 SetUpFileSystem();
503 GURL invalid_file; 508 GURL invalid_file;
504 blob_data_->AppendFileSystemFile( 509 blob_data_->AppendFileSystemFile(
505 invalid_file, 0, std::numeric_limits<uint64_t>::max(), base::Time()); 510 invalid_file, 0, std::numeric_limits<uint64_t>::max(), base::Time());
506 TestErrorRequest(500); 511 TestErrorRequest(net::ERR_FAILED);
507 } 512 }
508 513
509 TEST_F(BlobURLRequestJobTest, TestGetChangedFileSystemFileRequest) { 514 TEST_F(BlobURLRequestJobTest, TestGetChangedFileSystemFileRequest) {
510 SetUpFileSystem(); 515 SetUpFileSystem();
511 base::Time old_time = temp_file_system_file_modification_time1_ - 516 base::Time old_time = temp_file_system_file_modification_time1_ -
512 base::TimeDelta::FromSeconds(10); 517 base::TimeDelta::FromSeconds(10);
513 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 0, 3, old_time); 518 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 0, 3, old_time);
514 TestErrorRequest(404); 519 TestErrorRequest(net::ERR_FILE_NOT_FOUND);
515 } 520 }
516 521
517 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileSystemFileRequest) { 522 TEST_F(BlobURLRequestJobTest, TestGetSlicedFileSystemFileRequest) {
518 SetUpFileSystem(); 523 SetUpFileSystem();
519 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 2, 4, 524 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 2, 4,
520 temp_file_system_file_modification_time1_); 525 temp_file_system_file_modification_time1_);
521 std::string result(kTestFileSystemFileData1 + 2, 4); 526 std::string result(kTestFileSystemFileData1 + 2, 4);
522 TestSuccessNonrangeRequest(result, 4); 527 TestSuccessNonrangeRequest(result, 4);
523 } 528 }
524 529
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 TestRequest("GET", net::HttpRequestHeaders()); 655 TestRequest("GET", net::HttpRequestHeaders());
651 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1), 656 EXPECT_EQ(static_cast<int>(arraysize(kTestDiskCacheData2) - 1),
652 response_headers_->GetContentLength()); 657 response_headers_->GetContentLength());
653 658
654 EXPECT_TRUE(response_metadata_.empty()); 659 EXPECT_TRUE(response_metadata_.empty());
655 } 660 }
656 661
657 TEST_F(BlobURLRequestJobTest, BrokenBlob) { 662 TEST_F(BlobURLRequestJobTest, BrokenBlob) {
658 blob_handle_ = blob_context_.AddBrokenBlob( 663 blob_handle_ = blob_context_.AddBrokenBlob(
659 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); 664 "uuid", "", "", storage::BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS);
660 TestErrorRequest(500); 665 TestErrorRequest(net::ERR_FAILED);
661 } 666 }
662 667
663 } // namespace content 668 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/blob_storage/blob_url_loader_factory.cc ('k') | content/browser/frame_host/frame_tree_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698