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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 380993002: Upstream RunBlockingPoolTask(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 5 months 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 #include "chrome/browser/chromeos/drive/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // Disable delaying so that the sync starts immediately. 144 // Disable delaying so that the sync starts immediately.
145 file_system_->sync_client_for_testing()->set_delay_for_testing( 145 file_system_->sync_client_for_testing()->set_delay_for_testing(
146 base::TimeDelta::FromSeconds(0)); 146 base::TimeDelta::FromSeconds(0));
147 } 147 }
148 148
149 // Loads the full resource list via FakeDriveService. 149 // Loads the full resource list via FakeDriveService.
150 bool LoadFullResourceList() { 150 bool LoadFullResourceList() {
151 FileError error = FILE_ERROR_FAILED; 151 FileError error = FILE_ERROR_FAILED;
152 file_system_->change_list_loader_for_testing()->LoadIfNeeded( 152 file_system_->change_list_loader_for_testing()->LoadIfNeeded(
153 google_apis::test_util::CreateCopyResultCallback(&error)); 153 google_apis::test_util::CreateCopyResultCallback(&error));
154 test_util::RunBlockingPoolTask(); 154 content::RunAllBlockingPoolTasksUntilIdle();
155 return error == FILE_ERROR_OK; 155 return error == FILE_ERROR_OK;
156 } 156 }
157 157
158 // Gets resource entry by path synchronously. 158 // Gets resource entry by path synchronously.
159 scoped_ptr<ResourceEntry> GetResourceEntrySync( 159 scoped_ptr<ResourceEntry> GetResourceEntrySync(
160 const base::FilePath& file_path) { 160 const base::FilePath& file_path) {
161 FileError error = FILE_ERROR_FAILED; 161 FileError error = FILE_ERROR_FAILED;
162 scoped_ptr<ResourceEntry> entry; 162 scoped_ptr<ResourceEntry> entry;
163 file_system_->GetResourceEntry( 163 file_system_->GetResourceEntry(
164 file_path, 164 file_path,
165 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 165 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
166 test_util::RunBlockingPoolTask(); 166 content::RunAllBlockingPoolTasksUntilIdle();
167 167
168 return entry.Pass(); 168 return entry.Pass();
169 } 169 }
170 170
171 // Gets directory info by path synchronously. 171 // Gets directory info by path synchronously.
172 scoped_ptr<ResourceEntryVector> ReadDirectorySync( 172 scoped_ptr<ResourceEntryVector> ReadDirectorySync(
173 const base::FilePath& file_path) { 173 const base::FilePath& file_path) {
174 FileError error = FILE_ERROR_FAILED; 174 FileError error = FILE_ERROR_FAILED;
175 scoped_ptr<ResourceEntryVector> entries(new ResourceEntryVector); 175 scoped_ptr<ResourceEntryVector> entries(new ResourceEntryVector);
176 file_system_->ReadDirectory( 176 file_system_->ReadDirectory(
177 file_path, 177 file_path,
178 base::Bind(&AccumulateReadDirectoryResult, entries.get()), 178 base::Bind(&AccumulateReadDirectoryResult, entries.get()),
179 google_apis::test_util::CreateCopyResultCallback(&error)); 179 google_apis::test_util::CreateCopyResultCallback(&error));
180 test_util::RunBlockingPoolTask(); 180 content::RunAllBlockingPoolTasksUntilIdle();
181 if (error != FILE_ERROR_OK) 181 if (error != FILE_ERROR_OK)
182 entries.reset(); 182 entries.reset();
183 return entries.Pass(); 183 return entries.Pass();
184 } 184 }
185 185
186 // Used to implement ReadDirectorySync(). 186 // Used to implement ReadDirectorySync().
187 static void AccumulateReadDirectoryResult( 187 static void AccumulateReadDirectoryResult(
188 ResourceEntryVector* out_entries, 188 ResourceEntryVector* out_entries,
189 scoped_ptr<ResourceEntryVector> entries) { 189 scoped_ptr<ResourceEntryVector> entries) {
190 ASSERT_TRUE(entries); 190 ASSERT_TRUE(entries);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 322 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
323 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Copied.txt")); 323 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Copied.txt"));
324 EXPECT_TRUE(GetResourceEntrySync(src_file_path)); 324 EXPECT_TRUE(GetResourceEntrySync(src_file_path));
325 EXPECT_FALSE(GetResourceEntrySync(dest_file_path)); 325 EXPECT_FALSE(GetResourceEntrySync(dest_file_path));
326 326
327 FileError error = FILE_ERROR_FAILED; 327 FileError error = FILE_ERROR_FAILED;
328 file_system_->Copy(src_file_path, 328 file_system_->Copy(src_file_path,
329 dest_file_path, 329 dest_file_path,
330 false, // preserve_last_modified, 330 false, // preserve_last_modified,
331 google_apis::test_util::CreateCopyResultCallback(&error)); 331 google_apis::test_util::CreateCopyResultCallback(&error));
332 test_util::RunBlockingPoolTask(); 332 content::RunAllBlockingPoolTasksUntilIdle();
333 EXPECT_EQ(FILE_ERROR_OK, error); 333 EXPECT_EQ(FILE_ERROR_OK, error);
334 334
335 // Entry is added on the server. 335 // Entry is added on the server.
336 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); 336 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path);
337 ASSERT_TRUE(entry); 337 ASSERT_TRUE(entry);
338 338
339 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 339 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
340 scoped_ptr<google_apis::FileResource> server_entry; 340 scoped_ptr<google_apis::FileResource> server_entry;
341 fake_drive_service_->GetFileResource( 341 fake_drive_service_->GetFileResource(
342 entry->resource_id(), 342 entry->resource_id(),
343 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 343 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
344 test_util::RunBlockingPoolTask(); 344 content::RunAllBlockingPoolTasksUntilIdle();
345 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 345 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
346 ASSERT_TRUE(server_entry); 346 ASSERT_TRUE(server_entry);
347 EXPECT_EQ(entry->title(), server_entry->title()); 347 EXPECT_EQ(entry->title(), server_entry->title());
348 EXPECT_FALSE(server_entry->IsDirectory()); 348 EXPECT_FALSE(server_entry->IsDirectory());
349 } 349 }
350 350
351 TEST_F(FileSystemTest, Move) { 351 TEST_F(FileSystemTest, Move) {
352 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 352 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
353 base::FilePath dest_file_path( 353 base::FilePath dest_file_path(
354 FILE_PATH_LITERAL("drive/root/Directory 1/Moved.txt")); 354 FILE_PATH_LITERAL("drive/root/Directory 1/Moved.txt"));
355 EXPECT_TRUE(GetResourceEntrySync(src_file_path)); 355 EXPECT_TRUE(GetResourceEntrySync(src_file_path));
356 EXPECT_FALSE(GetResourceEntrySync(dest_file_path)); 356 EXPECT_FALSE(GetResourceEntrySync(dest_file_path));
357 scoped_ptr<ResourceEntry> parent = 357 scoped_ptr<ResourceEntry> parent =
358 GetResourceEntrySync(dest_file_path.DirName()); 358 GetResourceEntrySync(dest_file_path.DirName());
359 ASSERT_TRUE(parent); 359 ASSERT_TRUE(parent);
360 360
361 FileError error = FILE_ERROR_FAILED; 361 FileError error = FILE_ERROR_FAILED;
362 file_system_->Move(src_file_path, 362 file_system_->Move(src_file_path,
363 dest_file_path, 363 dest_file_path,
364 google_apis::test_util::CreateCopyResultCallback(&error)); 364 google_apis::test_util::CreateCopyResultCallback(&error));
365 test_util::RunBlockingPoolTask(); 365 content::RunAllBlockingPoolTasksUntilIdle();
366 EXPECT_EQ(FILE_ERROR_OK, error); 366 EXPECT_EQ(FILE_ERROR_OK, error);
367 367
368 // Entry is moved on the server. 368 // Entry is moved on the server.
369 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path); 369 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path);
370 ASSERT_TRUE(entry); 370 ASSERT_TRUE(entry);
371 371
372 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 372 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
373 scoped_ptr<google_apis::FileResource> server_entry; 373 scoped_ptr<google_apis::FileResource> server_entry;
374 fake_drive_service_->GetFileResource( 374 fake_drive_service_->GetFileResource(
375 entry->resource_id(), 375 entry->resource_id(),
376 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 376 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
377 test_util::RunBlockingPoolTask(); 377 content::RunAllBlockingPoolTasksUntilIdle();
378 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 378 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
379 ASSERT_TRUE(server_entry); 379 ASSERT_TRUE(server_entry);
380 EXPECT_EQ(entry->title(), server_entry->title()); 380 EXPECT_EQ(entry->title(), server_entry->title());
381 381
382 ASSERT_FALSE(server_entry->parents().empty()); 382 ASSERT_FALSE(server_entry->parents().empty());
383 EXPECT_EQ(parent->resource_id(), server_entry->parents()[0].file_id()); 383 EXPECT_EQ(parent->resource_id(), server_entry->parents()[0].file_id());
384 } 384 }
385 385
386 TEST_F(FileSystemTest, Remove) { 386 TEST_F(FileSystemTest, Remove) {
387 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 387 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
388 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); 388 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
389 ASSERT_TRUE(entry); 389 ASSERT_TRUE(entry);
390 390
391 FileError error = FILE_ERROR_FAILED; 391 FileError error = FILE_ERROR_FAILED;
392 file_system_->Remove( 392 file_system_->Remove(
393 file_path, 393 file_path,
394 false, // is_resursive 394 false, // is_resursive
395 google_apis::test_util::CreateCopyResultCallback(&error)); 395 google_apis::test_util::CreateCopyResultCallback(&error));
396 test_util::RunBlockingPoolTask(); 396 content::RunAllBlockingPoolTasksUntilIdle();
397 EXPECT_EQ(FILE_ERROR_OK, error); 397 EXPECT_EQ(FILE_ERROR_OK, error);
398 398
399 // Entry is removed on the server. 399 // Entry is removed on the server.
400 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 400 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
401 scoped_ptr<google_apis::FileResource> server_entry; 401 scoped_ptr<google_apis::FileResource> server_entry;
402 fake_drive_service_->GetFileResource( 402 fake_drive_service_->GetFileResource(
403 entry->resource_id(), 403 entry->resource_id(),
404 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 404 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
405 test_util::RunBlockingPoolTask(); 405 content::RunAllBlockingPoolTasksUntilIdle();
406 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 406 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
407 ASSERT_TRUE(server_entry); 407 ASSERT_TRUE(server_entry);
408 EXPECT_TRUE(server_entry->labels().is_trashed()); 408 EXPECT_TRUE(server_entry->labels().is_trashed());
409 } 409 }
410 410
411 TEST_F(FileSystemTest, CreateDirectory) { 411 TEST_F(FileSystemTest, CreateDirectory) {
412 base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory")); 412 base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory"));
413 EXPECT_FALSE(GetResourceEntrySync(directory_path)); 413 EXPECT_FALSE(GetResourceEntrySync(directory_path));
414 414
415 FileError error = FILE_ERROR_FAILED; 415 FileError error = FILE_ERROR_FAILED;
416 file_system_->CreateDirectory( 416 file_system_->CreateDirectory(
417 directory_path, 417 directory_path,
418 true, // is_exclusive 418 true, // is_exclusive
419 false, // is_recursive 419 false, // is_recursive
420 google_apis::test_util::CreateCopyResultCallback(&error)); 420 google_apis::test_util::CreateCopyResultCallback(&error));
421 test_util::RunBlockingPoolTask(); 421 content::RunAllBlockingPoolTasksUntilIdle();
422 EXPECT_EQ(FILE_ERROR_OK, error); 422 EXPECT_EQ(FILE_ERROR_OK, error);
423 423
424 // Directory is created on the server. 424 // Directory is created on the server.
425 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(directory_path); 425 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(directory_path);
426 ASSERT_TRUE(entry); 426 ASSERT_TRUE(entry);
427 427
428 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 428 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
429 scoped_ptr<google_apis::FileResource> server_entry; 429 scoped_ptr<google_apis::FileResource> server_entry;
430 fake_drive_service_->GetFileResource( 430 fake_drive_service_->GetFileResource(
431 entry->resource_id(), 431 entry->resource_id(),
432 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 432 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
433 test_util::RunBlockingPoolTask(); 433 content::RunAllBlockingPoolTasksUntilIdle();
434 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 434 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
435 ASSERT_TRUE(server_entry); 435 ASSERT_TRUE(server_entry);
436 EXPECT_EQ(entry->title(), server_entry->title()); 436 EXPECT_EQ(entry->title(), server_entry->title());
437 EXPECT_TRUE(server_entry->IsDirectory()); 437 EXPECT_TRUE(server_entry->IsDirectory());
438 } 438 }
439 439
440 TEST_F(FileSystemTest, CreateFile) { 440 TEST_F(FileSystemTest, CreateFile) {
441 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt")); 441 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt"));
442 EXPECT_FALSE(GetResourceEntrySync(file_path)); 442 EXPECT_FALSE(GetResourceEntrySync(file_path));
443 443
444 FileError error = FILE_ERROR_FAILED; 444 FileError error = FILE_ERROR_FAILED;
445 file_system_->CreateFile( 445 file_system_->CreateFile(
446 file_path, 446 file_path,
447 true, // is_exclusive 447 true, // is_exclusive
448 "text/plain", 448 "text/plain",
449 google_apis::test_util::CreateCopyResultCallback(&error)); 449 google_apis::test_util::CreateCopyResultCallback(&error));
450 test_util::RunBlockingPoolTask(); 450 content::RunAllBlockingPoolTasksUntilIdle();
451 EXPECT_EQ(FILE_ERROR_OK, error); 451 EXPECT_EQ(FILE_ERROR_OK, error);
452 452
453 // File is created on the server. 453 // File is created on the server.
454 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); 454 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
455 ASSERT_TRUE(entry); 455 ASSERT_TRUE(entry);
456 456
457 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 457 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
458 scoped_ptr<google_apis::FileResource> server_entry; 458 scoped_ptr<google_apis::FileResource> server_entry;
459 fake_drive_service_->GetFileResource( 459 fake_drive_service_->GetFileResource(
460 entry->resource_id(), 460 entry->resource_id(),
461 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 461 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
462 test_util::RunBlockingPoolTask(); 462 content::RunAllBlockingPoolTasksUntilIdle();
463 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 463 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
464 ASSERT_TRUE(server_entry); 464 ASSERT_TRUE(server_entry);
465 EXPECT_EQ(entry->title(), server_entry->title()); 465 EXPECT_EQ(entry->title(), server_entry->title());
466 EXPECT_FALSE(server_entry->IsDirectory()); 466 EXPECT_FALSE(server_entry->IsDirectory());
467 } 467 }
468 468
469 TEST_F(FileSystemTest, TouchFile) { 469 TEST_F(FileSystemTest, TouchFile) {
470 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 470 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
471 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); 471 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
472 ASSERT_TRUE(entry); 472 ASSERT_TRUE(entry);
473 473
474 base::Time last_accessed = 474 base::Time last_accessed =
475 base::Time::FromInternalValue(entry->file_info().last_accessed()) + 475 base::Time::FromInternalValue(entry->file_info().last_accessed()) +
476 base::TimeDelta::FromSeconds(1); 476 base::TimeDelta::FromSeconds(1);
477 base::Time last_modified = 477 base::Time last_modified =
478 base::Time::FromInternalValue(entry->file_info().last_modified()) + 478 base::Time::FromInternalValue(entry->file_info().last_modified()) +
479 base::TimeDelta::FromSeconds(1); 479 base::TimeDelta::FromSeconds(1);
480 480
481 FileError error = FILE_ERROR_FAILED; 481 FileError error = FILE_ERROR_FAILED;
482 file_system_->TouchFile( 482 file_system_->TouchFile(
483 file_path, 483 file_path,
484 last_accessed, 484 last_accessed,
485 last_modified, 485 last_modified,
486 google_apis::test_util::CreateCopyResultCallback(&error)); 486 google_apis::test_util::CreateCopyResultCallback(&error));
487 test_util::RunBlockingPoolTask(); 487 content::RunAllBlockingPoolTasksUntilIdle();
488 EXPECT_EQ(FILE_ERROR_OK, error); 488 EXPECT_EQ(FILE_ERROR_OK, error);
489 489
490 // File is touched on the server. 490 // File is touched on the server.
491 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 491 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
492 scoped_ptr<google_apis::FileResource> server_entry; 492 scoped_ptr<google_apis::FileResource> server_entry;
493 fake_drive_service_->GetFileResource( 493 fake_drive_service_->GetFileResource(
494 entry->resource_id(), 494 entry->resource_id(),
495 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 495 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
496 test_util::RunBlockingPoolTask(); 496 content::RunAllBlockingPoolTasksUntilIdle();
497 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 497 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
498 ASSERT_TRUE(server_entry); 498 ASSERT_TRUE(server_entry);
499 EXPECT_EQ(last_accessed, server_entry->last_viewed_by_me_date()); 499 EXPECT_EQ(last_accessed, server_entry->last_viewed_by_me_date());
500 EXPECT_EQ(last_modified, server_entry->modified_date()); 500 EXPECT_EQ(last_modified, server_entry->modified_date());
501 } 501 }
502 502
503 TEST_F(FileSystemTest, TruncateFile) { 503 TEST_F(FileSystemTest, TruncateFile) {
504 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 504 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
505 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path); 505 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
506 ASSERT_TRUE(entry); 506 ASSERT_TRUE(entry);
507 507
508 const int64 kLength = entry->file_info().size() + 100; 508 const int64 kLength = entry->file_info().size() + 100;
509 509
510 FileError error = FILE_ERROR_FAILED; 510 FileError error = FILE_ERROR_FAILED;
511 file_system_->TruncateFile( 511 file_system_->TruncateFile(
512 file_path, 512 file_path,
513 kLength, 513 kLength,
514 google_apis::test_util::CreateCopyResultCallback(&error)); 514 google_apis::test_util::CreateCopyResultCallback(&error));
515 test_util::RunBlockingPoolTask(); 515 content::RunAllBlockingPoolTasksUntilIdle();
516 EXPECT_EQ(FILE_ERROR_OK, error); 516 EXPECT_EQ(FILE_ERROR_OK, error);
517 517
518 // File is touched on the server. 518 // File is touched on the server.
519 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 519 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
520 scoped_ptr<google_apis::FileResource> server_entry; 520 scoped_ptr<google_apis::FileResource> server_entry;
521 fake_drive_service_->GetFileResource( 521 fake_drive_service_->GetFileResource(
522 entry->resource_id(), 522 entry->resource_id(),
523 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); 523 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
524 test_util::RunBlockingPoolTask(); 524 content::RunAllBlockingPoolTasksUntilIdle();
525 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 525 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
526 ASSERT_TRUE(server_entry); 526 ASSERT_TRUE(server_entry);
527 EXPECT_EQ(kLength, server_entry->file_size()); 527 EXPECT_EQ(kLength, server_entry->file_size());
528 } 528 }
529 529
530 TEST_F(FileSystemTest, DuplicatedAsyncInitialization) { 530 TEST_F(FileSystemTest, DuplicatedAsyncInitialization) {
531 base::RunLoop loop; 531 base::RunLoop loop;
532 532
533 int counter = 0; 533 int counter = 0;
534 const GetResourceEntryCallback& callback = base::Bind( 534 const GetResourceEntryCallback& callback = base::Bind(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 // changestamp (i.e. the local metadata is up-to-date), so no request for 660 // changestamp (i.e. the local metadata is up-to-date), so no request for
661 // new resource list (i.e., call to GetResourceList) should happen. 661 // new resource list (i.e., call to GetResourceList) should happen.
662 EXPECT_EQ(0, fake_drive_service_->file_list_load_count()); 662 EXPECT_EQ(0, fake_drive_service_->file_list_load_count());
663 663
664 // Since the file system has verified that it holds the latest snapshot, 664 // Since the file system has verified that it holds the latest snapshot,
665 // it should change its state to "loaded", which admits periodic refresh. 665 // it should change its state to "loaded", which admits periodic refresh.
666 // To test it, call CheckForUpdates and verify it does try to check updates. 666 // To test it, call CheckForUpdates and verify it does try to check updates.
667 const int about_resource_load_count_before = 667 const int about_resource_load_count_before =
668 fake_drive_service_->about_resource_load_count(); 668 fake_drive_service_->about_resource_load_count();
669 file_system_->CheckForUpdates(); 669 file_system_->CheckForUpdates();
670 test_util::RunBlockingPoolTask(); 670 content::RunAllBlockingPoolTasksUntilIdle();
671 EXPECT_LT(about_resource_load_count_before, 671 EXPECT_LT(about_resource_load_count_before,
672 fake_drive_service_->about_resource_load_count()); 672 fake_drive_service_->about_resource_load_count());
673 } 673 }
674 674
675 TEST_F(FileSystemTest, LoadFileSystemFromCacheWhileOffline) { 675 TEST_F(FileSystemTest, LoadFileSystemFromCacheWhileOffline) {
676 ASSERT_NO_FATAL_FAILURE(SetUpTestFileSystem(USE_OLD_TIMESTAMP)); 676 ASSERT_NO_FATAL_FAILURE(SetUpTestFileSystem(USE_OLD_TIMESTAMP));
677 677
678 // Make GetResourceList fail for simulating offline situation. This will 678 // Make GetResourceList fail for simulating offline situation. This will
679 // leave the file system "loaded from cache, but not synced with server" 679 // leave the file system "loaded from cache, but not synced with server"
680 // state. 680 // state.
(...skipping 21 matching lines...) Expand all
702 FILE_PATH_LITERAL("drive/root/Dir1/SubDir2/File3")))); 702 FILE_PATH_LITERAL("drive/root/Dir1/SubDir2/File3"))));
703 703
704 // Since the file system has at least succeeded to load cached snapshot, 704 // Since the file system has at least succeeded to load cached snapshot,
705 // the file system should be able to start periodic refresh. 705 // the file system should be able to start periodic refresh.
706 // To test it, call CheckForUpdates and verify it does try to check 706 // To test it, call CheckForUpdates and verify it does try to check
707 // updates, which will cause directory changes. 707 // updates, which will cause directory changes.
708 fake_drive_service_->set_offline(false); 708 fake_drive_service_->set_offline(false);
709 709
710 file_system_->CheckForUpdates(); 710 file_system_->CheckForUpdates();
711 711
712 test_util::RunBlockingPoolTask(); 712 content::RunAllBlockingPoolTasksUntilIdle();
713 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 713 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
714 EXPECT_EQ(1, fake_drive_service_->change_list_load_count()); 714 EXPECT_EQ(1, fake_drive_service_->change_list_load_count());
715 715
716 ASSERT_LE(0u, mock_directory_observer_->changed_directories().size()); 716 ASSERT_LE(0u, mock_directory_observer_->changed_directories().size());
717 ASSERT_LE(1u, mock_directory_observer_->changed_files().size()); 717 ASSERT_LE(1u, mock_directory_observer_->changed_files().size());
718 } 718 }
719 719
720 TEST_F(FileSystemTest, ReadDirectoryWhileRefreshing) { 720 TEST_F(FileSystemTest, ReadDirectoryWhileRefreshing) {
721 // Use old timestamp so the fast fetch will be performed. 721 // Use old timestamp so the fast fetch will be performed.
722 ASSERT_NO_FATAL_FAILURE(SetUpTestFileSystem(USE_OLD_TIMESTAMP)); 722 ASSERT_NO_FATAL_FAILURE(SetUpTestFileSystem(USE_OLD_TIMESTAMP));
(...skipping 23 matching lines...) Expand all
746 // CreateDirectory ensures the resource list is loaded before it runs. 746 // CreateDirectory ensures the resource list is loaded before it runs.
747 747
748 base::FilePath existing_directory( 748 base::FilePath existing_directory(
749 FILE_PATH_LITERAL("drive/root/Directory 1")); 749 FILE_PATH_LITERAL("drive/root/Directory 1"));
750 FileError error = FILE_ERROR_FAILED; 750 FileError error = FILE_ERROR_FAILED;
751 file_system_->CreateDirectory( 751 file_system_->CreateDirectory(
752 existing_directory, 752 existing_directory,
753 true, // is_exclusive 753 true, // is_exclusive
754 false, // is_recursive 754 false, // is_recursive
755 google_apis::test_util::CreateCopyResultCallback(&error)); 755 google_apis::test_util::CreateCopyResultCallback(&error));
756 test_util::RunBlockingPoolTask(); 756 content::RunAllBlockingPoolTasksUntilIdle();
757 757
758 // It should fail because is_exclusive is set to true. 758 // It should fail because is_exclusive is set to true.
759 EXPECT_EQ(FILE_ERROR_EXISTS, error); 759 EXPECT_EQ(FILE_ERROR_EXISTS, error);
760 } 760 }
761 761
762 TEST_F(FileSystemTest, CreateDirectoryRecursively) { 762 TEST_F(FileSystemTest, CreateDirectoryRecursively) {
763 // Intentionally *not* calling LoadFullResourceList(), for testing that 763 // Intentionally *not* calling LoadFullResourceList(), for testing that
764 // CreateDirectory ensures the resource list is loaded before it runs. 764 // CreateDirectory ensures the resource list is loaded before it runs.
765 765
766 base::FilePath new_directory( 766 base::FilePath new_directory(
767 FILE_PATH_LITERAL("drive/root/Directory 1/a/b/c/d")); 767 FILE_PATH_LITERAL("drive/root/Directory 1/a/b/c/d"));
768 FileError error = FILE_ERROR_FAILED; 768 FileError error = FILE_ERROR_FAILED;
769 file_system_->CreateDirectory( 769 file_system_->CreateDirectory(
770 new_directory, 770 new_directory,
771 true, // is_exclusive 771 true, // is_exclusive
772 true, // is_recursive 772 true, // is_recursive
773 google_apis::test_util::CreateCopyResultCallback(&error)); 773 google_apis::test_util::CreateCopyResultCallback(&error));
774 test_util::RunBlockingPoolTask(); 774 content::RunAllBlockingPoolTasksUntilIdle();
775 775
776 EXPECT_EQ(FILE_ERROR_OK, error); 776 EXPECT_EQ(FILE_ERROR_OK, error);
777 777
778 scoped_ptr<ResourceEntry> entry(GetResourceEntrySync(new_directory)); 778 scoped_ptr<ResourceEntry> entry(GetResourceEntrySync(new_directory));
779 ASSERT_TRUE(entry); 779 ASSERT_TRUE(entry);
780 EXPECT_TRUE(entry->file_info().is_directory()); 780 EXPECT_TRUE(entry->file_info().is_directory());
781 } 781 }
782 782
783 TEST_F(FileSystemTest, PinAndUnpin) { 783 TEST_F(FileSystemTest, PinAndUnpin) {
784 ASSERT_TRUE(LoadFullResourceList()); 784 ASSERT_TRUE(LoadFullResourceList());
785 785
786 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 786 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
787 787
788 // Get the file info. 788 // Get the file info.
789 scoped_ptr<ResourceEntry> entry(GetResourceEntrySync(file_path)); 789 scoped_ptr<ResourceEntry> entry(GetResourceEntrySync(file_path));
790 ASSERT_TRUE(entry); 790 ASSERT_TRUE(entry);
791 791
792 // Pin the file. 792 // Pin the file.
793 FileError error = FILE_ERROR_FAILED; 793 FileError error = FILE_ERROR_FAILED;
794 file_system_->Pin(file_path, 794 file_system_->Pin(file_path,
795 google_apis::test_util::CreateCopyResultCallback(&error)); 795 google_apis::test_util::CreateCopyResultCallback(&error));
796 test_util::RunBlockingPoolTask(); 796 content::RunAllBlockingPoolTasksUntilIdle();
797 EXPECT_EQ(FILE_ERROR_OK, error); 797 EXPECT_EQ(FILE_ERROR_OK, error);
798 798
799 entry = GetResourceEntrySync(file_path); 799 entry = GetResourceEntrySync(file_path);
800 ASSERT_TRUE(entry); 800 ASSERT_TRUE(entry);
801 EXPECT_TRUE(entry->file_specific_info().cache_state().is_pinned()); 801 EXPECT_TRUE(entry->file_specific_info().cache_state().is_pinned());
802 EXPECT_TRUE(entry->file_specific_info().cache_state().is_present()); 802 EXPECT_TRUE(entry->file_specific_info().cache_state().is_present());
803 803
804 // Unpin the file. 804 // Unpin the file.
805 error = FILE_ERROR_FAILED; 805 error = FILE_ERROR_FAILED;
806 file_system_->Unpin(file_path, 806 file_system_->Unpin(file_path,
807 google_apis::test_util::CreateCopyResultCallback(&error)); 807 google_apis::test_util::CreateCopyResultCallback(&error));
808 test_util::RunBlockingPoolTask(); 808 content::RunAllBlockingPoolTasksUntilIdle();
809 EXPECT_EQ(FILE_ERROR_OK, error); 809 EXPECT_EQ(FILE_ERROR_OK, error);
810 810
811 entry = GetResourceEntrySync(file_path); 811 entry = GetResourceEntrySync(file_path);
812 ASSERT_TRUE(entry); 812 ASSERT_TRUE(entry);
813 EXPECT_FALSE(entry->file_specific_info().cache_state().is_pinned()); 813 EXPECT_FALSE(entry->file_specific_info().cache_state().is_pinned());
814 814
815 // Pinned file gets synced and it results in entry state changes. 815 // Pinned file gets synced and it results in entry state changes.
816 ASSERT_EQ(0u, mock_directory_observer_->changed_directories().size()); 816 ASSERT_EQ(0u, mock_directory_observer_->changed_directories().size());
817 ASSERT_EQ(1u, mock_directory_observer_->changed_files().size()); 817 ASSERT_EQ(1u, mock_directory_observer_->changed_files().size());
818 EXPECT_EQ(1u, 818 EXPECT_EQ(1u,
(...skipping 14 matching lines...) Expand all
833 FileError error_pin = FILE_ERROR_FAILED; 833 FileError error_pin = FILE_ERROR_FAILED;
834 file_system_->Pin( 834 file_system_->Pin(
835 file_path, 835 file_path,
836 google_apis::test_util::CreateCopyResultCallback(&error_pin)); 836 google_apis::test_util::CreateCopyResultCallback(&error_pin));
837 837
838 FileError error_unpin = FILE_ERROR_FAILED; 838 FileError error_unpin = FILE_ERROR_FAILED;
839 file_system_->Unpin( 839 file_system_->Unpin(
840 file_path, 840 file_path,
841 google_apis::test_util::CreateCopyResultCallback(&error_unpin)); 841 google_apis::test_util::CreateCopyResultCallback(&error_unpin));
842 842
843 test_util::RunBlockingPoolTask(); 843 content::RunAllBlockingPoolTasksUntilIdle();
844 EXPECT_EQ(FILE_ERROR_OK, error_pin); 844 EXPECT_EQ(FILE_ERROR_OK, error_pin);
845 EXPECT_EQ(FILE_ERROR_OK, error_unpin); 845 EXPECT_EQ(FILE_ERROR_OK, error_unpin);
846 846
847 // No cache file available because the sync was cancelled by Unpin(). 847 // No cache file available because the sync was cancelled by Unpin().
848 entry = GetResourceEntrySync(file_path); 848 entry = GetResourceEntrySync(file_path);
849 ASSERT_TRUE(entry); 849 ASSERT_TRUE(entry);
850 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present()); 850 EXPECT_FALSE(entry->file_specific_info().cache_state().is_present());
851 } 851 }
852 852
853 TEST_F(FileSystemTest, GetAvailableSpace) { 853 TEST_F(FileSystemTest, GetAvailableSpace) {
854 FileError error = FILE_ERROR_OK; 854 FileError error = FILE_ERROR_OK;
855 int64 bytes_total; 855 int64 bytes_total;
856 int64 bytes_used; 856 int64 bytes_used;
857 file_system_->GetAvailableSpace( 857 file_system_->GetAvailableSpace(
858 google_apis::test_util::CreateCopyResultCallback( 858 google_apis::test_util::CreateCopyResultCallback(
859 &error, &bytes_total, &bytes_used)); 859 &error, &bytes_total, &bytes_used));
860 test_util::RunBlockingPoolTask(); 860 content::RunAllBlockingPoolTasksUntilIdle();
861 EXPECT_EQ(6789012345LL, bytes_used); 861 EXPECT_EQ(6789012345LL, bytes_used);
862 EXPECT_EQ(9876543210LL, bytes_total); 862 EXPECT_EQ(9876543210LL, bytes_total);
863 } 863 }
864 864
865 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) { 865 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) {
866 ASSERT_TRUE(LoadFullResourceList()); 866 ASSERT_TRUE(LoadFullResourceList());
867 867
868 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 868 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
869 869
870 // Make the file cached. 870 // Make the file cached.
871 FileError error = FILE_ERROR_FAILED; 871 FileError error = FILE_ERROR_FAILED;
872 base::FilePath file_path; 872 base::FilePath file_path;
873 scoped_ptr<ResourceEntry> entry; 873 scoped_ptr<ResourceEntry> entry;
874 file_system_->GetFile( 874 file_system_->GetFile(
875 file_in_root, 875 file_in_root,
876 google_apis::test_util::CreateCopyResultCallback( 876 google_apis::test_util::CreateCopyResultCallback(
877 &error, &file_path, &entry)); 877 &error, &file_path, &entry));
878 test_util::RunBlockingPoolTask(); 878 content::RunAllBlockingPoolTasksUntilIdle();
879 EXPECT_EQ(FILE_ERROR_OK, error); 879 EXPECT_EQ(FILE_ERROR_OK, error);
880 880
881 // Test for mounting. 881 // Test for mounting.
882 error = FILE_ERROR_FAILED; 882 error = FILE_ERROR_FAILED;
883 file_path.clear(); 883 file_path.clear();
884 file_system_->MarkCacheFileAsMounted( 884 file_system_->MarkCacheFileAsMounted(
885 file_in_root, 885 file_in_root,
886 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 886 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
887 test_util::RunBlockingPoolTask(); 887 content::RunAllBlockingPoolTasksUntilIdle();
888 EXPECT_EQ(FILE_ERROR_OK, error); 888 EXPECT_EQ(FILE_ERROR_OK, error);
889 889
890 // Cannot remove a cache entry while it's being mounted. 890 // Cannot remove a cache entry while it's being mounted.
891 EXPECT_EQ(FILE_ERROR_IN_USE, cache_->Remove(entry->local_id())); 891 EXPECT_EQ(FILE_ERROR_IN_USE, cache_->Remove(entry->local_id()));
892 892
893 // Test for unmounting. 893 // Test for unmounting.
894 error = FILE_ERROR_FAILED; 894 error = FILE_ERROR_FAILED;
895 file_system_->MarkCacheFileAsUnmounted( 895 file_system_->MarkCacheFileAsUnmounted(
896 file_path, 896 file_path,
897 google_apis::test_util::CreateCopyResultCallback(&error)); 897 google_apis::test_util::CreateCopyResultCallback(&error));
898 test_util::RunBlockingPoolTask(); 898 content::RunAllBlockingPoolTasksUntilIdle();
899 EXPECT_EQ(FILE_ERROR_OK, error); 899 EXPECT_EQ(FILE_ERROR_OK, error);
900 900
901 // Now able to remove the cache entry. 901 // Now able to remove the cache entry.
902 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->local_id())); 902 EXPECT_EQ(FILE_ERROR_OK, cache_->Remove(entry->local_id()));
903 } 903 }
904 904
905 TEST_F(FileSystemTest, GetShareUrl) { 905 TEST_F(FileSystemTest, GetShareUrl) {
906 ASSERT_TRUE(LoadFullResourceList()); 906 ASSERT_TRUE(LoadFullResourceList());
907 907
908 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt")); 908 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt"));
909 const GURL kEmbedOrigin("chrome-extension://test-id"); 909 const GURL kEmbedOrigin("chrome-extension://test-id");
910 910
911 // Try to fetch the URL for the sharing dialog. 911 // Try to fetch the URL for the sharing dialog.
912 FileError error = FILE_ERROR_FAILED; 912 FileError error = FILE_ERROR_FAILED;
913 GURL share_url; 913 GURL share_url;
914 file_system_->GetShareUrl( 914 file_system_->GetShareUrl(
915 kFileInRoot, 915 kFileInRoot,
916 kEmbedOrigin, 916 kEmbedOrigin,
917 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); 917 google_apis::test_util::CreateCopyResultCallback(&error, &share_url));
918 test_util::RunBlockingPoolTask(); 918 content::RunAllBlockingPoolTasksUntilIdle();
919 919
920 // Verify the share url to the sharing dialog. 920 // Verify the share url to the sharing dialog.
921 EXPECT_EQ(FILE_ERROR_OK, error); 921 EXPECT_EQ(FILE_ERROR_OK, error);
922 EXPECT_TRUE(share_url.is_valid()); 922 EXPECT_TRUE(share_url.is_valid());
923 } 923 }
924 924
925 } // namespace drive 925 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698