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

Side by Side Diff: content/browser/fileapi/blob_url_request_job_unittest.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Snapshots now created by the Handle, one more rename Created 5 years, 11 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 11 matching lines...) Expand all
22 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
23 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
24 #include "net/url_request/url_request_job_factory_impl.h" 24 #include "net/url_request/url_request_job_factory_impl.h"
25 #include "storage/browser/blob/blob_url_request_job.h" 25 #include "storage/browser/blob/blob_url_request_job.h"
26 #include "storage/browser/fileapi/file_system_context.h" 26 #include "storage/browser/fileapi/file_system_context.h"
27 #include "storage/browser/fileapi/file_system_operation_context.h" 27 #include "storage/browser/fileapi/file_system_operation_context.h"
28 #include "storage/browser/fileapi/file_system_url.h" 28 #include "storage/browser/fileapi/file_system_url.h"
29 #include "storage/common/blob/blob_data.h" 29 #include "storage/common/blob/blob_data.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 31
32 using storage::BlobData; 32 using storage::BlobDataSnapshot;
33 using storage::BlobDataBuilder;
33 using storage::BlobURLRequestJob; 34 using storage::BlobURLRequestJob;
34 35
35 namespace content { 36 namespace content {
36 37
37 namespace { 38 namespace {
38 39
39 const int kBufferSize = 1024; 40 const int kBufferSize = 1024;
40 const char kTestData1[] = "Hello"; 41 const char kTestData1[] = "Hello";
41 const char kTestData2[] = "Here it is data."; 42 const char kTestData2[] = "Here it is data.";
42 const char kTestFileData1[] = "0123456789"; 43 const char kTestFileData1[] = "0123456789";
(...skipping 14 matching lines...) Expand all
57 // A simple ProtocolHandler implementation to create BlobURLRequestJob. 58 // A simple ProtocolHandler implementation to create BlobURLRequestJob.
58 class MockProtocolHandler : 59 class MockProtocolHandler :
59 public net::URLRequestJobFactory::ProtocolHandler { 60 public net::URLRequestJobFactory::ProtocolHandler {
60 public: 61 public:
61 MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} 62 MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {}
62 63
63 // net::URLRequestJobFactory::ProtocolHandler override. 64 // net::URLRequestJobFactory::ProtocolHandler override.
64 net::URLRequestJob* MaybeCreateJob( 65 net::URLRequestJob* MaybeCreateJob(
65 net::URLRequest* request, 66 net::URLRequest* request,
66 net::NetworkDelegate* network_delegate) const override { 67 net::NetworkDelegate* network_delegate) const override {
67 return new BlobURLRequestJob(request, 68 return new BlobURLRequestJob(request, network_delegate,
68 network_delegate, 69 test_->blob_data_->Build().Pass(),
69 test_->blob_data_.get(),
70 test_->file_system_context_.get(), 70 test_->file_system_context_.get(),
71 base::MessageLoopProxy::current().get()); 71 base::MessageLoopProxy::current().get());
72 } 72 }
73 73
74 private: 74 private:
75 BlobURLRequestJobTest* test_; 75 BlobURLRequestJobTest* test_;
76 }; 76 };
77 77
78 BlobURLRequestJobTest() 78 BlobURLRequestJobTest()
79 : blob_data_(new BlobData()), 79 : blob_data_(new BlobDataBuilder("uuid")), expected_status_code_(0) {}
80 expected_status_code_(0) {}
81 80
82 void SetUp() override { 81 void SetUp() override {
83 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 82 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
84 83
85 temp_file1_ = temp_dir_.path().AppendASCII("BlobFile1.dat"); 84 temp_file1_ = temp_dir_.path().AppendASCII("BlobFile1.dat");
86 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1), 85 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData1) - 1),
87 base::WriteFile(temp_file1_, kTestFileData1, 86 base::WriteFile(temp_file1_, kTestFileData1,
88 arraysize(kTestFileData1) - 1)); 87 arraysize(kTestFileData1) - 1));
89 base::File::Info file_info1; 88 base::File::Info file_info1;
90 base::GetFileInfo(temp_file1_, &file_info1); 89 base::GetFileInfo(temp_file1_, &file_info1);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4); 211 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4);
213 *expected_result += std::string(kTestData2 + 4, 5); 212 *expected_result += std::string(kTestData2 + 4, 5);
214 *expected_result += std::string(kTestFileData2 + 5, 6); 213 *expected_result += std::string(kTestFileData2 + 5, 6);
215 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); 214 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7);
216 } 215 }
217 216
218 // This only works if all the Blob items have a definite pre-computed length. 217 // This only works if all the Blob items have a definite pre-computed length.
219 // Otherwise, this will fail a CHECK. 218 // Otherwise, this will fail a CHECK.
220 int64 GetTotalBlobLength() const { 219 int64 GetTotalBlobLength() const {
221 int64 total = 0; 220 int64 total = 0;
222 const std::vector<BlobData::Item>& items = blob_data_->items(); 221 scoped_ptr<BlobDataSnapshot> data = blob_data_->Build();
223 for (std::vector<BlobData::Item>::const_iterator it = items.begin(); 222 const auto& items = data->items();
224 it != items.end(); ++it) { 223 for (const auto& item : items) {
225 int64 length = base::checked_cast<int64>(it->length()); 224 int64 length = base::checked_cast<int64>(item->length());
226 CHECK(length <= kint64max - total); 225 CHECK(length <= kint64max - total);
227 total += length; 226 total += length;
228 } 227 }
229 return total; 228 return total;
230 } 229 }
231 230
232 protected: 231 protected:
233 base::ScopedTempDir temp_dir_; 232 base::ScopedTempDir temp_dir_;
234 base::FilePath temp_file1_; 233 base::FilePath temp_file1_;
235 base::FilePath temp_file2_; 234 base::FilePath temp_file2_;
236 base::Time temp_file_modification_time1_; 235 base::Time temp_file_modification_time1_;
237 base::Time temp_file_modification_time2_; 236 base::Time temp_file_modification_time2_;
238 GURL file_system_root_url_; 237 GURL file_system_root_url_;
239 GURL temp_file_system_file1_; 238 GURL temp_file_system_file1_;
240 GURL temp_file_system_file2_; 239 GURL temp_file_system_file2_;
241 base::Time temp_file_system_file_modification_time1_; 240 base::Time temp_file_system_file_modification_time1_;
242 base::Time temp_file_system_file_modification_time2_; 241 base::Time temp_file_system_file_modification_time2_;
243 242
244 base::MessageLoopForIO message_loop_; 243 base::MessageLoopForIO message_loop_;
245 scoped_refptr<storage::FileSystemContext> file_system_context_; 244 scoped_refptr<storage::FileSystemContext> file_system_context_;
246 scoped_refptr<BlobData> blob_data_; 245 scoped_ptr<BlobDataBuilder> blob_data_;
246 scoped_ptr<BlobDataSnapshot> blob_data_snapshot_;
247 net::URLRequestJobFactoryImpl url_request_job_factory_; 247 net::URLRequestJobFactoryImpl url_request_job_factory_;
248 net::URLRequestContext url_request_context_; 248 net::URLRequestContext url_request_context_;
249 MockURLRequestDelegate url_request_delegate_; 249 MockURLRequestDelegate url_request_delegate_;
250 scoped_ptr<net::URLRequest> request_; 250 scoped_ptr<net::URLRequest> request_;
251 251
252 int expected_status_code_; 252 int expected_status_code_;
253 std::string expected_response_; 253 std::string expected_response_;
254 }; 254 };
255 255
256 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) { 256 TEST_F(BlobURLRequestJobTest, TestGetSimpleDataRequest) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); 407 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type));
408 EXPECT_EQ(kTestContentType, content_type); 408 EXPECT_EQ(kTestContentType, content_type);
409 void* iter = NULL; 409 void* iter = NULL;
410 std::string content_disposition; 410 std::string content_disposition;
411 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( 411 EXPECT_TRUE(request_->response_headers()->EnumerateHeader(
412 &iter, "Content-Disposition", &content_disposition)); 412 &iter, "Content-Disposition", &content_disposition));
413 EXPECT_EQ(kTestContentDisposition, content_disposition); 413 EXPECT_EQ(kTestContentDisposition, content_disposition);
414 } 414 }
415 415
416 } // namespace content 416 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698