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

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

Issue 13149003: drive: Use "/drive/root" namespace and fix Files app and tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge glitches. Created 7 years, 8 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/drive_file_system.h" 5 #include "chrome/browser/chromeos/drive/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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 301 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
302 } 302 }
303 303
304 // Flag for specifying the timestamp of the test filesystem cache. 304 // Flag for specifying the timestamp of the test filesystem cache.
305 enum SaveTestFileSystemParam { 305 enum SaveTestFileSystemParam {
306 USE_OLD_TIMESTAMP, 306 USE_OLD_TIMESTAMP,
307 USE_SERVER_TIMESTAMP, 307 USE_SERVER_TIMESTAMP,
308 }; 308 };
309 309
310 // Saves a file representing a filesystem with directories: 310 // Saves a file representing a filesystem with directories:
311 // drive, drive/Dir1, drive/Dir1/SubDir2 311 // drive/root, drive/root/Dir1, drive/root/Dir1/SubDir2
312 // and files 312 // and files
313 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. 313 // drive/root/File1, drive/root/Dir1/File2, drive/root/Dir1/SubDir2/File3.
314 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, 314 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321,
315 // equal to that of "account_metadata.json" test data, indicating the cache is 315 // equal to that of "account_metadata.json" test data, indicating the cache is
316 // holding the latest file system info. 316 // holding the latest file system info.
317 bool SaveTestFileSystem(SaveTestFileSystemParam param) { 317 bool SaveTestFileSystem(SaveTestFileSystemParam param) {
318 // Destroy the existing resource metadata to close DB. 318 // Destroy the existing resource metadata to close DB.
319 resource_metadata_.reset(); 319 resource_metadata_.reset();
320 320
321 const std::string root_resource_id = 321 const std::string root_resource_id =
322 fake_drive_service_->GetRootResourceId(); 322 fake_drive_service_->GetRootResourceId();
323 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests> 323 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
324 resource_metadata(new DriveResourceMetadata( 324 resource_metadata(new DriveResourceMetadata(
325 root_resource_id, 325 root_resource_id,
326 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META), 326 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META),
327 blocking_task_runner_)); 327 blocking_task_runner_));
328 328
329 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 329 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
330 resource_metadata->Initialize( 330 resource_metadata->Initialize(
331 google_apis::test_util::CreateCopyResultCallback(&error)); 331 google_apis::test_util::CreateCopyResultCallback(&error));
332 google_apis::test_util::RunBlockingPoolTask(); 332 google_apis::test_util::RunBlockingPoolTask();
333 if (error != DRIVE_FILE_OK) 333 if (error != DRIVE_FILE_OK)
334 return false; 334 return false;
335 335
336 resource_metadata->SetLargestChangestamp( 336 resource_metadata->SetLargestChangestamp(
337 param == USE_SERVER_TIMESTAMP ? 654321 : 1, 337 param == USE_SERVER_TIMESTAMP ? 654321 : 1,
338 google_apis::test_util::CreateCopyResultCallback(&error)); 338 google_apis::test_util::CreateCopyResultCallback(&error));
339 google_apis::test_util::RunBlockingPoolTask(); 339 google_apis::test_util::RunBlockingPoolTask();
340 if (error != DRIVE_FILE_OK) 340 if (error != DRIVE_FILE_OK)
341 return false; 341 return false;
342 342
343 // drive/File1 343 // drive/root is already prepared by DriveResourceMetadata.
344 // TODO(haruki): Create drive/root here when we start creating it in
345 // ChangeListLoader.
346 base::FilePath file_path;
347
348 // drive/root/File1
344 DriveEntryProto file1; 349 DriveEntryProto file1;
345 file1.set_title("File1"); 350 file1.set_title("File1");
346 file1.set_resource_id("resource_id:File1"); 351 file1.set_resource_id("resource_id:File1");
347 file1.set_parent_resource_id(root_resource_id); 352 file1.set_parent_resource_id(root_resource_id);
348 file1.mutable_file_specific_info()->set_file_md5("md5"); 353 file1.mutable_file_specific_info()->set_file_md5("md5");
349 file1.mutable_file_info()->set_is_directory(false); 354 file1.mutable_file_info()->set_is_directory(false);
350 file1.mutable_file_info()->set_size(1048576); 355 file1.mutable_file_info()->set_size(1048576);
351 base::FilePath file_path;
352 resource_metadata->AddEntry( 356 resource_metadata->AddEntry(
353 file1, 357 file1,
354 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 358 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
355 google_apis::test_util::RunBlockingPoolTask(); 359 google_apis::test_util::RunBlockingPoolTask();
356 if (error != DRIVE_FILE_OK) 360 if (error != DRIVE_FILE_OK)
357 return false; 361 return false;
358 362
359 // drive/Dir1 363 // drive/root/Dir1
360 DriveEntryProto dir1; 364 DriveEntryProto dir1;
361 dir1.set_title("Dir1"); 365 dir1.set_title("Dir1");
362 dir1.set_resource_id("resource_id:Dir1"); 366 dir1.set_resource_id("resource_id:Dir1");
363 dir1.set_parent_resource_id(root_resource_id); 367 dir1.set_parent_resource_id(root_resource_id);
364 dir1.mutable_file_info()->set_is_directory(true); 368 dir1.mutable_file_info()->set_is_directory(true);
365 resource_metadata->AddEntry( 369 resource_metadata->AddEntry(
366 dir1, 370 dir1,
367 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 371 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
368 google_apis::test_util::RunBlockingPoolTask(); 372 google_apis::test_util::RunBlockingPoolTask();
369 if (error != DRIVE_FILE_OK) 373 if (error != DRIVE_FILE_OK)
370 return false; 374 return false;
371 375
372 // drive/Dir1/File2 376 // drive/root/Dir1/File2
373 DriveEntryProto file2; 377 DriveEntryProto file2;
374 file2.set_title("File2"); 378 file2.set_title("File2");
375 file2.set_resource_id("resource_id:File2"); 379 file2.set_resource_id("resource_id:File2");
376 file2.set_parent_resource_id(dir1.resource_id()); 380 file2.set_parent_resource_id(dir1.resource_id());
377 file2.mutable_file_specific_info()->set_file_md5("md5"); 381 file2.mutable_file_specific_info()->set_file_md5("md5");
378 file2.mutable_file_info()->set_is_directory(false); 382 file2.mutable_file_info()->set_is_directory(false);
379 file2.mutable_file_info()->set_size(555); 383 file2.mutable_file_info()->set_size(555);
380 resource_metadata->AddEntry( 384 resource_metadata->AddEntry(
381 file2, 385 file2,
382 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 386 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
383 google_apis::test_util::RunBlockingPoolTask(); 387 google_apis::test_util::RunBlockingPoolTask();
384 if (error != DRIVE_FILE_OK) 388 if (error != DRIVE_FILE_OK)
385 return false; 389 return false;
386 390
387 // drive/Dir1/SubDir2 391 // drive/root/Dir1/SubDir2
388 DriveEntryProto dir2; 392 DriveEntryProto dir2;
389 dir2.set_title("SubDir2"); 393 dir2.set_title("SubDir2");
390 dir2.set_resource_id("resource_id:SubDir2"); 394 dir2.set_resource_id("resource_id:SubDir2");
391 dir2.set_parent_resource_id(dir1.resource_id()); 395 dir2.set_parent_resource_id(dir1.resource_id());
392 dir2.mutable_file_info()->set_is_directory(true); 396 dir2.mutable_file_info()->set_is_directory(true);
393 resource_metadata->AddEntry( 397 resource_metadata->AddEntry(
394 dir2, 398 dir2,
395 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 399 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
396 google_apis::test_util::RunBlockingPoolTask(); 400 google_apis::test_util::RunBlockingPoolTask();
397 if (error != DRIVE_FILE_OK) 401 if (error != DRIVE_FILE_OK)
398 return false; 402 return false;
399 403
400 // drive/Dir1/SubDir2/File3 404 // drive/root/Dir1/SubDir2/File3
401 DriveEntryProto file3; 405 DriveEntryProto file3;
402 file3.set_title("File3"); 406 file3.set_title("File3");
403 file3.set_resource_id("resource_id:File3"); 407 file3.set_resource_id("resource_id:File3");
404 file3.set_parent_resource_id(dir2.resource_id()); 408 file3.set_parent_resource_id(dir2.resource_id());
405 file3.mutable_file_specific_info()->set_file_md5("md5"); 409 file3.mutable_file_specific_info()->set_file_md5("md5");
406 file3.mutable_file_info()->set_is_directory(false); 410 file3.mutable_file_info()->set_is_directory(false);
407 file3.mutable_file_info()->set_size(12345); 411 file3.mutable_file_info()->set_size(12345);
408 resource_metadata->AddEntry( 412 resource_metadata->AddEntry(
409 file3, 413 file3,
410 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 414 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 ASSERT_FALSE(entries->empty()); 481 ASSERT_FALSE(entries->empty());
478 482
479 (*counter)++; 483 (*counter)++;
480 if (*counter >= expected_counter) 484 if (*counter >= expected_counter)
481 message_loop->Quit(); 485 message_loop->Quit();
482 } 486 }
483 487
484 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) { 488 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) {
485 // The root directory will be loaded that triggers the event. 489 // The root directory will be loaded that triggers the event.
486 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 490 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
487 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 491 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
488 492
489 int counter = 0; 493 int counter = 0;
490 ReadDirectoryWithSettingCallback callback = base::Bind( 494 ReadDirectoryWithSettingCallback callback = base::Bind(
491 &AsyncInitializationCallback, 495 &AsyncInitializationCallback,
492 &counter, 496 &counter,
493 2, 497 2,
494 &message_loop_); 498 &message_loop_);
495 499
496 file_system_->ReadDirectoryByPath( 500 file_system_->ReadDirectoryByPath(
497 base::FilePath(FILE_PATH_LITERAL("drive")), callback); 501 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback);
498 file_system_->ReadDirectoryByPath( 502 file_system_->ReadDirectoryByPath(
499 base::FilePath(FILE_PATH_LITERAL("drive")), callback); 503 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback);
500 message_loop_.Run(); // Wait to get our result 504 message_loop_.Run(); // Wait to get our result
501 EXPECT_EQ(2, counter); 505 EXPECT_EQ(2, counter);
502 506
503 // ReadDirectoryByPath() was called twice, but the account metadata should 507 // ReadDirectoryByPath() was called twice, but the account metadata should
504 // only be loaded once. In the past, there was a bug that caused it to be 508 // only be loaded once. In the past, there was a bug that caused it to be
505 // loaded twice. 509 // loaded twice.
506 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 510 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
507 // On the other hand, the resource list could be loaded twice. One for 511 // On the other hand, the resource list could be loaded twice. One for
508 // just the directory contents, and one for the entire resource list. 512 // just the directory contents, and one for the entire resource list.
509 // 513 //
510 // The |callback| function gets called back soon after the directory content 514 // The |callback| function gets called back soon after the directory content
511 // is loaded, and the full resource load is done in background asynchronously. 515 // is loaded, and the full resource load is done in background asynchronously.
512 // So it depends on timing whether we receive the full resource load request 516 // So it depends on timing whether we receive the full resource load request
513 // at this point. 517 // at this point.
514 EXPECT_TRUE(fake_drive_service_->resource_list_load_count() == 1 || 518 EXPECT_TRUE(fake_drive_service_->resource_list_load_count() == 1 ||
515 fake_drive_service_->resource_list_load_count() == 2) 519 fake_drive_service_->resource_list_load_count() == 2)
516 << ": " << fake_drive_service_->resource_list_load_count(); 520 << ": " << fake_drive_service_->resource_list_load_count();
517 } 521 }
518 522
519 TEST_F(DriveFileSystemTest, GetRootEntry) { 523 TEST_F(DriveFileSystemTest, GetGrandRootEntry) {
520 const base::FilePath kFilePath = base::FilePath(FILE_PATH_LITERAL("drive")); 524 const base::FilePath kFilePath =
525 base::FilePath(FILE_PATH_LITERAL("drive"));
526 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
527 ASSERT_TRUE(entry.get());
528 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id());
529
530 // Getting the grand root entry should not cause the resource load to happen.
531 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
532 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
533 }
534
535 TEST_F(DriveFileSystemTest, GetMyDriveRootEntry) {
536 const base::FilePath kFilePath =
537 base::FilePath(FILE_PATH_LITERAL("drive/root"));
521 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 538 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
522 ASSERT_TRUE(entry.get()); 539 ASSERT_TRUE(entry.get());
523 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); 540 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id());
524 541
525 // Getting the root entry should not cause the resource load to happen. 542 // Getting the "My Drive" root entry should not cause the resource load to
543 // happen.
544 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
545 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
546 }
547
548 TEST_F(DriveFileSystemTest, GetOtherDirEntry) {
549 const base::FilePath kFilePath =
550 base::FilePath(FILE_PATH_LITERAL("drive/other"));
551 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
552 ASSERT_TRUE(entry.get());
553 EXPECT_EQ(util::kDriveOtherDirSpecialResourceId, entry->resource_id());
554
555 // Getting the "other" directory entry should not cause the resource load to
556 // happen.
526 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); 557 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
527 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); 558 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
528 } 559 }
529 560
530 TEST_F(DriveFileSystemTest, GetNonRootEntry) { 561 TEST_F(DriveFileSystemTest, GetNonRootEntry) {
531 const base::FilePath kFilePath = 562 const base::FilePath kFilePath =
532 base::FilePath(FILE_PATH_LITERAL("drive/whatever.txt")); 563 base::FilePath(FILE_PATH_LITERAL("drive/root/whatever.txt"));
533 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 564 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
534 // The entry should not exist as the resource metadata only contains the 565 // The entry should not exist as the resource metadata only contains the
535 // root entry now. 566 // root entry now.
536 ASSERT_FALSE(entry.get()); 567 ASSERT_FALSE(entry.get());
537 568
538 // The resource load should happen because non-root entry is requested. 569 // The resource load should happen because non-root entry is requested.
539 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 570 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
540 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); 571 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
541 } 572 }
542 573
543 TEST_F(DriveFileSystemTest, SearchRootDirectory) { 574 TEST_F(DriveFileSystemTest, SearchRootDirectory) {
544 ASSERT_TRUE(LoadRootFeedDocument()); 575 ASSERT_TRUE(LoadRootFeedDocument());
545 576
546 const base::FilePath kFilePath = base::FilePath(FILE_PATH_LITERAL("drive")); 577 const base::FilePath kFilePath =
578 base::FilePath(FILE_PATH_LITERAL("drive/root"));
547 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 579 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
548 ASSERT_TRUE(entry.get()); 580 ASSERT_TRUE(entry.get());
549 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); 581 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id());
550 582
551 // The changestamp should be propagated to the root directory. 583 // The changestamp should be propagated to the root directory.
552 EXPECT_EQ(fake_drive_service_->largest_changestamp(), 584 EXPECT_EQ(fake_drive_service_->largest_changestamp(),
553 entry->directory_specific_info().changestamp()); 585 entry->directory_specific_info().changestamp());
554 } 586 }
555 587
556 TEST_F(DriveFileSystemTest, SearchExistingFile) { 588 TEST_F(DriveFileSystemTest, SearchExistingFile) {
557 ASSERT_TRUE(LoadRootFeedDocument()); 589 ASSERT_TRUE(LoadRootFeedDocument());
558 590
559 const base::FilePath kFilePath = base::FilePath( 591 const base::FilePath kFilePath = base::FilePath(
560 FILE_PATH_LITERAL("drive/File 1.txt")); 592 FILE_PATH_LITERAL("drive/root/File 1.txt"));
561 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 593 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
562 ASSERT_TRUE(entry.get()); 594 ASSERT_TRUE(entry.get());
563 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); 595 EXPECT_EQ("file:2_file_resource_id", entry->resource_id());
564 } 596 }
565 597
566 TEST_F(DriveFileSystemTest, SearchExistingDocument) { 598 TEST_F(DriveFileSystemTest, SearchExistingDocument) {
567 ASSERT_TRUE(LoadRootFeedDocument()); 599 ASSERT_TRUE(LoadRootFeedDocument());
568 600
569 const base::FilePath kFilePath = base::FilePath( 601 const base::FilePath kFilePath = base::FilePath(
570 FILE_PATH_LITERAL("drive/Document 1.gdoc")); 602 FILE_PATH_LITERAL("drive/root/Document 1.gdoc"));
571 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 603 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
572 ASSERT_TRUE(entry.get()); 604 ASSERT_TRUE(entry.get());
573 EXPECT_EQ("document:5_document_resource_id", entry->resource_id()); 605 EXPECT_EQ("document:5_document_resource_id", entry->resource_id());
574 } 606 }
575 607
576 TEST_F(DriveFileSystemTest, SearchNonExistingFile) { 608 TEST_F(DriveFileSystemTest, SearchNonExistingFile) {
577 ASSERT_TRUE(LoadRootFeedDocument()); 609 ASSERT_TRUE(LoadRootFeedDocument());
578 610
579 const base::FilePath kFilePath = base::FilePath( 611 const base::FilePath kFilePath = base::FilePath(
580 FILE_PATH_LITERAL("drive/nonexisting.file")); 612 FILE_PATH_LITERAL("drive/root/nonexisting.file"));
581 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 613 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
582 ASSERT_FALSE(entry.get()); 614 ASSERT_FALSE(entry.get());
583 } 615 }
584 616
585 TEST_F(DriveFileSystemTest, SearchEncodedFileNames) { 617 TEST_F(DriveFileSystemTest, SearchEncodedFileNames) {
586 ASSERT_TRUE(LoadRootFeedDocument()); 618 ASSERT_TRUE(LoadRootFeedDocument());
587 619
588 const base::FilePath kFilePath1 = base::FilePath( 620 const base::FilePath kFilePath1 = base::FilePath(
589 FILE_PATH_LITERAL("drive/Slash / in file 1.txt")); 621 FILE_PATH_LITERAL("drive/root/Slash / in file 1.txt"));
590 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); 622 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1);
591 ASSERT_FALSE(entry.get()); 623 ASSERT_FALSE(entry.get());
592 624
593 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe( 625 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe(
594 "drive/Slash \xE2\x88\x95 in file 1.txt"); 626 "drive/root/Slash \xE2\x88\x95 in file 1.txt");
595 entry = GetEntryInfoByPathSync(kFilePath2); 627 entry = GetEntryInfoByPathSync(kFilePath2);
596 ASSERT_TRUE(entry.get()); 628 ASSERT_TRUE(entry.get());
597 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); 629 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id());
598 630
599 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe( 631 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe(
600 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); 632 "drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt");
601 entry = GetEntryInfoByPathSync(kFilePath3); 633 entry = GetEntryInfoByPathSync(kFilePath3);
602 ASSERT_TRUE(entry.get()); 634 ASSERT_TRUE(entry.get());
603 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); 635 EXPECT_EQ("file:slash_subdir_file", entry->resource_id());
604 } 636 }
605 637
606 TEST_F(DriveFileSystemTest, SearchEncodedFileNamesLoadingRoot) { 638 TEST_F(DriveFileSystemTest, SearchEncodedFileNamesLoadingRoot) {
607 ASSERT_TRUE(LoadRootFeedDocument()); 639 ASSERT_TRUE(LoadRootFeedDocument());
608 640
609 const base::FilePath kFilePath1 = base::FilePath( 641 const base::FilePath kFilePath1 = base::FilePath(
610 FILE_PATH_LITERAL("drive/Slash / in file 1.txt")); 642 FILE_PATH_LITERAL("drive/root/Slash / in file 1.txt"));
611 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); 643 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1);
612 ASSERT_FALSE(entry.get()); 644 ASSERT_FALSE(entry.get());
613 645
614 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe( 646 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe(
615 "drive/Slash \xE2\x88\x95 in file 1.txt"); 647 "drive/root/Slash \xE2\x88\x95 in file 1.txt");
616 entry = GetEntryInfoByPathSync(kFilePath2); 648 entry = GetEntryInfoByPathSync(kFilePath2);
617 ASSERT_TRUE(entry.get()); 649 ASSERT_TRUE(entry.get());
618 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); 650 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id());
619 651
620 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe( 652 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe(
621 "drive/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); 653 "drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt");
622 entry = GetEntryInfoByPathSync(kFilePath3); 654 entry = GetEntryInfoByPathSync(kFilePath3);
623 ASSERT_TRUE(entry.get()); 655 ASSERT_TRUE(entry.get());
624 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); 656 EXPECT_EQ("file:slash_subdir_file", entry->resource_id());
625 } 657 }
626 658
627 TEST_F(DriveFileSystemTest, SearchDuplicateNames) { 659 TEST_F(DriveFileSystemTest, SearchDuplicateNames) {
628 ASSERT_TRUE(LoadRootFeedDocument()); 660 ASSERT_TRUE(LoadRootFeedDocument());
629 661
630 const base::FilePath kFilePath1 = base::FilePath( 662 const base::FilePath kFilePath1 = base::FilePath(
631 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 663 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt"));
632 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1); 664 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath1);
633 ASSERT_TRUE(entry.get()); 665 ASSERT_TRUE(entry.get());
634 const std::string resource_id1 = entry->resource_id(); 666 const std::string resource_id1 = entry->resource_id();
635 667
636 const base::FilePath kFilePath2 = base::FilePath( 668 const base::FilePath kFilePath2 = base::FilePath(
637 FILE_PATH_LITERAL("drive/Duplicate Name (2).txt")); 669 FILE_PATH_LITERAL("drive/root/Duplicate Name (2).txt"));
638 entry = GetEntryInfoByPathSync(kFilePath2); 670 entry = GetEntryInfoByPathSync(kFilePath2);
639 ASSERT_TRUE(entry.get()); 671 ASSERT_TRUE(entry.get());
640 const std::string resource_id2 = entry->resource_id(); 672 const std::string resource_id2 = entry->resource_id();
641 673
642 // The entries are de-duped non-deterministically, so we shouldn't rely on the 674 // The entries are de-duped non-deterministically, so we shouldn't rely on the
643 // names matching specific resource ids. 675 // names matching specific resource ids.
644 const std::string file3_resource_id = "file:3_file_resource_id"; 676 const std::string file3_resource_id = "file:3_file_resource_id";
645 const std::string file4_resource_id = "file:4_file_resource_id"; 677 const std::string file4_resource_id = "file:4_file_resource_id";
646 EXPECT_TRUE(file3_resource_id == resource_id1 || 678 EXPECT_TRUE(file3_resource_id == resource_id1 ||
647 file3_resource_id == resource_id2); 679 file3_resource_id == resource_id2);
648 EXPECT_TRUE(file4_resource_id == resource_id1 || 680 EXPECT_TRUE(file4_resource_id == resource_id1 ||
649 file4_resource_id == resource_id2); 681 file4_resource_id == resource_id2);
650 } 682 }
651 683
652 TEST_F(DriveFileSystemTest, SearchExistingDirectory) { 684 TEST_F(DriveFileSystemTest, SearchExistingDirectory) {
653 ASSERT_TRUE(LoadRootFeedDocument()); 685 ASSERT_TRUE(LoadRootFeedDocument());
654 686
655 const base::FilePath kFilePath = base::FilePath( 687 const base::FilePath kFilePath = base::FilePath(
656 FILE_PATH_LITERAL("drive/Directory 1")); 688 FILE_PATH_LITERAL("drive/root/Directory 1"));
657 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 689 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
658 ASSERT_TRUE(entry.get()); 690 ASSERT_TRUE(entry.get());
659 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id()); 691 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id());
660 692
661 // The changestamp should be propagated to the directory. 693 // The changestamp should be propagated to the directory.
662 EXPECT_EQ(fake_drive_service_->largest_changestamp(), 694 EXPECT_EQ(fake_drive_service_->largest_changestamp(),
663 entry->directory_specific_info().changestamp()); 695 entry->directory_specific_info().changestamp());
664 } 696 }
665 697
666 TEST_F(DriveFileSystemTest, SearchInSubdir) { 698 TEST_F(DriveFileSystemTest, SearchInSubdir) {
667 ASSERT_TRUE(LoadRootFeedDocument()); 699 ASSERT_TRUE(LoadRootFeedDocument());
668 700
669 const base::FilePath kFilePath = base::FilePath( 701 const base::FilePath kFilePath = base::FilePath(
670 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 702 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
671 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 703 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
672 ASSERT_TRUE(entry.get()); 704 ASSERT_TRUE(entry.get());
673 ASSERT_EQ("file:subdirectory_file_1_id", entry->resource_id()); 705 ASSERT_EQ("file:subdirectory_file_1_id", entry->resource_id());
674 } 706 }
675 707
676 // Check the reconstruction of the directory structure from only the root feed. 708 // Check the reconstruction of the directory structure from only the root feed.
677 TEST_F(DriveFileSystemTest, SearchInSubSubdir) { 709 TEST_F(DriveFileSystemTest, SearchInSubSubdir) {
678 ASSERT_TRUE(LoadRootFeedDocument()); 710 ASSERT_TRUE(LoadRootFeedDocument());
679 711
680 const base::FilePath kFilePath = base::FilePath( 712 const base::FilePath kFilePath = base::FilePath(
681 FILE_PATH_LITERAL("drive/Directory 1/Sub Directory Folder/" 713 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/"
682 "Sub Sub Directory Folder")); 714 "Sub Sub Directory Folder"));
683 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); 715 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath);
684 ASSERT_TRUE(entry.get()); 716 ASSERT_TRUE(entry.get());
685 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id()); 717 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id());
686 } 718 }
687 719
688 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_Root) { 720 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_Root) {
689 // The root directory will be loaded that triggers the event.
690 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 721 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
691 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 722 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
692 723
693 // ReadDirectoryByPath() should kick off the resource list loading. 724 // ReadDirectoryByPath() should kick off the resource list loading.
694 scoped_ptr<DriveEntryProtoVector> entries( 725 scoped_ptr<DriveEntryProtoVector> entries(
695 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"))); 726 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root")));
696 // The root directory should be read correctly. 727 // The root directory should be read correctly.
697 ASSERT_TRUE(entries.get()); 728 ASSERT_TRUE(entries.get());
698 EXPECT_EQ(8U, entries->size()); 729 EXPECT_EQ(8U, entries->size());
699 } 730 }
700 731
701 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_NonRootDirectory) { 732 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_NonRootDirectory) {
702 // ReadDirectoryByPath() should kick off the resource list loading. 733 // ReadDirectoryByPath() should kick off the resource list loading.
703 scoped_ptr<DriveEntryProtoVector> entries( 734 scoped_ptr<DriveEntryProtoVector> entries(
704 ReadDirectoryByPathSync( 735 ReadDirectoryByPathSync(
705 base::FilePath::FromUTF8Unsafe("drive/Directory 1"))); 736 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1")));
706 // The non root directory should also be read correctly. 737 // The non root directory should also be read correctly.
707 // There was a bug (crbug.com/181487), which broke this behavior. 738 // There was a bug (crbug.com/181487), which broke this behavior.
708 // Make sure this is fixed. 739 // Make sure this is fixed.
709 ASSERT_TRUE(entries.get()); 740 ASSERT_TRUE(entries.get());
710 EXPECT_EQ(3U, entries->size()); 741 EXPECT_EQ(3U, entries->size());
711 } 742 }
712 743
713 TEST_F(DriveFileSystemTest, FilePathTests) { 744 TEST_F(DriveFileSystemTest, FilePathTests) {
714 ASSERT_TRUE(LoadRootFeedDocument()); 745 ASSERT_TRUE(LoadRootFeedDocument());
715 746
716 EXPECT_TRUE( 747 EXPECT_TRUE(
717 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")))); 748 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"))));
718 EXPECT_TRUE( 749 EXPECT_TRUE(
719 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1")))); 750 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))));
720 EXPECT_TRUE(EntryExists( 751 EXPECT_TRUE(EntryExists(base::FilePath(
721 base::FilePath( 752 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"))));
722 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"))));
723 } 753 }
724 754
725 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) { 755 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) {
726 ASSERT_TRUE(LoadRootFeedDocument()); 756 ASSERT_TRUE(LoadRootFeedDocument());
727 757
728 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 758 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
729 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(2); 759 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2);
730 760
731 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_added_in_root.json")); 761 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_added_in_root.json"));
732 EXPECT_TRUE( 762 EXPECT_TRUE(EntryExists(
733 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Added file.gdoc")))); 763 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc"))));
734 764
735 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_root.json")); 765 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_root.json"));
736 EXPECT_FALSE( 766 EXPECT_FALSE(EntryExists(
737 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Added file.gdoc")))); 767 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc"))));
738 } 768 }
739 769
740 770
741 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) { 771 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) {
742 ASSERT_TRUE(LoadRootFeedDocument()); 772 ASSERT_TRUE(LoadRootFeedDocument());
743 773
744 EXPECT_TRUE( 774 EXPECT_TRUE(
745 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1")))); 775 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))));
746 776
747 // Add file to an existing directory. 777 // Add file to an existing directory.
748 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 778 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
749 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 779 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
750 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 780 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
751 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 781 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
782 .Times(1);
752 ASSERT_TRUE( 783 ASSERT_TRUE(
753 LoadChangeFeed("chromeos/gdata/delta_file_added_in_directory.json")); 784 LoadChangeFeed("chromeos/gdata/delta_file_added_in_directory.json"));
754 EXPECT_TRUE(EntryExists(base::FilePath( 785 EXPECT_TRUE(EntryExists(base::FilePath(
755 FILE_PATH_LITERAL("drive/Directory 1/Added file.gdoc")))); 786 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc"))));
756 787
757 // Remove that file from the directory. 788 // Remove that file from the directory.
758 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 789 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
759 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 790 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
791 .Times(1);
760 ASSERT_TRUE( 792 ASSERT_TRUE(
761 LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_directory.json")); 793 LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_directory.json"));
762 EXPECT_TRUE( 794 EXPECT_TRUE(
763 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1")))); 795 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))));
764 EXPECT_FALSE(EntryExists(base::FilePath( 796 EXPECT_FALSE(EntryExists(base::FilePath(
765 FILE_PATH_LITERAL("drive/Directory 1/Added file.gdoc")))); 797 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc"))));
766 } 798 }
767 799
768 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewDirectory) { 800 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewDirectory) {
769 ASSERT_TRUE(LoadRootFeedDocument()); 801 ASSERT_TRUE(LoadRootFeedDocument());
770 // Add file to a new directory. 802 // Add file to a new directory.
771 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 803 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
772 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 804 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
773 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 805 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
774 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Directory"))))).Times(1); 806 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Directory")))))
807 .Times(1);
775 808
776 ASSERT_TRUE( 809 ASSERT_TRUE(
777 LoadChangeFeed("chromeos/gdata/delta_file_added_in_new_directory.json")); 810 LoadChangeFeed("chromeos/gdata/delta_file_added_in_new_directory.json"));
778 811
779 EXPECT_TRUE( 812 EXPECT_TRUE(
780 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/New Directory")))); 813 EntryExists(base::FilePath(
814 FILE_PATH_LITERAL("drive/root/New Directory"))));
781 EXPECT_TRUE(EntryExists(base::FilePath( 815 EXPECT_TRUE(EntryExists(base::FilePath(
782 FILE_PATH_LITERAL("drive/New Directory/File in new dir.gdoc")))); 816 FILE_PATH_LITERAL("drive/root/New Directory/File in new dir.gdoc"))));
783 } 817 }
784 818
785 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewButDeletedDirectory) { 819 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewButDeletedDirectory) {
786 ASSERT_TRUE(LoadRootFeedDocument()); 820 ASSERT_TRUE(LoadRootFeedDocument());
787 821
788 // This feed contains the following updates: 822 // This feed contains the following updates:
789 // 1) A new PDF file is added to a new directory 823 // 1) A new PDF file is added to a new directory
790 // 2) but the new directory is marked "deleted" (i.e. moved to Trash) 824 // 2) but the new directory is marked "deleted" (i.e. moved to Trash)
791 // Hence, the PDF file should be just ignored. 825 // Hence, the PDF file should be just ignored.
792 ASSERT_TRUE(LoadChangeFeed( 826 ASSERT_TRUE(LoadChangeFeed(
793 "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json")); 827 "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json"));
794 } 828 }
795 829
796 TEST_F(DriveFileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) { 830 TEST_F(DriveFileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) {
797 ASSERT_TRUE(LoadRootFeedDocument()); 831 ASSERT_TRUE(LoadRootFeedDocument());
798 832
799 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 833 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
800 "drive/Directory 2")))); 834 "drive/root/Directory 2"))));
801 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 835 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
802 "drive/Directory 1")))); 836 "drive/root/Directory 1"))));
803 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 837 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
804 "drive/Directory 1/SubDirectory File 1.txt")))); 838 "drive/root/Directory 1/SubDirectory File 1.txt"))));
805 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 839 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
806 "drive/Directory 1/Sub Directory Folder")))); 840 "drive/root/Directory 1/Sub Directory Folder"))));
807 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 841 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
808 "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); 842 "drive/root/Directory 1/Sub Directory Folder/"
843 "Sub Sub Directory Folder"))));
809 844
810 // This will move "Directory 1" from "drive/" to "drive/Directory 2/". 845 // This will move "Directory 1" from "drive/root/" to
846 // "drive/root/Directory 2/".
811 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 847 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
812 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 848 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
813 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 849 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
814 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 850 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
851 .Times(1);
815 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 852 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
816 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 2"))))).Times(1); 853 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 2")))))
854 .Times(1);
817 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 855 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
818 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 2/Directory 1"))))) 856 Eq(base::FilePath(
819 .Times(1); 857 FILE_PATH_LITERAL("drive/root/Directory 2/Directory 1"))))).Times(1);
820 ASSERT_TRUE(LoadChangeFeed( 858 ASSERT_TRUE(LoadChangeFeed(
821 "chromeos/gdata/delta_dir_moved_from_root_to_directory.json")); 859 "chromeos/gdata/delta_dir_moved_from_root_to_directory.json"));
822 860
823 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 861 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
824 "drive/Directory 2")))); 862 "drive/root/Directory 2"))));
825 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 863 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
826 "drive/Directory 1")))); 864 "drive/root/Directory 1"))));
827 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 865 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
828 "drive/Directory 2/Directory 1")))); 866 "drive/root/Directory 2/Directory 1"))));
829 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 867 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
830 "drive/Directory 2/Directory 1/SubDirectory File 1.txt")))); 868 "drive/root/Directory 2/Directory 1/SubDirectory File 1.txt"))));
831 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 869 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
832 "drive/Directory 2/Directory 1/Sub Directory Folder")))); 870 "drive/root/Directory 2/Directory 1/Sub Directory Folder"))));
833 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 871 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
834 "drive/Directory 2/Directory 1/Sub Directory Folder/" 872 "drive/root/Directory 2/Directory 1/Sub Directory Folder/"
835 "Sub Sub Directory Folder")))); 873 "Sub Sub Directory Folder"))));
836 } 874 }
837 875
838 TEST_F(DriveFileSystemTest, ChangeFeed_FileMovedFromDirectoryToRoot) { 876 TEST_F(DriveFileSystemTest, ChangeFeed_FileMovedFromDirectoryToRoot) {
839 ASSERT_TRUE(LoadRootFeedDocument()); 877 ASSERT_TRUE(LoadRootFeedDocument());
840 878
841 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 879 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
842 "drive/Directory 1")))); 880 "drive/root/Directory 1"))));
843 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 881 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
844 "drive/Directory 1/Sub Directory Folder")))); 882 "drive/root/Directory 1/Sub Directory Folder"))));
845 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 883 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
846 "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); 884 "drive/root/Directory 1/Sub Directory Folder/"
885 "Sub Sub Directory Folder"))));
847 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 886 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
848 "drive/Directory 1/SubDirectory File 1.txt")))); 887 "drive/root/Directory 1/SubDirectory File 1.txt"))));
849 888
850 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 889 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
851 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 890 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
852 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 891 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
853 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 892 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
893 .Times(1);
854 ASSERT_TRUE(LoadChangeFeed( 894 ASSERT_TRUE(LoadChangeFeed(
855 "chromeos/gdata/delta_file_moved_from_directory_to_root.json")); 895 "chromeos/gdata/delta_file_moved_from_directory_to_root.json"));
856 896
857 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 897 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
858 "drive/Directory 1")))); 898 "drive/root/Directory 1"))));
859 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 899 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
860 "drive/Directory 1/Sub Directory Folder")))); 900 "drive/root/Directory 1/Sub Directory Folder"))));
861 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 901 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
862 "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")))); 902 "drive/root/Directory 1/Sub Directory Folder/"
903 "Sub Sub Directory Folder"))));
863 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 904 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
864 "drive/Directory 1/SubDirectory File 1.txt")))); 905 "drive/root/Directory 1/SubDirectory File 1.txt"))));
865 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 906 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
866 "drive/SubDirectory File 1.txt")))); 907 "drive/root/SubDirectory File 1.txt"))));
867 } 908 }
868 909
869 TEST_F(DriveFileSystemTest, ChangeFeed_FileRenamedInDirectory) { 910 TEST_F(DriveFileSystemTest, ChangeFeed_FileRenamedInDirectory) {
870 ASSERT_TRUE(LoadRootFeedDocument()); 911 ASSERT_TRUE(LoadRootFeedDocument());
871 912
872 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 913 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
873 "drive/Directory 1")))); 914 "drive/root/Directory 1"))));
874 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 915 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
875 "drive/Directory 1/SubDirectory File 1.txt")))); 916 "drive/root/Directory 1/SubDirectory File 1.txt"))));
876 917
877 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 918 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
878 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 919 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
879 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 920 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
880 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 921 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
922 .Times(1);
881 ASSERT_TRUE(LoadChangeFeed( 923 ASSERT_TRUE(LoadChangeFeed(
882 "chromeos/gdata/delta_file_renamed_in_directory.json")); 924 "chromeos/gdata/delta_file_renamed_in_directory.json"));
883 925
884 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 926 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
885 "drive/Directory 1")))); 927 "drive/root/Directory 1"))));
886 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 928 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
887 "drive/Directory 1/SubDirectory File 1.txt")))); 929 "drive/root/Directory 1/SubDirectory File 1.txt"))));
888 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 930 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
889 "drive/Directory 1/New SubDirectory File 1.txt")))); 931 "drive/root/Directory 1/New SubDirectory File 1.txt"))));
890 } 932 }
891 933
892 TEST_F(DriveFileSystemTest, CachedFeedLoading) { 934 TEST_F(DriveFileSystemTest, CachedFeedLoading) {
893 ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP)); 935 ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP));
894 // Tests that cached data can be loaded even if the server is not reachable. 936 // Tests that cached data can be loaded even if the server is not reachable.
895 fake_drive_service_->set_offline(true); 937 fake_drive_service_->set_offline(true);
896 938
897 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/File1")))); 939 EXPECT_TRUE(EntryExists(base::FilePath(
898 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Dir1")))); 940 FILE_PATH_LITERAL("drive/root/File1"))));
941 EXPECT_TRUE(EntryExists(base::FilePath(
942 FILE_PATH_LITERAL("drive/root/Dir1"))));
899 EXPECT_TRUE( 943 EXPECT_TRUE(
900 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Dir1/File2")))); 944 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Dir1/File2"))));
901 EXPECT_TRUE( 945 EXPECT_TRUE(EntryExists(base::FilePath(
902 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2")))); 946 FILE_PATH_LITERAL("drive/root/Dir1/SubDir2"))));
903 EXPECT_TRUE(EntryExists( 947 EXPECT_TRUE(EntryExists(
904 base::FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); 948 base::FilePath(FILE_PATH_LITERAL("drive/root/Dir1/SubDir2/File3"))));
905 } 949 }
906 950
907 TEST_F(DriveFileSystemTest, CachedFeedLoadingThenServerFeedLoading) { 951 TEST_F(DriveFileSystemTest, CachedFeedLoadingThenServerFeedLoading) {
908 ASSERT_TRUE(SaveTestFileSystem(USE_SERVER_TIMESTAMP)); 952 ASSERT_TRUE(SaveTestFileSystem(USE_SERVER_TIMESTAMP));
909 953
910 // Kicks loading of cached file system and query for server update. 954 // Kicks loading of cached file system and query for server update.
911 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath())); 955 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath()));
912 956
913 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, 957 // SaveTestFileSystem and "account_metadata.json" have the same changestamp,
914 // so no request for new feeds (i.e., call to GetResourceList) should happen. 958 // so no request for new feeds (i.e., call to GetResourceList) should happen.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); 995 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
952 } 996 }
953 997
954 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { 998 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
955 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 999 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
956 1000
957 ASSERT_TRUE(LoadRootFeedDocument()); 1001 ASSERT_TRUE(LoadRootFeedDocument());
958 1002
959 // We'll add a file to the Drive root directory. 1003 // We'll add a file to the Drive root directory.
960 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1004 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
961 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1005 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
962 1006
963 // Prepare a local file. 1007 // Prepare a local file.
964 base::ScopedTempDir temp_dir; 1008 base::ScopedTempDir temp_dir;
965 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1009 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
966 const base::FilePath local_src_file_path = 1010 const base::FilePath local_src_file_path =
967 temp_dir.path().AppendASCII("local.txt"); 1011 temp_dir.path().AppendASCII("local.txt");
968 const std::string kContent = "hello"; 1012 const std::string kContent = "hello";
969 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); 1013 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size());
970 1014
971 // Confirm that the remote file does not exist. 1015 // Confirm that the remote file does not exist.
972 const base::FilePath remote_dest_file_path( 1016 const base::FilePath remote_dest_file_path(
973 FILE_PATH_LITERAL("drive/remote.txt")); 1017 FILE_PATH_LITERAL("drive/root/remote.txt"));
974 EXPECT_FALSE(EntryExists(remote_dest_file_path)); 1018 EXPECT_FALSE(EntryExists(remote_dest_file_path));
975 1019
976 // Transfer the local file to Drive. 1020 // Transfer the local file to Drive.
977 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1021 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
978 file_system_->TransferFileFromLocalToRemote( 1022 file_system_->TransferFileFromLocalToRemote(
979 local_src_file_path, 1023 local_src_file_path,
980 remote_dest_file_path, 1024 remote_dest_file_path,
981 google_apis::test_util::CreateCopyResultCallback(&error)); 1025 google_apis::test_util::CreateCopyResultCallback(&error));
982 google_apis::test_util::RunBlockingPoolTask(); 1026 google_apis::test_util::RunBlockingPoolTask();
983 1027
(...skipping 15 matching lines...) Expand all
999 const std::string kEditUrl = 1043 const std::string kEditUrl =
1000 "https://3_document_self_link/document:5_document_resource_id"; 1044 "https://3_document_self_link/document:5_document_resource_id";
1001 const std::string kResourceId = "document:5_document_resource_id"; 1045 const std::string kResourceId = "document:5_document_resource_id";
1002 const std::string kContent = 1046 const std::string kContent =
1003 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}", 1047 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}",
1004 kEditUrl.c_str(), kResourceId.c_str()); 1048 kEditUrl.c_str(), kResourceId.c_str());
1005 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); 1049 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size());
1006 1050
1007 // Confirm that the remote file does not exist. 1051 // Confirm that the remote file does not exist.
1008 const base::FilePath remote_dest_file_path( 1052 const base::FilePath remote_dest_file_path(
1009 FILE_PATH_LITERAL("drive/Directory 1/Document 1.gdoc")); 1053 FILE_PATH_LITERAL("drive/root/Directory 1/Document 1.gdoc"));
1010 EXPECT_FALSE(EntryExists(remote_dest_file_path)); 1054 EXPECT_FALSE(EntryExists(remote_dest_file_path));
1011 1055
1012 // We'll add a file to the Drive root and then move to "Directory 1". 1056 // We'll add a file to the Drive root and then move to "Directory 1".
1013 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1057 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1014 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1058 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1015 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1059 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1016 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1060 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1061 .Times(1);
1017 1062
1018 // We'll copy a hosted document using CopyHostedDocument. 1063 // We'll copy a hosted document using CopyHostedDocument.
1019 // ".gdoc" suffix should be stripped when copying. 1064 // ".gdoc" suffix should be stripped when copying.
1020 scoped_ptr<base::Value> value = 1065 scoped_ptr<base::Value> value =
1021 google_apis::test_util::LoadJSONFile( 1066 google_apis::test_util::LoadJSONFile(
1022 "chromeos/gdata/uploaded_document.json"); 1067 "chromeos/gdata/uploaded_document.json");
1023 scoped_ptr<google_apis::ResourceEntry> resource_entry = 1068 scoped_ptr<google_apis::ResourceEntry> resource_entry =
1024 google_apis::ResourceEntry::ExtractAndParse(*value); 1069 google_apis::ResourceEntry::ExtractAndParse(*value);
1025 1070
1026 1071
(...skipping 10 matching lines...) Expand all
1037 // Now the remote file should exist. 1082 // Now the remote file should exist.
1038 EXPECT_TRUE(EntryExists(remote_dest_file_path)); 1083 EXPECT_TRUE(EntryExists(remote_dest_file_path));
1039 } 1084 }
1040 1085
1041 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { 1086 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) {
1042 ASSERT_TRUE(LoadRootFeedDocument()); 1087 ASSERT_TRUE(LoadRootFeedDocument());
1043 1088
1044 // The transfered file is cached and the change of "offline available" 1089 // The transfered file is cached and the change of "offline available"
1045 // attribute is notified. 1090 // attribute is notified.
1046 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1091 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1047 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1092 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1048 1093
1049 base::ScopedTempDir temp_dir; 1094 base::ScopedTempDir temp_dir;
1050 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1095 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1051 base::FilePath local_dest_file_path = 1096 base::FilePath local_dest_file_path =
1052 temp_dir.path().AppendASCII("local_copy.txt"); 1097 temp_dir.path().AppendASCII("local_copy.txt");
1053 1098
1054 base::FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1099 base::FilePath remote_src_file_path(
1100 FILE_PATH_LITERAL("drive/root/File 1.txt"));
1055 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync( 1101 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync(
1056 remote_src_file_path); 1102 remote_src_file_path);
1057 const int64 file_size = file->file_info().size(); 1103 const int64 file_size = file->file_info().size();
1058 1104
1059 // Pretend we have enough space. 1105 // Pretend we have enough space.
1060 fake_free_disk_space_getter_->set_fake_free_disk_space( 1106 fake_free_disk_space_getter_->set_fake_free_disk_space(
1061 file_size + kMinFreeSpace); 1107 file_size + kMinFreeSpace);
1062 1108
1063 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1109 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1064 file_system_->TransferFileFromRemoteToLocal( 1110 file_system_->TransferFileFromRemoteToLocal(
(...skipping 25 matching lines...) Expand all
1090 } 1136 }
1091 1137
1092 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { 1138 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) {
1093 ASSERT_TRUE(LoadRootFeedDocument()); 1139 ASSERT_TRUE(LoadRootFeedDocument());
1094 1140
1095 base::ScopedTempDir temp_dir; 1141 base::ScopedTempDir temp_dir;
1096 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1142 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1097 base::FilePath local_dest_file_path = 1143 base::FilePath local_dest_file_path =
1098 temp_dir.path().AppendASCII("local_copy.txt"); 1144 temp_dir.path().AppendASCII("local_copy.txt");
1099 base::FilePath remote_src_file_path( 1145 base::FilePath remote_src_file_path(
1100 FILE_PATH_LITERAL("drive/Document 1.gdoc")); 1146 FILE_PATH_LITERAL("drive/root/Document 1.gdoc"));
1101 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1147 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1102 file_system_->TransferFileFromRemoteToLocal( 1148 file_system_->TransferFileFromRemoteToLocal(
1103 remote_src_file_path, 1149 remote_src_file_path,
1104 local_dest_file_path, 1150 local_dest_file_path,
1105 google_apis::test_util::CreateCopyResultCallback(&error)); 1151 google_apis::test_util::CreateCopyResultCallback(&error));
1106 google_apis::test_util::RunBlockingPoolTask(); 1152 google_apis::test_util::RunBlockingPoolTask();
1107 1153
1108 EXPECT_EQ(DRIVE_FILE_OK, error); 1154 EXPECT_EQ(DRIVE_FILE_OK, error);
1109 1155
1110 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( 1156 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync(
1111 remote_src_file_path); 1157 remote_src_file_path);
1112 ASSERT_TRUE(entry_proto.get()); 1158 ASSERT_TRUE(entry_proto.get());
1113 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); 1159 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path);
1114 } 1160 }
1115 1161
1116 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { 1162 TEST_F(DriveFileSystemTest, CopyNotExistingFile) {
1117 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); 1163 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1118 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1164 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1119 1165
1120 ASSERT_TRUE(LoadRootFeedDocument()); 1166 ASSERT_TRUE(LoadRootFeedDocument());
1121 1167
1122 EXPECT_FALSE(EntryExists(src_file_path)); 1168 EXPECT_FALSE(EntryExists(src_file_path));
1123 1169
1124 DriveFileError error = DRIVE_FILE_OK; 1170 DriveFileError error = DRIVE_FILE_OK;
1125 file_system_->Copy( 1171 file_system_->Copy(
1126 src_file_path, 1172 src_file_path,
1127 dest_file_path, 1173 dest_file_path,
1128 google_apis::test_util::CreateCopyResultCallback(&error)); 1174 google_apis::test_util::CreateCopyResultCallback(&error));
1129 google_apis::test_util::RunBlockingPoolTask(); 1175 google_apis::test_util::RunBlockingPoolTask();
1130 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 1176 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1131 1177
1132 EXPECT_FALSE(EntryExists(src_file_path)); 1178 EXPECT_FALSE(EntryExists(src_file_path));
1133 EXPECT_FALSE(EntryExists(dest_file_path)); 1179 EXPECT_FALSE(EntryExists(dest_file_path));
1134 } 1180 }
1135 1181
1136 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { 1182 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) {
1137 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1183 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1138 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); 1184 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy"));
1139 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); 1185 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log"));
1140 1186
1141 ASSERT_TRUE(LoadRootFeedDocument()); 1187 ASSERT_TRUE(LoadRootFeedDocument());
1142 1188
1143 ASSERT_TRUE(EntryExists(src_file_path)); 1189 ASSERT_TRUE(EntryExists(src_file_path));
1144 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1190 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1145 src_file_path); 1191 src_file_path);
1146 ASSERT_TRUE(src_entry_proto.get()); 1192 ASSERT_TRUE(src_entry_proto.get());
1147 std::string src_file_path_resource_id = 1193 std::string src_file_path_resource_id =
1148 src_entry_proto->resource_id(); 1194 src_entry_proto->resource_id();
1149 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1195 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1150 1196
1151 EXPECT_FALSE(EntryExists(dest_parent_path)); 1197 EXPECT_FALSE(EntryExists(dest_parent_path));
1152 1198
1153 DriveFileError error = DRIVE_FILE_OK; 1199 DriveFileError error = DRIVE_FILE_OK;
1154 file_system_->Move( 1200 file_system_->Move(
1155 src_file_path, 1201 src_file_path,
1156 dest_file_path, 1202 dest_file_path,
1157 google_apis::test_util::CreateCopyResultCallback(&error)); 1203 google_apis::test_util::CreateCopyResultCallback(&error));
1158 google_apis::test_util::RunBlockingPoolTask(); 1204 google_apis::test_util::RunBlockingPoolTask();
1159 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 1205 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1160 1206
1161 EXPECT_TRUE(EntryExists(src_file_path)); 1207 EXPECT_TRUE(EntryExists(src_file_path));
1162 EXPECT_FALSE(EntryExists(dest_parent_path)); 1208 EXPECT_FALSE(EntryExists(dest_parent_path));
1163 EXPECT_FALSE(EntryExists(dest_file_path)); 1209 EXPECT_FALSE(EntryExists(dest_file_path));
1164 } 1210 }
1165 1211
1166 // Test the case where the parent of |dest_file_path| is an existing file, 1212 // Test the case where the parent of |dest_file_path| is an existing file,
1167 // not a directory. 1213 // not a directory.
1168 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { 1214 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) {
1169 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); 1215 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Document 1.gdoc"));
1170 base::FilePath dest_parent_path( 1216 base::FilePath dest_parent_path(
1171 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 1217 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt"));
1172 base::FilePath dest_file_path(FILE_PATH_LITERAL( 1218 base::FilePath dest_file_path(FILE_PATH_LITERAL(
1173 "drive/Duplicate Name.txt/Document 1.gdoc")); 1219 "drive/root/Duplicate Name.txt/Document 1.gdoc"));
1174 1220
1175 ASSERT_TRUE(LoadRootFeedDocument()); 1221 ASSERT_TRUE(LoadRootFeedDocument());
1176 1222
1177 ASSERT_TRUE(EntryExists(src_file_path)); 1223 ASSERT_TRUE(EntryExists(src_file_path));
1178 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1224 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1179 src_file_path); 1225 src_file_path);
1180 ASSERT_TRUE(src_entry_proto.get()); 1226 ASSERT_TRUE(src_entry_proto.get());
1181 std::string src_file_resource_id = 1227 std::string src_file_resource_id =
1182 src_entry_proto->resource_id(); 1228 src_entry_proto->resource_id();
1183 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1229 EXPECT_FALSE(src_entry_proto->edit_url().empty());
(...skipping 13 matching lines...) Expand all
1197 1243
1198 EXPECT_TRUE(EntryExists(src_file_path)); 1244 EXPECT_TRUE(EntryExists(src_file_path));
1199 EXPECT_TRUE(EntryExists(src_file_path)); 1245 EXPECT_TRUE(EntryExists(src_file_path));
1200 EXPECT_TRUE(EntryExists(dest_parent_path)); 1246 EXPECT_TRUE(EntryExists(dest_parent_path));
1201 1247
1202 EXPECT_FALSE(EntryExists(dest_file_path)); 1248 EXPECT_FALSE(EntryExists(dest_file_path));
1203 } 1249 }
1204 1250
1205 TEST_F(DriveFileSystemTest, RenameFile) { 1251 TEST_F(DriveFileSystemTest, RenameFile) {
1206 const base::FilePath src_file_path( 1252 const base::FilePath src_file_path(
1207 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1253 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1208 const base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1254 const base::FilePath src_parent_path(
1255 FILE_PATH_LITERAL("drive/root/Directory 1"));
1209 const base::FilePath dest_file_path( 1256 const base::FilePath dest_file_path(
1210 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); 1257 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log"));
1211 1258
1212 ASSERT_TRUE(LoadRootFeedDocument()); 1259 ASSERT_TRUE(LoadRootFeedDocument());
1213 1260
1214 ASSERT_TRUE(EntryExists(src_file_path)); 1261 ASSERT_TRUE(EntryExists(src_file_path));
1215 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1262 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1216 src_file_path); 1263 src_file_path);
1217 ASSERT_TRUE(src_entry_proto.get()); 1264 ASSERT_TRUE(src_entry_proto.get());
1218 std::string src_file_resource_id = 1265 std::string src_file_resource_id =
1219 src_entry_proto->resource_id(); 1266 src_entry_proto->resource_id();
1220 1267
1221 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1268 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1222 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1269 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1270 .Times(1);
1223 1271
1224 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1272 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1225 file_system_->Move( 1273 file_system_->Move(
1226 src_file_path, 1274 src_file_path,
1227 dest_file_path, 1275 dest_file_path,
1228 google_apis::test_util::CreateCopyResultCallback(&error)); 1276 google_apis::test_util::CreateCopyResultCallback(&error));
1229 google_apis::test_util::RunBlockingPoolTask(); 1277 google_apis::test_util::RunBlockingPoolTask();
1230 EXPECT_EQ(DRIVE_FILE_OK, error); 1278 EXPECT_EQ(DRIVE_FILE_OK, error);
1231 1279
1232 EXPECT_FALSE(EntryExists(src_file_path)); 1280 EXPECT_FALSE(EntryExists(src_file_path));
1233 EXPECT_TRUE(EntryExists(dest_file_path)); 1281 EXPECT_TRUE(EntryExists(dest_file_path));
1234 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1282 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1235 } 1283 }
1236 1284
1237 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { 1285 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) {
1238 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1286 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1239 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1287 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
1240 base::FilePath dest_file_path( 1288 base::FilePath dest_file_path(
1241 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); 1289 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log"));
1242 1290
1243 ASSERT_TRUE(LoadRootFeedDocument()); 1291 ASSERT_TRUE(LoadRootFeedDocument());
1244 1292
1245 ASSERT_TRUE(EntryExists(src_file_path)); 1293 ASSERT_TRUE(EntryExists(src_file_path));
1246 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1294 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1247 src_file_path); 1295 src_file_path);
1248 ASSERT_TRUE(src_entry_proto.get()); 1296 ASSERT_TRUE(src_entry_proto.get());
1249 std::string src_file_resource_id = 1297 std::string src_file_resource_id =
1250 src_entry_proto->resource_id(); 1298 src_entry_proto->resource_id();
1251 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1299 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1252 1300
1253 ASSERT_TRUE(EntryExists(dest_parent_path)); 1301 ASSERT_TRUE(EntryExists(dest_parent_path));
1254 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( 1302 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync(
1255 dest_parent_path); 1303 dest_parent_path);
1256 ASSERT_TRUE(dest_parent_proto.get()); 1304 ASSERT_TRUE(dest_parent_proto.get());
1257 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); 1305 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1258 EXPECT_FALSE(dest_parent_proto->download_url().empty()); 1306 EXPECT_FALSE(dest_parent_proto->download_url().empty());
1259 1307
1260 // Expect notification for both source and destination directories. 1308 // Expect notification for both source and destination directories.
1261 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1309 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1262 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1310 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1263 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1311 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1264 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1312 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1313 .Times(1);
1265 1314
1266 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1315 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1267 file_system_->Move( 1316 file_system_->Move(
1268 src_file_path, 1317 src_file_path,
1269 dest_file_path, 1318 dest_file_path,
1270 google_apis::test_util::CreateCopyResultCallback(&error)); 1319 google_apis::test_util::CreateCopyResultCallback(&error));
1271 google_apis::test_util::RunBlockingPoolTask(); 1320 google_apis::test_util::RunBlockingPoolTask();
1272 EXPECT_EQ(DRIVE_FILE_OK, error); 1321 EXPECT_EQ(DRIVE_FILE_OK, error);
1273 1322
1274 EXPECT_FALSE(EntryExists(src_file_path)); 1323 EXPECT_FALSE(EntryExists(src_file_path));
1275 EXPECT_TRUE(EntryExists(dest_file_path)); 1324 EXPECT_TRUE(EntryExists(dest_file_path));
1276 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1325 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1277 } 1326 }
1278 1327
1279 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { 1328 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) {
1280 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1329 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
1281 base::FilePath src_file_path( 1330 base::FilePath src_file_path(
1282 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1331 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1283 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1332 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1284 1333
1285 ASSERT_TRUE(LoadRootFeedDocument()); 1334 ASSERT_TRUE(LoadRootFeedDocument());
1286 1335
1287 ASSERT_TRUE(EntryExists(src_file_path)); 1336 ASSERT_TRUE(EntryExists(src_file_path));
1288 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1337 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1289 src_file_path); 1338 src_file_path);
1290 ASSERT_TRUE(src_entry_proto.get()); 1339 ASSERT_TRUE(src_entry_proto.get());
1291 std::string src_file_resource_id = 1340 std::string src_file_resource_id =
1292 src_entry_proto->resource_id(); 1341 src_entry_proto->resource_id();
1293 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1342 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1294 1343
1295 ASSERT_TRUE(EntryExists(src_parent_path)); 1344 ASSERT_TRUE(EntryExists(src_parent_path));
1296 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync( 1345 scoped_ptr<DriveEntryProto> src_parent_proto = GetEntryInfoByPathSync(
1297 src_parent_path); 1346 src_parent_path);
1298 ASSERT_TRUE(src_parent_proto.get()); 1347 ASSERT_TRUE(src_parent_proto.get());
1299 ASSERT_TRUE(src_parent_proto->file_info().is_directory()); 1348 ASSERT_TRUE(src_parent_proto->file_info().is_directory());
1300 EXPECT_FALSE(src_parent_proto->download_url().empty()); 1349 EXPECT_FALSE(src_parent_proto->download_url().empty());
1301 1350
1302 // Expect notification for both source and destination directories. 1351 // Expect notification for both source and destination directories.
1303 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1352 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1304 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1353 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1305 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1354 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1306 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1355 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1356 .Times(1);
1307 1357
1308 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1358 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1309 file_system_->Move( 1359 file_system_->Move(
1310 src_file_path, 1360 src_file_path,
1311 dest_file_path, 1361 dest_file_path,
1312 google_apis::test_util::CreateCopyResultCallback(&error)); 1362 google_apis::test_util::CreateCopyResultCallback(&error));
1313 google_apis::test_util::RunBlockingPoolTask(); 1363 google_apis::test_util::RunBlockingPoolTask();
1314 EXPECT_EQ(DRIVE_FILE_OK, error); 1364 EXPECT_EQ(DRIVE_FILE_OK, error);
1315 1365
1316 EXPECT_FALSE(EntryExists(src_file_path)); 1366 EXPECT_FALSE(EntryExists(src_file_path));
1317 ASSERT_TRUE(EntryExists(dest_file_path)); 1367 ASSERT_TRUE(EntryExists(dest_file_path));
1318 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1368 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1319 } 1369 }
1320 1370
1321 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { 1371 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) {
1322 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1372 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
1323 base::FilePath src_file_path( 1373 base::FilePath src_file_path(
1324 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1374 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1325 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/New Folder 1")); 1375 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/New Folder 1"));
1326 base::FilePath dest_file_path( 1376 base::FilePath dest_file_path(
1327 FILE_PATH_LITERAL("drive/New Folder 1/Test.log")); 1377 FILE_PATH_LITERAL("drive/root/New Folder 1/Test.log"));
1328 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1378 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1329 1379
1330 ASSERT_TRUE(LoadRootFeedDocument()); 1380 ASSERT_TRUE(LoadRootFeedDocument());
1331 1381
1332 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1382 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1333 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1383 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1334 1384
1335 AddDirectoryFromFile(dest_parent_path, 1385 AddDirectoryFromFile(dest_parent_path,
1336 "chromeos/gdata/directory_entry_atom.json"); 1386 "chromeos/gdata/directory_entry_atom.json");
1337 1387
1338 ASSERT_TRUE(EntryExists(src_file_path)); 1388 ASSERT_TRUE(EntryExists(src_file_path));
1339 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1389 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1340 src_file_path); 1390 src_file_path);
1341 ASSERT_TRUE(src_entry_proto.get()); 1391 ASSERT_TRUE(src_entry_proto.get());
1342 std::string src_file_resource_id = 1392 std::string src_file_resource_id =
1343 src_entry_proto->resource_id(); 1393 src_entry_proto->resource_id();
(...skipping 10 matching lines...) Expand all
1354 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( 1404 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync(
1355 dest_parent_path); 1405 dest_parent_path);
1356 ASSERT_TRUE(dest_parent_proto.get()); 1406 ASSERT_TRUE(dest_parent_proto.get());
1357 ASSERT_TRUE(dest_parent_proto->file_info().is_directory()); 1407 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1358 EXPECT_FALSE(dest_parent_proto->download_url().empty()); 1408 EXPECT_FALSE(dest_parent_proto->download_url().empty());
1359 1409
1360 EXPECT_FALSE(EntryExists(interim_file_path)); 1410 EXPECT_FALSE(EntryExists(interim_file_path));
1361 1411
1362 // Expect notification for both source and destination directories. 1412 // Expect notification for both source and destination directories.
1363 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1413 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1364 Eq(base::FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1414 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1415 .Times(1);
1365 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1416 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1366 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); 1417 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1")))))
1418 .Times(1);
1367 1419
1368 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1420 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1369 file_system_->Move( 1421 file_system_->Move(
1370 src_file_path, 1422 src_file_path,
1371 dest_file_path, 1423 dest_file_path,
1372 google_apis::test_util::CreateCopyResultCallback(&error)); 1424 google_apis::test_util::CreateCopyResultCallback(&error));
1373 google_apis::test_util::RunBlockingPoolTask(); 1425 google_apis::test_util::RunBlockingPoolTask();
1374 EXPECT_EQ(DRIVE_FILE_OK, error); 1426 EXPECT_EQ(DRIVE_FILE_OK, error);
1375 1427
1376 EXPECT_FALSE(EntryExists(src_file_path)); 1428 EXPECT_FALSE(EntryExists(src_file_path));
1377 EXPECT_FALSE(EntryExists(interim_file_path)); 1429 EXPECT_FALSE(EntryExists(interim_file_path));
1378 1430
1379 EXPECT_FALSE(EntryExists(src_file_path)); 1431 EXPECT_FALSE(EntryExists(src_file_path));
1380 EXPECT_TRUE(EntryExists(dest_file_path)); 1432 EXPECT_TRUE(EntryExists(dest_file_path));
1381 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1433 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1382 } 1434 }
1383 1435
1384 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { 1436 TEST_F(DriveFileSystemTest, MoveNotExistingFile) {
1385 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); 1437 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1386 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1438 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1387 1439
1388 ASSERT_TRUE(LoadRootFeedDocument()); 1440 ASSERT_TRUE(LoadRootFeedDocument());
1389 1441
1390 EXPECT_FALSE(EntryExists(src_file_path)); 1442 EXPECT_FALSE(EntryExists(src_file_path));
1391 1443
1392 DriveFileError error = DRIVE_FILE_OK; 1444 DriveFileError error = DRIVE_FILE_OK;
1393 file_system_->Move( 1445 file_system_->Move(
1394 src_file_path, 1446 src_file_path,
1395 dest_file_path, 1447 dest_file_path,
1396 google_apis::test_util::CreateCopyResultCallback(&error)); 1448 google_apis::test_util::CreateCopyResultCallback(&error));
1397 google_apis::test_util::RunBlockingPoolTask(); 1449 google_apis::test_util::RunBlockingPoolTask();
1398 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 1450 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1399 1451
1400 EXPECT_FALSE(EntryExists(src_file_path)); 1452 EXPECT_FALSE(EntryExists(src_file_path));
1401 EXPECT_FALSE(EntryExists(dest_file_path)); 1453 EXPECT_FALSE(EntryExists(dest_file_path));
1402 } 1454 }
1403 1455
1404 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { 1456 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) {
1405 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1457 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1406 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); 1458 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy"));
1407 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); 1459 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log"));
1408 1460
1409 ASSERT_TRUE(LoadRootFeedDocument()); 1461 ASSERT_TRUE(LoadRootFeedDocument());
1410 1462
1411 ASSERT_TRUE(EntryExists(src_file_path)); 1463 ASSERT_TRUE(EntryExists(src_file_path));
1412 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1464 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1413 src_file_path); 1465 src_file_path);
1414 ASSERT_TRUE(src_entry_proto.get()); 1466 ASSERT_TRUE(src_entry_proto.get());
1415 std::string src_file_resource_id = 1467 std::string src_file_resource_id =
1416 src_entry_proto->resource_id(); 1468 src_entry_proto->resource_id();
1417 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1469 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1418 1470
1419 EXPECT_FALSE(EntryExists(dest_parent_path)); 1471 EXPECT_FALSE(EntryExists(dest_parent_path));
1420 1472
1421 DriveFileError error = DRIVE_FILE_OK; 1473 DriveFileError error = DRIVE_FILE_OK;
1422 file_system_->Move( 1474 file_system_->Move(
1423 src_file_path, 1475 src_file_path,
1424 dest_file_path, 1476 dest_file_path,
1425 google_apis::test_util::CreateCopyResultCallback(&error)); 1477 google_apis::test_util::CreateCopyResultCallback(&error));
1426 google_apis::test_util::RunBlockingPoolTask(); 1478 google_apis::test_util::RunBlockingPoolTask();
1427 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 1479 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1428 1480
1429 EXPECT_FALSE(EntryExists(dest_parent_path)); 1481 EXPECT_FALSE(EntryExists(dest_parent_path));
1430 EXPECT_FALSE(EntryExists(dest_file_path)); 1482 EXPECT_FALSE(EntryExists(dest_file_path));
1431 } 1483 }
1432 1484
1433 // Test the case where the parent of |dest_file_path| is a existing file, 1485 // Test the case where the parent of |dest_file_path| is a existing file,
1434 // not a directory. 1486 // not a directory.
1435 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { 1487 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) {
1436 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1488 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1437 base::FilePath dest_parent_path( 1489 base::FilePath dest_parent_path(
1438 FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 1490 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt"));
1439 base::FilePath dest_file_path(FILE_PATH_LITERAL( 1491 base::FilePath dest_file_path(FILE_PATH_LITERAL(
1440 "drive/Duplicate Name.txt/Test.log")); 1492 "drive/root/Duplicate Name.txt/Test.log"));
1441 1493
1442 ASSERT_TRUE(LoadRootFeedDocument()); 1494 ASSERT_TRUE(LoadRootFeedDocument());
1443 1495
1444 ASSERT_TRUE(EntryExists(src_file_path)); 1496 ASSERT_TRUE(EntryExists(src_file_path));
1445 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1497 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1446 src_file_path); 1498 src_file_path);
1447 ASSERT_TRUE(src_entry_proto.get()); 1499 ASSERT_TRUE(src_entry_proto.get());
1448 std::string src_file_resource_id = 1500 std::string src_file_resource_id =
1449 src_entry_proto->resource_id(); 1501 src_entry_proto->resource_id();
1450 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1502 EXPECT_FALSE(src_entry_proto->edit_url().empty());
(...skipping 12 matching lines...) Expand all
1463 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error); 1515 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error);
1464 1516
1465 EXPECT_TRUE(EntryExists(src_file_path)); 1517 EXPECT_TRUE(EntryExists(src_file_path));
1466 EXPECT_TRUE(EntryExists(dest_parent_path)); 1518 EXPECT_TRUE(EntryExists(dest_parent_path));
1467 EXPECT_FALSE(EntryExists(dest_file_path)); 1519 EXPECT_FALSE(EntryExists(dest_file_path));
1468 } 1520 }
1469 1521
1470 TEST_F(DriveFileSystemTest, RemoveEntries) { 1522 TEST_F(DriveFileSystemTest, RemoveEntries) {
1471 ASSERT_TRUE(LoadRootFeedDocument()); 1523 ASSERT_TRUE(LoadRootFeedDocument());
1472 1524
1473 base::FilePath nonexisting_file(FILE_PATH_LITERAL("drive/Dummy file.txt")); 1525 base::FilePath nonexisting_file(
1474 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1526 FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1475 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/Directory 1")); 1527 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1528 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1"));
1476 base::FilePath file_in_subdir( 1529 base::FilePath file_in_subdir(
1477 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1530 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1478 1531
1479 ASSERT_TRUE(EntryExists(file_in_root)); 1532 ASSERT_TRUE(EntryExists(file_in_root));
1480 scoped_ptr<DriveEntryProto> file_in_root_proto = GetEntryInfoByPathSync( 1533 scoped_ptr<DriveEntryProto> file_in_root_proto = GetEntryInfoByPathSync(
1481 file_in_root); 1534 file_in_root);
1482 ASSERT_TRUE(file_in_root_proto.get()); 1535 ASSERT_TRUE(file_in_root_proto.get());
1483 1536
1484 ASSERT_TRUE(EntryExists(dir_in_root)); 1537 ASSERT_TRUE(EntryExists(dir_in_root));
1485 scoped_ptr<DriveEntryProto> dir_in_root_proto = GetEntryInfoByPathSync( 1538 scoped_ptr<DriveEntryProto> dir_in_root_proto = GetEntryInfoByPathSync(
1486 dir_in_root); 1539 dir_in_root);
1487 ASSERT_TRUE(dir_in_root_proto.get()); 1540 ASSERT_TRUE(dir_in_root_proto.get());
1488 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory()); 1541 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory());
1489 1542
1490 ASSERT_TRUE(EntryExists(file_in_subdir)); 1543 ASSERT_TRUE(EntryExists(file_in_subdir));
1491 scoped_ptr<DriveEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync( 1544 scoped_ptr<DriveEntryProto> file_in_subdir_proto = GetEntryInfoByPathSync(
1492 file_in_subdir); 1545 file_in_subdir);
1493 ASSERT_TRUE(file_in_subdir_proto.get()); 1546 ASSERT_TRUE(file_in_subdir_proto.get());
1494 1547
1495 // Once for file in root and once for file... 1548 // Once for file in root and once for file...
1496 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1549 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1497 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(2); 1550 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2);
1498 1551
1499 // Remove first file in root. 1552 // Remove first file in root.
1500 EXPECT_TRUE(RemoveEntry(file_in_root)); 1553 EXPECT_TRUE(RemoveEntry(file_in_root));
1501 EXPECT_FALSE(EntryExists(file_in_root)); 1554 EXPECT_FALSE(EntryExists(file_in_root));
1502 EXPECT_TRUE(EntryExists(dir_in_root)); 1555 EXPECT_TRUE(EntryExists(dir_in_root));
1503 EXPECT_TRUE(EntryExists(file_in_subdir)); 1556 EXPECT_TRUE(EntryExists(file_in_subdir));
1504 1557
1505 // Remove directory. 1558 // Remove directory.
1506 EXPECT_TRUE(RemoveEntry(dir_in_root)); 1559 EXPECT_TRUE(RemoveEntry(dir_in_root));
1507 EXPECT_FALSE(EntryExists(file_in_root)); 1560 EXPECT_FALSE(EntryExists(file_in_root));
1508 EXPECT_FALSE(EntryExists(dir_in_root)); 1561 EXPECT_FALSE(EntryExists(dir_in_root));
1509 EXPECT_FALSE(EntryExists(file_in_subdir)); 1562 EXPECT_FALSE(EntryExists(file_in_subdir));
1510 1563
1511 // Try removing file in already removed subdirectory. 1564 // Try removing file in already removed subdirectory.
1512 EXPECT_FALSE(RemoveEntry(file_in_subdir)); 1565 EXPECT_FALSE(RemoveEntry(file_in_subdir));
1513 1566
1514 // Try removing non-existing file. 1567 // Try removing non-existing file.
1515 EXPECT_FALSE(RemoveEntry(nonexisting_file)); 1568 EXPECT_FALSE(RemoveEntry(nonexisting_file));
1516 1569
1517 // Try removing root file element. 1570 // Try removing root file element.
1518 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive")))); 1571 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive/root"))));
1519 1572
1520 // Need this to ensure OnDirectoryChanged() is run. 1573 // Need this to ensure OnDirectoryChanged() is run.
1521 google_apis::test_util::RunBlockingPoolTask(); 1574 google_apis::test_util::RunBlockingPoolTask();
1522 } 1575 }
1523 1576
1524 TEST_F(DriveFileSystemTest, CreateDirectory) { 1577 TEST_F(DriveFileSystemTest, CreateDirectory) {
1525 ASSERT_TRUE(LoadRootFeedDocument()); 1578 ASSERT_TRUE(LoadRootFeedDocument());
1526 1579
1527 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1580 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1528 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1581 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1529 1582
1530 // Create directory in root. 1583 // Create directory in root.
1531 base::FilePath dir_path(FILE_PATH_LITERAL("drive/New Folder 1")); 1584 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1"));
1532 EXPECT_FALSE(EntryExists(dir_path)); 1585 EXPECT_FALSE(EntryExists(dir_path));
1533 AddDirectoryFromFile(dir_path, "chromeos/gdata/directory_entry_atom.json"); 1586 AddDirectoryFromFile(dir_path, "chromeos/gdata/directory_entry_atom.json");
1534 EXPECT_TRUE(EntryExists(dir_path)); 1587 EXPECT_TRUE(EntryExists(dir_path));
1535 1588
1536 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1589 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1537 Eq(base::FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); 1590 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1")))))
1591 .Times(1);
1538 1592
1539 // Create directory in a sub directory. 1593 // Create directory in a sub directory.
1540 base::FilePath subdir_path( 1594 base::FilePath subdir_path(
1541 FILE_PATH_LITERAL("drive/New Folder 1/New Folder 2")); 1595 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2"));
1542 EXPECT_FALSE(EntryExists(subdir_path)); 1596 EXPECT_FALSE(EntryExists(subdir_path));
1543 AddDirectoryFromFile(subdir_path, 1597 AddDirectoryFromFile(subdir_path,
1544 "chromeos/gdata/directory_entry_atom2.json"); 1598 "chromeos/gdata/directory_entry_atom2.json");
1545 EXPECT_TRUE(EntryExists(subdir_path)); 1599 EXPECT_TRUE(EntryExists(subdir_path));
1546 } 1600 }
1547 1601
1548 // Create a directory through the document service 1602 // Create a directory through the document service
1549 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { 1603 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) {
1550 ASSERT_TRUE(LoadRootFeedDocument()); 1604 ASSERT_TRUE(LoadRootFeedDocument());
1551 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1605 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1552 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1606 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1553 1607
1554 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1608 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1555 file_system_->CreateDirectory( 1609 file_system_->CreateDirectory(
1556 base::FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), 1610 base::FilePath(FILE_PATH_LITERAL("drive/root/Sample Directory Title")),
1557 false, // is_exclusive 1611 false, // is_exclusive
1558 true, // is_recursive 1612 true, // is_recursive
1559 google_apis::test_util::CreateCopyResultCallback(&error)); 1613 google_apis::test_util::CreateCopyResultCallback(&error));
1560 google_apis::test_util::RunBlockingPoolTask(); 1614 google_apis::test_util::RunBlockingPoolTask();
1561 1615
1562 EXPECT_EQ(DRIVE_FILE_OK, error); 1616 EXPECT_EQ(DRIVE_FILE_OK, error);
1563 } 1617 }
1564 1618
1565 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { 1619 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) {
1566 ASSERT_TRUE(LoadRootFeedDocument()); 1620 ASSERT_TRUE(LoadRootFeedDocument());
1567 1621
1568 // The transfered file is cached and the change of "offline available" 1622 // The transfered file is cached and the change of "offline available"
1569 // attribute is notified. 1623 // attribute is notified.
1570 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1624 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1571 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1625 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1572 1626
1573 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1627 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1574 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1628 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1575 const int64 file_size = entry_proto->file_info().size(); 1629 const int64 file_size = entry_proto->file_info().size();
1576 1630
1577 // Pretend we have enough space. 1631 // Pretend we have enough space.
1578 fake_free_disk_space_getter_->set_fake_free_disk_space( 1632 fake_free_disk_space_getter_->set_fake_free_disk_space(
1579 file_size + kMinFreeSpace); 1633 file_size + kMinFreeSpace);
1580 1634
1581 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1635 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1582 base::FilePath file_path; 1636 base::FilePath file_path;
1583 std::string mime_type; 1637 std::string mime_type;
1584 DriveFileType file_type; 1638 DriveFileType file_type;
1585 file_system_->GetFileByPath(file_in_root, 1639 file_system_->GetFileByPath(file_in_root,
1586 google_apis::test_util::CreateCopyResultCallback( 1640 google_apis::test_util::CreateCopyResultCallback(
1587 &error, &file_path, &mime_type, &file_type)); 1641 &error, &file_path, &mime_type, &file_type));
1588 google_apis::test_util::RunBlockingPoolTask(); 1642 google_apis::test_util::RunBlockingPoolTask();
1589 1643
1590 EXPECT_EQ(DRIVE_FILE_OK, error); 1644 EXPECT_EQ(DRIVE_FILE_OK, error);
1591 EXPECT_EQ(REGULAR_FILE, file_type); 1645 EXPECT_EQ(REGULAR_FILE, file_type);
1592 } 1646 }
1593 1647
1594 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { 1648 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) {
1595 ASSERT_TRUE(LoadRootFeedDocument()); 1649 ASSERT_TRUE(LoadRootFeedDocument());
1596 1650
1597 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1651 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1598 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1652 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1599 1653
1600 // Pretend we have no space at all. 1654 // Pretend we have no space at all.
1601 fake_free_disk_space_getter_->set_fake_free_disk_space(0); 1655 fake_free_disk_space_getter_->set_fake_free_disk_space(0);
1602 1656
1603 DriveFileError error = DRIVE_FILE_OK; 1657 DriveFileError error = DRIVE_FILE_OK;
1604 base::FilePath file_path; 1658 base::FilePath file_path;
1605 std::string mime_type; 1659 std::string mime_type;
1606 DriveFileType file_type; 1660 DriveFileType file_type;
1607 file_system_->GetFileByPath(file_in_root, 1661 file_system_->GetFileByPath(file_in_root,
1608 google_apis::test_util::CreateCopyResultCallback( 1662 google_apis::test_util::CreateCopyResultCallback(
1609 &error, &file_path, &mime_type, &file_type)); 1663 &error, &file_path, &mime_type, &file_type));
1610 google_apis::test_util::RunBlockingPoolTask(); 1664 google_apis::test_util::RunBlockingPoolTask();
1611 1665
1612 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); 1666 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error);
1613 } 1667 }
1614 1668
1615 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { 1669 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) {
1616 ASSERT_TRUE(LoadRootFeedDocument()); 1670 ASSERT_TRUE(LoadRootFeedDocument());
1617 1671
1618 // The transfered file is cached and the change of "offline available" 1672 // The transfered file is cached and the change of "offline available"
1619 // attribute is notified. 1673 // attribute is notified.
1620 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1674 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1621 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1675 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1622 1676
1623 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1677 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1624 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1678 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1625 const int64 file_size = entry_proto->file_info().size(); 1679 const int64 file_size = entry_proto->file_info().size();
1626 1680
1627 // Pretend we have no space first (checked before downloading a file), 1681 // Pretend we have no space first (checked before downloading a file),
1628 // but then start reporting we have space. This is to emulate that 1682 // but then start reporting we have space. This is to emulate that
1629 // the disk space was freed up by removing temporary files. 1683 // the disk space was freed up by removing temporary files.
1630 fake_free_disk_space_getter_->set_fake_free_disk_space( 1684 fake_free_disk_space_getter_->set_fake_free_disk_space(
1631 file_size + kMinFreeSpace); 1685 file_size + kMinFreeSpace);
1632 fake_free_disk_space_getter_->set_fake_free_disk_space(0); 1686 fake_free_disk_space_getter_->set_fake_free_disk_space(0);
1633 fake_free_disk_space_getter_->set_fake_free_disk_space( 1687 fake_free_disk_space_getter_->set_fake_free_disk_space(
(...skipping 29 matching lines...) Expand all
1663 EXPECT_EQ(DRIVE_FILE_OK, error); 1717 EXPECT_EQ(DRIVE_FILE_OK, error);
1664 EXPECT_EQ(REGULAR_FILE, file_type); 1718 EXPECT_EQ(REGULAR_FILE, file_type);
1665 1719
1666 // The cache entry should be removed in order to free up space. 1720 // The cache entry should be removed in order to free up space.
1667 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); 1721 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>"));
1668 } 1722 }
1669 1723
1670 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { 1724 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) {
1671 ASSERT_TRUE(LoadRootFeedDocument()); 1725 ASSERT_TRUE(LoadRootFeedDocument());
1672 1726
1673 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1727 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1674 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1728 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1675 const int64 file_size = entry_proto->file_info().size(); 1729 const int64 file_size = entry_proto->file_info().size();
1676 1730
1677 // Pretend we have enough space first (checked before downloading a file), 1731 // Pretend we have enough space first (checked before downloading a file),
1678 // but then start reporting we have not enough space. This is to emulate that 1732 // but then start reporting we have not enough space. This is to emulate that
1679 // the disk space becomes full after the file is downloaded for some reason 1733 // the disk space becomes full after the file is downloaded for some reason
1680 // (ex. the actual file was larger than the expected size). 1734 // (ex. the actual file was larger than the expected size).
1681 fake_free_disk_space_getter_->set_fake_free_disk_space( 1735 fake_free_disk_space_getter_->set_fake_free_disk_space(
1682 file_size + kMinFreeSpace); 1736 file_size + kMinFreeSpace);
1683 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); 1737 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1);
1684 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1); 1738 fake_free_disk_space_getter_->set_fake_free_disk_space(kMinFreeSpace - 1);
1685 1739
1686 DriveFileError error = DRIVE_FILE_OK; 1740 DriveFileError error = DRIVE_FILE_OK;
1687 base::FilePath file_path; 1741 base::FilePath file_path;
1688 std::string mime_type; 1742 std::string mime_type;
1689 DriveFileType file_type; 1743 DriveFileType file_type;
1690 file_system_->GetFileByPath(file_in_root, 1744 file_system_->GetFileByPath(file_in_root,
1691 google_apis::test_util::CreateCopyResultCallback( 1745 google_apis::test_util::CreateCopyResultCallback(
1692 &error, &file_path, &mime_type, &file_type)); 1746 &error, &file_path, &mime_type, &file_type));
1693 google_apis::test_util::RunBlockingPoolTask(); 1747 google_apis::test_util::RunBlockingPoolTask();
1694 1748
1695 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error); 1749 EXPECT_EQ(DRIVE_FILE_ERROR_NO_SPACE, error);
1696 } 1750 }
1697 1751
1698 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { 1752 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) {
1699 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1753 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1700 1754
1701 ASSERT_TRUE(LoadRootFeedDocument()); 1755 ASSERT_TRUE(LoadRootFeedDocument());
1702 1756
1703 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1757 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1704 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1758 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1705 1759
1706 // Store something as cached version of this file. 1760 // Store something as cached version of this file.
1707 DriveFileError error = DRIVE_FILE_OK; 1761 DriveFileError error = DRIVE_FILE_OK;
1708 cache_->Store(entry_proto->resource_id(), 1762 cache_->Store(entry_proto->resource_id(),
1709 entry_proto->file_specific_info().file_md5(), 1763 entry_proto->file_specific_info().file_md5(),
1710 google_apis::test_util::GetTestFilePath( 1764 google_apis::test_util::GetTestFilePath(
1711 "chromeos/gdata/root_feed.json"), 1765 "chromeos/gdata/root_feed.json"),
1712 DriveCache::FILE_OPERATION_COPY, 1766 DriveCache::FILE_OPERATION_COPY,
1713 google_apis::test_util::CreateCopyResultCallback(&error)); 1767 google_apis::test_util::CreateCopyResultCallback(&error));
1714 google_apis::test_util::RunBlockingPoolTask(); 1768 google_apis::test_util::RunBlockingPoolTask();
1715 EXPECT_EQ(DRIVE_FILE_OK, error); 1769 EXPECT_EQ(DRIVE_FILE_OK, error);
1716 1770
1717 base::FilePath file_path; 1771 base::FilePath file_path;
1718 std::string mime_type; 1772 std::string mime_type;
1719 DriveFileType file_type; 1773 DriveFileType file_type;
1720 file_system_->GetFileByPath(file_in_root, 1774 file_system_->GetFileByPath(file_in_root,
1721 google_apis::test_util::CreateCopyResultCallback( 1775 google_apis::test_util::CreateCopyResultCallback(
1722 &error, &file_path, &mime_type, &file_type)); 1776 &error, &file_path, &mime_type, &file_type));
1723 google_apis::test_util::RunBlockingPoolTask(); 1777 google_apis::test_util::RunBlockingPoolTask();
1724 1778
1725 EXPECT_EQ(DRIVE_FILE_OK, error); 1779 EXPECT_EQ(DRIVE_FILE_OK, error);
1726 EXPECT_EQ(REGULAR_FILE, file_type); 1780 EXPECT_EQ(REGULAR_FILE, file_type);
1727 } 1781 }
1728 1782
1729 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { 1783 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) {
1730 ASSERT_TRUE(LoadRootFeedDocument()); 1784 ASSERT_TRUE(LoadRootFeedDocument());
1731 1785
1732 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/Document 1.gdoc")); 1786 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/Document 1.gdoc"));
1733 scoped_ptr<DriveEntryProto> src_entry_proto = 1787 scoped_ptr<DriveEntryProto> src_entry_proto =
1734 GetEntryInfoByPathSync(file_in_root); 1788 GetEntryInfoByPathSync(file_in_root);
1735 ASSERT_TRUE(src_entry_proto.get()); 1789 ASSERT_TRUE(src_entry_proto.get());
1736 1790
1737 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1791 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1738 base::FilePath file_path; 1792 base::FilePath file_path;
1739 std::string mime_type; 1793 std::string mime_type;
1740 DriveFileType file_type; 1794 DriveFileType file_type;
1741 file_system_->GetFileByPath(file_in_root, 1795 file_system_->GetFileByPath(file_in_root,
1742 google_apis::test_util::CreateCopyResultCallback( 1796 google_apis::test_util::CreateCopyResultCallback(
1743 &error, &file_path, &mime_type, &file_type)); 1797 &error, &file_path, &mime_type, &file_type));
1744 google_apis::test_util::RunBlockingPoolTask(); 1798 google_apis::test_util::RunBlockingPoolTask();
1745 1799
1746 EXPECT_EQ(HOSTED_DOCUMENT, file_type); 1800 EXPECT_EQ(HOSTED_DOCUMENT, file_type);
1747 EXPECT_FALSE(file_path.empty()); 1801 EXPECT_FALSE(file_path.empty());
1748 1802
1749 ASSERT_TRUE(src_entry_proto.get()); 1803 ASSERT_TRUE(src_entry_proto.get());
1750 VerifyHostedDocumentJSONFile(*src_entry_proto, file_path); 1804 VerifyHostedDocumentJSONFile(*src_entry_proto, file_path);
1751 } 1805 }
1752 1806
1753 TEST_F(DriveFileSystemTest, GetFileByResourceId) { 1807 TEST_F(DriveFileSystemTest, GetFileByResourceId) {
1754 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1808 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1755 1809
1756 // The transfered file is cached and the change of "offline available" 1810 // The transfered file is cached and the change of "offline available"
1757 // attribute is notified. 1811 // attribute is notified.
1758 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1812 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1759 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1813 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1760 1814
1761 ASSERT_TRUE(LoadRootFeedDocument()); 1815 ASSERT_TRUE(LoadRootFeedDocument());
1762 1816
1763 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1817 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1764 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1818 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1765 1819
1766 DriveFileError error = DRIVE_FILE_OK; 1820 DriveFileError error = DRIVE_FILE_OK;
1767 base::FilePath file_path; 1821 base::FilePath file_path;
1768 std::string mime_type; 1822 std::string mime_type;
1769 DriveFileType file_type; 1823 DriveFileType file_type;
1770 file_system_->GetFileByResourceId( 1824 file_system_->GetFileByResourceId(
1771 entry_proto->resource_id(), 1825 entry_proto->resource_id(),
1772 DriveClientContext(USER_INITIATED), 1826 DriveClientContext(USER_INITIATED),
1773 google_apis::test_util::CreateCopyResultCallback( 1827 google_apis::test_util::CreateCopyResultCallback(
1774 &error, &file_path, &mime_type, &file_type), 1828 &error, &file_path, &mime_type, &file_type),
1775 google_apis::GetContentCallback()); 1829 google_apis::GetContentCallback());
1776 google_apis::test_util::RunBlockingPoolTask(); 1830 google_apis::test_util::RunBlockingPoolTask();
1777 1831
1778 EXPECT_EQ(DRIVE_FILE_OK, error); 1832 EXPECT_EQ(DRIVE_FILE_OK, error);
1779 EXPECT_EQ(REGULAR_FILE, file_type); 1833 EXPECT_EQ(REGULAR_FILE, file_type);
1780 } 1834 }
1781 1835
1782 TEST_F(DriveFileSystemTest, CancelGetFile) { 1836 TEST_F(DriveFileSystemTest, CancelGetFile) {
1783 base::FilePath cancel_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1837 base::FilePath cancel_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1784 file_system_->CancelGetFile(cancel_file_path); 1838 file_system_->CancelGetFile(cancel_file_path);
1785 EXPECT_EQ(cancel_file_path, fake_drive_service_->last_cancelled_file()); 1839 EXPECT_EQ(cancel_file_path, fake_drive_service_->last_cancelled_file());
1786 } 1840 }
1787 1841
1788 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { 1842 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) {
1789 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1843 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1790 1844
1791 ASSERT_TRUE(LoadRootFeedDocument()); 1845 ASSERT_TRUE(LoadRootFeedDocument());
1792 1846
1793 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1847 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1794 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root)); 1848 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(file_in_root));
1795 1849
1796 // Store something as cached version of this file. 1850 // Store something as cached version of this file.
1797 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 1851 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1798 cache_->Store(entry_proto->resource_id(), 1852 cache_->Store(entry_proto->resource_id(),
1799 entry_proto->file_specific_info().file_md5(), 1853 entry_proto->file_specific_info().file_md5(),
1800 google_apis::test_util::GetTestFilePath( 1854 google_apis::test_util::GetTestFilePath(
1801 "chromeos/gdata/root_feed.json"), 1855 "chromeos/gdata/root_feed.json"),
1802 DriveCache::FILE_OPERATION_COPY, 1856 DriveCache::FILE_OPERATION_COPY,
1803 google_apis::test_util::CreateCopyResultCallback(&error)); 1857 google_apis::test_util::CreateCopyResultCallback(&error));
(...skipping 18 matching lines...) Expand all
1822 EXPECT_EQ(DRIVE_FILE_OK, error); 1876 EXPECT_EQ(DRIVE_FILE_OK, error);
1823 EXPECT_EQ(REGULAR_FILE, file_type); 1877 EXPECT_EQ(REGULAR_FILE, file_type);
1824 } 1878 }
1825 1879
1826 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { 1880 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) {
1827 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1881 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1828 1882
1829 ASSERT_TRUE(LoadRootFeedDocument()); 1883 ASSERT_TRUE(LoadRootFeedDocument());
1830 1884
1831 // This is a file defined in root_feed.json. 1885 // This is a file defined in root_feed.json.
1832 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/File 1.txt")); 1886 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1833 const std::string kResourceId("file:2_file_resource_id"); 1887 const std::string kResourceId("file:2_file_resource_id");
1834 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); 1888 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce");
1835 1889
1836 // Pin the file so it'll be store in "persistent" directory. 1890 // Pin the file so it'll be store in "persistent" directory.
1837 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1); 1891 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(kResourceId, kMd5)).Times(1);
1838 DriveFileError error = DRIVE_FILE_OK; 1892 DriveFileError error = DRIVE_FILE_OK;
1839 cache_->Pin(kResourceId, kMd5, 1893 cache_->Pin(kResourceId, kMd5,
1840 google_apis::test_util::CreateCopyResultCallback(&error)); 1894 google_apis::test_util::CreateCopyResultCallback(&error));
1841 google_apis::test_util::RunBlockingPoolTask(); 1895 google_apis::test_util::RunBlockingPoolTask();
1842 EXPECT_EQ(DRIVE_FILE_OK, error); 1896 EXPECT_EQ(DRIVE_FILE_OK, error);
(...skipping 23 matching lines...) Expand all
1866 EXPECT_EQ(DRIVE_FILE_OK, error); 1920 EXPECT_EQ(DRIVE_FILE_OK, error);
1867 1921
1868 // We'll notify the directory change to the observer upon completion. 1922 // We'll notify the directory change to the observer upon completion.
1869 EXPECT_CALL(*mock_directory_observer_, 1923 EXPECT_CALL(*mock_directory_observer_,
1870 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath()))) 1924 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath())))
1871 .Times(1); 1925 .Times(1);
1872 1926
1873 // Check the number of files in the root directory. We'll compare the 1927 // Check the number of files in the root directory. We'll compare the
1874 // number after updating a file. 1928 // number after updating a file.
1875 scoped_ptr<DriveEntryProtoVector> root_directory_entries( 1929 scoped_ptr<DriveEntryProtoVector> root_directory_entries(
1876 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"))); 1930 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive/root")));
1877 ASSERT_TRUE(root_directory_entries.get()); 1931 ASSERT_TRUE(root_directory_entries.get());
1878 const int num_files_in_root = CountFiles(*root_directory_entries); 1932 const int num_files_in_root = CountFiles(*root_directory_entries);
1879 1933
1880 // The callback will be called upon completion of 1934 // The callback will be called upon completion of
1881 // UpdateFileByResourceId(). 1935 // UpdateFileByResourceId().
1882 file_system_->UpdateFileByResourceId( 1936 file_system_->UpdateFileByResourceId(
1883 kResourceId, 1937 kResourceId,
1884 DriveClientContext(USER_INITIATED), 1938 DriveClientContext(USER_INITIATED),
1885 google_apis::test_util::CreateCopyResultCallback(&error)); 1939 google_apis::test_util::CreateCopyResultCallback(&error));
1886 google_apis::test_util::RunBlockingPoolTask(); 1940 google_apis::test_util::RunBlockingPoolTask();
1887 EXPECT_EQ(DRIVE_FILE_OK, error); 1941 EXPECT_EQ(DRIVE_FILE_OK, error);
1888 1942
1889 // Make sure that the number of files did not change (i.e. we updated an 1943 // Make sure that the number of files did not change (i.e. we updated an
1890 // existing file, rather than adding a new file. The number of files 1944 // existing file, rather than adding a new file. The number of files
1891 // increases if we don't handle the file update right). 1945 // increases if we don't handle the file update right).
1892 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); 1946 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries));
1893 } 1947 }
1894 1948
1895 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { 1949 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) {
1896 ASSERT_TRUE(LoadRootFeedDocument()); 1950 ASSERT_TRUE(LoadRootFeedDocument());
1897 1951
1898 // This is nonexistent in root_feed.json. 1952 // This is nonexistent in root_feed.json.
1899 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); 1953 const base::FilePath kFilePath(
1954 FILE_PATH_LITERAL("drive/root/Nonexistent.txt"));
1900 const std::string kResourceId("file:nonexistent_resource_id"); 1955 const std::string kResourceId("file:nonexistent_resource_id");
1901 const std::string kMd5("nonexistent_md5"); 1956 const std::string kMd5("nonexistent_md5");
1902 1957
1903 // The callback will be called upon completion of 1958 // The callback will be called upon completion of
1904 // UpdateFileByResourceId(). 1959 // UpdateFileByResourceId().
1905 DriveFileError error = DRIVE_FILE_OK; 1960 DriveFileError error = DRIVE_FILE_OK;
1906 file_system_->UpdateFileByResourceId( 1961 file_system_->UpdateFileByResourceId(
1907 kResourceId, 1962 kResourceId,
1908 DriveClientContext(USER_INITIATED), 1963 DriveClientContext(USER_INITIATED),
1909 google_apis::test_util::CreateCopyResultCallback(&error)); 1964 google_apis::test_util::CreateCopyResultCallback(&error));
1910 google_apis::test_util::RunBlockingPoolTask(); 1965 google_apis::test_util::RunBlockingPoolTask();
1911 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error); 1966 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1912 } 1967 }
1913 1968
1914 TEST_F(DriveFileSystemTest, ContentSearch) { 1969 TEST_F(DriveFileSystemTest, ContentSearch) {
1915 ASSERT_TRUE(LoadRootFeedDocument()); 1970 ASSERT_TRUE(LoadRootFeedDocument());
1916 1971
1917 const SearchResultPair kExpectedResults[] = { 1972 const SearchResultPair kExpectedResults[] = {
1918 { "drive/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", 1973 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder",
1919 true }, 1974 true },
1920 { "drive/Directory 1/Sub Directory Folder", true }, 1975 { "drive/root/Directory 1/Sub Directory Folder", true },
1921 { "drive/Directory 1/SubDirectory File 1.txt", false }, 1976 { "drive/root/Directory 1/SubDirectory File 1.txt", false },
1922 { "drive/Directory 1", true }, 1977 { "drive/root/Directory 1", true },
1923 { "drive/Directory 2", true }, 1978 { "drive/root/Directory 2", true },
1924 }; 1979 };
1925 1980
1926 SearchCallback callback = base::Bind(&DriveSearchCallback, 1981 SearchCallback callback = base::Bind(&DriveSearchCallback,
1927 &message_loop_, 1982 &message_loop_,
1928 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), 1983 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults),
1929 GURL()); 1984 GURL());
1930 1985
1931 file_system_->Search("Directory", GURL(), callback); 1986 file_system_->Search("Directory", GURL(), callback);
1932 message_loop_.Run(); // Wait to get our result. 1987 message_loop_.Run(); // Wait to get our result.
1933 } 1988 }
1934 1989
1935 TEST_F(DriveFileSystemTest, ContentSearchWithNewEntry) { 1990 TEST_F(DriveFileSystemTest, ContentSearchWithNewEntry) {
1936 ASSERT_TRUE(LoadRootFeedDocument()); 1991 ASSERT_TRUE(LoadRootFeedDocument());
1937 1992
1938 // Create a new directory in the drive service. 1993 // Create a new directory in the drive service.
1939 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 1994 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
1940 scoped_ptr<google_apis::ResourceEntry> resource_entry; 1995 scoped_ptr<google_apis::ResourceEntry> resource_entry;
1941 fake_drive_service_->AddNewDirectory( 1996 fake_drive_service_->AddNewDirectory(
1942 fake_drive_service_->GetRootResourceId(), // Add to the root directory. 1997 fake_drive_service_->GetRootResourceId(), // Add to the root directory.
1943 "New Directory 1!", 1998 "New Directory 1!",
1944 google_apis::test_util::CreateCopyResultCallback( 1999 google_apis::test_util::CreateCopyResultCallback(
1945 &error, &resource_entry)); 2000 &error, &resource_entry));
1946 message_loop_.RunUntilIdle(); 2001 message_loop_.RunUntilIdle();
1947 2002
1948 // As the result of the first Search(), only entries in the current file 2003 // As the result of the first Search(), only entries in the current file
1949 // system snapshot are expected to be returned (i.e. "New Directory 1!" 2004 // system snapshot are expected to be returned (i.e. "New Directory 1!"
1950 // shouldn't be included in the search result even though it matches 2005 // shouldn't be included in the search result even though it matches
1951 // "Directory 1". 2006 // "Directory 1".
1952 const SearchResultPair kExpectedResults[] = { 2007 const SearchResultPair kExpectedResults[] = {
1953 { "drive/Directory 1", true } 2008 { "drive/root/Directory 1", true }
1954 }; 2009 };
1955 2010
1956 // At the same time, unknown entry should trigger delta feed request. 2011 // At the same time, unknown entry should trigger delta feed request.
1957 // This will cause notification to directory observers (e.g., File Browser) 2012 // This will cause notification to directory observers (e.g., File Browser)
1958 // so that they can request search again. 2013 // so that they can request search again.
1959 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) 2014 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
1960 .Times(AtLeast(1)); 2015 .Times(AtLeast(1));
1961 2016
1962 SearchCallback callback = base::Bind(&DriveSearchCallback, 2017 SearchCallback callback = base::Bind(&DriveSearchCallback,
1963 &message_loop_, 2018 &message_loop_,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 google_apis::test_util::RunBlockingPoolTask(); 2063 google_apis::test_util::RunBlockingPoolTask();
2009 EXPECT_EQ(DRIVE_FILE_OK, error); 2064 EXPECT_EQ(DRIVE_FILE_OK, error);
2010 } 2065 }
2011 2066
2012 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { 2067 TEST_F(DriveFileSystemTest, OpenAndCloseFile) {
2013 ASSERT_TRUE(LoadRootFeedDocument()); 2068 ASSERT_TRUE(LoadRootFeedDocument());
2014 2069
2015 // The transfered file is cached and the change of "offline available" 2070 // The transfered file is cached and the change of "offline available"
2016 // attribute is notified. 2071 // attribute is notified.
2017 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 2072 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
2018 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 2073 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
2019 2074
2020 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/File 1.txt")); 2075 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt"));
2021 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot)); 2076 scoped_ptr<DriveEntryProto> entry_proto(GetEntryInfoByPathSync(kFileInRoot));
2022 const int64 file_size = entry_proto->file_info().size(); 2077 const int64 file_size = entry_proto->file_info().size();
2023 const std::string& file_resource_id = 2078 const std::string& file_resource_id =
2024 entry_proto->resource_id(); 2079 entry_proto->resource_id();
2025 const std::string& file_md5 = entry_proto->file_specific_info().file_md5(); 2080 const std::string& file_md5 = entry_proto->file_specific_info().file_md5();
2026 2081
2027 // A dirty file is created on close. 2082 // A dirty file is created on close.
2028 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id)) 2083 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(file_resource_id))
2029 .Times(1); 2084 .Times(1);
2030 2085
2031 // Pretend we have enough space. 2086 // Pretend we have enough space.
2032 fake_free_disk_space_getter_->set_fake_free_disk_space( 2087 fake_free_disk_space_getter_->set_fake_free_disk_space(
2033 file_size + kMinFreeSpace); 2088 file_size + kMinFreeSpace);
2034 2089
2035 // Open kFileInRoot ("drive/File 1.txt"). 2090 // Open kFileInRoot ("drive/root/File 1.txt").
2036 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 2091 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
2037 base::FilePath file_path; 2092 base::FilePath file_path;
2038 file_system_->OpenFile( 2093 file_system_->OpenFile(
2039 kFileInRoot, 2094 kFileInRoot,
2040 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 2095 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
2041 google_apis::test_util::RunBlockingPoolTask(); 2096 google_apis::test_util::RunBlockingPoolTask();
2042 const base::FilePath opened_file_path = file_path; 2097 const base::FilePath opened_file_path = file_path;
2043 2098
2044 // Verify that the file was properly opened. 2099 // Verify that the file was properly opened.
2045 EXPECT_EQ(DRIVE_FILE_OK, error); 2100 EXPECT_EQ(DRIVE_FILE_OK, error);
(...skipping 22 matching lines...) Expand all
2068 EXPECT_TRUE(cache_entry.is_persistent()); 2123 EXPECT_TRUE(cache_entry.is_persistent());
2069 2124
2070 base::FilePath cache_file_path; 2125 base::FilePath cache_file_path;
2071 cache_->GetFile(file_resource_id, file_md5, 2126 cache_->GetFile(file_resource_id, file_md5,
2072 google_apis::test_util::CreateCopyResultCallback( 2127 google_apis::test_util::CreateCopyResultCallback(
2073 &error, &cache_file_path)); 2128 &error, &cache_file_path));
2074 google_apis::test_util::RunBlockingPoolTask(); 2129 google_apis::test_util::RunBlockingPoolTask();
2075 EXPECT_EQ(DRIVE_FILE_OK, error); 2130 EXPECT_EQ(DRIVE_FILE_OK, error);
2076 EXPECT_EQ(cache_file_path, opened_file_path); 2131 EXPECT_EQ(cache_file_path, opened_file_path);
2077 2132
2078 // Close kFileInRoot ("drive/File 1.txt"). 2133 // Close kFileInRoot ("drive/root/File 1.txt").
2079 file_system_->CloseFile( 2134 file_system_->CloseFile(
2080 kFileInRoot, 2135 kFileInRoot,
2081 google_apis::test_util::CreateCopyResultCallback(&error)); 2136 google_apis::test_util::CreateCopyResultCallback(&error));
2082 google_apis::test_util::RunBlockingPoolTask(); 2137 google_apis::test_util::RunBlockingPoolTask();
2083 2138
2084 // Verify that the file was properly closed. 2139 // Verify that the file was properly closed.
2085 EXPECT_EQ(DRIVE_FILE_OK, error); 2140 EXPECT_EQ(DRIVE_FILE_OK, error);
2086 2141
2087 // Verify that the cache state was changed as expected. 2142 // Verify that the cache state was changed as expected.
2088 EXPECT_TRUE(GetCacheEntryFromOriginThread(file_resource_id, file_md5, 2143 EXPECT_TRUE(GetCacheEntryFromOriginThread(file_resource_id, file_md5,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2121 2176
2122 // An app for foo.exe should now be found, as the registry was loaded. 2177 // An app for foo.exe should now be found, as the registry was loaded.
2123 drive_webapps_registry_->GetWebAppsForFile( 2178 drive_webapps_registry_->GetWebAppsForFile(
2124 base::FilePath(FILE_PATH_LITERAL("foo.exe")), 2179 base::FilePath(FILE_PATH_LITERAL("foo.exe")),
2125 "" /* mime_type */, 2180 "" /* mime_type */,
2126 &apps); 2181 &apps);
2127 EXPECT_EQ(1U, apps.size()); 2182 EXPECT_EQ(1U, apps.size());
2128 } 2183 }
2129 2184
2130 } // namespace drive 2185 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_system.cc ('k') | chrome/browser/chromeos/drive/drive_file_system_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698