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

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

Issue 7608011: Simplify directory path accounting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build problem. 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
Dai Mikurube (NOT FULLTIME) 2011/08/12 05:17:54 I think this test should be kept. FileSystemObfus
ericu 2011/08/15 23:47:10 I agree that we need a test like this, but it does
Dai Mikurube (NOT FULLTIME) 2011/08/16 05:11:00 Ah, make sense. Actually, I'd like to test 1), 2)
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 // This test checks the entire behavior of FileSystem usage and quota, such as: 5 // This test checks the entire behavior of FileSystem usage and quota, such as:
6 // 1) the actual size of files on disk, 6 // 1) the actual size of files on disk,
7 // 2) the described size in .usage, and 7 // 2) the described size in .usage, and
8 // 3) the result of QuotaManager::GetUsageAndQuota. 8 // 3) the result of QuotaManager::GetUsageAndQuota.
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_callback_factory.h" 12 #include "base/memory/scoped_callback_factory.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "base/scoped_temp_dir.h" 16 #include "base/scoped_temp_dir.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webkit/fileapi/file_system_callback_dispatcher.h" 18 #include "webkit/fileapi/file_system_callback_dispatcher.h"
19 #include "webkit/fileapi/file_system_context.h"
20 #include "webkit/fileapi/file_system_operation.h" 19 #include "webkit/fileapi/file_system_operation.h"
21 #include "webkit/fileapi/file_system_test_helper.h" 20 #include "webkit/fileapi/file_system_test_helper.h"
22 #include "webkit/fileapi/file_system_usage_cache.h" 21 #include "webkit/fileapi/file_system_usage_cache.h"
23 #include "webkit/fileapi/file_system_util.h" 22 #include "webkit/fileapi/file_system_util.h"
24 #include "webkit/fileapi/local_file_system_file_util.h" 23 #include "webkit/fileapi/local_file_system_file_util.h"
25 #include "webkit/fileapi/quota_file_util.h" 24 #include "webkit/fileapi/quota_file_util.h"
26 #include "webkit/quota/mock_special_storage_policy.h"
27 #include "webkit/quota/quota_manager.h" 25 #include "webkit/quota/quota_manager.h"
28 26
29 namespace fileapi { 27 namespace fileapi {
30 28
31 const int kFileOperationStatusNotSet = 1; 29 const int kFileOperationStatusNotSet = 1;
32 30
33 class FileSystemQuotaTest : public testing::Test { 31 class FileSystemQuotaTest : public testing::Test {
34 public: 32 public:
35 FileSystemQuotaTest() 33 FileSystemQuotaTest()
36 : quota_file_util_(QuotaFileUtil::CreateDefault()), 34 : local_file_util_(
37 local_file_util_(new LocalFileSystemFileUtil(quota_file_util_)), 35 new LocalFileSystemFileUtil(QuotaFileUtil::CreateDefault())),
38 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 36 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
39 file_path_cost_(0),
40 status_(kFileOperationStatusNotSet), 37 status_(kFileOperationStatusNotSet),
41 quota_status_(quota::kQuotaStatusUnknown), 38 quota_status_(quota::kQuotaStatusUnknown),
42 usage_(-1), 39 usage_(-1),
43 quota_(-1) {} 40 quota_(-1) {}
44 41
45 FileSystemOperation* operation(); 42 FileSystemOperation* operation();
46 43
47 void set_status(int status) { status_ = status; } 44 void set_status(int status) { status_ = status; }
48 int status() const { return status_; } 45 int status() const { return status_; }
49 quota::QuotaStatusCode quota_status() const { return quota_status_; } 46 quota::QuotaStatusCode quota_status() const { return quota_status_; }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 82
86 bool VirtualFileExists(const FilePath& virtual_path) { 83 bool VirtualFileExists(const FilePath& virtual_path) {
87 return file_util::PathExists(PlatformPath(virtual_path)) && 84 return file_util::PathExists(PlatformPath(virtual_path)) &&
88 !file_util::DirectoryExists(PlatformPath(virtual_path)); 85 !file_util::DirectoryExists(PlatformPath(virtual_path));
89 } 86 }
90 87
91 bool VirtualDirectoryExists(const FilePath& virtual_path) { 88 bool VirtualDirectoryExists(const FilePath& virtual_path) {
92 return file_util::DirectoryExists(PlatformPath(virtual_path)); 89 return file_util::DirectoryExists(PlatformPath(virtual_path));
93 } 90 }
94 91
95 int64 ComputeFilePathCost(const FilePath& file_path) { 92 FilePath CreateVirtualTemporaryFileInDir(const FilePath& virtual_dir_path) {
96 return quota_file_util_->ComputeFilePathCost(file_path); 93 FilePath absolute_dir_path(PlatformPath(virtual_dir_path));
94 FilePath absolute_file_path;
95 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(absolute_dir_path,
96 &absolute_file_path));
97 return virtual_dir_path.Append(absolute_file_path.BaseName());
97 } 98 }
98 99
99 void CreateVirtualDirectory(const FilePath& virtual_path) { 100 FilePath CreateVirtualTemporaryDirInDir(const FilePath& virtual_dir_path) {
100 operation()->CreateDirectory(URLForPath(virtual_path), false, false); 101 FilePath absolute_parent_dir_path(PlatformPath(virtual_dir_path));
101 MessageLoop::current()->RunAllPending(); 102 FilePath absolute_child_dir_path;
102 file_path_cost_ += ComputeFilePathCost(virtual_path); 103 EXPECT_TRUE(file_util::CreateTemporaryDirInDir(absolute_parent_dir_path,
104 FILE_PATH_LITERAL(""),
105 &absolute_child_dir_path));
106 return virtual_dir_path.Append(absolute_child_dir_path.BaseName());
103 } 107 }
104 108
105 void CreateVirtualFile(const FilePath& virtual_path) { 109 FilePath CreateVirtualTemporaryDir() {
106 operation()->CreateFile(URLForPath(virtual_path), false); 110 return CreateVirtualTemporaryDirInDir(FilePath());
107 MessageLoop::current()->RunAllPending();
108 file_path_cost_ += ComputeFilePathCost(virtual_path);
109 }
110
111 void set_file_path_cost(int64 file_path_cost) {
112 file_path_cost_ = file_path_cost;
113 }
114
115 int64 file_path_cost() const {
116 return file_path_cost_;
117 }
118
119 void AddToFilePathCost(int64 addition) {
120 file_path_cost_ += addition;
121 } 111 }
122 112
123 FilePath child_dir_path_; 113 FilePath child_dir_path_;
124 FilePath child_file1_path_; 114 FilePath child_file1_path_;
125 FilePath child_file2_path_; 115 FilePath child_file2_path_;
126 FilePath grandchild_file1_path_; 116 FilePath grandchild_file1_path_;
127 FilePath grandchild_file2_path_; 117 FilePath grandchild_file2_path_;
128 118
129 protected: 119 private:
130 FileSystemTestOriginHelper test_helper_; 120 FileSystemTestOriginHelper test_helper_;
131 121
132 ScopedTempDir work_dir_; 122 ScopedTempDir work_dir_;
133 scoped_refptr<quota::QuotaManager> quota_manager_; 123 scoped_refptr<quota::QuotaManager> quota_manager_;
134 QuotaFileUtil* quota_file_util_;
135 scoped_ptr<LocalFileSystemFileUtil> local_file_util_; 124 scoped_ptr<LocalFileSystemFileUtil> local_file_util_;
136 125
137 base::ScopedCallbackFactory<FileSystemQuotaTest> callback_factory_; 126 base::ScopedCallbackFactory<FileSystemQuotaTest> callback_factory_;
138 127
139 int64 file_path_cost_;
140
141 // For post-operation status. 128 // For post-operation status.
142 int status_; 129 int status_;
143 quota::QuotaStatusCode quota_status_; 130 quota::QuotaStatusCode quota_status_;
144 int64 usage_; 131 int64 usage_;
145 int64 quota_; 132 int64 quota_;
146 133
147 private:
148 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest); 134 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest);
149 }; 135 };
150 136
151 class FileSystemObfuscatedQuotaTest : public FileSystemQuotaTest {
152 public:
153 virtual void SetUp();
154
155 int64 RevokeUsageCache() {
156 quota_manager_->ResetUsageTracker(test_helper_.storage_type());
157 return test_helper_.RevokeUsageCache();
158 }
159
160 private:
161 scoped_refptr<FileSystemContext> file_system_context_;
162 };
163
164 namespace { 137 namespace {
165 138
166 class MockDispatcher : public FileSystemCallbackDispatcher { 139 class MockDispatcher : public FileSystemCallbackDispatcher {
167 public: 140 public:
168 explicit MockDispatcher(FileSystemQuotaTest* test) : test_(test) { } 141 explicit MockDispatcher(FileSystemQuotaTest* test) : test_(test) { }
169 142
170 virtual void DidFail(base::PlatformFileError status) { 143 virtual void DidFail(base::PlatformFileError status) {
171 test_->set_status(status); 144 test_->set_status(status);
172 } 145 }
173 146
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 207 }
235 208
236 void FileSystemQuotaTest::OnGetUsageAndQuota( 209 void FileSystemQuotaTest::OnGetUsageAndQuota(
237 quota::QuotaStatusCode status, int64 usage, int64 quota) { 210 quota::QuotaStatusCode status, int64 usage, int64 quota) {
238 quota_status_ = status; 211 quota_status_ = status;
239 usage_ = usage; 212 usage_ = usage;
240 quota_ = quota; 213 quota_ = quota;
241 } 214 }
242 215
243 void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) { 216 void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) {
244 child_dir_path_ = virtual_path.AppendASCII("childdir"); 217 child_dir_path_ = CreateVirtualTemporaryDirInDir(virtual_path);
245 CreateVirtualDirectory(child_dir_path_); 218 child_file1_path_ = CreateVirtualTemporaryFileInDir(virtual_path);
246 child_file1_path_ = virtual_path.AppendASCII("childfile1"); 219 child_file2_path_ = CreateVirtualTemporaryFileInDir(virtual_path);
247 CreateVirtualFile(child_file1_path_); 220 grandchild_file1_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_);
248 child_file2_path_ = virtual_path.AppendASCII("childlongfile2"); 221 grandchild_file2_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_);
249 CreateVirtualFile(child_file2_path_);
250 grandchild_file1_path_ = child_dir_path_.AppendASCII("grchildfile1");
251 CreateVirtualFile(grandchild_file1_path_);
252 grandchild_file2_path_ = child_dir_path_.AppendASCII("grchildlongfile2");
253 CreateVirtualFile(grandchild_file2_path_);
254 } 222 }
255 223
256 TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) { 224 TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) {
257 FilePath src_dir_path = FilePath(FILE_PATH_LITERAL("src")); 225 FilePath src_dir_path(CreateVirtualTemporaryDir());
258 CreateVirtualDirectory(src_dir_path);
259 PrepareFileSet(src_dir_path); 226 PrepareFileSet(src_dir_path);
260 FilePath dest_dir_path = FilePath(FILE_PATH_LITERAL("dest")); 227 FilePath dest_dir_path(CreateVirtualTemporaryDir());
261 CreateVirtualDirectory(dest_dir_path);
262 228
263 EXPECT_EQ(0, ActualSize()); 229 EXPECT_EQ(0, ActualSize());
264 230
265 operation()->Truncate(URLForPath(child_file1_path_), 5000); 231 operation()->Truncate(URLForPath(child_file1_path_), 5000);
266 operation()->Truncate(URLForPath(child_file2_path_), 400); 232 operation()->Truncate(URLForPath(child_file2_path_), 400);
267 operation()->Truncate(URLForPath(grandchild_file1_path_), 30); 233 operation()->Truncate(URLForPath(grandchild_file1_path_), 30);
268 operation()->Truncate(URLForPath(grandchild_file2_path_), 2); 234 operation()->Truncate(URLForPath(grandchild_file2_path_), 2);
269 MessageLoop::current()->RunAllPending(); 235 MessageLoop::current()->RunAllPending();
270 236
271 const int64 all_file_size = 5000 + 400 + 30 + 2; 237 const int64 all_file_size = 5000 + 400 + 30 + 2;
272 const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize; 238 const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize;
273 239
274 EXPECT_EQ(all_file_size, ActualSize()); 240 EXPECT_EQ(all_file_size, ActualSize());
275 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), 241 EXPECT_EQ(all_file_size + usage_file_size, SizeInUsageFile());
276 SizeInUsageFile());
277 GetUsageAndQuotaFromQuotaManager(); 242 GetUsageAndQuotaFromQuotaManager();
278 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 243 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
279 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage()); 244 EXPECT_EQ(all_file_size + usage_file_size, usage());
280 ASSERT_LT(all_file_size, quota()); 245 ASSERT_LT(all_file_size, quota());
281 246
282 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 247 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
283 MessageLoop::current()->RunAllPending(); 248 MessageLoop::current()->RunAllPending();
284 AddToFilePathCost(-ComputeFilePathCost(src_dir_path));
285 249
286 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 250 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
287 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( 251 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
288 child_dir_path_.BaseName()))); 252 child_dir_path_.BaseName())));
289 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( 253 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append(
290 child_dir_path_.BaseName()).Append( 254 child_dir_path_.BaseName()).Append(
291 grandchild_file1_path_.BaseName()))); 255 grandchild_file1_path_.BaseName())));
292 256
293 EXPECT_EQ(all_file_size, ActualSize()); 257 EXPECT_EQ(all_file_size, ActualSize());
294 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), 258 EXPECT_EQ(all_file_size + usage_file_size, SizeInUsageFile());
295 SizeInUsageFile());
296 GetUsageAndQuotaFromQuotaManager(); 259 GetUsageAndQuotaFromQuotaManager();
297 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 260 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
298 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage()); 261 EXPECT_EQ(all_file_size + usage_file_size, usage());
299 ASSERT_LT(all_file_size, quota()); 262 ASSERT_LT(all_file_size, quota());
300 } 263 }
301 264
302 TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) { 265 TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) {
303 FilePath src_dir_path = FilePath(FILE_PATH_LITERAL("src")); 266 FilePath src_dir_path(CreateVirtualTemporaryDir());
304 CreateVirtualDirectory(src_dir_path);
305 PrepareFileSet(src_dir_path); 267 PrepareFileSet(src_dir_path);
306 FilePath dest_dir1_path = FilePath(FILE_PATH_LITERAL("dest1")); 268 FilePath dest_dir1_path(CreateVirtualTemporaryDir());
307 CreateVirtualDirectory(dest_dir1_path); 269 FilePath dest_dir2_path(CreateVirtualTemporaryDir());
308 FilePath dest_dir2_path = FilePath(FILE_PATH_LITERAL("destnonexisting2"));
309 270
310 EXPECT_EQ(0, ActualSize()); 271 EXPECT_EQ(0, ActualSize());
311 272
312 operation()->Truncate(URLForPath(child_file1_path_), 8000); 273 operation()->Truncate(URLForPath(child_file1_path_), 8000);
313 operation()->Truncate(URLForPath(child_file2_path_), 700); 274 operation()->Truncate(URLForPath(child_file2_path_), 700);
314 operation()->Truncate(URLForPath(grandchild_file1_path_), 60); 275 operation()->Truncate(URLForPath(grandchild_file1_path_), 60);
315 operation()->Truncate(URLForPath(grandchild_file2_path_), 5); 276 operation()->Truncate(URLForPath(grandchild_file2_path_), 5);
316 MessageLoop::current()->RunAllPending(); 277 MessageLoop::current()->RunAllPending();
317 278
318 const int64 child_file_size = 8000 + 700; 279 const int64 child_file_size = 8000 + 700;
319 const int64 grandchild_file_size = 60 + 5; 280 const int64 grandchild_file_size = 60 + 5;
320 const int64 all_file_size = child_file_size + grandchild_file_size; 281 const int64 all_file_size = child_file_size + grandchild_file_size;
321 const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize; 282 const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize;
322 283
323 EXPECT_EQ(all_file_size, ActualSize()); 284 EXPECT_EQ(all_file_size, ActualSize());
324 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), 285 EXPECT_EQ(all_file_size + usage_file_size, SizeInUsageFile());
325 SizeInUsageFile());
326 GetUsageAndQuotaFromQuotaManager(); 286 GetUsageAndQuotaFromQuotaManager();
327 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 287 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
328 EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage()); 288 EXPECT_EQ(all_file_size + usage_file_size, usage());
329 ASSERT_LT(all_file_size, quota()); 289 ASSERT_LT(all_file_size, quota());
330 290
331 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path)); 291 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path));
332 MessageLoop::current()->RunAllPending(); 292 MessageLoop::current()->RunAllPending();
333 AddToFilePathCost(ComputeFilePathCost(child_dir_path_) +
334 ComputeFilePathCost(child_file1_path_) +
335 ComputeFilePathCost(child_file2_path_) +
336 ComputeFilePathCost(grandchild_file1_path_) +
337 ComputeFilePathCost(grandchild_file2_path_));
338 293
339 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 294 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
340 EXPECT_TRUE(VirtualDirectoryExists(src_dir_path.Append( 295 EXPECT_TRUE(VirtualDirectoryExists(src_dir_path.Append(
341 child_dir_path_.BaseName()))); 296 child_dir_path_.BaseName())));
342 EXPECT_TRUE(VirtualFileExists(src_dir_path.Append( 297 EXPECT_TRUE(VirtualFileExists(src_dir_path.Append(
343 child_dir_path_.BaseName()).Append( 298 child_dir_path_.BaseName()).Append(
344 grandchild_file1_path_.BaseName()))); 299 grandchild_file1_path_.BaseName())));
345 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 300 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
346 EXPECT_TRUE(VirtualDirectoryExists(dest_dir1_path.Append( 301 EXPECT_TRUE(VirtualDirectoryExists(dest_dir1_path.Append(
347 child_dir_path_.BaseName()))); 302 child_dir_path_.BaseName())));
348 EXPECT_TRUE(VirtualFileExists(dest_dir1_path.Append( 303 EXPECT_TRUE(VirtualFileExists(dest_dir1_path.Append(
349 child_dir_path_.BaseName()).Append( 304 child_dir_path_.BaseName()).Append(
350 grandchild_file1_path_.BaseName()))); 305 grandchild_file1_path_.BaseName())));
351 306
352 EXPECT_EQ(2 * all_file_size, ActualSize()); 307 EXPECT_EQ(2 * all_file_size, ActualSize());
353 EXPECT_EQ(2 * all_file_size + usage_file_size + file_path_cost(), 308 EXPECT_EQ(2 * all_file_size + usage_file_size, SizeInUsageFile());
354 SizeInUsageFile());
355 GetUsageAndQuotaFromQuotaManager(); 309 GetUsageAndQuotaFromQuotaManager();
356 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 310 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
357 EXPECT_EQ(2 * all_file_size + usage_file_size + file_path_cost(), usage()); 311 EXPECT_EQ(2 * all_file_size + usage_file_size, usage());
358 ASSERT_LT(2 * all_file_size, quota()); 312 ASSERT_LT(2 * all_file_size, quota());
359 313
360 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path)); 314 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path));
361 MessageLoop::current()->RunAllPending(); 315 MessageLoop::current()->RunAllPending();
362 AddToFilePathCost(ComputeFilePathCost(dest_dir2_path) +
363 ComputeFilePathCost(grandchild_file1_path_) +
364 ComputeFilePathCost(grandchild_file2_path_));
365 316
366 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 317 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
367 318
368 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, 319 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size,
369 ActualSize()); 320 ActualSize());
370 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size + 321 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size,
371 file_path_cost(), SizeInUsageFile()); 322 SizeInUsageFile());
372 GetUsageAndQuotaFromQuotaManager(); 323 GetUsageAndQuotaFromQuotaManager();
373 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 324 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
374 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size + 325 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size,
375 file_path_cost(), usage()); 326 usage());
376 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota()); 327 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota());
377 } 328 }
378 329
379 void FileSystemObfuscatedQuotaTest::SetUp() {
380 ASSERT_TRUE(work_dir_.CreateUniqueTempDir());
381 FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem");
382 file_util::CreateDirectory(filesystem_dir_path);
383
384 quota_manager_ = new quota::QuotaManager(
385 false /* is_incognito */,
386 filesystem_dir_path,
387 base::MessageLoopProxy::CreateForCurrentThread(),
388 base::MessageLoopProxy::CreateForCurrentThread(),
389 NULL);
390
391 file_system_context_ = new FileSystemContext(
392 base::MessageLoopProxy::CreateForCurrentThread(),
393 base::MessageLoopProxy::CreateForCurrentThread(),
394 new quota::MockSpecialStoragePolicy(),
395 quota_manager_->proxy(),
396 filesystem_dir_path,
397 false /* incognito */,
398 true /* allow_file_access_from_files */,
399 false /* unlimitedquota */,
400 NULL);
401
402 test_helper_.SetUp(file_system_context_,
403 NULL /* sandbox_provider's internal file_util */);
404 }
405
406 TEST_F(FileSystemObfuscatedQuotaTest, TestRevokeUsageCache) {
407 FilePath dir_path = FilePath(FILE_PATH_LITERAL("test"));
408 CreateVirtualDirectory(dir_path);
409 PrepareFileSet(dir_path);
410
411 operation()->Truncate(URLForPath(child_file1_path_), 3000);
412 operation()->Truncate(URLForPath(child_file2_path_), 400);
413 operation()->Truncate(URLForPath(grandchild_file1_path_), 10);
414 operation()->Truncate(URLForPath(grandchild_file2_path_), 6);
415 MessageLoop::current()->RunAllPending();
416
417 const int64 all_file_size = 3000 + 400 + 10 + 6;
418
419 EXPECT_EQ(all_file_size + file_path_cost(), SizeInUsageFile());
420 GetUsageAndQuotaFromQuotaManager();
421 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
422 EXPECT_EQ(all_file_size + file_path_cost(), usage());
423 ASSERT_LT(all_file_size, quota());
424
425 RevokeUsageCache();
426 EXPECT_EQ(-1, SizeInUsageFile());
427
428 GetUsageAndQuotaFromQuotaManager();
429 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
430 EXPECT_EQ(all_file_size + file_path_cost(), SizeInUsageFile());
431 EXPECT_EQ(all_file_size + file_path_cost(), usage());
432 ASSERT_LT(all_file_size, quota());
433 }
434
435 } // namespace fileapi 330 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698