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

Side by Side Diff: webkit/blob/blob_url_request_job_unittest.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « webkit/blob/blob_storage_controller.cc ('k') | webkit/blob/local_file_stream_reader.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return GURL(file_system_root_url_.spec() + filename); 202 return GURL(file_system_root_url_.spec() + filename);
203 } 203 }
204 204
205 void WriteFileSystemFile(const std::string& filename, 205 void WriteFileSystemFile(const std::string& filename,
206 const char* buf, int buf_size, 206 const char* buf, int buf_size,
207 base::Time* modification_time) { 207 base::Time* modification_time) {
208 fileapi::FileSystemURL url = 208 fileapi::FileSystemURL url =
209 file_system_context_->CreateCrackedFileSystemURL( 209 file_system_context_->CreateCrackedFileSystemURL(
210 GURL(kFileSystemURLOrigin), 210 GURL(kFileSystemURLOrigin),
211 kFileSystemType, 211 kFileSystemType,
212 FilePath().AppendASCII(filename)); 212 base::FilePath().AppendASCII(filename));
213 213
214 fileapi::FileSystemFileUtil* file_util = 214 fileapi::FileSystemFileUtil* file_util =
215 file_system_context_->GetFileUtil(kFileSystemType); 215 file_system_context_->GetFileUtil(kFileSystemType);
216 216
217 fileapi::FileSystemOperationContext context(file_system_context_); 217 fileapi::FileSystemOperationContext context(file_system_context_);
218 context.set_allowed_bytes_growth(1024); 218 context.set_allowed_bytes_growth(1024);
219 219
220 base::PlatformFile handle = base::kInvalidPlatformFileValue; 220 base::PlatformFile handle = base::kInvalidPlatformFileValue;
221 bool created = false; 221 bool created = false;
222 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen( 222 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen(
223 &context, 223 &context,
224 url, 224 url,
225 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, 225 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
226 &handle, 226 &handle,
227 &created)); 227 &created));
228 EXPECT_TRUE(created); 228 EXPECT_TRUE(created);
229 ASSERT_NE(base::kInvalidPlatformFileValue, handle); 229 ASSERT_NE(base::kInvalidPlatformFileValue, handle);
230 ASSERT_EQ(buf_size, 230 ASSERT_EQ(buf_size,
231 base::WritePlatformFile(handle, 0 /* offset */, buf, buf_size)); 231 base::WritePlatformFile(handle, 0 /* offset */, buf, buf_size));
232 base::ClosePlatformFile(handle); 232 base::ClosePlatformFile(handle);
233 233
234 base::PlatformFileInfo file_info; 234 base::PlatformFileInfo file_info;
235 FilePath platform_path; 235 base::FilePath platform_path;
236 ASSERT_EQ(base::PLATFORM_FILE_OK, 236 ASSERT_EQ(base::PLATFORM_FILE_OK,
237 file_util->GetFileInfo(&context, url, &file_info, 237 file_util->GetFileInfo(&context, url, &file_info,
238 &platform_path)); 238 &platform_path));
239 if (modification_time) 239 if (modification_time)
240 *modification_time = file_info.last_modified; 240 *modification_time = file_info.last_modified;
241 } 241 }
242 242
243 void OnValidateFileSystem(base::PlatformFileError result, 243 void OnValidateFileSystem(base::PlatformFileError result,
244 const std::string& name, 244 const std::string& name,
245 const GURL& root) { 245 const GURL& root) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 *expected_result = std::string(kTestData1 + 1, 2); 290 *expected_result = std::string(kTestData1 + 1, 2);
291 *expected_result += std::string(kTestFileData1 + 2, 3); 291 *expected_result += std::string(kTestFileData1 + 2, 3);
292 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4); 292 *expected_result += std::string(kTestFileSystemFileData1 + 3, 4);
293 *expected_result += std::string(kTestData2 + 4, 5); 293 *expected_result += std::string(kTestData2 + 4, 5);
294 *expected_result += std::string(kTestFileData2 + 5, 6); 294 *expected_result += std::string(kTestFileData2 + 5, 6);
295 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7); 295 *expected_result += std::string(kTestFileSystemFileData2 + 6, 7);
296 } 296 }
297 297
298 protected: 298 protected:
299 base::ScopedTempDir temp_dir_; 299 base::ScopedTempDir temp_dir_;
300 FilePath temp_file1_; 300 base::FilePath temp_file1_;
301 FilePath temp_file2_; 301 base::FilePath temp_file2_;
302 base::Time temp_file_modification_time1_; 302 base::Time temp_file_modification_time1_;
303 base::Time temp_file_modification_time2_; 303 base::Time temp_file_modification_time2_;
304 GURL file_system_root_url_; 304 GURL file_system_root_url_;
305 GURL temp_file_system_file1_; 305 GURL temp_file_system_file1_;
306 GURL temp_file_system_file2_; 306 GURL temp_file_system_file2_;
307 base::Time temp_file_system_file_modification_time1_; 307 base::Time temp_file_system_file_modification_time1_;
308 base::Time temp_file_system_file_modification_time2_; 308 base::Time temp_file_system_file_modification_time2_;
309 309
310 MessageLoop message_loop_; 310 MessageLoop message_loop_;
311 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 311 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
(...skipping 11 matching lines...) Expand all
323 blob_data_->AppendData(kTestData1); 323 blob_data_->AppendData(kTestData1);
324 TestSuccessRequest(kTestData1); 324 TestSuccessRequest(kTestData1);
325 } 325 }
326 326
327 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) { 327 TEST_F(BlobURLRequestJobTest, TestGetSimpleFileRequest) {
328 blob_data_->AppendFile(temp_file1_, 0, -1, base::Time()); 328 blob_data_->AppendFile(temp_file1_, 0, -1, base::Time());
329 TestSuccessRequest(kTestFileData1); 329 TestSuccessRequest(kTestFileData1);
330 } 330 }
331 331
332 TEST_F(BlobURLRequestJobTest, TestGetLargeFileRequest) { 332 TEST_F(BlobURLRequestJobTest, TestGetLargeFileRequest) {
333 FilePath large_temp_file = temp_dir_.path().AppendASCII("LargeBlob.dat"); 333 base::FilePath large_temp_file = temp_dir_.path().AppendASCII("LargeBlob.dat") ;
334 std::string large_data; 334 std::string large_data;
335 large_data.reserve(kBufferSize * 5); 335 large_data.reserve(kBufferSize * 5);
336 for (int i = 0; i < kBufferSize * 5; ++i) 336 for (int i = 0; i < kBufferSize * 5; ++i)
337 large_data.append(1, static_cast<char>(i % 256)); 337 large_data.append(1, static_cast<char>(i % 256));
338 ASSERT_EQ(static_cast<int>(large_data.size()), 338 ASSERT_EQ(static_cast<int>(large_data.size()),
339 file_util::WriteFile(large_temp_file, large_data.data(), 339 file_util::WriteFile(large_temp_file, large_data.data(),
340 large_data.size())); 340 large_data.size()));
341 blob_data_->AppendFile(large_temp_file, 0, -1, base::Time()); 341 blob_data_->AppendFile(large_temp_file, 0, -1, base::Time());
342 TestSuccessRequest(large_data); 342 TestSuccessRequest(large_data);
343 } 343 }
344 344
345 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) { 345 TEST_F(BlobURLRequestJobTest, TestGetNonExistentFileRequest) {
346 FilePath non_existent_file = 346 base::FilePath non_existent_file =
347 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na")); 347 temp_file1_.InsertBeforeExtension(FILE_PATH_LITERAL("-na"));
348 blob_data_->AppendFile(non_existent_file, 0, -1, base::Time()); 348 blob_data_->AppendFile(non_existent_file, 0, -1, base::Time());
349 TestErrorRequest(404); 349 TestErrorRequest(404);
350 } 350 }
351 351
352 TEST_F(BlobURLRequestJobTest, TestGetChangedFileRequest) { 352 TEST_F(BlobURLRequestJobTest, TestGetChangedFileRequest) {
353 base::Time old_time = 353 base::Time old_time =
354 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10); 354 temp_file_modification_time1_ - base::TimeDelta::FromSeconds(10);
355 blob_data_->AppendFile(temp_file1_, 0, 3, old_time); 355 blob_data_->AppendFile(temp_file1_, 0, 3, old_time);
356 TestErrorRequest(404); 356 TestErrorRequest(404);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type)); 449 EXPECT_TRUE(request_->response_headers()->GetMimeType(&content_type));
450 EXPECT_EQ(kTestContentType, content_type); 450 EXPECT_EQ(kTestContentType, content_type);
451 void* iter = NULL; 451 void* iter = NULL;
452 std::string content_disposition; 452 std::string content_disposition;
453 EXPECT_TRUE(request_->response_headers()->EnumerateHeader( 453 EXPECT_TRUE(request_->response_headers()->EnumerateHeader(
454 &iter, "Content-Disposition", &content_disposition)); 454 &iter, "Content-Disposition", &content_disposition));
455 EXPECT_EQ(kTestContentDisposition, content_disposition); 455 EXPECT_EQ(kTestContentDisposition, content_disposition);
456 } 456 }
457 457
458 } // namespace webkit_blob 458 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/blob_storage_controller.cc ('k') | webkit/blob/local_file_stream_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698