Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: webkit/fileapi/local_file_system_quota_unittest.cc

Issue 11595003: webkit: Update the calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This test checks the entire behavior of FileSystem usage and quota, such as: 5 // This test checks the entire behavior of FileSystem usage and quota, such as:
6 // 1) the actual size of files on disk, 6 // 1) the actual size of files on disk,
7 // 2) the described size in .usage, and 7 // 2) the described size in .usage, and
8 // 3) the result of QuotaManager::GetUsageAndQuota. 8 // 3) the result of QuotaManager::GetUsageAndQuota.
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 int64 SizeByQuotaUtil() { 90 int64 SizeByQuotaUtil() {
91 return test_helper_.GetCachedOriginUsage(); 91 return test_helper_.GetCachedOriginUsage();
92 } 92 }
93 93
94 void GetUsageAndQuotaFromQuotaManager() { 94 void GetUsageAndQuotaFromQuotaManager() {
95 quota_manager_->GetUsageAndQuota( 95 quota_manager_->GetUsageAndQuota(
96 test_helper_.origin(), test_helper_.storage_type(), 96 test_helper_.origin(), test_helper_.storage_type(),
97 base::Bind(&LocalFileSystemQuotaTest::OnGetUsageAndQuota, 97 base::Bind(&LocalFileSystemQuotaTest::OnGetUsageAndQuota,
98 weak_factory_.GetWeakPtr())); 98 weak_factory_.GetWeakPtr()));
99 MessageLoop::current()->RunAllPending(); 99 MessageLoop::current()->RunUntilIdle();
100 } 100 }
101 101
102 bool FileExists(const FilePath& virtual_path) { 102 bool FileExists(const FilePath& virtual_path) {
103 FileSystemURL path = test_helper_.CreateURL(virtual_path); 103 FileSystemURL path = test_helper_.CreateURL(virtual_path);
104 scoped_ptr<FileSystemOperationContext> context(NewContext()); 104 scoped_ptr<FileSystemOperationContext> context(NewContext());
105 return FileUtilHelper::PathExists(context.get(), file_util(), path); 105 return FileUtilHelper::PathExists(context.get(), file_util(), path);
106 } 106 }
107 107
108 bool DirectoryExists(const FilePath& virtual_path) { 108 bool DirectoryExists(const FilePath& virtual_path) {
109 FileSystemURL path = test_helper_.CreateURL(virtual_path); 109 FileSystemURL path = test_helper_.CreateURL(virtual_path);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 int total_path_cost = SizeByQuotaUtil(); 236 int total_path_cost = SizeByQuotaUtil();
237 237
238 operation()->Truncate(URLForPath(child_file1_path_), 5000, 238 operation()->Truncate(URLForPath(child_file1_path_), 5000,
239 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 239 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
240 operation()->Truncate(URLForPath(child_file2_path_), 400, 240 operation()->Truncate(URLForPath(child_file2_path_), 400,
241 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 241 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
242 operation()->Truncate(URLForPath(grandchild_file1_path_), 30, 242 operation()->Truncate(URLForPath(grandchild_file1_path_), 30,
243 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 243 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
244 operation()->Truncate(URLForPath(grandchild_file2_path_), 2, 244 operation()->Truncate(URLForPath(grandchild_file2_path_), 2,
245 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 245 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
246 MessageLoop::current()->RunAllPending(); 246 MessageLoop::current()->RunUntilIdle();
247 247
248 const int64 all_file_size = 5000 + 400 + 30 + 2; 248 const int64 all_file_size = 5000 + 400 + 30 + 2;
249 249
250 EXPECT_EQ(all_file_size, ActualFileSize()); 250 EXPECT_EQ(all_file_size, ActualFileSize());
251 EXPECT_EQ(all_file_size + total_path_cost, SizeByQuotaUtil()); 251 EXPECT_EQ(all_file_size + total_path_cost, SizeByQuotaUtil());
252 GetUsageAndQuotaFromQuotaManager(); 252 GetUsageAndQuotaFromQuotaManager();
253 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 253 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
254 EXPECT_EQ(all_file_size + total_path_cost, usage()); 254 EXPECT_EQ(all_file_size + total_path_cost, usage());
255 ASSERT_LT(all_file_size + total_path_cost, quota()); 255 ASSERT_LT(all_file_size + total_path_cost, quota());
256 256
257 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), 257 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
258 RecordStatusCallback()); 258 RecordStatusCallback());
259 MessageLoop::current()->RunAllPending(); 259 MessageLoop::current()->RunUntilIdle();
260 260
261 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 261 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
262 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( 262 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append(
263 VirtualPath::BaseName(child_dir_path_)))); 263 VirtualPath::BaseName(child_dir_path_))));
264 EXPECT_TRUE(FileExists(dest_dir_path.Append( 264 EXPECT_TRUE(FileExists(dest_dir_path.Append(
265 VirtualPath::BaseName(child_dir_path_)).Append( 265 VirtualPath::BaseName(child_dir_path_)).Append(
266 VirtualPath::BaseName(grandchild_file1_path_)))); 266 VirtualPath::BaseName(grandchild_file1_path_))));
267 267
268 EXPECT_EQ(all_file_size, ActualFileSize()); 268 EXPECT_EQ(all_file_size, ActualFileSize());
269 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, 269 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost,
(...skipping 14 matching lines...) Expand all
284 int total_path_cost = SizeByQuotaUtil(); 284 int total_path_cost = SizeByQuotaUtil();
285 285
286 operation()->Truncate(URLForPath(child_file1_path_), 8000, 286 operation()->Truncate(URLForPath(child_file1_path_), 8000,
287 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 287 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
288 operation()->Truncate(URLForPath(child_file2_path_), 700, 288 operation()->Truncate(URLForPath(child_file2_path_), 700,
289 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 289 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
290 operation()->Truncate(URLForPath(grandchild_file1_path_), 60, 290 operation()->Truncate(URLForPath(grandchild_file1_path_), 60,
291 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 291 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
292 operation()->Truncate(URLForPath(grandchild_file2_path_), 5, 292 operation()->Truncate(URLForPath(grandchild_file2_path_), 5,
293 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK)); 293 base::Bind(&AssertFileErrorEq, base::PLATFORM_FILE_OK));
294 MessageLoop::current()->RunAllPending(); 294 MessageLoop::current()->RunUntilIdle();
295 295
296 const int64 child_file_size = 8000 + 700; 296 const int64 child_file_size = 8000 + 700;
297 const int64 grandchild_file_size = 60 + 5; 297 const int64 grandchild_file_size = 60 + 5;
298 const int64 all_file_size = child_file_size + grandchild_file_size; 298 const int64 all_file_size = child_file_size + grandchild_file_size;
299 int64 expected_usage = all_file_size + total_path_cost; 299 int64 expected_usage = all_file_size + total_path_cost;
300 300
301 EXPECT_EQ(all_file_size, ActualFileSize()); 301 EXPECT_EQ(all_file_size, ActualFileSize());
302 EXPECT_EQ(expected_usage, SizeByQuotaUtil()); 302 EXPECT_EQ(expected_usage, SizeByQuotaUtil());
303 GetUsageAndQuotaFromQuotaManager(); 303 GetUsageAndQuotaFromQuotaManager();
304 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 304 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
305 EXPECT_EQ(expected_usage, usage()); 305 EXPECT_EQ(expected_usage, usage());
306 ASSERT_LT(expected_usage, quota()); 306 ASSERT_LT(expected_usage, quota());
307 307
308 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path), 308 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path),
309 RecordStatusCallback()); 309 RecordStatusCallback());
310 MessageLoop::current()->RunAllPending(); 310 MessageLoop::current()->RunUntilIdle();
311 expected_usage += all_file_size + 311 expected_usage += all_file_size +
312 child_path_cost_ + grandchild_path_cost_; 312 child_path_cost_ + grandchild_path_cost_;
313 313
314 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 314 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
315 EXPECT_TRUE(DirectoryExists(src_dir_path.Append( 315 EXPECT_TRUE(DirectoryExists(src_dir_path.Append(
316 VirtualPath::BaseName(child_dir_path_)))); 316 VirtualPath::BaseName(child_dir_path_))));
317 EXPECT_TRUE(FileExists(src_dir_path.Append( 317 EXPECT_TRUE(FileExists(src_dir_path.Append(
318 VirtualPath::BaseName(child_dir_path_)).Append( 318 VirtualPath::BaseName(child_dir_path_)).Append(
319 VirtualPath::BaseName(grandchild_file1_path_)))); 319 VirtualPath::BaseName(grandchild_file1_path_))));
320 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 320 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
321 EXPECT_TRUE(DirectoryExists(dest_dir1_path.Append( 321 EXPECT_TRUE(DirectoryExists(dest_dir1_path.Append(
322 VirtualPath::BaseName(child_dir_path_)))); 322 VirtualPath::BaseName(child_dir_path_))));
323 EXPECT_TRUE(FileExists(dest_dir1_path.Append( 323 EXPECT_TRUE(FileExists(dest_dir1_path.Append(
324 VirtualPath::BaseName(child_dir_path_)).Append( 324 VirtualPath::BaseName(child_dir_path_)).Append(
325 VirtualPath::BaseName(grandchild_file1_path_)))); 325 VirtualPath::BaseName(grandchild_file1_path_))));
326 326
327 EXPECT_EQ(2 * all_file_size, ActualFileSize()); 327 EXPECT_EQ(2 * all_file_size, ActualFileSize());
328 EXPECT_EQ(expected_usage, SizeByQuotaUtil()); 328 EXPECT_EQ(expected_usage, SizeByQuotaUtil());
329 GetUsageAndQuotaFromQuotaManager(); 329 GetUsageAndQuotaFromQuotaManager();
330 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 330 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
331 EXPECT_EQ(expected_usage, usage()); 331 EXPECT_EQ(expected_usage, usage());
332 ASSERT_LT(expected_usage, quota()); 332 ASSERT_LT(expected_usage, quota());
333 333
334 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path), 334 operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path),
335 RecordStatusCallback()); 335 RecordStatusCallback());
336 MessageLoop::current()->RunAllPending(); 336 MessageLoop::current()->RunUntilIdle();
337 337
338 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 338 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
339 expected_usage += grandchild_file_size + grandchild_path_cost_; 339 expected_usage += grandchild_file_size + grandchild_path_cost_;
340 340
341 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualFileSize()); 341 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, ActualFileSize());
342 EXPECT_EQ(expected_usage, SizeByQuotaUtil()); 342 EXPECT_EQ(expected_usage, SizeByQuotaUtil());
343 GetUsageAndQuotaFromQuotaManager(); 343 GetUsageAndQuotaFromQuotaManager();
344 EXPECT_EQ(quota::kQuotaStatusOk, quota_status()); 344 EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
345 EXPECT_EQ(expected_usage, usage()); 345 EXPECT_EQ(expected_usage, usage());
346 ASSERT_LT(expected_usage, quota()); 346 ASSERT_LT(expected_usage, quota());
347 } 347 }
348 348
349 } // namespace fileapi 349 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/local_file_system_operation_write_unittest.cc ('k') | webkit/fileapi/local_file_system_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698