OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "content/public/test/async_file_test_helper.h" | 11 #include "content/public/test/async_file_test_helper.h" |
12 #include "content/public/test/test_file_system_context.h" | 12 #include "content/public/test/test_file_system_context.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 #include "webkit/browser/fileapi/file_system_context.h" | 15 #include "storage/browser/fileapi/file_system_context.h" |
16 #include "webkit/browser/fileapi/file_system_quota_client.h" | 16 #include "storage/browser/fileapi/file_system_quota_client.h" |
17 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 17 #include "storage/browser/fileapi/file_system_usage_cache.h" |
18 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 18 #include "storage/browser/fileapi/obfuscated_file_util.h" |
19 #include "webkit/common/fileapi/file_system_types.h" | 19 #include "storage/common/fileapi/file_system_types.h" |
20 #include "webkit/common/fileapi/file_system_util.h" | 20 #include "storage/common/fileapi/file_system_util.h" |
21 #include "webkit/common/quota/quota_types.h" | 21 #include "storage/common/quota/quota_types.h" |
22 | 22 |
23 using content::AsyncFileTestHelper; | 23 using content::AsyncFileTestHelper; |
24 using fileapi::FileSystemQuotaClient; | 24 using storage::FileSystemQuotaClient; |
25 using fileapi::FileSystemURL; | 25 using storage::FileSystemURL; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 namespace { | 28 namespace { |
29 | 29 |
30 const char kDummyURL1[] = "http://www.dummy.org"; | 30 const char kDummyURL1[] = "http://www.dummy.org"; |
31 const char kDummyURL2[] = "http://www.example.com"; | 31 const char kDummyURL2[] = "http://www.example.com"; |
32 const char kDummyURL3[] = "http://www.bleh"; | 32 const char kDummyURL3[] = "http://www.bleh"; |
33 | 33 |
34 // Declared to shorten the variable names. | 34 // Declared to shorten the variable names. |
35 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; | 35 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 quota::StorageType type) { | 112 quota::StorageType type) { |
113 quota_client->GetOriginUsage( | 113 quota_client->GetOriginUsage( |
114 GURL(origin_url), type, | 114 GURL(origin_url), type, |
115 base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage, | 115 base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage, |
116 weak_factory_.GetWeakPtr())); | 116 weak_factory_.GetWeakPtr())); |
117 } | 117 } |
118 | 118 |
119 bool CreateFileSystemDirectory(const base::FilePath& file_path, | 119 bool CreateFileSystemDirectory(const base::FilePath& file_path, |
120 const std::string& origin_url, | 120 const std::string& origin_url, |
121 quota::StorageType storage_type) { | 121 quota::StorageType storage_type) { |
122 fileapi::FileSystemType type = | 122 storage::FileSystemType type = |
123 fileapi::QuotaStorageTypeToFileSystemType(storage_type); | 123 storage::QuotaStorageTypeToFileSystemType(storage_type); |
124 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 124 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
125 GURL(origin_url), type, file_path); | 125 GURL(origin_url), type, file_path); |
126 | 126 |
127 base::File::Error result = | 127 base::File::Error result = |
128 AsyncFileTestHelper::CreateDirectory(file_system_context_, url); | 128 AsyncFileTestHelper::CreateDirectory(file_system_context_, url); |
129 return result == base::File::FILE_OK; | 129 return result == base::File::FILE_OK; |
130 } | 130 } |
131 | 131 |
132 bool CreateFileSystemFile(const base::FilePath& file_path, | 132 bool CreateFileSystemFile(const base::FilePath& file_path, |
133 int64 file_size, | 133 int64 file_size, |
134 const std::string& origin_url, | 134 const std::string& origin_url, |
135 quota::StorageType storage_type) { | 135 quota::StorageType storage_type) { |
136 if (file_path.empty()) | 136 if (file_path.empty()) |
137 return false; | 137 return false; |
138 | 138 |
139 fileapi::FileSystemType type = | 139 storage::FileSystemType type = |
140 fileapi::QuotaStorageTypeToFileSystemType(storage_type); | 140 storage::QuotaStorageTypeToFileSystemType(storage_type); |
141 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 141 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
142 GURL(origin_url), type, file_path); | 142 GURL(origin_url), type, file_path); |
143 | 143 |
144 base::File::Error result = | 144 base::File::Error result = |
145 AsyncFileTestHelper::CreateFile(file_system_context_, url); | 145 AsyncFileTestHelper::CreateFile(file_system_context_, url); |
146 if (result != base::File::FILE_OK) | 146 if (result != base::File::FILE_OK) |
147 return false; | 147 return false; |
148 | 148 |
149 result = AsyncFileTestHelper::TruncateFile( | 149 result = AsyncFileTestHelper::TruncateFile( |
150 file_system_context_, url, file_size); | 150 file_system_context_, url, file_size); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, | 182 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, |
183 int num_files, | 183 int num_files, |
184 const std::string& origin_url, | 184 const std::string& origin_url, |
185 quota::StorageType type) { | 185 quota::StorageType type) { |
186 int64 file_paths_cost = 0; | 186 int64 file_paths_cost = 0; |
187 for (int i = 0; i < num_files; i++) { | 187 for (int i = 0; i < num_files; i++) { |
188 if (files[i].type == type && | 188 if (files[i].type == type && |
189 GURL(files[i].origin_url) == GURL(origin_url)) { | 189 GURL(files[i].origin_url) == GURL(origin_url)) { |
190 base::FilePath path = base::FilePath().AppendASCII(files[i].name); | 190 base::FilePath path = base::FilePath().AppendASCII(files[i].name); |
191 if (!path.empty()) { | 191 if (!path.empty()) { |
192 file_paths_cost += fileapi::ObfuscatedFileUtil::ComputeFilePathCost( | 192 file_paths_cost += |
193 path); | 193 storage::ObfuscatedFileUtil::ComputeFilePathCost(path); |
194 } | 194 } |
195 } | 195 } |
196 } | 196 } |
197 return file_paths_cost; | 197 return file_paths_cost; |
198 } | 198 } |
199 | 199 |
200 void DeleteOriginData(FileSystemQuotaClient* quota_client, | 200 void DeleteOriginData(FileSystemQuotaClient* quota_client, |
201 const std::string& origin, | 201 const std::string& origin, |
202 quota::StorageType type) { | 202 quota::StorageType type) { |
203 deletion_status_ = quota::kQuotaStatusUnknown; | 203 deletion_status_ = quota::kQuotaStatusUnknown; |
(...skipping 22 matching lines...) Expand all Loading... |
226 void OnGetAdditionalUsage(int64 usage_unused) { | 226 void OnGetAdditionalUsage(int64 usage_unused) { |
227 ++additional_callback_count_; | 227 ++additional_callback_count_; |
228 } | 228 } |
229 | 229 |
230 void OnDeleteOrigin(quota::QuotaStatusCode status) { | 230 void OnDeleteOrigin(quota::QuotaStatusCode status) { |
231 deletion_status_ = status; | 231 deletion_status_ = status; |
232 } | 232 } |
233 | 233 |
234 base::ScopedTempDir data_dir_; | 234 base::ScopedTempDir data_dir_; |
235 base::MessageLoop message_loop_; | 235 base::MessageLoop message_loop_; |
236 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 236 scoped_refptr<storage::FileSystemContext> file_system_context_; |
237 base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_; | 237 base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_; |
238 int64 usage_; | 238 int64 usage_; |
239 int additional_callback_count_; | 239 int additional_callback_count_; |
240 std::set<GURL> origins_; | 240 std::set<GURL> origins_; |
241 quota::QuotaStatusCode deletion_status_; | 241 quota::QuotaStatusCode deletion_status_; |
242 | 242 |
243 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); | 243 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); |
244 }; | 244 }; |
245 | 245 |
246 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { | 246 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 GetOriginUsage(quota_client.get(), | 561 GetOriginUsage(quota_client.get(), |
562 "https://bar.com/", | 562 "https://bar.com/", |
563 kPersistent)); | 563 kPersistent)); |
564 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, | 564 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
565 GetOriginUsage(quota_client.get(), | 565 GetOriginUsage(quota_client.get(), |
566 "https://bar.com/", | 566 "https://bar.com/", |
567 kTemporary)); | 567 kTemporary)); |
568 } | 568 } |
569 | 569 |
570 } // namespace content | 570 } // namespace content |
OLD | NEW |