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

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

Issue 431143002: Remove failing DCHECKs in Blob code. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback. Created 6 years, 4 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
« no previous file with comments | « no previous file | webkit/browser/blob/blob_storage_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
102 &temp_empty_file_));
103 base::File::Info empty_file_info;
104 base::GetFileInfo(temp_empty_file_, &empty_file_info);
105 temp_empty_file_modification_time_ = empty_file_info.last_modified;
106
101 url_request_job_factory_.SetProtocolHandler("blob", 107 url_request_job_factory_.SetProtocolHandler("blob",
102 new MockProtocolHandler(this)); 108 new MockProtocolHandler(this));
103 url_request_context_.set_job_factory(&url_request_job_factory_); 109 url_request_context_.set_job_factory(&url_request_job_factory_);
104 } 110 }
105 111
106 virtual void TearDown() { 112 virtual void TearDown() {
107 } 113 }
108 114
109 void SetUpFileSystem() { 115 void SetUpFileSystem() {
110 // Prepare file system. 116 // Prepare file system.
(...skipping 13 matching lines...) Expand all
124 const char kFilename1[] = "FileSystemFile1.dat"; 130 const char kFilename1[] = "FileSystemFile1.dat";
125 temp_file_system_file1_ = GetFileSystemURL(kFilename1); 131 temp_file_system_file1_ = GetFileSystemURL(kFilename1);
126 WriteFileSystemFile(kFilename1, kTestFileSystemFileData1, 132 WriteFileSystemFile(kFilename1, kTestFileSystemFileData1,
127 arraysize(kTestFileSystemFileData1) - 1, 133 arraysize(kTestFileSystemFileData1) - 1,
128 &temp_file_system_file_modification_time1_); 134 &temp_file_system_file_modification_time1_);
129 const char kFilename2[] = "FileSystemFile2.dat"; 135 const char kFilename2[] = "FileSystemFile2.dat";
130 temp_file_system_file2_ = GetFileSystemURL(kFilename2); 136 temp_file_system_file2_ = GetFileSystemURL(kFilename2);
131 WriteFileSystemFile(kFilename2, kTestFileSystemFileData2, 137 WriteFileSystemFile(kFilename2, kTestFileSystemFileData2,
132 arraysize(kTestFileSystemFileData2) - 1, 138 arraysize(kTestFileSystemFileData2) - 1,
133 &temp_file_system_file_modification_time2_); 139 &temp_file_system_file_modification_time2_);
140 const char kEmptyFilename[] = "EmptyFileSystemFile.dat";
141 temp_empty_file_system_file_ = GetFileSystemURL(kEmptyFilename);
142 WriteFileSystemFile(kEmptyFilename, kTestFileSystemFileData1,
143 0, &temp_empty_file_system_file_modification_time_);
134 } 144 }
135 145
136 GURL GetFileSystemURL(const std::string& filename) { 146 GURL GetFileSystemURL(const std::string& filename) {
137 return GURL(file_system_root_url_.spec() + filename); 147 return GURL(file_system_root_url_.spec() + filename);
138 } 148 }
139 149
140 void WriteFileSystemFile(const std::string& filename, 150 void WriteFileSystemFile(const std::string& filename,
141 const char* buf, int buf_size, 151 const char* buf, int buf_size,
142 base::Time* modification_time) { 152 base::Time* modification_time) {
143 fileapi::FileSystemURL url = 153 fileapi::FileSystemURL url =
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 211
202 void BuildComplicatedData(std::string* expected_result) { 212 void BuildComplicatedData(std::string* expected_result) {
203 blob_data_->AppendData(kTestData1 + 1, 2); 213 blob_data_->AppendData(kTestData1 + 1, 2);
204 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_); 214 blob_data_->AppendFile(temp_file1_, 2, 3, temp_file_modification_time1_);
205 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 3, 4, 215 blob_data_->AppendFileSystemFile(temp_file_system_file1_, 3, 4,
206 temp_file_system_file_modification_time1_); 216 temp_file_system_file_modification_time1_);
207 blob_data_->AppendData(kTestData2 + 4, 5); 217 blob_data_->AppendData(kTestData2 + 4, 5);
208 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_); 218 blob_data_->AppendFile(temp_file2_, 5, 6, temp_file_modification_time2_);
209 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7, 219 blob_data_->AppendFileSystemFile(temp_file_system_file2_, 6, 7,
210 temp_file_system_file_modification_time2_); 220 temp_file_system_file_modification_time2_);
221 blob_data_->AppendFile(temp_empty_file_, 0, 0,
222 temp_empty_file_modification_time_);
223 blob_data_->AppendFileSystemFile(
224 temp_empty_file_system_file_, 0, 0,
225 temp_empty_file_system_file_modification_time_);
211 *expected_result = std::string(kTestData1 + 1, 2); 226 *expected_result = std::string(kTestData1 + 1, 2);
212 *expected_result += std::string(kTestFileData1 + 2, 3); 227 *expected_result += std::string(kTestFileData1 + 2, 3);
213 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4); 228 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4);
214 *expected_result += std::string(kTestData2 + 4, 5); 229 *expected_result += std::string(kTestData2 + 4, 5);
215 *expected_result += std::string(kTestFileData2 + 5, 6); 230 *expected_result += std::string(kTestFileData2 + 5, 6);
216 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); 231 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7);
217 } 232 }
218 233
219 // This only works if all the Blob items have a definite pre-computed length. 234 // This only works if all the Blob items have a definite pre-computed length.
220 // Otherwise, this will fail a CHECK. 235 // Otherwise, this will fail a CHECK.
221 int64 GetTotalBlobLength() const { 236 int64 GetTotalBlobLength() const {
222 int64 total = 0; 237 int64 total = 0;
223 const std::vector<BlobData::Item>& items = blob_data_->items(); 238 const std::vector<BlobData::Item>& items = blob_data_->items();
224 for (std::vector<BlobData::Item>::const_iterator it = items.begin(); 239 for (std::vector<BlobData::Item>::const_iterator it = items.begin();
225 it != items.end(); ++it) { 240 it != items.end(); ++it) {
226 int64 length = base::checked_cast<int64>(it->length()); 241 int64 length = base::checked_cast<int64>(it->length());
227 CHECK(length <= kint64max - total); 242 CHECK(length <= kint64max - total);
228 total += length; 243 total += length;
229 } 244 }
230 return total; 245 return total;
231 } 246 }
232 247
233 protected: 248 protected:
234 base::ScopedTempDir temp_dir_; 249 base::ScopedTempDir temp_dir_;
250 base::FilePath temp_empty_file_;
235 base::FilePath temp_file1_; 251 base::FilePath temp_file1_;
236 base::FilePath temp_file2_; 252 base::FilePath temp_file2_;
253 base::Time temp_empty_file_modification_time_;
237 base::Time temp_file_modification_time1_; 254 base::Time temp_file_modification_time1_;
238 base::Time temp_file_modification_time2_; 255 base::Time temp_file_modification_time2_;
239 GURL file_system_root_url_; 256 GURL file_system_root_url_;
257 GURL temp_empty_file_system_file_;
240 GURL temp_file_system_file1_; 258 GURL temp_file_system_file1_;
241 GURL temp_file_system_file2_; 259 GURL temp_file_system_file2_;
260 base::Time temp_empty_file_system_file_modification_time_;
242 base::Time temp_file_system_file_modification_time1_; 261 base::Time temp_file_system_file_modification_time1_;
243 base::Time temp_file_system_file_modification_time2_; 262 base::Time temp_file_system_file_modification_time2_;
244 263
245 base::MessageLoopForIO message_loop_; 264 base::MessageLoopForIO message_loop_;
246 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 265 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
247 scoped_refptr<BlobData> blob_data_; 266 scoped_refptr<BlobData> blob_data_;
248 net::URLRequestJobFactoryImpl url_request_job_factory_; 267 net::URLRequestJobFactoryImpl url_request_job_factory_;
249 net::URLRequestContext url_request_context_; 268 net::URLRequestContext url_request_context_;
250 MockURLRequestDelegate url_request_delegate_; 269 MockURLRequestDelegate url_request_delegate_;
251 scoped_ptr<net::URLRequest> request_; 270 scoped_ptr<net::URLRequest> request_;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 std::string content_type; 426 std::string content_type;
408 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); 427 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type));
409 EXPECT_EQ(kTestContentType, content_type); 428 EXPECT_EQ(kTestContentType, content_type);
410 void* iter = NULL; 429 void* iter = NULL;
411 std::string content_disposition; 430 std::string content_disposition;
412 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( 431 EXPECT_TRUE(request_->response_headers()->EnumerateHeader(
413 &iter, "Content-Disposition", &content_disposition)); 432 &iter, "Content-Disposition", &content_disposition));
414 EXPECT_EQ(kTestContentDisposition, content_disposition); 433 EXPECT_EQ(kTestContentDisposition, content_disposition);
415 } 434 }
416 435
436 TEST_F(BlobURLRequestJobTest, TestGetEmptyDataRequest) {
437 TestSuccessNonrangeRequest("", 0);
438 }
439
417 } // namespace content 440 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | webkit/browser/blob/blob_storage_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698