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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service_unittest.cc

Issue 11411280: Sync FileSystem: Use app id part of the URL for its directory title. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 379
380 EXPECT_EQ("folder:sync_root_resource_id", 380 EXPECT_EQ("folder:sync_root_resource_id",
381 metadata_store()->sync_root_directory()); 381 metadata_store()->sync_root_directory());
382 382
383 EXPECT_EQ(0u, metadata_store()->batch_sync_origins().size()); 383 EXPECT_EQ(0u, metadata_store()->batch_sync_origins().size());
384 EXPECT_EQ(0u, metadata_store()->incremental_sync_origins().size()); 384 EXPECT_EQ(0u, metadata_store()->incremental_sync_origins().size());
385 EXPECT_EQ(0u, pending_changes().size()); 385 EXPECT_EQ(0u, pending_changes().size());
386 } 386 }
387 387
388 TEST_F(DriveFileSyncServiceTest, BatchSyncOnInitialization) { 388 TEST_F(DriveFileSyncServiceTest, BatchSyncOnInitialization) {
389 const GURL kOrigin1("http://example.com"); 389 const GURL kOrigin1("chrome-extension://example.com");
390 const GURL kOrigin2("http://hoge.example.com"); 390 const GURL kOrigin2("chrome-extension://hoge.example.com");
kinuko 2012/11/30 07:13:28 could we also replace the host part with more plau
tzik 2012/12/03 08:12:08 Done.
391 const std::string kDirectoryResourceId1( 391 const std::string kDirectoryResourceId1(
392 "folder:origin_directory_resource_id"); 392 "folder:origin_directory_resource_id");
393 const std::string kDirectoryResourceId2( 393 const std::string kDirectoryResourceId2(
394 "folder:origin_directory_resource_id2"); 394 "folder:origin_directory_resource_id2");
395 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 395 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
396 396
397 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 397 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
398 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); 398 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1);
399 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); 399 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2);
400 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); 400 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 // kOrigin1 should be a batch sync origin and kOrigin2 should be an 432 // kOrigin1 should be a batch sync origin and kOrigin2 should be an
433 // incremental sync origin. 433 // incremental sync origin.
434 // 4 pending remote changes are from listing_files_in_directory as batch sync 434 // 4 pending remote changes are from listing_files_in_directory as batch sync
435 // changes. 435 // changes.
436 EXPECT_EQ(1u, metadata_store()->batch_sync_origins().size()); 436 EXPECT_EQ(1u, metadata_store()->batch_sync_origins().size());
437 EXPECT_EQ(1u, metadata_store()->incremental_sync_origins().size()); 437 EXPECT_EQ(1u, metadata_store()->incremental_sync_origins().size());
438 EXPECT_EQ(4u, pending_changes().size()); 438 EXPECT_EQ(4u, pending_changes().size());
439 } 439 }
440 440
441 TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) { 441 TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) {
442 const GURL kOrigin("http://example.com"); 442 const GURL kOrigin("chrome-extension://example.com");
443 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 443 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
444 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 444 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
445 const GURL kSyncRootContentURL("https://sync_root_content_url/"); 445 const GURL kSyncRootContentURL("https://sync_root_content_url/");
446 446
447 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 447 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
448 448
449 EXPECT_CALL(*mock_remote_observer(), 449 EXPECT_CALL(*mock_remote_observer(),
450 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) 450 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _))
451 .Times(AtLeast(1)); 451 .Times(AtLeast(1));
452 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(0)) 452 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(0))
453 .Times(AnyNumber()); 453 .Times(AnyNumber());
454 454
455 InSequence sequence; 455 InSequence sequence;
456 456
457 scoped_ptr<Value> origin_directory_not_found(LoadJSONFile( 457 scoped_ptr<Value> origin_directory_not_found(LoadJSONFile(
458 "sync_file_system/origin_directory_not_found.json")); 458 "sync_file_system/origin_directory_not_found.json"));
459 std::string query = FormatTitleQuery(kOrigin.spec()); 459 std::string query = FormatTitleQuery(
460 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
460 461
461 EXPECT_CALL(*mock_drive_service(), 462 EXPECT_CALL(*mock_drive_service(),
462 GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _)) 463 GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _))
463 .WillOnce(InvokeGetDataCallback5( 464 .WillOnce(InvokeGetDataCallback5(
464 google_apis::HTTP_SUCCESS, 465 google_apis::HTTP_SUCCESS,
465 base::Passed(&origin_directory_not_found))) 466 base::Passed(&origin_directory_not_found)))
466 .RetiresOnSaturation(); 467 .RetiresOnSaturation();
467 468
468 // If the directory for the origin is missing, DriveFileSyncService should 469 // If the directory for the origin is missing, DriveFileSyncService should
469 // attempt to create it. And as a preparation, it should fetch the content url 470 // attempt to create it. And as a preparation, it should fetch the content url
470 // of the parent directory. 471 // of the parent directory.
471 // 472 //
472 // |sync_root_entry| contains kSyncRootContentURL which is to be added as 473 // |sync_root_entry| contains kSyncRootContentURL which is to be added as
473 // a new origin directory under the root directory. 474 // a new origin directory under the root directory.
474 scoped_ptr<Value> sync_root_entry(LoadJSONFile( 475 scoped_ptr<Value> sync_root_entry(LoadJSONFile(
475 "sync_file_system/sync_root_entry.json")); 476 "sync_file_system/sync_root_entry.json"));
476 EXPECT_CALL(*mock_drive_service(), 477 EXPECT_CALL(*mock_drive_service(),
477 GetDocumentEntry(kSyncRootResourceId, _)) 478 GetDocumentEntry(kSyncRootResourceId, _))
478 .WillOnce(InvokeGetDataCallback1( 479 .WillOnce(InvokeGetDataCallback1(
479 google_apis::HTTP_SUCCESS, 480 google_apis::HTTP_SUCCESS,
480 base::Passed(&sync_root_entry))); 481 base::Passed(&sync_root_entry)));
481 482
482 scoped_ptr<Value> origin_directory_created(LoadJSONFile( 483 scoped_ptr<Value> origin_directory_created(LoadJSONFile(
483 "sync_file_system/origin_directory_created.json")); 484 "sync_file_system/origin_directory_created.json"));
484 FilePath::StringType dirname = 485 FilePath::StringType dirname = FilePath().AppendASCII(
485 FilePath().AppendASCII(kOrigin.spec()).value(); 486 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)).value();
486 EXPECT_CALL(*mock_drive_service(), 487 EXPECT_CALL(*mock_drive_service(),
487 AddNewDirectory(kSyncRootContentURL, dirname, _)) 488 AddNewDirectory(kSyncRootContentURL, dirname, _))
488 .WillOnce(InvokeGetDataCallback2( 489 .WillOnce(InvokeGetDataCallback2(
489 google_apis::HTTP_SUCCESS, 490 google_apis::HTTP_SUCCESS,
490 base::Passed(&origin_directory_created))); 491 base::Passed(&origin_directory_created)));
491 492
492 // Once the directory is created GetAccountMetadata should be called to get 493 // Once the directory is created GetAccountMetadata should be called to get
493 // the largest changestamp for the origin as a prepariation of the batch sync. 494 // the largest changestamp for the origin as a prepariation of the batch sync.
494 scoped_ptr<Value> account_metadata(LoadJSONFile( 495 scoped_ptr<Value> account_metadata(LoadJSONFile(
495 "gdata/account_metadata.json")); 496 "gdata/account_metadata.json"));
(...skipping 17 matching lines...) Expand all
513 kOrigin, base::Bind(&ExpectEqStatus, &done, fileapi::SYNC_STATUS_OK)); 514 kOrigin, base::Bind(&ExpectEqStatus, &done, fileapi::SYNC_STATUS_OK));
514 message_loop()->RunUntilIdle(); 515 message_loop()->RunUntilIdle();
515 EXPECT_TRUE(done); 516 EXPECT_TRUE(done);
516 517
517 EXPECT_EQ(1u, metadata_store()->batch_sync_origins().size()); 518 EXPECT_EQ(1u, metadata_store()->batch_sync_origins().size());
518 EXPECT_TRUE(metadata_store()->incremental_sync_origins().empty()); 519 EXPECT_TRUE(metadata_store()->incremental_sync_origins().empty());
519 EXPECT_TRUE(pending_changes().empty()); 520 EXPECT_TRUE(pending_changes().empty());
520 } 521 }
521 522
522 TEST_F(DriveFileSyncServiceTest, RegisterExistingOrigin) { 523 TEST_F(DriveFileSyncServiceTest, RegisterExistingOrigin) {
523 const GURL kOrigin("http://example.com"); 524 const GURL kOrigin("chrome-extension://example.com");
524 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 525 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
525 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 526 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
526 527
527 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 528 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
528 529
529 EXPECT_CALL(*mock_remote_observer(), 530 EXPECT_CALL(*mock_remote_observer(),
530 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _)) 531 OnRemoteServiceStateUpdated(REMOTE_SERVICE_OK, _))
531 .Times(AtLeast(1)); 532 .Times(AtLeast(1));
532 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(4)) 533 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeAvailable(4))
533 .Times(AnyNumber()); 534 .Times(AnyNumber());
534 535
535 InSequence sequence; 536 InSequence sequence;
536 537
537 scoped_ptr<Value> origin_directory_found(LoadJSONFile( 538 scoped_ptr<Value> origin_directory_found(LoadJSONFile(
538 "sync_file_system/origin_directory_found.json")); 539 "sync_file_system/origin_directory_found.json"));
539 std::string query = FormatTitleQuery("http://example.com/"); 540 std::string query = FormatTitleQuery(
541 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
540 EXPECT_CALL(*mock_drive_service(), 542 EXPECT_CALL(*mock_drive_service(),
541 GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _)) 543 GetDocuments(GURL(), 0, query, false, kSyncRootResourceId, _))
542 .WillOnce(InvokeGetDataCallback5( 544 .WillOnce(InvokeGetDataCallback5(
543 google_apis::HTTP_SUCCESS, 545 google_apis::HTTP_SUCCESS,
544 base::Passed(&origin_directory_found))) 546 base::Passed(&origin_directory_found)))
545 .RetiresOnSaturation(); 547 .RetiresOnSaturation();
546 548
547 scoped_ptr<Value> account_metadata(LoadJSONFile( 549 scoped_ptr<Value> account_metadata(LoadJSONFile(
548 "gdata/account_metadata.json")); 550 "gdata/account_metadata.json"));
549 EXPECT_CALL(*mock_drive_service(), GetAccountMetadata(_)) 551 EXPECT_CALL(*mock_drive_service(), GetAccountMetadata(_))
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 message_loop()->RunUntilIdle(); 631 message_loop()->RunUntilIdle();
630 EXPECT_TRUE(done); 632 EXPECT_TRUE(done);
631 633
632 EXPECT_TRUE(metadata_store()->batch_sync_origins().empty()); 634 EXPECT_TRUE(metadata_store()->batch_sync_origins().empty());
633 EXPECT_EQ(1u, metadata_store()->incremental_sync_origins().size()); 635 EXPECT_EQ(1u, metadata_store()->incremental_sync_origins().size());
634 EXPECT_TRUE(pending_changes().empty()); 636 EXPECT_TRUE(pending_changes().empty());
635 } 637 }
636 638
637 TEST_F(DriveFileSyncServiceTest, ResolveSyncOperationType) { 639 TEST_F(DriveFileSyncServiceTest, ResolveSyncOperationType) {
638 const fileapi::FileSystemURL url = fileapi::CreateSyncableFileSystemURL( 640 const fileapi::FileSystemURL url = fileapi::CreateSyncableFileSystemURL(
639 GURL("http://example.com/"), 641 GURL("chrome-extension://example.com/"),
640 DriveFileSyncService::kServiceName, 642 DriveFileSyncService::kServiceName,
641 FilePath().AppendASCII("path/to/file")); 643 FilePath().AppendASCII("path/to/file"));
642 const std::string kResourceId("123456"); 644 const std::string kResourceId("123456");
643 const int64 kChangestamp = 654321; 645 const int64 kChangestamp = 654321;
644 646
645 scoped_ptr<Value> sync_root_found(LoadJSONFile( 647 scoped_ptr<Value> sync_root_found(LoadJSONFile(
646 "sync_file_system/sync_root_found.json")); 648 "sync_file_system/sync_root_found.json"));
647 std::string query = FormatTitleQuery(kSyncRootDirectoryName); 649 std::string query = FormatTitleQuery(kSyncRootDirectoryName);
648 EXPECT_CALL(*mock_drive_service(), 650 EXPECT_CALL(*mock_drive_service(),
649 GetDocuments(GURL(), 0, query, false, std::string(), _)) 651 GetDocuments(GURL(), 0, query, false, std::string(), _))
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 *LoadJSONFile("gdata/file_entry.json"))); 853 *LoadJSONFile("gdata/file_entry.json")));
852 AppendIncrementalRemoteChange(kOrigin, entry.get(), 12345); 854 AppendIncrementalRemoteChange(kOrigin, entry.get(), 12345);
853 ProcessRemoteChange(fileapi::SYNC_STATUS_OK, 855 ProcessRemoteChange(fileapi::SYNC_STATUS_OK,
854 CreateURL(kOrigin, kFileName), 856 CreateURL(kOrigin, kFileName),
855 fileapi::SYNC_OPERATION_UPDATE); 857 fileapi::SYNC_OPERATION_UPDATE);
856 } 858 }
857 859
858 #endif // !defined(OS_ANDROID) 860 #endif // !defined(OS_ANDROID)
859 861
860 } // namespace sync_file_system 862 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698