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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 temp_file_modification_time1_ = file_info1.last_modified; | 91 temp_file_modification_time1_ = file_info1.last_modified; |
92 | 92 |
93 temp_file2_ = temp_dir_.path().AppendASCII("BlobFile2.dat"); | 93 temp_file2_ = temp_dir_.path().AppendASCII("BlobFile2.dat"); |
94 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1), | 94 ASSERT_EQ(static_cast<int>(arraysize(kTestFileData2) - 1), |
95 base::WriteFile(temp_file2_, kTestFileData2, | 95 base::WriteFile(temp_file2_, kTestFileData2, |
96 arraysize(kTestFileData2) - 1)); | 96 arraysize(kTestFileData2) - 1)); |
97 base::File::Info file_info2; | 97 base::File::Info file_info2; |
98 base::GetFileInfo(temp_file2_, &file_info2); | 98 base::GetFileInfo(temp_file2_, &file_info2); |
99 temp_file_modification_time2_ = file_info2.last_modified; | 99 temp_file_modification_time2_ = file_info2.last_modified; |
100 | 100 |
101 temp_empty_file_ = temp_dir_.path().AppendASCII("EmptyBlobFile.dat"); | |
102 ASSERT_EQ(static_cast<int>(0), | |
cmumford
2014/07/31 18:44:43
Why the static_cast? Isn't 0 an integer literal al
pwnall-personal
2014/07/31 19:34:47
Done.
| |
103 base::WriteFile(temp_empty_file_, kTestFileData1, 0)); | |
cmumford
2014/07/31 18:44:43
Nit: This certainly works, but maybe CreateTempora
pwnall-personal
2014/07/31 19:34:47
Done.
| |
104 base::File::Info empty_file_info; | |
105 base::GetFileInfo(temp_empty_file_, &empty_file_info); | |
106 temp_empty_file_modification_time_ = empty_file_info.last_modified; | |
107 | |
101 url_request_job_factory_.SetProtocolHandler("blob", | 108 url_request_job_factory_.SetProtocolHandler("blob", |
102 new MockProtocolHandler(this)); | 109 new MockProtocolHandler(this)); |
103 url_request_context_.set_job_factory(&url_request_job_factory_); | 110 url_request_context_.set_job_factory(&url_request_job_factory_); |
104 } | 111 } |
105 | 112 |
106 virtual void TearDown() { | 113 virtual void TearDown() { |
107 } | 114 } |
108 | 115 |
109 void SetUpFileSystem() { | 116 void SetUpFileSystem() { |
110 // Prepare file system. | 117 // Prepare file system. |
(...skipping 13 matching lines...) Expand all Loading... | |
124 const char kFilename1[] = "FileSystemFile1.dat"; | 131 const char kFilename1[] = "FileSystemFile1.dat"; |
125 temp_file_system_file1_ = GetFileSystemURL(kFilename1); | 132 temp_file_system_file1_ = GetFileSystemURL(kFilename1); |
126 WriteFileSystemFile(kFilename1, kTestFileSystemFileData1, | 133 WriteFileSystemFile(kFilename1, kTestFileSystemFileData1, |
127 arraysize(kTestFileSystemFileData1) - 1, | 134 arraysize(kTestFileSystemFileData1) - 1, |
128 &temp_file_system_file_modification_time1_); | 135 &temp_file_system_file_modification_time1_); |
129 const char kFilename2[] = "FileSystemFile2.dat"; | 136 const char kFilename2[] = "FileSystemFile2.dat"; |
130 temp_file_system_file2_ = GetFileSystemURL(kFilename2); | 137 temp_file_system_file2_ = GetFileSystemURL(kFilename2); |
131 WriteFileSystemFile(kFilename2, kTestFileSystemFileData2, | 138 WriteFileSystemFile(kFilename2, kTestFileSystemFileData2, |
132 arraysize(kTestFileSystemFileData2) - 1, | 139 arraysize(kTestFileSystemFileData2) - 1, |
133 &temp_file_system_file_modification_time2_); | 140 &temp_file_system_file_modification_time2_); |
141 const char kEmptyFilename[] = "EmptyFileSystemFile.dat"; | |
142 temp_empty_file_system_file_ = GetFileSystemURL(kEmptyFilename); | |
143 WriteFileSystemFile(kEmptyFilename, kTestFileSystemFileData1, | |
144 0, &temp_empty_file_system_file_modification_time_); | |
134 } | 145 } |
135 | 146 |
136 GURL GetFileSystemURL(const std::string& filename) { | 147 GURL GetFileSystemURL(const std::string& filename) { |
137 return GURL(file_system_root_url_.spec() + filename); | 148 return GURL(file_system_root_url_.spec() + filename); |
138 } | 149 } |
139 | 150 |
140 void WriteFileSystemFile(const std::string& filename, | 151 void WriteFileSystemFile(const std::string& filename, |
141 const char* buf, int buf_size, | 152 const char* buf, int buf_size, |
142 base::Time* modification_time) { | 153 base::Time* modification_time) { |
143 fileapi::FileSystemURL url = | 154 fileapi::FileSystemURL url = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 212 |
202 void BuildComplicatedData(std::string* expected_result) { | 213 void BuildComplicatedData(std::string* expected_result) { |
203 blob_data_->AppendData(kTestData1 + 1, 2); | 214 blob_data_->AppendData(kTestData1 + 1, 2); |
204 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); | 215 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); |
205 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 3, 4, | 216 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 3, 4, |
206 temp_file_system_file_modification_time1_); | 217 temp_file_system_file_modification_time1_); |
207 blob_data_->AppendData(kTestData2 + 4, 5); | 218 blob_data_->AppendData(kTestData2 + 4, 5); |
208 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_); | 219 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_); |
209 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7, | 220 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7, |
210 temp_file_system_file_modification_time2_); | 221 temp_file_system_file_modification_time2_); |
222 blob_data_->AppendFile(temp_empty_file_, 0, 0, | |
223 temp_empty_file_modification_time_); | |
224 blob_data_->AppendFileSystemFile( | |
225 temp_empty_file_system_file_, 0, 0, | |
226 temp_empty_file_system_file_modification_time_); | |
211 *expected_result = std::string(kTestData1 + 1, 2); | 227 *expected_result = std::string(kTestData1 + 1, 2); |
212 *expected_result += std::string(kTestFileData1 + 2, 3); | 228 *expected_result += std::string(kTestFileData1 + 2, 3); |
213 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4); | 229 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4); |
214 *expected_result += std::string(kTestData2 + 4, 5); | 230 *expected_result += std::string(kTestData2 + 4, 5); |
215 *expected_result += std::string(kTestFileData2 + 5, 6); | 231 *expected_result += std::string(kTestFileData2 + 5, 6); |
216 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); | 232 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); |
217 } | 233 } |
218 | 234 |
219 // This only works if all the Blob items have a definite pre-computed length. | 235 // This only works if all the Blob items have a definite pre-computed length. |
220 // Otherwise, this will fail a CHECK. | 236 // Otherwise, this will fail a CHECK. |
221 int64 GetTotalBlobLength() const { | 237 int64 GetTotalBlobLength() const { |
222 int64 total = 0; | 238 int64 total = 0; |
223 const std::vector<BlobData::Item>& items = blob_data_->items(); | 239 const std::vector<BlobData::Item>& items = blob_data_->items(); |
224 for (std::vector<BlobData::Item>::const_iterator it = items.begin(); | 240 for (std::vector<BlobData::Item>::const_iterator it = items.begin(); |
225 it != items.end(); ++it) { | 241 it != items.end(); ++it) { |
226 int64 length = base::checked_cast<int64>(it->length()); | 242 int64 length = base::checked_cast<int64>(it->length()); |
227 CHECK(length <= kint64max - total); | 243 CHECK(length <= kint64max - total); |
228 total += length; | 244 total += length; |
229 } | 245 } |
230 return total; | 246 return total; |
231 } | 247 } |
232 | 248 |
233 protected: | 249 protected: |
234 base::ScopedTempDir temp_dir_; | 250 base::ScopedTempDir temp_dir_; |
251 base::FilePath temp_empty_file_; | |
235 base::FilePath temp_file1_; | 252 base::FilePath temp_file1_; |
236 base::FilePath temp_file2_; | 253 base::FilePath temp_file2_; |
254 base::Time temp_empty_file_modification_time_; | |
237 base::Time temp_file_modification_time1_; | 255 base::Time temp_file_modification_time1_; |
238 base::Time temp_file_modification_time2_; | 256 base::Time temp_file_modification_time2_; |
239 GURL file_system_root_url_; | 257 GURL file_system_root_url_; |
258 GURL temp_empty_file_system_file_; | |
240 GURL temp_file_system_file1_; | 259 GURL temp_file_system_file1_; |
241 GURL temp_file_system_file2_; | 260 GURL temp_file_system_file2_; |
261 base::Time temp_empty_file_system_file_modification_time_; | |
242 base::Time temp_file_system_file_modification_time1_; | 262 base::Time temp_file_system_file_modification_time1_; |
243 base::Time temp_file_system_file_modification_time2_; | 263 base::Time temp_file_system_file_modification_time2_; |
244 | 264 |
245 base::MessageLoopForIO message_loop_; | 265 base::MessageLoopForIO message_loop_; |
246 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 266 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
247 scoped_refptr<BlobData> blob_data_; | 267 scoped_refptr<BlobData> blob_data_; |
248 net::URLRequestJobFactoryImpl url_request_job_factory_; | 268 net::URLRequestJobFactoryImpl url_request_job_factory_; |
249 net::URLRequestContext url_request_context_; | 269 net::URLRequestContext url_request_context_; |
250 MockURLRequestDelegate url_request_delegate_; | 270 MockURLRequestDelegate url_request_delegate_; |
251 scoped_ptr<net::URLRequest> request_; | 271 scoped_ptr<net::URLRequest> request_; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 std::string content_type; | 427 std::string content_type; |
408 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); | 428 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); |
409 EXPECT_EQ(kTestContentType, content_type); | 429 EXPECT_EQ(kTestContentType, content_type); |
410 void* iter = NULL; | 430 void* iter = NULL; |
411 std::string content_disposition; | 431 std::string content_disposition; |
412 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( | 432 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( |
413 &iter, "Content-Disposition", &content_disposition)); | 433 &iter, "Content-Disposition", &content_disposition)); |
414 EXPECT_EQ(kTestContentDisposition, content_disposition); | 434 EXPECT_EQ(kTestContentDisposition, content_disposition); |
415 } | 435 } |
416 | 436 |
437 TEST_F(BlobURLRequestJobTest, TestGetEmptyDataRequest) { | |
438 TestSuccessNonrangeRequest("", 0); | |
439 } | |
440 | |
417 } // namespace content | 441 } // namespace content |
OLD | NEW |