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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 int64 GetFileSizeOnDisk(const char* test_file_path) { | 96 int64 GetFileSizeOnDisk(const char* test_file_path) { |
97 // There might be in-flight flush/write. | 97 // There might be in-flight flush/write. |
98 base::MessageLoop::current()->PostTask( | 98 base::MessageLoop::current()->PostTask( |
99 FROM_HERE, base::Bind(&base::DoNothing)); | 99 FROM_HERE, base::Bind(&base::DoNothing)); |
100 base::RunLoop().RunUntilIdle(); | 100 base::RunLoop().RunUntilIdle(); |
101 | 101 |
102 FileSystemURL url = GetFileSystemURL(test_file_path); | 102 FileSystemURL url = GetFileSystemURL(test_file_path); |
103 base::File::Info file_info; | 103 base::File::Info file_info; |
104 EXPECT_EQ(base::File::FILE_OK, | 104 EXPECT_EQ(base::File::FILE_OK, |
105 AsyncFileTestHelper::GetMetadata( | 105 AsyncFileTestHelper::GetMetadata( |
106 file_system_context_, url, &file_info)); | 106 file_system_context_.get(), url, &file_info)); |
107 return file_info.size; | 107 return file_info.size; |
108 } | 108 } |
109 | 109 |
110 FileSystemURL GetFileSystemURL(const char* file_name) const { | 110 FileSystemURL GetFileSystemURL(const char* file_name) const { |
111 return file_system_context_->CreateCrackedFileSystemURL( | 111 return file_system_context_->CreateCrackedFileSystemURL( |
112 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); | 112 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); |
113 } | 113 } |
114 | 114 |
115 FileWriterDelegate* CreateWriterDelegate( | 115 FileWriterDelegate* CreateWriterDelegate( |
116 const char* test_file_path, | 116 const char* test_file_path, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 }; | 242 }; |
243 | 243 |
244 } // namespace (anonymous) | 244 } // namespace (anonymous) |
245 | 245 |
246 void FileWriterDelegateTest::SetUp() { | 246 void FileWriterDelegateTest::SetUp() { |
247 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 247 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
248 | 248 |
249 file_system_context_ = CreateFileSystemContextForTesting( | 249 file_system_context_ = CreateFileSystemContextForTesting( |
250 NULL, dir_.path()); | 250 NULL, dir_.path()); |
251 ASSERT_EQ(base::File::FILE_OK, | 251 ASSERT_EQ(base::File::FILE_OK, |
252 AsyncFileTestHelper::CreateFile( | 252 AsyncFileTestHelper::CreateFile(file_system_context_.get(), |
253 file_system_context_, GetFileSystemURL("test"))); | 253 GetFileSystemURL("test"))); |
254 job_factory_.reset(new BlobURLRequestJobFactory(&content_)); | 254 job_factory_.reset(new BlobURLRequestJobFactory(&content_)); |
255 empty_context_.set_job_factory(job_factory_.get()); | 255 empty_context_.set_job_factory(job_factory_.get()); |
256 } | 256 } |
257 | 257 |
258 void FileWriterDelegateTest::TearDown() { | 258 void FileWriterDelegateTest::TearDown() { |
259 file_system_context_ = NULL; | 259 file_system_context_ = NULL; |
260 base::RunLoop().RunUntilIdle(); | 260 base::RunLoop().RunUntilIdle(); |
261 } | 261 } |
262 | 262 |
263 TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimit) { | 263 TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimit) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 EXPECT_EQ(kAllowedGrowth, result.bytes_written()); | 340 EXPECT_EQ(kAllowedGrowth, result.bytes_written()); |
341 EXPECT_EQ(base::File::FILE_OK, result.status()); | 341 EXPECT_EQ(base::File::FILE_OK, result.status()); |
342 ASSERT_EQ(FileWriterDelegate::SUCCESS_COMPLETED, result.write_status()); | 342 ASSERT_EQ(FileWriterDelegate::SUCCESS_COMPLETED, result.write_status()); |
343 } | 343 } |
344 | 344 |
345 TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimitConcurrent) { | 345 TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimitConcurrent) { |
346 scoped_ptr<FileWriterDelegate> file_writer_delegate2; | 346 scoped_ptr<FileWriterDelegate> file_writer_delegate2; |
347 scoped_ptr<net::URLRequest> request2; | 347 scoped_ptr<net::URLRequest> request2; |
348 | 348 |
349 ASSERT_EQ(base::File::FILE_OK, | 349 ASSERT_EQ(base::File::FILE_OK, |
350 AsyncFileTestHelper::CreateFile( | 350 AsyncFileTestHelper::CreateFile(file_system_context_.get(), |
351 file_system_context_, GetFileSystemURL("test2"))); | 351 GetFileSystemURL("test2"))); |
352 | 352 |
353 const GURL kBlobURL("blob:nolimitconcurrent"); | 353 const GURL kBlobURL("blob:nolimitconcurrent"); |
354 const GURL kBlobURL2("blob:nolimitconcurrent2"); | 354 const GURL kBlobURL2("blob:nolimitconcurrent2"); |
355 content_ = kData; | 355 content_ = kData; |
356 | 356 |
357 PrepareForWrite("test", kBlobURL, 0, kint64max); | 357 PrepareForWrite("test", kBlobURL, 0, kint64max); |
358 | 358 |
359 // Credate another FileWriterDelegate for concurrent write. | 359 // Credate another FileWriterDelegate for concurrent write. |
360 file_writer_delegate2.reset(CreateWriterDelegate("test2", 0, kint64max)); | 360 file_writer_delegate2.reset(CreateWriterDelegate("test2", 0, kint64max)); |
361 request2 = empty_context_.CreateRequest( | 361 request2 = empty_context_.CreateRequest( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 file_writer_delegate_.reset(); | 477 file_writer_delegate_.reset(); |
478 | 478 |
479 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); | 479 EXPECT_EQ(pre_write_usage + allowed_growth, usage()); |
480 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); | 480 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); |
481 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); | 481 EXPECT_EQ(kOverlap + allowed_growth, result.bytes_written()); |
482 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); | 482 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, result.status()); |
483 } | 483 } |
484 } | 484 } |
485 | 485 |
486 } // namespace content | 486 } // namespace content |
OLD | NEW |