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/platform_file.h" | 10 #include "base/platform_file.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.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/async_file_test_helper.h" | 15 #include "webkit/browser/fileapi/async_file_test_helper.h" |
16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "webkit/browser/fileapi/file_system_context.h" |
17 #include "webkit/browser/fileapi/file_system_quota_client.h" | 17 #include "webkit/browser/fileapi/file_system_quota_client.h" |
18 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 18 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
19 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 19 #include "webkit/browser/fileapi/obfuscated_file_util.h" |
20 #include "webkit/common/fileapi/file_system_types.h" | 20 #include "webkit/common/fileapi/file_system_types.h" |
21 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "webkit/common/fileapi/file_system_util.h" |
22 #include "webkit/common/quota/quota_types.h" | 22 #include "webkit/common/quota/quota_types.h" |
23 | 23 |
24 namespace fileapi { | 24 using fileapi::AsyncFileTestHelper; |
| 25 using fileapi::FileSystemQuotaClient; |
| 26 using fileapi::FileSystemType; |
| 27 using fileapi::FileSystemURL; |
| 28 |
| 29 namespace content { |
25 namespace { | 30 namespace { |
26 | 31 |
27 const char kDummyURL1[] = "http://www.dummy.org"; | 32 const char kDummyURL1[] = "http://www.dummy.org"; |
28 const char kDummyURL2[] = "http://www.example.com"; | 33 const char kDummyURL2[] = "http://www.example.com"; |
29 const char kDummyURL3[] = "http://www.bleh"; | 34 const char kDummyURL3[] = "http://www.bleh"; |
30 | 35 |
31 // Declared to shorten the variable names. | 36 // Declared to shorten the variable names. |
32 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; | 37 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; |
33 const quota::StorageType kPersistent = quota::kStorageTypePersistent; | 38 const quota::StorageType kPersistent = quota::kStorageTypePersistent; |
34 | 39 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 76 } |
72 | 77 |
73 int64 GetOriginUsage(FileSystemQuotaClient* quota_client, | 78 int64 GetOriginUsage(FileSystemQuotaClient* quota_client, |
74 const std::string& origin_url, | 79 const std::string& origin_url, |
75 quota::StorageType type) { | 80 quota::StorageType type) { |
76 GetOriginUsageAsync(quota_client, origin_url, type); | 81 GetOriginUsageAsync(quota_client, origin_url, type); |
77 base::RunLoop().RunUntilIdle(); | 82 base::RunLoop().RunUntilIdle(); |
78 return usage_; | 83 return usage_; |
79 } | 84 } |
80 | 85 |
81 const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client, | 86 const std::set<GURL>& GetOriginsForType( |
82 quota::StorageType type) { | 87 FileSystemQuotaClient* quota_client, |
| 88 quota::StorageType type) { |
83 origins_.clear(); | 89 origins_.clear(); |
84 quota_client->GetOriginsForType( | 90 quota_client->GetOriginsForType( |
85 type, | 91 type, |
86 base::Bind(&FileSystemQuotaClientTest::OnGetOrigins, | 92 base::Bind(&FileSystemQuotaClientTest::OnGetOrigins, |
87 weak_factory_.GetWeakPtr())); | 93 weak_factory_.GetWeakPtr())); |
88 base::RunLoop().RunUntilIdle(); | 94 base::RunLoop().RunUntilIdle(); |
89 return origins_; | 95 return origins_; |
90 } | 96 } |
91 | 97 |
92 const std::set<GURL>& GetOriginsForHost(FileSystemQuotaClient* quota_client, | 98 const std::set<GURL>& GetOriginsForHost( |
93 quota::StorageType type, | 99 FileSystemQuotaClient* quota_client, |
94 const std::string& host) { | 100 quota::StorageType type, |
| 101 const std::string& host) { |
95 origins_.clear(); | 102 origins_.clear(); |
96 quota_client->GetOriginsForHost( | 103 quota_client->GetOriginsForHost( |
97 type, host, | 104 type, host, |
98 base::Bind(&FileSystemQuotaClientTest::OnGetOrigins, | 105 base::Bind(&FileSystemQuotaClientTest::OnGetOrigins, |
99 weak_factory_.GetWeakPtr())); | 106 weak_factory_.GetWeakPtr())); |
100 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
101 return origins_; | 108 return origins_; |
102 } | 109 } |
103 | 110 |
104 void RunAdditionalOriginUsageTask(FileSystemQuotaClient* quota_client, | 111 void RunAdditionalOriginUsageTask( |
105 const std::string& origin_url, | 112 FileSystemQuotaClient* quota_client, |
106 quota::StorageType type) { | 113 const std::string& origin_url, |
| 114 quota::StorageType type) { |
107 quota_client->GetOriginUsage( | 115 quota_client->GetOriginUsage( |
108 GURL(origin_url), type, | 116 GURL(origin_url), type, |
109 base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage, | 117 base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage, |
110 weak_factory_.GetWeakPtr())); | 118 weak_factory_.GetWeakPtr())); |
111 } | 119 } |
112 | 120 |
113 bool CreateFileSystemDirectory(const base::FilePath& file_path, | 121 bool CreateFileSystemDirectory(const base::FilePath& file_path, |
114 const std::string& origin_url, | 122 const std::string& origin_url, |
115 quota::StorageType storage_type) { | 123 quota::StorageType storage_type) { |
116 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 124 FileSystemType type = fileapi::QuotaStorageTypeToFileSystemType( |
| 125 storage_type); |
117 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 126 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
118 GURL(origin_url), type, file_path); | 127 GURL(origin_url), type, file_path); |
119 | 128 |
120 base::PlatformFileError result = | 129 base::PlatformFileError result = |
121 AsyncFileTestHelper::CreateDirectory(file_system_context_, url); | 130 AsyncFileTestHelper::CreateDirectory(file_system_context_, url); |
122 return result == base::PLATFORM_FILE_OK; | 131 return result == base::PLATFORM_FILE_OK; |
123 } | 132 } |
124 | 133 |
125 bool CreateFileSystemFile(const base::FilePath& file_path, | 134 bool CreateFileSystemFile(const base::FilePath& file_path, |
126 int64 file_size, | 135 int64 file_size, |
127 const std::string& origin_url, | 136 const std::string& origin_url, |
128 quota::StorageType storage_type) { | 137 quota::StorageType storage_type) { |
129 if (file_path.empty()) | 138 if (file_path.empty()) |
130 return false; | 139 return false; |
131 | 140 |
132 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 141 FileSystemType type = fileapi::QuotaStorageTypeToFileSystemType( |
| 142 storage_type); |
133 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 143 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
134 GURL(origin_url), type, file_path); | 144 GURL(origin_url), type, file_path); |
135 | 145 |
136 base::PlatformFileError result = | 146 base::PlatformFileError result = |
137 AsyncFileTestHelper::CreateFile(file_system_context_, url); | 147 AsyncFileTestHelper::CreateFile(file_system_context_, url); |
138 if (result != base::PLATFORM_FILE_OK) | 148 if (result != base::PLATFORM_FILE_OK) |
139 return false; | 149 return false; |
140 | 150 |
141 result = AsyncFileTestHelper::TruncateFile( | 151 result = AsyncFileTestHelper::TruncateFile( |
142 file_system_context_, url, file_size); | 152 file_system_context_, url, file_size); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, | 184 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, |
175 int num_files, | 185 int num_files, |
176 const std::string& origin_url, | 186 const std::string& origin_url, |
177 quota::StorageType type) { | 187 quota::StorageType type) { |
178 int64 file_paths_cost = 0; | 188 int64 file_paths_cost = 0; |
179 for (int i = 0; i < num_files; i++) { | 189 for (int i = 0; i < num_files; i++) { |
180 if (files[i].type == type && | 190 if (files[i].type == type && |
181 GURL(files[i].origin_url) == GURL(origin_url)) { | 191 GURL(files[i].origin_url) == GURL(origin_url)) { |
182 base::FilePath path = base::FilePath().AppendASCII(files[i].name); | 192 base::FilePath path = base::FilePath().AppendASCII(files[i].name); |
183 if (!path.empty()) { | 193 if (!path.empty()) { |
184 file_paths_cost += ObfuscatedFileUtil::ComputeFilePathCost(path); | 194 file_paths_cost += fileapi::ObfuscatedFileUtil::ComputeFilePathCost( |
| 195 path); |
185 } | 196 } |
186 } | 197 } |
187 } | 198 } |
188 return file_paths_cost; | 199 return file_paths_cost; |
189 } | 200 } |
190 | 201 |
191 void DeleteOriginData(FileSystemQuotaClient* quota_client, | 202 void DeleteOriginData(FileSystemQuotaClient* quota_client, |
192 const std::string& origin, | 203 const std::string& origin, |
193 quota::StorageType type) { | 204 quota::StorageType type) { |
194 deletion_status_ = quota::kQuotaStatusUnknown; | 205 deletion_status_ = quota::kQuotaStatusUnknown; |
(...skipping 22 matching lines...) Expand all Loading... |
217 void OnGetAdditionalUsage(int64 usage_unused) { | 228 void OnGetAdditionalUsage(int64 usage_unused) { |
218 ++additional_callback_count_; | 229 ++additional_callback_count_; |
219 } | 230 } |
220 | 231 |
221 void OnDeleteOrigin(quota::QuotaStatusCode status) { | 232 void OnDeleteOrigin(quota::QuotaStatusCode status) { |
222 deletion_status_ = status; | 233 deletion_status_ = status; |
223 } | 234 } |
224 | 235 |
225 base::ScopedTempDir data_dir_; | 236 base::ScopedTempDir data_dir_; |
226 base::MessageLoop message_loop_; | 237 base::MessageLoop message_loop_; |
227 scoped_refptr<FileSystemContext> file_system_context_; | 238 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
228 base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_; | 239 base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_; |
229 int64 usage_; | 240 int64 usage_; |
230 int additional_callback_count_; | 241 int additional_callback_count_; |
231 std::set<GURL> origins_; | 242 std::set<GURL> origins_; |
232 quota::QuotaStatusCode deletion_status_; | 243 quota::QuotaStatusCode deletion_status_; |
233 | 244 |
234 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); | 245 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); |
235 }; | 246 }; |
236 | 247 |
237 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { | 248 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 EXPECT_EQ(32 + file_paths_cost_persistent_bar_https, | 562 EXPECT_EQ(32 + file_paths_cost_persistent_bar_https, |
552 GetOriginUsage(quota_client.get(), | 563 GetOriginUsage(quota_client.get(), |
553 "https://bar.com/", | 564 "https://bar.com/", |
554 kPersistent)); | 565 kPersistent)); |
555 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, | 566 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
556 GetOriginUsage(quota_client.get(), | 567 GetOriginUsage(quota_client.get(), |
557 "https://bar.com/", | 568 "https://bar.com/", |
558 kTemporary)); | 569 kTemporary)); |
559 } | 570 } |
560 | 571 |
561 } // namespace fileapi | 572 } // namespace content |
OLD | NEW |