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 // 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/bind.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_callback_factory.h" | 13 #include "base/memory/scoped_callback_factory.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/platform_file.h" | 16 #include "base/platform_file.h" |
16 #include "base/scoped_temp_dir.h" | 17 #include "base/scoped_temp_dir.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 19 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
19 #include "webkit/fileapi/file_system_operation.h" | 20 #include "webkit/fileapi/file_system_operation.h" |
20 #include "webkit/fileapi/file_system_test_helper.h" | 21 #include "webkit/fileapi/file_system_test_helper.h" |
21 #include "webkit/fileapi/file_system_usage_cache.h" | 22 #include "webkit/fileapi/file_system_usage_cache.h" |
22 #include "webkit/fileapi/file_system_util.h" | 23 #include "webkit/fileapi/file_system_util.h" |
23 #include "webkit/fileapi/local_file_util.h" | 24 #include "webkit/fileapi/local_file_util.h" |
24 #include "webkit/fileapi/quota_file_util.h" | 25 #include "webkit/fileapi/quota_file_util.h" |
25 #include "webkit/quota/quota_manager.h" | 26 #include "webkit/quota/quota_manager.h" |
26 | 27 |
27 namespace fileapi { | 28 namespace fileapi { |
28 | 29 |
29 const int kFileOperationStatusNotSet = 1; | 30 const int kFileOperationStatusNotSet = 1; |
30 | 31 |
31 class FileSystemQuotaTest : public testing::Test { | 32 class FileSystemQuotaTest : public testing::Test { |
32 public: | 33 public: |
33 FileSystemQuotaTest() | 34 FileSystemQuotaTest() |
34 : local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())), | 35 : local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())), |
35 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 36 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
36 status_(kFileOperationStatusNotSet), | 37 status_(kFileOperationStatusNotSet), |
37 quota_status_(quota::kQuotaStatusUnknown), | 38 quota_status_(quota::kQuotaStatusUnknown), |
38 usage_(-1), | 39 usage_(-1), |
39 quota_(-1) {} | 40 quota_(-1) {} |
40 | 41 |
41 FileSystemOperation* operation(); | 42 FileSystemOperation* operation(); |
42 | 43 |
43 void set_status(int status) { status_ = status; } | 44 void set_status(int status) { status_ = status; } |
44 int status() const { return status_; } | 45 int status() const { return status_; } |
45 quota::QuotaStatusCode quota_status() const { return quota_status_; } | 46 quota::QuotaStatusCode quota_status() const { return quota_status_; } |
(...skipping 21 matching lines...) Expand all Loading... |
67 return test_helper_.ComputeCurrentOriginUsage(); | 68 return test_helper_.ComputeCurrentOriginUsage(); |
68 } | 69 } |
69 | 70 |
70 int64 SizeInUsageFile() { | 71 int64 SizeInUsageFile() { |
71 return test_helper_.GetCachedOriginUsage(); | 72 return test_helper_.GetCachedOriginUsage(); |
72 } | 73 } |
73 | 74 |
74 void GetUsageAndQuotaFromQuotaManager() { | 75 void GetUsageAndQuotaFromQuotaManager() { |
75 quota_manager_->GetUsageAndQuota( | 76 quota_manager_->GetUsageAndQuota( |
76 test_helper_.origin(), test_helper_.storage_type(), | 77 test_helper_.origin(), test_helper_.storage_type(), |
77 callback_factory_.NewCallback( | 78 base::Bind(&FileSystemQuotaTest::OnGetUsageAndQuota, |
78 &FileSystemQuotaTest::OnGetUsageAndQuota)); | 79 weak_factory_.GetWeakPtr())); |
79 MessageLoop::current()->RunAllPending(); | 80 MessageLoop::current()->RunAllPending(); |
80 } | 81 } |
81 | 82 |
82 bool VirtualFileExists(const FilePath& virtual_path) { | 83 bool VirtualFileExists(const FilePath& virtual_path) { |
83 return file_util::PathExists(PlatformPath(virtual_path)) && | 84 return file_util::PathExists(PlatformPath(virtual_path)) && |
84 !file_util::DirectoryExists(PlatformPath(virtual_path)); | 85 !file_util::DirectoryExists(PlatformPath(virtual_path)); |
85 } | 86 } |
86 | 87 |
87 bool VirtualDirectoryExists(const FilePath& virtual_path) { | 88 bool VirtualDirectoryExists(const FilePath& virtual_path) { |
88 return file_util::DirectoryExists(PlatformPath(virtual_path)); | 89 return file_util::DirectoryExists(PlatformPath(virtual_path)); |
(...skipping 26 matching lines...) Expand all Loading... |
115 FilePath grandchild_file1_path_; | 116 FilePath grandchild_file1_path_; |
116 FilePath grandchild_file2_path_; | 117 FilePath grandchild_file2_path_; |
117 | 118 |
118 protected: | 119 protected: |
119 FileSystemTestOriginHelper test_helper_; | 120 FileSystemTestOriginHelper test_helper_; |
120 | 121 |
121 ScopedTempDir work_dir_; | 122 ScopedTempDir work_dir_; |
122 scoped_refptr<quota::QuotaManager> quota_manager_; | 123 scoped_refptr<quota::QuotaManager> quota_manager_; |
123 scoped_ptr<LocalFileUtil> local_file_util_; | 124 scoped_ptr<LocalFileUtil> local_file_util_; |
124 | 125 |
125 base::ScopedCallbackFactory<FileSystemQuotaTest> callback_factory_; | 126 base::WeakPtrFactory<FileSystemQuotaTest> weak_factory_; |
126 | 127 |
127 // For post-operation status. | 128 // For post-operation status. |
128 int status_; | 129 int status_; |
129 quota::QuotaStatusCode quota_status_; | 130 quota::QuotaStatusCode quota_status_; |
130 int64 usage_; | 131 int64 usage_; |
131 int64 quota_; | 132 int64 quota_; |
132 | 133 |
133 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest); | 134 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest); |
134 }; | 135 }; |
135 | 136 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 329 |
329 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualSize()); | 330 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualSize()); |
330 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, SizeInUsageFile()); | 331 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, SizeInUsageFile()); |
331 GetUsageAndQuotaFromQuotaManager(); | 332 GetUsageAndQuotaFromQuotaManager(); |
332 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); | 333 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); |
333 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, usage()); | 334 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, usage()); |
334 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota()); | 335 ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota()); |
335 } | 336 } |
336 | 337 |
337 } // namespace fileapi | 338 } // namespace fileapi |
OLD | NEW |