| 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 11 matching lines...) Expand all Loading... |
| 22 #include "webkit/blob/blob_storage_controller.h" | 22 #include "webkit/blob/blob_storage_controller.h" |
| 23 #include "webkit/blob/blob_url_request_job.h" | 23 #include "webkit/blob/blob_url_request_job.h" |
| 24 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 24 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 25 #include "webkit/fileapi/file_system_context.h" | 25 #include "webkit/fileapi/file_system_context.h" |
| 26 #include "webkit/fileapi/file_system_file_util.h" | 26 #include "webkit/fileapi/file_system_file_util.h" |
| 27 #include "webkit/fileapi/file_system_operation.h" | 27 #include "webkit/fileapi/file_system_operation.h" |
| 28 #include "webkit/fileapi/file_system_path_manager.h" | 28 #include "webkit/fileapi/file_system_path_manager.h" |
| 29 #include "webkit/fileapi/file_system_test_helper.h" | 29 #include "webkit/fileapi/file_system_test_helper.h" |
| 30 #include "webkit/fileapi/file_system_util.h" | 30 #include "webkit/fileapi/file_system_util.h" |
| 31 #include "webkit/fileapi/local_file_system_file_util.h" | 31 #include "webkit/fileapi/local_file_system_file_util.h" |
| 32 #include "webkit/fileapi/quota_file_util.h" |
| 32 #include "webkit/quota/quota_manager.h" | 33 #include "webkit/quota/quota_manager.h" |
| 33 | 34 |
| 34 using quota::QuotaManager; | 35 using quota::QuotaManager; |
| 35 | 36 |
| 36 namespace fileapi { | 37 namespace fileapi { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 class MockQuotaManager : public QuotaManager { | 41 class MockQuotaManager : public QuotaManager { |
| 41 public: | 42 public: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 bool complete() const { return complete_; } | 91 bool complete() const { return complete_; } |
| 91 | 92 |
| 92 virtual void SetUp(); | 93 virtual void SetUp(); |
| 93 virtual void TearDown(); | 94 virtual void TearDown(); |
| 94 | 95 |
| 95 protected: | 96 protected: |
| 96 GURL URLForPath(const FilePath& path) const { | 97 GURL URLForPath(const FilePath& path) const { |
| 97 return test_helper_.GetURLForPath(path); | 98 return test_helper_.GetURLForPath(path); |
| 98 } | 99 } |
| 99 | 100 |
| 101 scoped_ptr<LocalFileSystemFileUtil> local_file_util_; |
| 100 scoped_refptr<MockQuotaManager> quota_manager_; | 102 scoped_refptr<MockQuotaManager> quota_manager_; |
| 101 FileSystemTestOriginHelper test_helper_; | 103 FileSystemTestOriginHelper test_helper_; |
| 102 | 104 |
| 103 MessageLoop loop_; | 105 MessageLoop loop_; |
| 104 | 106 |
| 105 ScopedTempDir dir_; | 107 ScopedTempDir dir_; |
| 106 FilePath filesystem_dir_; | 108 FilePath filesystem_dir_; |
| 107 FilePath file_; | 109 FilePath file_; |
| 108 FilePath virtual_path_; | 110 FilePath virtual_path_; |
| 109 | 111 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 private: | 178 private: |
| 177 FileSystemOperationWriteTest* test_; | 179 FileSystemOperationWriteTest* test_; |
| 178 }; | 180 }; |
| 179 | 181 |
| 180 } // namespace (anonymous) | 182 } // namespace (anonymous) |
| 181 | 183 |
| 182 void FileSystemOperationWriteTest::SetUp() { | 184 void FileSystemOperationWriteTest::SetUp() { |
| 183 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 185 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
| 184 FilePath base_dir = dir_.path().AppendASCII("filesystem"); | 186 FilePath base_dir = dir_.path().AppendASCII("filesystem"); |
| 185 | 187 |
| 188 local_file_util_.reset( |
| 189 new LocalFileSystemFileUtil(QuotaFileUtil::GetInstance())); |
| 186 quota_manager_ = new MockQuotaManager(base_dir, 1024); | 190 quota_manager_ = new MockQuotaManager(base_dir, 1024); |
| 187 test_helper_.SetUp(base_dir, | 191 test_helper_.SetUp(base_dir, |
| 188 false /* incognito */, | 192 false /* incognito */, |
| 189 false /* unlimited quota */, | 193 false /* unlimited quota */, |
| 190 quota_manager_->proxy(), | 194 quota_manager_->proxy(), |
| 191 LocalFileSystemFileUtil::GetInstance()); | 195 local_file_util_.get()); |
| 192 filesystem_dir_ = test_helper_.GetOriginRootPath(); | 196 filesystem_dir_ = test_helper_.GetOriginRootPath(); |
| 193 | 197 |
| 194 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_, &file_)); | 198 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_, &file_)); |
| 195 virtual_path_ = file_.BaseName(); | 199 virtual_path_ = file_.BaseName(); |
| 196 | 200 |
| 197 net::URLRequest::RegisterProtocolFactory("blob", &BlobURLRequestJobFactory); | 201 net::URLRequest::RegisterProtocolFactory("blob", &BlobURLRequestJobFactory); |
| 198 } | 202 } |
| 199 | 203 |
| 200 void FileSystemOperationWriteTest::TearDown() { | 204 void FileSystemOperationWriteTest::TearDown() { |
| 201 net::URLRequest::RegisterProtocolFactory("blob", NULL); | 205 net::URLRequest::RegisterProtocolFactory("blob", NULL); |
| 202 quota_manager_ = NULL; | 206 quota_manager_ = NULL; |
| 203 test_helper_.TearDown(); | 207 test_helper_.TearDown(); |
| 208 local_file_util_.reset(); |
| 204 } | 209 } |
| 205 | 210 |
| 206 FileSystemOperation* FileSystemOperationWriteTest::operation() { | 211 FileSystemOperation* FileSystemOperationWriteTest::operation() { |
| 207 return test_helper_.NewOperation(new MockDispatcher(this)); | 212 return test_helper_.NewOperation(new MockDispatcher(this)); |
| 208 } | 213 } |
| 209 | 214 |
| 210 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { | 215 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { |
| 211 GURL blob_url("blob:success"); | 216 GURL blob_url("blob:success"); |
| 212 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 217 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 213 blob_data->AppendData("Hello, world!\n"); | 218 blob_data->AppendData("Hello, world!\n"); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); | 334 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); |
| 330 | 335 |
| 331 EXPECT_EQ(10, bytes_written()); | 336 EXPECT_EQ(10, bytes_written()); |
| 332 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 337 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 333 EXPECT_TRUE(complete()); | 338 EXPECT_TRUE(complete()); |
| 334 } | 339 } |
| 335 | 340 |
| 336 // TODO(ericu,dmikurube): Add tests for Cancel. | 341 // TODO(ericu,dmikurube): Add tests for Cancel. |
| 337 | 342 |
| 338 } // namespace fileapi | 343 } // namespace fileapi |
| OLD | NEW |