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 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/scoped_callback_factory.h" | 7 #include "base/memory/scoped_callback_factory.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.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 "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webkit/fileapi/file_system_context.h" | 14 #include "webkit/fileapi/file_system_context.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_quota_client.h" | 16 #include "webkit/fileapi/file_system_quota_client.h" |
17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
18 #include "webkit/fileapi/file_system_usage_cache.h" | 18 #include "webkit/fileapi/file_system_usage_cache.h" |
19 #include "webkit/fileapi/file_system_util.h" | 19 #include "webkit/fileapi/file_system_util.h" |
| 20 #include "webkit/fileapi/obfuscated_file_system_file_util.h" |
20 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 21 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
21 #include "webkit/fileapi/quota_file_util.h" | 22 #include "webkit/fileapi/quota_file_util.h" |
22 #include "webkit/quota/quota_types.h" | 23 #include "webkit/quota/quota_types.h" |
23 | 24 |
24 namespace fileapi { | 25 namespace fileapi { |
25 namespace { | 26 namespace { |
26 | 27 |
27 const char kDummyURL1[] = "http://www.dummy.org"; | 28 const char kDummyURL1[] = "http://www.dummy.org"; |
28 const char kDummyURL2[] = "http://www.example.com"; | 29 const char kDummyURL2[] = "http://www.example.com"; |
29 const char kDummyURL3[] = "http://www.bleh"; | 30 const char kDummyURL3[] = "http://www.bleh"; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void InitializeOriginFiles(FileSystemQuotaClient* quota_client, | 189 void InitializeOriginFiles(FileSystemQuotaClient* quota_client, |
189 const TestFile* files, | 190 const TestFile* files, |
190 int num_files) { | 191 int num_files) { |
191 for (int i = 0; i < num_files; i++) { | 192 for (int i = 0; i < num_files; i++) { |
192 FilePath path = FilePath().AppendASCII(files[i].name); | 193 FilePath path = FilePath().AppendASCII(files[i].name); |
193 if (files[i].isDirectory) { | 194 if (files[i].isDirectory) { |
194 ASSERT_TRUE(CreateFileSystemDirectory( | 195 ASSERT_TRUE(CreateFileSystemDirectory( |
195 path, files[i].origin_url, files[i].type)); | 196 path, files[i].origin_url, files[i].type)); |
196 if (path.empty()) { | 197 if (path.empty()) { |
197 // Create the usage cache. | 198 // Create the usage cache. |
| 199 // HACK--we always create the root [an empty path] first. If we |
| 200 // create it later, this will fail due to a quota mismatch. If we |
| 201 // call this before we create the root, it succeeds, but hasn't |
| 202 // actually created the cache. |
198 ASSERT_EQ(0, GetOriginUsage( | 203 ASSERT_EQ(0, GetOriginUsage( |
199 quota_client, files[i].origin_url, files[i].type)); | 204 quota_client, files[i].origin_url, files[i].type)); |
200 } | 205 } |
201 } else { | 206 } else { |
202 ASSERT_TRUE(CreateFileSystemFile( | 207 ASSERT_TRUE(CreateFileSystemFile( |
203 path, files[i].size, files[i].origin_url, files[i].type)); | 208 path, files[i].size, files[i].origin_url, files[i].type)); |
204 } | 209 } |
205 } | 210 } |
206 } | 211 } |
207 | 212 |
| 213 // This is a bit fragile--it depends on the test data always creating a |
| 214 // directory before adding a file or directory to it, so that we can just |
| 215 // count the basename of each addition. A recursive creation of a path, which |
| 216 // created more than one directory in a single shot, would break this. |
208 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, | 217 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, |
209 int num_files, | 218 int num_files, |
210 const std::string& origin_url, | 219 const std::string& origin_url, |
211 quota::StorageType type) { | 220 quota::StorageType type) { |
212 int64 file_paths_cost = 0; | 221 int64 file_paths_cost = 0; |
213 for (int i = 0; i < num_files; i++) { | 222 for (int i = 0; i < num_files; i++) { |
214 if (files[i].type == type && | 223 if (files[i].type == type && |
215 GURL(files[i].origin_url) == GURL(origin_url)) { | 224 GURL(files[i].origin_url) == GURL(origin_url)) { |
216 FilePath path = FilePath().AppendASCII(files[i].name); | 225 FilePath path = FilePath().AppendASCII(files[i].name); |
217 if (!path.empty()) { | 226 if (!path.empty()) { |
218 // TODO(dmikurube): Use QuotaFileUtil in the actual -FileUtil stack. | 227 file_paths_cost += |
219 scoped_ptr<QuotaFileUtil> file_util(QuotaFileUtil::CreateDefault()); | 228 ObfuscatedFileSystemFileUtil::ComputeFilePathCost(path); |
220 file_paths_cost += file_util->ComputeFilePathCost(path); | |
221 } | 229 } |
222 } | 230 } |
223 } | 231 } |
224 return file_paths_cost; | 232 return file_paths_cost; |
225 } | 233 } |
226 | 234 |
227 void DeleteOriginData(FileSystemQuotaClient* quota_client, | 235 void DeleteOriginData(FileSystemQuotaClient* quota_client, |
228 const std::string& origin, | 236 const std::string& origin, |
229 quota::StorageType type) { | 237 quota::StorageType type) { |
230 deletion_status_ = quota::kQuotaStatusUnknown; | 238 deletion_status_ = quota::kQuotaStatusUnknown; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 287 } |
280 | 288 |
281 TEST_F(FileSystemQuotaClientTest, NoFileTest) { | 289 TEST_F(FileSystemQuotaClientTest, NoFileTest) { |
282 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 290 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
283 const TestFile kFiles[] = { | 291 const TestFile kFiles[] = { |
284 {true, NULL, 0, kDummyURL1, kTemporary}, | 292 {true, NULL, 0, kDummyURL1, kTemporary}, |
285 }; | 293 }; |
286 InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); | 294 InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
287 | 295 |
288 for (int i = 0; i < 2; i++) { | 296 for (int i = 0; i < 2; i++) { |
289 EXPECT_EQ(0, | 297 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
290 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | |
291 } | 298 } |
292 } | 299 } |
293 | 300 |
294 TEST_F(FileSystemQuotaClientTest, OneFileTest) { | 301 TEST_F(FileSystemQuotaClientTest, OneFileTest) { |
295 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 302 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
296 const TestFile kFiles[] = { | 303 const TestFile kFiles[] = { |
297 {true, NULL, 0, kDummyURL1, kTemporary}, | 304 {true, NULL, 0, kDummyURL1, kTemporary}, |
298 {false, "foo", 4921, kDummyURL1, kTemporary}, | 305 {false, "foo", 4921, kDummyURL1, kTemporary}, |
299 }; | 306 }; |
300 InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); | 307 InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 GetOriginUsage(quota_client.get(), | 598 GetOriginUsage(quota_client.get(), |
592 "https://bar.com/", | 599 "https://bar.com/", |
593 kPersistent)); | 600 kPersistent)); |
594 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, | 601 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
595 GetOriginUsage(quota_client.get(), | 602 GetOriginUsage(quota_client.get(), |
596 "https://bar.com/", | 603 "https://bar.com/", |
597 kTemporary)); | 604 kTemporary)); |
598 } | 605 } |
599 | 606 |
600 } // namespace fileapi | 607 } // namespace fileapi |
OLD | NEW |