OLD | NEW |
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 <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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 protected: | 80 protected: |
81 virtual void SetUp() OVERRIDE; | 81 virtual void SetUp() OVERRIDE; |
82 virtual void TearDown() OVERRIDE; | 82 virtual void TearDown() OVERRIDE; |
83 | 83 |
84 FileSystemFileUtil* file_util() { | 84 FileSystemFileUtil* file_util() { |
85 return file_system_context_->GetFileUtil(kFileSystemType); | 85 return file_system_context_->GetFileUtil(kFileSystemType); |
86 } | 86 } |
87 | 87 |
88 int64 usage() { | 88 int64 usage() { |
89 return file_system_context_->GetQuotaUtil(kFileSystemType)-> | 89 return file_system_context_->GetQuotaUtil(kFileSystemType) |
90 GetOriginUsageOnFileThread(file_system_context_, | 90 ->GetOriginUsageOnFileThread( |
91 kOrigin, | 91 file_system_context_.get(), kOrigin, kFileSystemType); |
92 kFileSystemType); | |
93 } | 92 } |
94 | 93 |
95 int64 GetFileSizeOnDisk(const char* test_file_path) { | 94 int64 GetFileSizeOnDisk(const char* test_file_path) { |
96 // There might be in-flight flush/write. | 95 // There might be in-flight flush/write. |
97 base::MessageLoop::current()->PostTask( | 96 base::MessageLoop::current()->PostTask( |
98 FROM_HERE, base::Bind(&base::DoNothing)); | 97 FROM_HERE, base::Bind(&base::DoNothing)); |
99 base::MessageLoop::current()->RunUntilIdle(); | 98 base::MessageLoop::current()->RunUntilIdle(); |
100 | 99 |
101 FileSystemURL url = GetFileSystemURL(test_file_path); | 100 FileSystemURL url = GetFileSystemURL(test_file_path); |
102 base::PlatformFileInfo file_info; | 101 base::PlatformFileInfo file_info; |
103 base::FilePath platform_path; | 102 base::FilePath platform_path; |
104 EXPECT_EQ(base::PLATFORM_FILE_OK, | 103 EXPECT_EQ(base::PLATFORM_FILE_OK, |
105 file_util()->GetFileInfo(NewOperationContext().get(), url, | 104 file_util()->GetFileInfo(NewOperationContext().get(), url, |
106 &file_info, &platform_path)); | 105 &file_info, &platform_path)); |
107 return file_info.size; | 106 return file_info.size; |
108 } | 107 } |
109 | 108 |
110 FileSystemURL GetFileSystemURL(const char* file_name) const { | 109 FileSystemURL GetFileSystemURL(const char* file_name) const { |
111 return file_system_context_->CreateCrackedFileSystemURL( | 110 return file_system_context_->CreateCrackedFileSystemURL( |
112 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); | 111 kOrigin, kFileSystemType, base::FilePath().FromUTF8Unsafe(file_name)); |
113 } | 112 } |
114 | 113 |
115 scoped_ptr<FileSystemOperationContext> NewOperationContext() { | 114 scoped_ptr<FileSystemOperationContext> NewOperationContext() { |
116 FileSystemOperationContext* context = | 115 FileSystemOperationContext* context = |
117 new FileSystemOperationContext(file_system_context_); | 116 new FileSystemOperationContext(file_system_context_.get()); |
118 context->set_update_observers( | 117 context->set_update_observers( |
119 *file_system_context_->GetUpdateObservers(kFileSystemType)); | 118 *file_system_context_->GetUpdateObservers(kFileSystemType)); |
120 context->set_root_path(dir_.path()); | 119 context->set_root_path(dir_.path()); |
121 return make_scoped_ptr(context); | 120 return make_scoped_ptr(context); |
122 } | 121 } |
123 | 122 |
124 FileWriterDelegate* CreateWriterDelegate( | 123 FileWriterDelegate* CreateWriterDelegate( |
125 const char* test_file_path, | 124 const char* test_file_path, |
126 int64 offset, | 125 int64 offset, |
127 int64 allowed_growth, | 126 int64 allowed_growth, |
128 Result* result) { | 127 Result* result) { |
129 SandboxFileStreamWriter* writer = new SandboxFileStreamWriter( | 128 SandboxFileStreamWriter* writer = new SandboxFileStreamWriter( |
130 file_system_context_, | 129 file_system_context_.get(), |
131 GetFileSystemURL(test_file_path), | 130 GetFileSystemURL(test_file_path), |
132 offset, | 131 offset, |
133 *file_system_context_->GetUpdateObservers(kFileSystemType)); | 132 *file_system_context_->GetUpdateObservers(kFileSystemType)); |
134 writer->set_default_quota(allowed_growth); | 133 writer->set_default_quota(allowed_growth); |
135 return new FileWriterDelegate( | 134 return new FileWriterDelegate( |
136 base::Bind(&Result::DidWrite, base::Unretained(result)), | 135 base::Bind(&Result::DidWrite, base::Unretained(result)), |
137 scoped_ptr<FileStreamWriter>(writer)); | 136 scoped_ptr<FileStreamWriter>(writer)); |
138 } | 137 } |
139 | 138 |
140 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, | 139 // Creates and sets up a FileWriterDelegate for writing the given |blob_url|, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 file_writer_delegate_.reset(); | 456 file_writer_delegate_.reset(); |
458 | 457 |
459 EXPECT_EQ(pre_write_usage + allowed_growth, | 458 EXPECT_EQ(pre_write_usage + allowed_growth, |
460 usage()); | 459 usage()); |
461 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); | 460 EXPECT_EQ(GetFileSizeOnDisk("test"), usage()); |
462 EXPECT_EQ(kOverlap + allowed_growth, result_->bytes_written()); | 461 EXPECT_EQ(kOverlap + allowed_growth, result_->bytes_written()); |
463 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); | 462 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status()); |
464 } | 463 } |
465 | 464 |
466 } // namespace fileapi | 465 } // namespace fileapi |
OLD | NEW |