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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.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/mock_file_system_options.h" |
20 #include "webkit/fileapi/obfuscated_file_util.h" | 21 #include "webkit/fileapi/obfuscated_file_util.h" |
| 22 #include "webkit/fileapi/quota_file_util.h" |
21 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 23 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
22 #include "webkit/fileapi/quota_file_util.h" | |
23 #include "webkit/quota/quota_types.h" | 24 #include "webkit/quota/quota_types.h" |
24 | 25 |
25 namespace fileapi { | 26 namespace fileapi { |
26 namespace { | 27 namespace { |
27 | 28 |
28 const char kDummyURL1[] = "http://www.dummy.org"; | 29 const char kDummyURL1[] = "http://www.dummy.org"; |
29 const char kDummyURL2[] = "http://www.example.com"; | 30 const char kDummyURL2[] = "http://www.example.com"; |
30 const char kDummyURL3[] = "http://www.bleh"; | 31 const char kDummyURL3[] = "http://www.bleh"; |
31 | 32 |
32 // Declared to shorten the variable names. | 33 // Declared to shorten the variable names. |
33 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; | 34 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; |
34 const quota::StorageType kPersistent = quota::kStorageTypePersistent; | 35 const quota::StorageType kPersistent = quota::kStorageTypePersistent; |
35 | 36 |
36 class MockFileSystemPathManager : public FileSystemPathManager { | |
37 public: | |
38 explicit MockFileSystemPathManager(const FilePath& filesystem_path) | |
39 : FileSystemPathManager(base::MessageLoopProxy::current(), | |
40 filesystem_path, NULL, false, true) {} | |
41 }; | |
42 | |
43 } // namespace | 37 } // namespace |
44 | 38 |
45 class FileSystemQuotaClientTest : public testing::Test { | 39 class FileSystemQuotaClientTest : public testing::Test { |
46 public: | 40 public: |
47 FileSystemQuotaClientTest() | 41 FileSystemQuotaClientTest() |
48 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 42 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
49 additional_callback_count_(0), | 43 additional_callback_count_(0), |
50 deletion_status_(quota::kQuotaStatusUnknown) { | 44 deletion_status_(quota::kQuotaStatusUnknown) { |
51 } | 45 } |
52 | 46 |
53 void SetUp() { | 47 void SetUp() { |
54 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 48 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
55 file_system_context_ = | 49 file_system_context_ = |
56 new FileSystemContext( | 50 new FileSystemContext( |
57 base::MessageLoopProxy::current(), | 51 base::MessageLoopProxy::current(), |
58 base::MessageLoopProxy::current(), | 52 base::MessageLoopProxy::current(), |
59 NULL, NULL, | 53 NULL, NULL, |
60 FilePath(), false /* is_incognito */, true /* allow_file_access */, | 54 data_dir_.path(), |
61 new MockFileSystemPathManager(data_dir_.path())); | 55 CreateDisallowFileAccessOptions()); |
62 } | 56 } |
63 | 57 |
64 struct TestFile { | 58 struct TestFile { |
65 bool isDirectory; | 59 bool isDirectory; |
66 const char* name; | 60 const char* name; |
67 int64 size; | 61 int64 size; |
68 const char* origin_url; | 62 const char* origin_url; |
69 quota::StorageType type; | 63 quota::StorageType type; |
70 }; | 64 }; |
71 | 65 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 quota_client->GetOriginUsage( | 116 quota_client->GetOriginUsage( |
123 GURL(origin_url), type, | 117 GURL(origin_url), type, |
124 base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage, | 118 base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage, |
125 weak_factory_.GetWeakPtr())); | 119 weak_factory_.GetWeakPtr())); |
126 } | 120 } |
127 | 121 |
128 FilePath GetOriginBasePath(const std::string& origin_url, | 122 FilePath GetOriginBasePath(const std::string& origin_url, |
129 quota::StorageType type) { | 123 quota::StorageType type) { |
130 // Note: this test assumes sandbox_provider impl is used for | 124 // Note: this test assumes sandbox_provider impl is used for |
131 // temporary and persistent filesystem. | 125 // temporary and persistent filesystem. |
132 return file_system_context_->path_manager()->sandbox_provider()-> | 126 return file_system_context_->sandbox_provider()-> |
133 GetBaseDirectoryForOriginAndType( | 127 GetBaseDirectoryForOriginAndType( |
134 GURL(origin_url), QuotaStorageTypeToFileSystemType(type), true); | 128 GURL(origin_url), QuotaStorageTypeToFileSystemType(type), true); |
135 } | 129 } |
136 | 130 |
137 FileSystemOperationContext* CreateFileSystemOperationContext( | 131 FileSystemOperationContext* CreateFileSystemOperationContext( |
138 FileSystemFileUtil* file_util, | 132 FileSystemFileUtil* file_util, |
139 const FilePath& virtual_path, | 133 const FilePath& virtual_path, |
140 const std::string& origin_url, | 134 const std::string& origin_url, |
141 quota::StorageType type) { | 135 quota::StorageType type) { |
142 FileSystemOperationContext* context = | 136 FileSystemOperationContext* context = |
143 new FileSystemOperationContext(file_system_context_, file_util); | 137 new FileSystemOperationContext(file_system_context_, file_util); |
144 context->set_src_origin_url(GURL(origin_url)); | 138 context->set_src_origin_url(GURL(origin_url)); |
145 context->set_src_type(QuotaStorageTypeToFileSystemType(type)); | 139 context->set_src_type(QuotaStorageTypeToFileSystemType(type)); |
146 context->set_allowed_bytes_growth(100000000); | 140 context->set_allowed_bytes_growth(100000000); |
147 return context; | 141 return context; |
148 } | 142 } |
149 | 143 |
150 bool CreateFileSystemDirectory(const FilePath& path, | 144 bool CreateFileSystemDirectory(const FilePath& path, |
151 const std::string& origin_url, | 145 const std::string& origin_url, |
152 quota::StorageType type) { | 146 quota::StorageType type) { |
153 FileSystemFileUtil* file_util = file_system_context_->path_manager()-> | 147 FileSystemFileUtil* file_util = file_system_context_-> |
154 GetFileUtil(QuotaStorageTypeToFileSystemType(type)); | 148 GetFileUtil(QuotaStorageTypeToFileSystemType(type)); |
155 | 149 |
156 scoped_ptr<FileSystemOperationContext> context( | 150 scoped_ptr<FileSystemOperationContext> context( |
157 CreateFileSystemOperationContext(file_util, path, origin_url, type)); | 151 CreateFileSystemOperationContext(file_util, path, origin_url, type)); |
158 | 152 |
159 base::PlatformFileError result = | 153 base::PlatformFileError result = |
160 file_util->CreateDirectory(context.get(), path, false, false); | 154 file_util->CreateDirectory(context.get(), path, false, false); |
161 if (result != base::PLATFORM_FILE_OK) | 155 if (result != base::PLATFORM_FILE_OK) |
162 return false; | 156 return false; |
163 return true; | 157 return true; |
164 } | 158 } |
165 | 159 |
166 bool CreateFileSystemFile(const FilePath& path, | 160 bool CreateFileSystemFile(const FilePath& path, |
167 int64 file_size, | 161 int64 file_size, |
168 const std::string& origin_url, | 162 const std::string& origin_url, |
169 quota::StorageType type) { | 163 quota::StorageType type) { |
170 if (path.empty()) | 164 if (path.empty()) |
171 return false; | 165 return false; |
172 | 166 |
173 FileSystemFileUtil* file_util = file_system_context_->path_manager()-> | 167 FileSystemFileUtil* file_util = file_system_context_-> |
174 sandbox_provider()->GetFileUtil(); | 168 sandbox_provider()->GetFileUtil(); |
175 | 169 |
176 scoped_ptr<FileSystemOperationContext> context( | 170 scoped_ptr<FileSystemOperationContext> context( |
177 CreateFileSystemOperationContext(file_util, path, origin_url, type)); | 171 CreateFileSystemOperationContext(file_util, path, origin_url, type)); |
178 | 172 |
179 bool created = false; | 173 bool created = false; |
180 if (base::PLATFORM_FILE_OK != | 174 if (base::PLATFORM_FILE_OK != |
181 file_util->EnsureFileExists(context.get(), path, &created)) | 175 file_util->EnsureFileExists(context.get(), path, &created)) |
182 return false; | 176 return false; |
183 EXPECT_TRUE(created); | 177 EXPECT_TRUE(created); |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 GetOriginUsage(quota_client.get(), | 592 GetOriginUsage(quota_client.get(), |
599 "https://bar.com/", | 593 "https://bar.com/", |
600 kPersistent)); | 594 kPersistent)); |
601 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, | 595 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
602 GetOriginUsage(quota_client.get(), | 596 GetOriginUsage(quota_client.get(), |
603 "https://bar.com/", | 597 "https://bar.com/", |
604 kTemporary)); | 598 kTemporary)); |
605 } | 599 } |
606 | 600 |
607 } // namespace fileapi | 601 } // namespace fileapi |
OLD | NEW |