| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) | 5 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) |
| 6 // rather than as part of test_shell_tests because they rely on being able | 6 // rather than as part of test_shell_tests because they rely on being able |
| 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses | 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses |
| 8 // TYPE_UI, which URLRequest doesn't allow. | 8 // TYPE_UI, which URLRequest doesn't allow. |
| 9 // | 9 // |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 public: | 75 public: |
| 76 FileWriterDelegateTest() | 76 FileWriterDelegateTest() |
| 77 : loop_(MessageLoop::TYPE_IO), | 77 : loop_(MessageLoop::TYPE_IO), |
| 78 file_(base::kInvalidPlatformFileValue) {} | 78 file_(base::kInvalidPlatformFileValue) {} |
| 79 | 79 |
| 80 protected: | 80 protected: |
| 81 virtual void SetUp(); | 81 virtual void SetUp(); |
| 82 virtual void TearDown(); | 82 virtual void TearDown(); |
| 83 | 83 |
| 84 virtual void SetUpTestHelper(const FilePath& base_dir) { | 84 virtual void SetUpTestHelper(const FilePath& base_dir) { |
| 85 test_helper_.SetUp(base_dir, QuotaFileUtil::GetInstance()); | 85 quota_file_util_.reset(QuotaFileUtil::CreateDefault()); |
| 86 test_helper_.SetUp(base_dir, quota_file_util_.get()); |
| 86 } | 87 } |
| 87 | 88 |
| 88 int64 ComputeCurrentOriginUsage() { | 89 int64 ComputeCurrentOriginUsage() { |
| 89 base::FlushPlatformFile(file_); | 90 base::FlushPlatformFile(file_); |
| 90 return test_helper_.ComputeCurrentOriginUsage(); | 91 return test_helper_.ComputeCurrentOriginUsage(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 // Creates and sets up a FileWriterDelegate for writing the given |blob_url| | 94 // Creates and sets up a FileWriterDelegate for writing the given |blob_url| |
| 94 // to a file (file_) from |offset| with |allowed_growth| quota setting. | 95 // to a file (file_) from |offset| with |allowed_growth| quota setting. |
| 95 void PrepareForWrite(const GURL& blob_url, | 96 void PrepareForWrite(const GURL& blob_url, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 108 file_writer_delegate_.reset(new FileWriterDelegate( | 109 file_writer_delegate_.reset(new FileWriterDelegate( |
| 109 CreateNewOperation(result_.get(), allowed_growth), | 110 CreateNewOperation(result_.get(), allowed_growth), |
| 110 offset, base::MessageLoopProxy::CreateForCurrentThread())); | 111 offset, base::MessageLoopProxy::CreateForCurrentThread())); |
| 111 request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get())); | 112 request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get())); |
| 112 } | 113 } |
| 113 | 114 |
| 114 FileSystemOperation* CreateNewOperation(Result* result, int64 quota); | 115 FileSystemOperation* CreateNewOperation(Result* result, int64 quota); |
| 115 | 116 |
| 116 static net::URLRequest::ProtocolFactory Factory; | 117 static net::URLRequest::ProtocolFactory Factory; |
| 117 | 118 |
| 119 scoped_ptr<QuotaFileUtil> quota_file_util_; |
| 118 scoped_ptr<FileWriterDelegate> file_writer_delegate_; | 120 scoped_ptr<FileWriterDelegate> file_writer_delegate_; |
| 119 scoped_ptr<net::URLRequest> request_; | 121 scoped_ptr<net::URLRequest> request_; |
| 120 scoped_ptr<Result> result_; | 122 scoped_ptr<Result> result_; |
| 121 FileSystemTestOriginHelper test_helper_; | 123 FileSystemTestOriginHelper test_helper_; |
| 122 | 124 |
| 123 MessageLoop loop_; | 125 MessageLoop loop_; |
| 124 ScopedTempDir dir_; | 126 ScopedTempDir dir_; |
| 125 FilePath file_path_; | 127 FilePath file_path_; |
| 126 PlatformFile file_; | 128 PlatformFile file_; |
| 127 | 129 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); | 475 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); |
| 474 EXPECT_TRUE(result_->complete()); | 476 EXPECT_TRUE(result_->complete()); |
| 475 } | 477 } |
| 476 | 478 |
| 477 class FileWriterDelegateUnlimitedTest : public FileWriterDelegateTest { | 479 class FileWriterDelegateUnlimitedTest : public FileWriterDelegateTest { |
| 478 protected: | 480 protected: |
| 479 virtual void SetUpTestHelper(const FilePath& path) OVERRIDE; | 481 virtual void SetUpTestHelper(const FilePath& path) OVERRIDE; |
| 480 }; | 482 }; |
| 481 | 483 |
| 482 void FileWriterDelegateUnlimitedTest::SetUpTestHelper(const FilePath& path) { | 484 void FileWriterDelegateUnlimitedTest::SetUpTestHelper(const FilePath& path) { |
| 485 quota_file_util_.reset(QuotaFileUtil::CreateDefault()); |
| 483 test_helper_.SetUp( | 486 test_helper_.SetUp( |
| 484 path, | 487 path, |
| 485 false /* incognito */, | 488 false /* incognito */, |
| 486 true /* unlimited */, | 489 true /* unlimited */, |
| 487 NULL /* quota manager proxy */, | 490 NULL /* quota manager proxy */, |
| 488 QuotaFileUtil::GetInstance()); | 491 quota_file_util_.get()); |
| 489 } | 492 } |
| 490 | 493 |
| 491 TEST_F(FileWriterDelegateUnlimitedTest, WriteWithQuota) { | 494 TEST_F(FileWriterDelegateUnlimitedTest, WriteWithQuota) { |
| 492 const GURL kBlobURL("blob:with-unlimited"); | 495 const GURL kBlobURL("blob:with-unlimited"); |
| 493 content_ = kData; | 496 content_ = kData; |
| 494 | 497 |
| 495 // Set small allowed_growth bytes | 498 // Set small allowed_growth bytes |
| 496 PrepareForWrite(kBlobURL, 0, 10); | 499 PrepareForWrite(kBlobURL, 0, 10); |
| 497 | 500 |
| 498 // We shouldn't fail as the context is configured as 'unlimited'. | 501 // We shouldn't fail as the context is configured as 'unlimited'. |
| 499 file_writer_delegate_->Start(file_, request_.get()); | 502 file_writer_delegate_->Start(file_, request_.get()); |
| 500 MessageLoop::current()->Run(); | 503 MessageLoop::current()->Run(); |
| 501 EXPECT_EQ(kDataSize + FileSystemUsageCache::kUsageFileSize, | 504 EXPECT_EQ(kDataSize + FileSystemUsageCache::kUsageFileSize, |
| 502 test_helper_.GetCachedOriginUsage()); | 505 test_helper_.GetCachedOriginUsage()); |
| 503 EXPECT_EQ(ComputeCurrentOriginUsage() + FileSystemUsageCache::kUsageFileSize, | 506 EXPECT_EQ(ComputeCurrentOriginUsage() + FileSystemUsageCache::kUsageFileSize, |
| 504 test_helper_.GetCachedOriginUsage()); | 507 test_helper_.GetCachedOriginUsage()); |
| 505 EXPECT_EQ(kDataSize, result_->bytes_written()); | 508 EXPECT_EQ(kDataSize, result_->bytes_written()); |
| 506 EXPECT_EQ(base::PLATFORM_FILE_OK, result_->status()); | 509 EXPECT_EQ(base::PLATFORM_FILE_OK, result_->status()); |
| 507 EXPECT_TRUE(result_->complete()); | 510 EXPECT_TRUE(result_->complete()); |
| 508 } | 511 } |
| 509 | 512 |
| 510 } // namespace fileapi | 513 } // namespace fileapi |
| OLD | NEW |