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 <stdint.h> |
| 6 |
6 #include "base/bind.h" | 7 #include "base/bind.h" |
7 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" |
9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
10 #include "content/public/test/async_file_test_helper.h" | 12 #include "content/public/test/async_file_test_helper.h" |
11 #include "content/public/test/test_file_system_context.h" | 13 #include "content/public/test/test_file_system_context.h" |
12 #include "storage/browser/fileapi/file_system_context.h" | 14 #include "storage/browser/fileapi/file_system_context.h" |
13 #include "storage/browser/fileapi/file_system_quota_client.h" | 15 #include "storage/browser/fileapi/file_system_quota_client.h" |
14 #include "storage/browser/fileapi/file_system_usage_cache.h" | 16 #include "storage/browser/fileapi/file_system_usage_cache.h" |
15 #include "storage/browser/fileapi/obfuscated_file_util.h" | 17 #include "storage/browser/fileapi/obfuscated_file_util.h" |
16 #include "storage/common/fileapi/file_system_types.h" | 18 #include "storage/common/fileapi/file_system_types.h" |
17 #include "storage/common/fileapi/file_system_util.h" | 19 #include "storage/common/fileapi/file_system_util.h" |
18 #include "storage/common/quota/quota_types.h" | 20 #include "storage/common/quota/quota_types.h" |
(...skipping 26 matching lines...) Expand all Loading... |
45 | 47 |
46 void SetUp() override { | 48 void SetUp() override { |
47 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 49 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
48 file_system_context_ = CreateFileSystemContextForTesting( | 50 file_system_context_ = CreateFileSystemContextForTesting( |
49 NULL, data_dir_.path()); | 51 NULL, data_dir_.path()); |
50 } | 52 } |
51 | 53 |
52 struct TestFile { | 54 struct TestFile { |
53 bool isDirectory; | 55 bool isDirectory; |
54 const char* name; | 56 const char* name; |
55 int64 size; | 57 int64_t size; |
56 const char* origin_url; | 58 const char* origin_url; |
57 storage::StorageType type; | 59 storage::StorageType type; |
58 }; | 60 }; |
59 | 61 |
60 protected: | 62 protected: |
61 FileSystemQuotaClient* NewQuotaClient(bool is_incognito) { | 63 FileSystemQuotaClient* NewQuotaClient(bool is_incognito) { |
62 return new FileSystemQuotaClient(file_system_context_.get(), is_incognito); | 64 return new FileSystemQuotaClient(file_system_context_.get(), is_incognito); |
63 } | 65 } |
64 | 66 |
65 void GetOriginUsageAsync(FileSystemQuotaClient* quota_client, | 67 void GetOriginUsageAsync(FileSystemQuotaClient* quota_client, |
66 const std::string& origin_url, | 68 const std::string& origin_url, |
67 storage::StorageType type) { | 69 storage::StorageType type) { |
68 quota_client->GetOriginUsage( | 70 quota_client->GetOriginUsage( |
69 GURL(origin_url), type, | 71 GURL(origin_url), type, |
70 base::Bind(&FileSystemQuotaClientTest::OnGetUsage, | 72 base::Bind(&FileSystemQuotaClientTest::OnGetUsage, |
71 weak_factory_.GetWeakPtr())); | 73 weak_factory_.GetWeakPtr())); |
72 } | 74 } |
73 | 75 |
74 int64 GetOriginUsage(FileSystemQuotaClient* quota_client, | 76 int64_t GetOriginUsage(FileSystemQuotaClient* quota_client, |
75 const std::string& origin_url, | 77 const std::string& origin_url, |
76 storage::StorageType type) { | 78 storage::StorageType type) { |
77 GetOriginUsageAsync(quota_client, origin_url, type); | 79 GetOriginUsageAsync(quota_client, origin_url, type); |
78 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
79 return usage_; | 81 return usage_; |
80 } | 82 } |
81 | 83 |
82 const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client, | 84 const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client, |
83 storage::StorageType type) { | 85 storage::StorageType type) { |
84 origins_.clear(); | 86 origins_.clear(); |
85 quota_client->GetOriginsForType( | 87 quota_client->GetOriginsForType( |
86 type, | 88 type, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 storage::QuotaStorageTypeToFileSystemType(storage_type); | 120 storage::QuotaStorageTypeToFileSystemType(storage_type); |
119 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 121 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
120 GURL(origin_url), type, file_path); | 122 GURL(origin_url), type, file_path); |
121 | 123 |
122 base::File::Error result = | 124 base::File::Error result = |
123 AsyncFileTestHelper::CreateDirectory(file_system_context_.get(), url); | 125 AsyncFileTestHelper::CreateDirectory(file_system_context_.get(), url); |
124 return result == base::File::FILE_OK; | 126 return result == base::File::FILE_OK; |
125 } | 127 } |
126 | 128 |
127 bool CreateFileSystemFile(const base::FilePath& file_path, | 129 bool CreateFileSystemFile(const base::FilePath& file_path, |
128 int64 file_size, | 130 int64_t file_size, |
129 const std::string& origin_url, | 131 const std::string& origin_url, |
130 storage::StorageType storage_type) { | 132 storage::StorageType storage_type) { |
131 if (file_path.empty()) | 133 if (file_path.empty()) |
132 return false; | 134 return false; |
133 | 135 |
134 storage::FileSystemType type = | 136 storage::FileSystemType type = |
135 storage::QuotaStorageTypeToFileSystemType(storage_type); | 137 storage::QuotaStorageTypeToFileSystemType(storage_type); |
136 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 138 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
137 GURL(origin_url), type, file_path); | 139 GURL(origin_url), type, file_path); |
138 | 140 |
(...skipping 28 matching lines...) Expand all Loading... |
167 ASSERT_TRUE(CreateFileSystemFile( | 169 ASSERT_TRUE(CreateFileSystemFile( |
168 path, files[i].size, files[i].origin_url, files[i].type)); | 170 path, files[i].size, files[i].origin_url, files[i].type)); |
169 } | 171 } |
170 } | 172 } |
171 } | 173 } |
172 | 174 |
173 // This is a bit fragile--it depends on the test data always creating a | 175 // This is a bit fragile--it depends on the test data always creating a |
174 // directory before adding a file or directory to it, so that we can just | 176 // directory before adding a file or directory to it, so that we can just |
175 // count the basename of each addition. A recursive creation of a path, which | 177 // count the basename of each addition. A recursive creation of a path, which |
176 // created more than one directory in a single shot, would break this. | 178 // created more than one directory in a single shot, would break this. |
177 int64 ComputeFilePathsCostForOriginAndType(const TestFile* files, | 179 int64_t ComputeFilePathsCostForOriginAndType(const TestFile* files, |
178 int num_files, | 180 int num_files, |
179 const std::string& origin_url, | 181 const std::string& origin_url, |
180 storage::StorageType type) { | 182 storage::StorageType type) { |
181 int64 file_paths_cost = 0; | 183 int64_t file_paths_cost = 0; |
182 for (int i = 0; i < num_files; i++) { | 184 for (int i = 0; i < num_files; i++) { |
183 if (files[i].type == type && | 185 if (files[i].type == type && |
184 GURL(files[i].origin_url) == GURL(origin_url)) { | 186 GURL(files[i].origin_url) == GURL(origin_url)) { |
185 base::FilePath path = base::FilePath().AppendASCII(files[i].name); | 187 base::FilePath path = base::FilePath().AppendASCII(files[i].name); |
186 if (!path.empty()) { | 188 if (!path.empty()) { |
187 file_paths_cost += | 189 file_paths_cost += |
188 storage::ObfuscatedFileUtil::ComputeFilePathCost(path); | 190 storage::ObfuscatedFileUtil::ComputeFilePathCost(path); |
189 } | 191 } |
190 } | 192 } |
191 } | 193 } |
192 return file_paths_cost; | 194 return file_paths_cost; |
193 } | 195 } |
194 | 196 |
195 void DeleteOriginData(FileSystemQuotaClient* quota_client, | 197 void DeleteOriginData(FileSystemQuotaClient* quota_client, |
196 const std::string& origin, | 198 const std::string& origin, |
197 storage::StorageType type) { | 199 storage::StorageType type) { |
198 deletion_status_ = storage::kQuotaStatusUnknown; | 200 deletion_status_ = storage::kQuotaStatusUnknown; |
199 quota_client->DeleteOriginData( | 201 quota_client->DeleteOriginData( |
200 GURL(origin), type, | 202 GURL(origin), type, |
201 base::Bind(&FileSystemQuotaClientTest::OnDeleteOrigin, | 203 base::Bind(&FileSystemQuotaClientTest::OnDeleteOrigin, |
202 weak_factory_.GetWeakPtr())); | 204 weak_factory_.GetWeakPtr())); |
203 } | 205 } |
204 | 206 |
205 int64 usage() const { return usage_; } | 207 int64_t usage() const { return usage_; } |
206 storage::QuotaStatusCode status() { return deletion_status_; } | 208 storage::QuotaStatusCode status() { return deletion_status_; } |
207 int additional_callback_count() const { return additional_callback_count_; } | 209 int additional_callback_count() const { return additional_callback_count_; } |
208 void set_additional_callback_count(int count) { | 210 void set_additional_callback_count(int count) { |
209 additional_callback_count_ = count; | 211 additional_callback_count_ = count; |
210 } | 212 } |
211 | 213 |
212 private: | 214 private: |
213 void OnGetUsage(int64 usage) { | 215 void OnGetUsage(int64_t usage) { usage_ = usage; } |
214 usage_ = usage; | |
215 } | |
216 | 216 |
217 void OnGetOrigins(const std::set<GURL>& origins) { | 217 void OnGetOrigins(const std::set<GURL>& origins) { |
218 origins_ = origins; | 218 origins_ = origins; |
219 } | 219 } |
220 | 220 |
221 void OnGetAdditionalUsage(int64 usage_unused) { | 221 void OnGetAdditionalUsage(int64_t usage_unused) { |
222 ++additional_callback_count_; | 222 ++additional_callback_count_; |
223 } | 223 } |
224 | 224 |
225 void OnDeleteOrigin(storage::QuotaStatusCode status) { | 225 void OnDeleteOrigin(storage::QuotaStatusCode status) { |
226 deletion_status_ = status; | 226 deletion_status_ = status; |
227 } | 227 } |
228 | 228 |
229 base::ScopedTempDir data_dir_; | 229 base::ScopedTempDir data_dir_; |
230 base::MessageLoop message_loop_; | 230 base::MessageLoop message_loop_; |
231 scoped_refptr<storage::FileSystemContext> file_system_context_; | 231 scoped_refptr<storage::FileSystemContext> file_system_context_; |
232 int64 usage_; | 232 int64_t usage_; |
233 int additional_callback_count_; | 233 int additional_callback_count_; |
234 std::set<GURL> origins_; | 234 std::set<GURL> origins_; |
235 storage::QuotaStatusCode deletion_status_; | 235 storage::QuotaStatusCode deletion_status_; |
236 base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_; | 236 base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_; |
237 | 237 |
238 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); | 238 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest); |
239 }; | 239 }; |
240 | 240 |
241 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { | 241 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) { |
242 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 242 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
(...skipping 13 matching lines...) Expand all Loading... |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 TEST_F(FileSystemQuotaClientTest, OneFileTest) { | 259 TEST_F(FileSystemQuotaClientTest, OneFileTest) { |
260 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 260 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
261 const TestFile kFiles[] = { | 261 const TestFile kFiles[] = { |
262 {true, NULL, 0, kDummyURL1, kTemporary}, | 262 {true, NULL, 0, kDummyURL1, kTemporary}, |
263 {false, "foo", 4921, kDummyURL1, kTemporary}, | 263 {false, "foo", 4921, kDummyURL1, kTemporary}, |
264 }; | 264 }; |
265 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 265 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
266 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( | 266 const int64_t file_paths_cost = ComputeFilePathsCostForOriginAndType( |
267 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | 267 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); |
268 | 268 |
269 for (int i = 0; i < 2; i++) { | 269 for (int i = 0; i < 2; i++) { |
270 EXPECT_EQ(4921 + file_paths_cost, | 270 EXPECT_EQ(4921 + file_paths_cost, |
271 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 271 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
272 } | 272 } |
273 } | 273 } |
274 | 274 |
275 TEST_F(FileSystemQuotaClientTest, TwoFilesTest) { | 275 TEST_F(FileSystemQuotaClientTest, TwoFilesTest) { |
276 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 276 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
277 const TestFile kFiles[] = { | 277 const TestFile kFiles[] = { |
278 {true, NULL, 0, kDummyURL1, kTemporary}, | 278 {true, NULL, 0, kDummyURL1, kTemporary}, |
279 {false, "foo", 10310, kDummyURL1, kTemporary}, | 279 {false, "foo", 10310, kDummyURL1, kTemporary}, |
280 {false, "bar", 41, kDummyURL1, kTemporary}, | 280 {false, "bar", 41, kDummyURL1, kTemporary}, |
281 }; | 281 }; |
282 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 282 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
283 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( | 283 const int64_t file_paths_cost = ComputeFilePathsCostForOriginAndType( |
284 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | 284 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); |
285 | 285 |
286 for (int i = 0; i < 2; i++) { | 286 for (int i = 0; i < 2; i++) { |
287 EXPECT_EQ(10310 + 41 + file_paths_cost, | 287 EXPECT_EQ(10310 + 41 + file_paths_cost, |
288 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 288 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 TEST_F(FileSystemQuotaClientTest, EmptyFilesTest) { | 292 TEST_F(FileSystemQuotaClientTest, EmptyFilesTest) { |
293 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 293 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
294 const TestFile kFiles[] = { | 294 const TestFile kFiles[] = { |
295 {true, NULL, 0, kDummyURL1, kTemporary}, | 295 {true, NULL, 0, kDummyURL1, kTemporary}, |
296 {false, "foo", 0, kDummyURL1, kTemporary}, | 296 {false, "foo", 0, kDummyURL1, kTemporary}, |
297 {false, "bar", 0, kDummyURL1, kTemporary}, | 297 {false, "bar", 0, kDummyURL1, kTemporary}, |
298 {false, "baz", 0, kDummyURL1, kTemporary}, | 298 {false, "baz", 0, kDummyURL1, kTemporary}, |
299 }; | 299 }; |
300 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 300 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
301 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( | 301 const int64_t file_paths_cost = ComputeFilePathsCostForOriginAndType( |
302 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | 302 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); |
303 | 303 |
304 for (int i = 0; i < 2; i++) { | 304 for (int i = 0; i < 2; i++) { |
305 EXPECT_EQ(file_paths_cost, | 305 EXPECT_EQ(file_paths_cost, |
306 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 306 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 TEST_F(FileSystemQuotaClientTest, SubDirectoryTest) { | 310 TEST_F(FileSystemQuotaClientTest, SubDirectoryTest) { |
311 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 311 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
312 const TestFile kFiles[] = { | 312 const TestFile kFiles[] = { |
313 {true, NULL, 0, kDummyURL1, kTemporary}, | 313 {true, NULL, 0, kDummyURL1, kTemporary}, |
314 {true, "dirtest", 0, kDummyURL1, kTemporary}, | 314 {true, "dirtest", 0, kDummyURL1, kTemporary}, |
315 {false, "dirtest/foo", 11921, kDummyURL1, kTemporary}, | 315 {false, "dirtest/foo", 11921, kDummyURL1, kTemporary}, |
316 {false, "bar", 4814, kDummyURL1, kTemporary}, | 316 {false, "bar", 4814, kDummyURL1, kTemporary}, |
317 }; | 317 }; |
318 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 318 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
319 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( | 319 const int64_t file_paths_cost = ComputeFilePathsCostForOriginAndType( |
320 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | 320 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); |
321 | 321 |
322 for (int i = 0; i < 2; i++) { | 322 for (int i = 0; i < 2; i++) { |
323 EXPECT_EQ(11921 + 4814 + file_paths_cost, | 323 EXPECT_EQ(11921 + 4814 + file_paths_cost, |
324 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 324 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 TEST_F(FileSystemQuotaClientTest, MultiTypeTest) { | 328 TEST_F(FileSystemQuotaClientTest, MultiTypeTest) { |
329 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 329 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
330 const TestFile kFiles[] = { | 330 const TestFile kFiles[] = { |
331 {true, NULL, 0, kDummyURL1, kTemporary}, | 331 {true, NULL, 0, kDummyURL1, kTemporary}, |
332 {true, "dirtest", 0, kDummyURL1, kTemporary}, | 332 {true, "dirtest", 0, kDummyURL1, kTemporary}, |
333 {false, "dirtest/foo", 133, kDummyURL1, kTemporary}, | 333 {false, "dirtest/foo", 133, kDummyURL1, kTemporary}, |
334 {false, "bar", 14, kDummyURL1, kTemporary}, | 334 {false, "bar", 14, kDummyURL1, kTemporary}, |
335 {true, NULL, 0, kDummyURL1, kPersistent}, | 335 {true, NULL, 0, kDummyURL1, kPersistent}, |
336 {true, "dirtest", 0, kDummyURL1, kPersistent}, | 336 {true, "dirtest", 0, kDummyURL1, kPersistent}, |
337 {false, "dirtest/foo", 193, kDummyURL1, kPersistent}, | 337 {false, "dirtest/foo", 193, kDummyURL1, kPersistent}, |
338 {false, "bar", 9, kDummyURL1, kPersistent}, | 338 {false, "bar", 9, kDummyURL1, kPersistent}, |
339 }; | 339 }; |
340 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 340 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
341 const int64 file_paths_cost_temporary = ComputeFilePathsCostForOriginAndType( | 341 const int64_t file_paths_cost_temporary = |
342 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | 342 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
343 const int64 file_paths_cost_persistent = ComputeFilePathsCostForOriginAndType( | 343 kDummyURL1, kTemporary); |
344 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | 344 const int64_t file_paths_cost_persistent = |
| 345 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
| 346 kDummyURL1, kTemporary); |
345 | 347 |
346 for (int i = 0; i < 2; i++) { | 348 for (int i = 0; i < 2; i++) { |
347 EXPECT_EQ(133 + 14 + file_paths_cost_temporary, | 349 EXPECT_EQ(133 + 14 + file_paths_cost_temporary, |
348 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 350 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
349 EXPECT_EQ(193 + 9 + file_paths_cost_persistent, | 351 EXPECT_EQ(193 + 9 + file_paths_cost_persistent, |
350 GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); | 352 GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); |
351 } | 353 } |
352 } | 354 } |
353 | 355 |
354 TEST_F(FileSystemQuotaClientTest, MultiDomainTest) { | 356 TEST_F(FileSystemQuotaClientTest, MultiDomainTest) { |
(...skipping 10 matching lines...) Expand all Loading... |
365 {true, NULL, 0, kDummyURL2, kTemporary}, | 367 {true, NULL, 0, kDummyURL2, kTemporary}, |
366 {true, "dom", 0, kDummyURL2, kTemporary}, | 368 {true, "dom", 0, kDummyURL2, kTemporary}, |
367 {false, "dom/fan", 1319, kDummyURL2, kTemporary}, | 369 {false, "dom/fan", 1319, kDummyURL2, kTemporary}, |
368 {false, "bar", 113, kDummyURL2, kTemporary}, | 370 {false, "bar", 113, kDummyURL2, kTemporary}, |
369 {true, NULL, 0, kDummyURL2, kPersistent}, | 371 {true, NULL, 0, kDummyURL2, kPersistent}, |
370 {true, "dom", 0, kDummyURL2, kPersistent}, | 372 {true, "dom", 0, kDummyURL2, kPersistent}, |
371 {false, "dom/fan", 2013, kDummyURL2, kPersistent}, | 373 {false, "dom/fan", 2013, kDummyURL2, kPersistent}, |
372 {false, "baz", 18, kDummyURL2, kPersistent}, | 374 {false, "baz", 18, kDummyURL2, kPersistent}, |
373 }; | 375 }; |
374 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 376 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
375 const int64 file_paths_cost_temporary1 = ComputeFilePathsCostForOriginAndType( | 377 const int64_t file_paths_cost_temporary1 = |
376 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | |
377 const int64 file_paths_cost_persistent1 = | |
378 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), | 378 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
379 kDummyURL1, kPersistent); | 379 kDummyURL1, kTemporary); |
380 const int64 file_paths_cost_temporary2 = ComputeFilePathsCostForOriginAndType( | 380 const int64_t file_paths_cost_persistent1 = |
381 kFiles, arraysize(kFiles), kDummyURL2, kTemporary); | |
382 const int64 file_paths_cost_persistent2 = | |
383 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), | 381 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
384 kDummyURL2, kPersistent); | 382 kDummyURL1, kPersistent); |
| 383 const int64_t file_paths_cost_temporary2 = |
| 384 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
| 385 kDummyURL2, kTemporary); |
| 386 const int64_t file_paths_cost_persistent2 = |
| 387 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
| 388 kDummyURL2, kPersistent); |
385 | 389 |
386 for (int i = 0; i < 2; i++) { | 390 for (int i = 0; i < 2; i++) { |
387 EXPECT_EQ(1331 + 134 + file_paths_cost_temporary1, | 391 EXPECT_EQ(1331 + 134 + file_paths_cost_temporary1, |
388 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 392 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
389 EXPECT_EQ(1903 + 19 + file_paths_cost_persistent1, | 393 EXPECT_EQ(1903 + 19 + file_paths_cost_persistent1, |
390 GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); | 394 GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); |
391 EXPECT_EQ(1319 + 113 + file_paths_cost_temporary2, | 395 EXPECT_EQ(1319 + 113 + file_paths_cost_temporary2, |
392 GetOriginUsage(quota_client.get(), kDummyURL2, kTemporary)); | 396 GetOriginUsage(quota_client.get(), kDummyURL2, kTemporary)); |
393 EXPECT_EQ(2013 + 18 + file_paths_cost_persistent2, | 397 EXPECT_EQ(2013 + 18 + file_paths_cost_persistent2, |
394 GetOriginUsage(quota_client.get(), kDummyURL2, kPersistent)); | 398 GetOriginUsage(quota_client.get(), kDummyURL2, kPersistent)); |
395 } | 399 } |
396 } | 400 } |
397 | 401 |
398 TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) { | 402 TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) { |
399 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); | 403 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false)); |
400 const TestFile kFiles[] = { | 404 const TestFile kFiles[] = { |
401 {true, NULL, 0, kDummyURL1, kTemporary}, | 405 {true, NULL, 0, kDummyURL1, kTemporary}, |
402 {false, "foo", 11, kDummyURL1, kTemporary}, | 406 {false, "foo", 11, kDummyURL1, kTemporary}, |
403 {false, "bar", 22, kDummyURL1, kTemporary}, | 407 {false, "bar", 22, kDummyURL1, kTemporary}, |
404 }; | 408 }; |
405 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 409 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
406 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType( | 410 const int64_t file_paths_cost = ComputeFilePathsCostForOriginAndType( |
407 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); | 411 kFiles, arraysize(kFiles), kDummyURL1, kTemporary); |
408 | 412 |
409 // Dispatching three GetUsage tasks. | 413 // Dispatching three GetUsage tasks. |
410 set_additional_callback_count(0); | 414 set_additional_callback_count(0); |
411 GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary); | 415 GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary); |
412 RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); | 416 RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); |
413 RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); | 417 RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary); |
414 base::RunLoop().RunUntilIdle(); | 418 base::RunLoop().RunUntilIdle(); |
415 EXPECT_EQ(11 + 22 + file_paths_cost, usage()); | 419 EXPECT_EQ(11 + 22 + file_paths_cost, usage()); |
416 EXPECT_EQ(2, additional_callback_count()); | 420 EXPECT_EQ(2, additional_callback_count()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 {true, NULL, 0, "http://bar.com/", kTemporary}, | 502 {true, NULL, 0, "http://bar.com/", kTemporary}, |
499 {false, "d", 8, "http://bar.com/", kTemporary}, | 503 {false, "d", 8, "http://bar.com/", kTemporary}, |
500 {true, NULL, 0, "http://bar.com/", kPersistent}, | 504 {true, NULL, 0, "http://bar.com/", kPersistent}, |
501 {false, "e", 16, "http://bar.com/", kPersistent}, | 505 {false, "e", 16, "http://bar.com/", kPersistent}, |
502 {true, NULL, 0, "https://bar.com/", kPersistent}, | 506 {true, NULL, 0, "https://bar.com/", kPersistent}, |
503 {false, "f", 32, "https://bar.com/", kPersistent}, | 507 {false, "f", 32, "https://bar.com/", kPersistent}, |
504 {true, NULL, 0, "https://bar.com/", kTemporary}, | 508 {true, NULL, 0, "https://bar.com/", kTemporary}, |
505 {false, "g", 64, "https://bar.com/", kTemporary}, | 509 {false, "g", 64, "https://bar.com/", kTemporary}, |
506 }; | 510 }; |
507 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); | 511 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles)); |
508 const int64 file_paths_cost_temporary_foo_https = | 512 const int64_t file_paths_cost_temporary_foo_https = |
509 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), | 513 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
510 "https://foo.com/", kTemporary); | 514 "https://foo.com/", kTemporary); |
511 const int64 file_paths_cost_persistent_foo = | 515 const int64_t file_paths_cost_persistent_foo = |
512 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), | 516 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
513 "http://foo.com/", kPersistent); | 517 "http://foo.com/", kPersistent); |
514 const int64 file_paths_cost_temporary_bar = | 518 const int64_t file_paths_cost_temporary_bar = |
515 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), | 519 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
516 "http://bar.com/", kTemporary); | 520 "http://bar.com/", kTemporary); |
517 const int64 file_paths_cost_temporary_bar_https = | 521 const int64_t file_paths_cost_temporary_bar_https = |
518 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), | 522 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
519 "https://bar.com/", kTemporary); | 523 "https://bar.com/", kTemporary); |
520 const int64 file_paths_cost_persistent_bar_https = | 524 const int64_t file_paths_cost_persistent_bar_https = |
521 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), | 525 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles), |
522 "https://bar.com/", kPersistent); | 526 "https://bar.com/", kPersistent); |
523 | 527 |
524 DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary); | 528 DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary); |
525 base::RunLoop().RunUntilIdle(); | 529 base::RunLoop().RunUntilIdle(); |
526 EXPECT_EQ(storage::kQuotaStatusOk, status()); | 530 EXPECT_EQ(storage::kQuotaStatusOk, status()); |
527 | 531 |
528 DeleteOriginData(quota_client.get(), "http://bar.com/", kPersistent); | 532 DeleteOriginData(quota_client.get(), "http://bar.com/", kPersistent); |
529 base::RunLoop().RunUntilIdle(); | 533 base::RunLoop().RunUntilIdle(); |
530 EXPECT_EQ(storage::kQuotaStatusOk, status()); | 534 EXPECT_EQ(storage::kQuotaStatusOk, status()); |
531 | 535 |
532 DeleteOriginData(quota_client.get(), "http://buz.com/", kTemporary); | 536 DeleteOriginData(quota_client.get(), "http://buz.com/", kTemporary); |
(...skipping 23 matching lines...) Expand all Loading... |
556 GetOriginUsage(quota_client.get(), | 560 GetOriginUsage(quota_client.get(), |
557 "https://bar.com/", | 561 "https://bar.com/", |
558 kPersistent)); | 562 kPersistent)); |
559 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, | 563 EXPECT_EQ(64 + file_paths_cost_temporary_bar_https, |
560 GetOriginUsage(quota_client.get(), | 564 GetOriginUsage(quota_client.get(), |
561 "https://bar.com/", | 565 "https://bar.com/", |
562 kTemporary)); | 566 kTemporary)); |
563 } | 567 } |
564 | 568 |
565 } // namespace content | 569 } // namespace content |
OLD | NEW |