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

Side by Side Diff: webkit/fileapi/quota_file_util_unittest.cc

Issue 7312023: Refactoring: Change all -FileUtils non-Singleton and to own underlying FileUtils. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reflected the comments. Created 9 years, 4 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/fileapi/quota_file_util.cc ('k') | webkit/fileapi/sandbox_mount_point_provider.cc » ('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) 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 #include "webkit/fileapi/quota_file_util.h" 5 #include "webkit/fileapi/quota_file_util.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/memory/scoped_callback_factory.h" 8 #include "base/memory/scoped_callback_factory.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webkit/fileapi/file_system_context.h" 13 #include "webkit/fileapi/file_system_context.h"
14 #include "webkit/fileapi/file_system_file_util.h" 14 #include "webkit/fileapi/file_system_file_util.h"
15 #include "webkit/fileapi/file_system_operation_context.h" 15 #include "webkit/fileapi/file_system_operation_context.h"
16 #include "webkit/fileapi/file_system_path_manager.h" 16 #include "webkit/fileapi/file_system_path_manager.h"
17 #include "webkit/fileapi/file_system_test_helper.h" 17 #include "webkit/fileapi/file_system_test_helper.h"
18 #include "webkit/fileapi/file_system_types.h" 18 #include "webkit/fileapi/file_system_types.h"
19 #include "webkit/fileapi/file_system_usage_cache.h" 19 #include "webkit/fileapi/file_system_usage_cache.h"
20 #include "webkit/fileapi/quota_file_util.h" 20 #include "webkit/fileapi/quota_file_util.h"
21 21
22 namespace fileapi { 22 namespace fileapi {
23 23
24 class QuotaFileUtilTest : public testing::Test { 24 class QuotaFileUtilTest : public testing::Test {
25 public: 25 public:
26 QuotaFileUtilTest() 26 QuotaFileUtilTest()
27 : quota_file_util_(QuotaFileUtil::GetInstance()), 27 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
28 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
29 } 28 }
30 29
31 void SetUp() { 30 void SetUp() {
32 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 31 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
33 quota_test_helper_.SetUp(data_dir_.path(), quota_file_util_); 32 quota_file_util_.reset(QuotaFileUtil::CreateDefault());
33 quota_test_helper_.SetUp(data_dir_.path(), quota_file_util_.get());
34 obfuscated_test_helper_.SetUp( 34 obfuscated_test_helper_.SetUp(
35 quota_test_helper_.file_system_context(), NULL); 35 quota_test_helper_.file_system_context(), NULL);
36 base_dir_ = obfuscated_test_helper_.GetOriginRootPath(); 36 base_dir_ = obfuscated_test_helper_.GetOriginRootPath();
37 } 37 }
38 38
39 void TearDown() { 39 void TearDown() {
40 quota_test_helper_.TearDown(); 40 quota_test_helper_.TearDown();
41 obfuscated_test_helper_.TearDown(); 41 obfuscated_test_helper_.TearDown();
42 } 42 }
43 43
(...skipping 17 matching lines...) Expand all
61 int64 ComputeFilePathCost(const char* file_name) { 61 int64 ComputeFilePathCost(const char* file_name) {
62 return quota_file_util_->ComputeFilePathCost( 62 return quota_file_util_->ComputeFilePathCost(
63 FilePath().AppendASCII(file_name)); 63 FilePath().AppendASCII(file_name));
64 } 64 }
65 65
66 base::PlatformFileError EnsureFileExists( 66 base::PlatformFileError EnsureFileExists(
67 const char* file_name, bool* created) { 67 const char* file_name, bool* created) {
68 int64 file_path_cost = ComputeFilePathCost(file_name); 68 int64 file_path_cost = ComputeFilePathCost(file_name);
69 scoped_ptr<FileSystemOperationContext> context(NewContext( 69 scoped_ptr<FileSystemOperationContext> context(NewContext(
70 file_path_cost, Path(file_name), FilePath())); 70 file_path_cost, Path(file_name), FilePath()));
71 return QuotaFileUtil::GetInstance()->EnsureFileExists( 71 return quota_file_util_->EnsureFileExists(
72 context.get(), Path(file_name), created); 72 context.get(), Path(file_name), created);
73 } 73 }
74 74
75 base::PlatformFileError Truncate( 75 base::PlatformFileError Truncate(
76 const char* file_name, int64 size, int64 quota) { 76 const char* file_name, int64 size, int64 quota) {
77 scoped_ptr<FileSystemOperationContext> context(NewContext( 77 scoped_ptr<FileSystemOperationContext> context(NewContext(
78 quota, Path(file_name), FilePath())); 78 quota, Path(file_name), FilePath()));
79 return QuotaFileUtil::GetInstance()->Truncate( 79 return quota_file_util_->Truncate(
80 context.get(), Path(file_name), size); 80 context.get(), Path(file_name), size);
81 } 81 }
82 82
83 void CheckUsage(int64 estimated_content, int64 estimated_path) { 83 void CheckUsage(int64 estimated_content, int64 estimated_path) {
84 ASSERT_EQ(estimated_content + estimated_path, 84 ASSERT_EQ(estimated_content + estimated_path,
85 quota_test_helper().GetCachedOriginUsage()); 85 quota_test_helper().GetCachedOriginUsage());
86 ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage() + 86 ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage() +
87 estimated_path, 87 estimated_path,
88 quota_test_helper().GetCachedOriginUsage()); 88 quota_test_helper().GetCachedOriginUsage());
89 } 89 }
90 90
91 QuotaFileUtil* quota_file_util() const {
92 return quota_file_util_.get();
93 }
94
91 const FileSystemTestOriginHelper& quota_test_helper() const { 95 const FileSystemTestOriginHelper& quota_test_helper() const {
92 return quota_test_helper_; 96 return quota_test_helper_;
93 } 97 }
94 98
95 private: 99 private:
96 QuotaFileUtil* quota_file_util_;
97 ScopedTempDir data_dir_; 100 ScopedTempDir data_dir_;
98 FilePath base_dir_; 101 FilePath base_dir_;
99 FileSystemTestOriginHelper obfuscated_test_helper_; 102 FileSystemTestOriginHelper obfuscated_test_helper_;
100 FileSystemTestOriginHelper quota_test_helper_; 103 FileSystemTestOriginHelper quota_test_helper_;
104 scoped_ptr<QuotaFileUtil> quota_file_util_;
101 base::ScopedCallbackFactory<QuotaFileUtilTest> callback_factory_; 105 base::ScopedCallbackFactory<QuotaFileUtilTest> callback_factory_;
102 106
103 DISALLOW_COPY_AND_ASSIGN(QuotaFileUtilTest); 107 DISALLOW_COPY_AND_ASSIGN(QuotaFileUtilTest);
104 }; 108 };
105 109
106 TEST_F(QuotaFileUtilTest, CreateAndClose) { 110 TEST_F(QuotaFileUtilTest, CreateAndClose) {
107 const char *file_name = "test_file"; 111 const char *file_name = "test_file";
108 int64 file_path_cost = ComputeFilePathCost(file_name); 112 int64 file_path_cost = ComputeFilePathCost(file_name);
109 113
110 int file_flags = base::PLATFORM_FILE_CREATE | 114 int file_flags = base::PLATFORM_FILE_CREATE |
111 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; 115 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
112 base::PlatformFile file_handle; 116 base::PlatformFile file_handle;
113 bool created; 117 bool created;
114 scoped_ptr<FileSystemOperationContext> context; 118 scoped_ptr<FileSystemOperationContext> context;
115 119
116 created = false; 120 created = false;
117 context.reset(NewContext(file_path_cost - 1, Path(file_name), FilePath())); 121 context.reset(NewContext(file_path_cost - 1, Path(file_name), FilePath()));
118 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 122 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, quota_file_util()->CreateOrOpen(
119 QuotaFileUtil::GetInstance()->CreateOrOpen( 123 context.get(), Path(file_name), file_flags, &file_handle, &created));
120 context.get(), Path(file_name), file_flags, &file_handle, &created));
121 ASSERT_FALSE(created); 124 ASSERT_FALSE(created);
122 125
123 created = false; 126 created = false;
124 context.reset(NewContext(file_path_cost, Path(file_name), FilePath())); 127 context.reset(NewContext(file_path_cost, Path(file_name), FilePath()));
125 ASSERT_EQ(base::PLATFORM_FILE_OK, 128 ASSERT_EQ(base::PLATFORM_FILE_OK, quota_file_util()->CreateOrOpen(
126 QuotaFileUtil::GetInstance()->CreateOrOpen( 129 context.get(), Path(file_name), file_flags, &file_handle, &created));
127 context.get(), Path(file_name), file_flags, &file_handle, &created));
128 ASSERT_TRUE(created); 130 ASSERT_TRUE(created);
129 131
130 context.reset(NewContext(0, FilePath(), FilePath())); 132 context.reset(NewContext(0, FilePath(), FilePath()));
131 EXPECT_EQ(base::PLATFORM_FILE_OK, 133 EXPECT_EQ(base::PLATFORM_FILE_OK, quota_file_util()->Close(
132 QuotaFileUtil::GetInstance()->Close(context.get(), file_handle)); 134 context.get(), file_handle));
133 } 135 }
134 136
135 TEST_F(QuotaFileUtilTest, EnsureFileExists) { 137 TEST_F(QuotaFileUtilTest, EnsureFileExists) {
136 const char *file_name = "foobar"; 138 const char *file_name = "foobar";
137 139
138 bool created; 140 bool created;
139 scoped_ptr<FileSystemOperationContext> context; 141 scoped_ptr<FileSystemOperationContext> context;
140 142
141 created = false; 143 created = false;
142 context.reset(NewContext( 144 context.reset(NewContext(
143 ComputeFilePathCost(file_name) - 1, Path(file_name), FilePath())); 145 ComputeFilePathCost(file_name) - 1, Path(file_name), FilePath()));
144 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 146 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
145 QuotaFileUtil::GetInstance()->EnsureFileExists( 147 quota_file_util()->EnsureFileExists(
146 context.get(), Path(file_name), &created)); 148 context.get(), Path(file_name), &created));
147 ASSERT_FALSE(created); 149 ASSERT_FALSE(created);
148 150
149 created = false; 151 created = false;
150 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); 152 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created));
151 ASSERT_TRUE(created); 153 ASSERT_TRUE(created);
152 154
153 created = false; 155 created = false;
154 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); 156 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created));
155 ASSERT_FALSE(created); 157 ASSERT_FALSE(created);
156 } 158 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 scoped_ptr<FileSystemOperationContext> context; 193 scoped_ptr<FileSystemOperationContext> context;
192 194
193 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020)); 195 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
194 CheckUsage(1020, file_path_cost); 196 CheckUsage(1020, file_path_cost);
195 197
196 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(prior_file, 1, 1)); 198 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(prior_file, 1, 1));
197 CheckUsage(1021, file_path_cost); 199 CheckUsage(1021, file_path_cost);
198 200
199 context.reset(NewContext(1020 + ComputeFilePathCost(to_file1), 201 context.reset(NewContext(1020 + ComputeFilePathCost(to_file1),
200 Path(from_file), Path(to_file1))); 202 Path(from_file), Path(to_file1)));
201 ASSERT_EQ(base::PLATFORM_FILE_OK, 203 ASSERT_EQ(base::PLATFORM_FILE_OK, quota_file_util()->Copy(
202 QuotaFileUtil::GetInstance()->Copy(context.get(), 204 context.get(), Path(from_file), Path(to_file1)));
203 Path(from_file),
204 Path(to_file1)));
205 file_path_cost += ComputeFilePathCost(to_file1); 205 file_path_cost += ComputeFilePathCost(to_file1);
206 CheckUsage(2041, file_path_cost); 206 CheckUsage(2041, file_path_cost);
207 207
208 context.reset(NewContext(1020 + ComputeFilePathCost(to_file2) - 1, 208 context.reset(NewContext(1020 + ComputeFilePathCost(to_file2) - 1,
209 Path(from_file), Path(to_file2))); 209 Path(from_file), Path(to_file2)));
210 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 210 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
211 QuotaFileUtil::GetInstance()->Copy(context.get(), 211 quota_file_util()->Copy(context.get(),
212 Path(from_file), 212 Path(from_file),
213 Path(to_file2))); 213 Path(to_file2)));
214 CheckUsage(2041, file_path_cost); 214 CheckUsage(2041, file_path_cost);
215 215
216 context.reset(NewContext(1019, Path(from_file), Path(prior_file))); 216 context.reset(NewContext(1019, Path(from_file), Path(prior_file)));
217 ASSERT_EQ(base::PLATFORM_FILE_OK, 217 ASSERT_EQ(base::PLATFORM_FILE_OK,
218 QuotaFileUtil::GetInstance()->Copy(context.get(), 218 quota_file_util()->Copy(context.get(),
219 Path(from_file), 219 Path(from_file),
220 Path(prior_file))); 220 Path(prior_file)));
221 CheckUsage(3060, file_path_cost); 221 CheckUsage(3060, file_path_cost);
222 } 222 }
223 223
224 TEST_F(QuotaFileUtilTest, CopyDirectory) { 224 TEST_F(QuotaFileUtilTest, CopyDirectory) {
225 int64 file_path_cost = 0; 225 int64 file_path_cost = 0;
226 const char *from_dir = "fromdir"; 226 const char *from_dir = "fromdir";
227 const char *from_file1 = "fromdir/fromfile1"; 227 const char *from_file1 = "fromdir/fromfile1";
228 const char *from_file2 = "fromdir/fromlongerfile2"; 228 const char *from_file2 = "fromdir/fromlongerfile2";
229 const char *to_dir1 = "todir1"; 229 const char *to_dir1 = "todir1";
230 const char *to_dir2 = "tolongerdir2"; 230 const char *to_dir2 = "tolongerdir2";
231 bool created; 231 bool created;
232 scoped_ptr<FileSystemOperationContext> context; 232 scoped_ptr<FileSystemOperationContext> context;
233 233
234 context.reset(NewContext(ComputeFilePathCost(from_dir), 234 context.reset(NewContext(ComputeFilePathCost(from_dir),
235 Path(from_dir), FilePath())); 235 Path(from_dir), FilePath()));
236 ASSERT_EQ(base::PLATFORM_FILE_OK, 236 ASSERT_EQ(base::PLATFORM_FILE_OK,
237 QuotaFileUtil::GetInstance()->CreateDirectory(context.get(), 237 quota_file_util()->CreateDirectory(context.get(),
238 Path(from_dir), 238 Path(from_dir),
239 false, false)); 239 false, false));
240 file_path_cost += ComputeFilePathCost(from_dir); 240 file_path_cost += ComputeFilePathCost(from_dir);
241 241
242 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file1, &created)); 242 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file1, &created));
243 ASSERT_TRUE(created); 243 ASSERT_TRUE(created);
244 file_path_cost += ComputeFilePathCost(from_file1); 244 file_path_cost += ComputeFilePathCost(from_file1);
245 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file2, &created)); 245 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file2, &created));
246 ASSERT_TRUE(created); 246 ASSERT_TRUE(created);
247 file_path_cost += ComputeFilePathCost(from_file2); 247 file_path_cost += ComputeFilePathCost(from_file2);
248 248
249 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file1, 520, 520)); 249 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file1, 520, 520));
250 CheckUsage(520, file_path_cost); 250 CheckUsage(520, file_path_cost);
251 251
252 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file2, 500, 500)); 252 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file2, 500, 500));
253 CheckUsage(1020, file_path_cost); 253 CheckUsage(1020, file_path_cost);
254 254
255 context.reset(NewContext(1020 + 255 context.reset(NewContext(1020 +
256 ComputeFilePathCost(to_dir1) + 256 ComputeFilePathCost(to_dir1) +
257 ComputeFilePathCost(from_file1) + 257 ComputeFilePathCost(from_file1) +
258 ComputeFilePathCost(from_file2), 258 ComputeFilePathCost(from_file2),
259 Path(from_dir), Path(to_dir1))); 259 Path(from_dir), Path(to_dir1)));
260 ASSERT_EQ(base::PLATFORM_FILE_OK, 260 ASSERT_EQ(base::PLATFORM_FILE_OK,
261 QuotaFileUtil::GetInstance()->Copy(context.get(), 261 quota_file_util()->Copy(context.get(),
262 Path(from_dir), 262 Path(from_dir),
263 Path(to_dir1))); 263 Path(to_dir1)));
264 file_path_cost += ComputeFilePathCost(to_dir1) + 264 file_path_cost += ComputeFilePathCost(to_dir1) +
265 ComputeFilePathCost(from_file1) + 265 ComputeFilePathCost(from_file1) +
266 ComputeFilePathCost(from_file2); 266 ComputeFilePathCost(from_file2);
267 CheckUsage(2040, file_path_cost); 267 CheckUsage(2040, file_path_cost);
268 268
269 context.reset(NewContext(1020 + 269 context.reset(NewContext(1020 +
270 ComputeFilePathCost(to_dir2) + 270 ComputeFilePathCost(to_dir2) +
271 ComputeFilePathCost(from_file1) + 271 ComputeFilePathCost(from_file1) +
272 ComputeFilePathCost(from_file2) - 1, 272 ComputeFilePathCost(from_file2) - 1,
273 Path(from_dir), Path(to_dir2))); 273 Path(from_dir), Path(to_dir2)));
274 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 274 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
275 QuotaFileUtil::GetInstance()->Copy(context.get(), 275 quota_file_util()->Copy(context.get(),
276 Path(from_dir), 276 Path(from_dir),
277 Path(to_dir2))); 277 Path(to_dir2)));
278 int64 file_path_cost1 = file_path_cost + 278 int64 file_path_cost1 = file_path_cost +
279 ComputeFilePathCost(to_dir2) + ComputeFilePathCost(from_file1); 279 ComputeFilePathCost(to_dir2) + ComputeFilePathCost(from_file1);
280 int64 file_path_cost2 = file_path_cost + 280 int64 file_path_cost2 = file_path_cost +
281 ComputeFilePathCost(to_dir2) + ComputeFilePathCost(from_file2); 281 ComputeFilePathCost(to_dir2) + ComputeFilePathCost(from_file2);
282 ASSERT_TRUE((2560 + file_path_cost1) == 282 ASSERT_TRUE((2560 + file_path_cost1) ==
283 quota_test_helper().GetCachedOriginUsage() || 283 quota_test_helper().GetCachedOriginUsage() ||
284 (2540 + file_path_cost2) == 284 (2540 + file_path_cost2) ==
285 quota_test_helper().GetCachedOriginUsage()); 285 quota_test_helper().GetCachedOriginUsage());
286 ASSERT_TRUE((quota_test_helper().ComputeCurrentOriginUsage() + file_path_cost1 286 ASSERT_TRUE((quota_test_helper().ComputeCurrentOriginUsage() + file_path_cost1
287 == quota_test_helper().GetCachedOriginUsage()) || 287 == quota_test_helper().GetCachedOriginUsage()) ||
(...skipping 10 matching lines...) Expand all
298 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 298 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
299 ASSERT_TRUE(created); 299 ASSERT_TRUE(created);
300 file_path_cost += ComputeFilePathCost(from_file); 300 file_path_cost += ComputeFilePathCost(from_file);
301 scoped_ptr<FileSystemOperationContext> context; 301 scoped_ptr<FileSystemOperationContext> context;
302 302
303 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020)); 303 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
304 CheckUsage(1020, file_path_cost); 304 CheckUsage(1020, file_path_cost);
305 305
306 context.reset(NewContext(0, Path(from_file), Path(to_file))); 306 context.reset(NewContext(0, Path(from_file), Path(to_file)));
307 ASSERT_EQ(base::PLATFORM_FILE_OK, 307 ASSERT_EQ(base::PLATFORM_FILE_OK,
308 QuotaFileUtil::GetInstance()->Move(context.get(), 308 quota_file_util()->Move(context.get(),
309 Path(from_file), 309 Path(from_file),
310 Path(to_file))); 310 Path(to_file)));
311 file_path_cost -= ComputeFilePathCost(from_file); 311 file_path_cost -= ComputeFilePathCost(from_file);
312 file_path_cost += ComputeFilePathCost(to_file); 312 file_path_cost += ComputeFilePathCost(to_file);
313 CheckUsage(1020, file_path_cost); 313 CheckUsage(1020, file_path_cost);
314 314
315 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 315 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
316 ASSERT_TRUE(created); 316 ASSERT_TRUE(created);
317 file_path_cost += ComputeFilePathCost(from_file); 317 file_path_cost += ComputeFilePathCost(from_file);
318 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(prior_file, &created)); 318 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(prior_file, &created));
319 ASSERT_TRUE(created); 319 ASSERT_TRUE(created);
320 file_path_cost += ComputeFilePathCost(prior_file); 320 file_path_cost += ComputeFilePathCost(prior_file);
321 321
322 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020)); 322 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
323 CheckUsage(2040, file_path_cost); 323 CheckUsage(2040, file_path_cost);
324 324
325 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(prior_file, 1, 1)); 325 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(prior_file, 1, 1));
326 CheckUsage(2041, file_path_cost); 326 CheckUsage(2041, file_path_cost);
327 327
328 context.reset(NewContext(ComputeFilePathCost(prior_file) - 328 context.reset(NewContext(ComputeFilePathCost(prior_file) -
329 ComputeFilePathCost(from_file) - 1 - 1, 329 ComputeFilePathCost(from_file) - 1 - 1,
330 Path(from_file), Path(prior_file))); 330 Path(from_file), Path(prior_file)));
331 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, 331 ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
332 QuotaFileUtil::GetInstance()->Move(context.get(), 332 quota_file_util()->Move(context.get(),
333 Path(from_file), 333 Path(from_file),
334 Path(prior_file))); 334 Path(prior_file)));
335 CheckUsage(2041, file_path_cost); 335 CheckUsage(2041, file_path_cost);
336 336
337 context.reset(NewContext(ComputeFilePathCost(prior_file) - 337 context.reset(NewContext(ComputeFilePathCost(prior_file) -
338 ComputeFilePathCost(from_file) - 1, 338 ComputeFilePathCost(from_file) - 1,
339 Path(from_file), Path(prior_file))); 339 Path(from_file), Path(prior_file)));
340 ASSERT_EQ(base::PLATFORM_FILE_OK, 340 ASSERT_EQ(base::PLATFORM_FILE_OK,
341 QuotaFileUtil::GetInstance()->Move(context.get(), 341 quota_file_util()->Move(context.get(),
342 Path(from_file), 342 Path(from_file),
343 Path(prior_file))); 343 Path(prior_file)));
344 file_path_cost -= ComputeFilePathCost(from_file); 344 file_path_cost -= ComputeFilePathCost(from_file);
345 file_path_cost += ComputeFilePathCost(prior_file); 345 file_path_cost += ComputeFilePathCost(prior_file);
346 CheckUsage(2040, file_path_cost); 346 CheckUsage(2040, file_path_cost);
347 } 347 }
348 348
349 TEST_F(QuotaFileUtilTest, MoveDirectory) { 349 TEST_F(QuotaFileUtilTest, MoveDirectory) {
350 int64 file_path_cost = 0; 350 int64 file_path_cost = 0;
351 const char *from_dir = "fromdir"; 351 const char *from_dir = "fromdir";
352 const char *from_file = "fromdir/fromfile"; 352 const char *from_file = "fromdir/fromfile";
353 const char *to_dir1 = "todir1"; 353 const char *to_dir1 = "todir1";
354 const char *to_dir2 = "tolongnamedir2"; 354 const char *to_dir2 = "tolongnamedir2";
355 bool created; 355 bool created;
356 scoped_ptr<FileSystemOperationContext> context; 356 scoped_ptr<FileSystemOperationContext> context;
357 357
358 context.reset(NewContext(QuotaFileUtil::kNoLimit, 358 context.reset(NewContext(QuotaFileUtil::kNoLimit,
359 Path(from_dir), FilePath())); 359 Path(from_dir), FilePath()));
360 ASSERT_EQ(base::PLATFORM_FILE_OK, 360 ASSERT_EQ(base::PLATFORM_FILE_OK,
361 QuotaFileUtil::GetInstance()->CreateDirectory(context.get(), 361 quota_file_util()->CreateDirectory(context.get(),
362 Path(from_dir), 362 Path(from_dir),
363 false, false)); 363 false, false));
364 file_path_cost += ComputeFilePathCost(from_dir); 364 file_path_cost += ComputeFilePathCost(from_dir);
365 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 365 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
366 ASSERT_TRUE(created); 366 ASSERT_TRUE(created);
367 file_path_cost += ComputeFilePathCost(from_file); 367 file_path_cost += ComputeFilePathCost(from_file);
368 368
369 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020)); 369 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
370 CheckUsage(1020, file_path_cost); 370 CheckUsage(1020, file_path_cost);
371 371
372 context.reset(NewContext(1020, Path(from_dir), Path(to_dir1))); 372 context.reset(NewContext(1020, Path(from_dir), Path(to_dir1)));
373 ASSERT_EQ(base::PLATFORM_FILE_OK, 373 ASSERT_EQ(base::PLATFORM_FILE_OK,
374 QuotaFileUtil::GetInstance()->Move(context.get(), 374 quota_file_util()->Move(context.get(),
375 Path(from_dir), 375 Path(from_dir),
376 Path(to_dir1))); 376 Path(to_dir1)));
377 file_path_cost -= ComputeFilePathCost(from_dir); 377 file_path_cost -= ComputeFilePathCost(from_dir);
378 file_path_cost += ComputeFilePathCost(to_dir1); 378 file_path_cost += ComputeFilePathCost(to_dir1);
379 CheckUsage(1020, file_path_cost); 379 CheckUsage(1020, file_path_cost);
380 380
381 context.reset(NewContext(QuotaFileUtil::kNoLimit, 381 context.reset(NewContext(QuotaFileUtil::kNoLimit,
382 Path(from_dir), FilePath())); 382 Path(from_dir), FilePath()));
383 ASSERT_EQ(base::PLATFORM_FILE_OK, 383 ASSERT_EQ(base::PLATFORM_FILE_OK,
384 QuotaFileUtil::GetInstance()->CreateDirectory(context.get(), 384 quota_file_util()->CreateDirectory(context.get(),
385 Path(from_dir), 385 Path(from_dir),
386 false, false)); 386 false, false));
387 file_path_cost += ComputeFilePathCost(from_dir); 387 file_path_cost += ComputeFilePathCost(from_dir);
388 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created)); 388 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
389 ASSERT_TRUE(created); 389 ASSERT_TRUE(created);
390 file_path_cost += ComputeFilePathCost(from_file); 390 file_path_cost += ComputeFilePathCost(from_file);
391 391
392 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020)); 392 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
393 CheckUsage(2040, file_path_cost); 393 CheckUsage(2040, file_path_cost);
394 394
395 context.reset(NewContext(1019, Path(from_dir), Path(to_dir2))); 395 context.reset(NewContext(1019, Path(from_dir), Path(to_dir2)));
396 EXPECT_EQ(base::PLATFORM_FILE_OK, 396 EXPECT_EQ(base::PLATFORM_FILE_OK,
397 QuotaFileUtil::GetInstance()->Move(context.get(), 397 quota_file_util()->Move(context.get(),
398 Path(from_dir), 398 Path(from_dir),
399 Path(to_dir2))); 399 Path(to_dir2)));
400 file_path_cost -= ComputeFilePathCost(from_dir); 400 file_path_cost -= ComputeFilePathCost(from_dir);
401 file_path_cost += ComputeFilePathCost(to_dir2); 401 file_path_cost += ComputeFilePathCost(to_dir2);
402 CheckUsage(2040, file_path_cost); 402 CheckUsage(2040, file_path_cost);
403 } 403 }
404 404
405 TEST_F(QuotaFileUtilTest, Remove) { 405 TEST_F(QuotaFileUtilTest, Remove) {
406 int64 file_path_cost = 0; 406 int64 file_path_cost = 0;
407 const char *dir = "dir"; 407 const char *dir = "dir";
408 const char *file = "file"; 408 const char *file = "file";
409 const char *dfile1 = "dir/dfile1"; 409 const char *dfile1 = "dir/dfile1";
410 const char *dfile2 = "dir/dfile2"; 410 const char *dfile2 = "dir/dfile2";
411 bool created; 411 bool created;
412 scoped_ptr<FileSystemOperationContext> context; 412 scoped_ptr<FileSystemOperationContext> context;
413 413
414 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file, &created)); 414 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file, &created));
415 ASSERT_TRUE(created); 415 ASSERT_TRUE(created);
416 file_path_cost += ComputeFilePathCost(file); 416 file_path_cost += ComputeFilePathCost(file);
417 context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(dir), FilePath())); 417 context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(dir), FilePath()));
418 ASSERT_EQ(base::PLATFORM_FILE_OK, 418 ASSERT_EQ(base::PLATFORM_FILE_OK,
419 QuotaFileUtil::GetInstance()->CreateDirectory(context.get(), 419 quota_file_util()->CreateDirectory(context.get(),
420 Path(dir), 420 Path(dir),
421 false, false)); 421 false, false));
422 file_path_cost += ComputeFilePathCost(dir); 422 file_path_cost += ComputeFilePathCost(dir);
423 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(dfile1, &created)); 423 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(dfile1, &created));
424 ASSERT_TRUE(created); 424 ASSERT_TRUE(created);
425 file_path_cost += ComputeFilePathCost(dfile1); 425 file_path_cost += ComputeFilePathCost(dfile1);
426 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(dfile2, &created)); 426 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(dfile2, &created));
427 ASSERT_TRUE(created); 427 ASSERT_TRUE(created);
428 file_path_cost += ComputeFilePathCost(dfile2); 428 file_path_cost += ComputeFilePathCost(dfile2);
429 429
430 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(file, 340, 340)); 430 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(file, 340, 340));
431 CheckUsage(340, file_path_cost); 431 CheckUsage(340, file_path_cost);
432 432
433 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(dfile1, 1020, 1020)); 433 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(dfile1, 1020, 1020));
434 CheckUsage(1360, file_path_cost); 434 CheckUsage(1360, file_path_cost);
435 435
436 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(dfile2, 120, 120)); 436 ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(dfile2, 120, 120));
437 CheckUsage(1480, file_path_cost); 437 CheckUsage(1480, file_path_cost);
438 438
439 context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(file), FilePath())); 439 context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(file), FilePath()));
440 ASSERT_EQ(base::PLATFORM_FILE_OK, 440 ASSERT_EQ(base::PLATFORM_FILE_OK,
441 QuotaFileUtil::GetInstance()->Delete(context.get(), 441 quota_file_util()->Delete(context.get(),
442 Path(file), 442 Path(file),
443 false)); 443 false));
444 file_path_cost -= ComputeFilePathCost(file); 444 file_path_cost -= ComputeFilePathCost(file);
445 CheckUsage(1140, file_path_cost); 445 CheckUsage(1140, file_path_cost);
446 446
447 context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(dir), FilePath())); 447 context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(dir), FilePath()));
448 ASSERT_EQ(base::PLATFORM_FILE_OK, 448 ASSERT_EQ(base::PLATFORM_FILE_OK,
449 QuotaFileUtil::GetInstance()->Delete(context.get(), 449 quota_file_util()->Delete(context.get(),
450 Path(dir), 450 Path(dir),
451 true)); 451 true));
452 file_path_cost = 0; 452 file_path_cost = 0;
453 CheckUsage(0, 0); 453 CheckUsage(0, 0);
454 } 454 }
455 455
456 } // namespace fileapi 456 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/quota_file_util.cc ('k') | webkit/fileapi/sandbox_mount_point_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698