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

Side by Side Diff: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc

Issue 6931018: Initial implementation of "Synced Bookmarks" folder. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merge Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // TODO(akalin): This file is basically just a unit test for 5 // TODO(akalin): This file is basically just a unit test for
6 // BookmarkChangeProcessor. Write unit tests for 6 // BookmarkChangeProcessor. Write unit tests for
7 // BookmarkModelAssociator separately. 7 // BookmarkModelAssociator separately.
8 8
9 #include <stack> 9 #include <stack>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h"
12 #include "base/file_path.h" 13 #include "base/file_path.h"
13 #include "base/file_util.h" 14 #include "base/file_util.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 16 #include "base/message_loop.h"
16 #include "base/string16.h" 17 #include "base/string16.h"
17 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
18 #include "base/string_util.h" 19 #include "base/string_util.h"
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/bookmarks/bookmark_model.h" 21 #include "chrome/browser/bookmarks/bookmark_model.h"
21 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 22 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
22 #include "chrome/browser/sync/engine/syncapi.h" 23 #include "chrome/browser/sync/engine/syncapi.h"
23 #include "chrome/browser/sync/glue/bookmark_change_processor.h" 24 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
24 #include "chrome/browser/sync/glue/bookmark_model_associator.h" 25 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
25 #include "chrome/browser/sync/syncable/directory_manager.h" 26 #include "chrome/browser/sync/syncable/directory_manager.h"
27 #include "chrome/common/chrome_switches.h"
26 #include "chrome/test/sync/engine/test_id_factory.h" 28 #include "chrome/test/sync/engine/test_id_factory.h"
27 #include "chrome/test/sync/engine/test_user_share.h" 29 #include "chrome/test/sync/engine/test_user_share.h"
28 #include "chrome/test/testing_profile.h" 30 #include "chrome/test/testing_profile.h"
29 #include "content/browser/browser_thread.h" 31 #include "content/browser/browser_thread.h"
30 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
32 34
33 namespace browser_sync { 35 namespace browser_sync {
34 36
35 namespace { 37 namespace {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 model_(NULL) { 286 model_(NULL) {
285 } 287 }
286 288
287 virtual ~ProfileSyncServiceBookmarkTest() { 289 virtual ~ProfileSyncServiceBookmarkTest() {
288 StopSync(); 290 StopSync();
289 UnloadBookmarkModel(); 291 UnloadBookmarkModel();
290 } 292 }
291 293
292 virtual void SetUp() { 294 virtual void SetUp() {
293 test_user_share_.SetUp(); 295 test_user_share_.SetUp();
296 CommandLine::ForCurrentProcess()->AppendSwitch(
297 switches::kEnableSyncedBookmarksFolder);
294 } 298 }
295 299
296 virtual void TearDown() { 300 virtual void TearDown() {
297 test_user_share_.TearDown(); 301 test_user_share_.TearDown();
298 } 302 }
299 303
300 // Load (or re-load) the bookmark model. |load| controls use of the 304 // Load (or re-load) the bookmark model. |load| controls use of the
301 // bookmarks file on disk. |save| controls whether the newly loaded 305 // bookmarks file on disk. |save| controls whether the newly loaded
302 // bookmark model will write out a bookmark file as it goes. 306 // bookmark model will write out a bookmark file as it goes.
303 void LoadBookmarkModel(LoadOption load, SaveOption save) { 307 void LoadBookmarkModel(LoadOption load, SaveOption save) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), 357 return model_associator_->InitSyncNodeFromChromeId(bnode->id(),
354 sync_node); 358 sync_node);
355 } 359 }
356 360
357 void ExpectSyncerNodeMatching(sync_api::BaseTransaction* trans, 361 void ExpectSyncerNodeMatching(sync_api::BaseTransaction* trans,
358 const BookmarkNode* bnode) { 362 const BookmarkNode* bnode) {
359 sync_api::ReadNode gnode(trans); 363 sync_api::ReadNode gnode(trans);
360 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode)); 364 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode));
361 // Non-root node titles and parents must match. 365 // Non-root node titles and parents must match.
362 if (bnode != model_->GetBookmarkBarNode() && 366 if (bnode != model_->GetBookmarkBarNode() &&
367 bnode != model_->synced_node() &&
363 bnode != model_->other_node()) { 368 bnode != model_->other_node()) {
364 EXPECT_EQ(bnode->GetTitle(), WideToUTF16Hack(gnode.GetTitle())); 369 EXPECT_EQ(bnode->GetTitle(), WideToUTF16Hack(gnode.GetTitle()));
365 EXPECT_EQ( 370 EXPECT_EQ(
366 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()), 371 model_associator_->GetChromeNodeFromSyncId(gnode.GetParentId()),
367 bnode->parent()); 372 bnode->parent());
368 } 373 }
369 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder()); 374 EXPECT_EQ(bnode->is_folder(), gnode.GetIsFolder());
370 if (bnode->is_url()) 375 if (bnode->is_url())
371 EXPECT_EQ(bnode->GetURL(), gnode.GetURL()); 376 EXPECT_EQ(bnode->GetURL(), gnode.GetURL());
372 377
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 const BookmarkNode* parent = 457 const BookmarkNode* parent =
453 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); 458 model_associator_->GetChromeNodeFromSyncId(parent_sync_id);
454 EXPECT_TRUE(parent); 459 EXPECT_TRUE(parent);
455 EXPECT_EQ(node->parent(), parent); 460 EXPECT_EQ(node->parent(), parent);
456 } 461 }
457 462
458 void ExpectModelMatch(sync_api::BaseTransaction* trans) { 463 void ExpectModelMatch(sync_api::BaseTransaction* trans) {
459 const BookmarkNode* root = model_->root_node(); 464 const BookmarkNode* root = model_->root_node();
460 EXPECT_EQ(root->GetIndexOf(model_->GetBookmarkBarNode()), 0); 465 EXPECT_EQ(root->GetIndexOf(model_->GetBookmarkBarNode()), 0);
461 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); 466 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1);
467 EXPECT_EQ(root->GetIndexOf(model_->synced_node()), 2);
462 468
463 std::stack<int64> stack; 469 std::stack<int64> stack;
464 stack.push(bookmark_bar_id()); 470 stack.push(bookmark_bar_id());
465 while (!stack.empty()) { 471 while (!stack.empty()) {
466 int64 id = stack.top(); 472 int64 id = stack.top();
467 stack.pop(); 473 stack.pop();
468 if (!id) continue; 474 if (!id) continue;
469 475
470 ExpectBrowserNodeMatching(trans, id); 476 ExpectBrowserNodeMatching(trans, id);
471 477
472 sync_api::ReadNode gnode(trans); 478 sync_api::ReadNode gnode(trans);
473 ASSERT_TRUE(gnode.InitByIdLookup(id)); 479 ASSERT_TRUE(gnode.InitByIdLookup(id));
474 stack.push(gnode.GetFirstChildId()); 480 stack.push(gnode.GetFirstChildId());
475 stack.push(gnode.GetSuccessorId()); 481 stack.push(gnode.GetSuccessorId());
476 } 482 }
477 } 483 }
478 484
479 void ExpectModelMatch() { 485 void ExpectModelMatch() {
480 sync_api::ReadTransaction trans(test_user_share_.user_share()); 486 sync_api::ReadTransaction trans(test_user_share_.user_share());
481 ExpectModelMatch(&trans); 487 ExpectModelMatch(&trans);
482 } 488 }
483 489
490 int64 synced_bookmarks_id() {
491 return
492 model_associator_->GetSyncIdFromChromeId(model_->synced_node()->id());
493 }
494
484 int64 other_bookmarks_id() { 495 int64 other_bookmarks_id() {
485 return 496 return
486 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id()); 497 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id());
487 } 498 }
488 499
489 int64 bookmark_bar_id() { 500 int64 bookmark_bar_id() {
490 return model_associator_->GetSyncIdFromChromeId( 501 return model_associator_->GetSyncIdFromChromeId(
491 model_->GetBookmarkBarNode()->id()); 502 model_->GetBookmarkBarNode()->id());
492 } 503 }
493 504
(...skipping 13 matching lines...) Expand all
507 scoped_ptr<BookmarkChangeProcessor> change_processor_; 518 scoped_ptr<BookmarkChangeProcessor> change_processor_;
508 StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_; 519 StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_;
509 }; 520 };
510 521
511 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 522 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
512 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 523 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
513 StartSync(); 524 StartSync();
514 525
515 EXPECT_TRUE(other_bookmarks_id()); 526 EXPECT_TRUE(other_bookmarks_id());
516 EXPECT_TRUE(bookmark_bar_id()); 527 EXPECT_TRUE(bookmark_bar_id());
528 EXPECT_TRUE(synced_bookmarks_id());
517 529
518 ExpectModelMatch(); 530 ExpectModelMatch();
519 } 531 }
520 532
521 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { 533 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
522 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 534 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
523 StartSync(); 535 StartSync();
524 536
525 // Test addition. 537 // Test addition.
526 const BookmarkNode* folder = 538 const BookmarkNode* folder =
527 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); 539 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar"));
528 ExpectSyncerNodeMatching(folder); 540 ExpectSyncerNodeMatching(folder);
529 ExpectModelMatch(); 541 ExpectModelMatch();
530 const BookmarkNode* folder2 = 542 const BookmarkNode* folder2 =
531 model_->AddFolder(folder, 0, ASCIIToUTF16("nested")); 543 model_->AddFolder(folder, 0, ASCIIToUTF16("nested"));
532 ExpectSyncerNodeMatching(folder2); 544 ExpectSyncerNodeMatching(folder2);
533 ExpectModelMatch(); 545 ExpectModelMatch();
534 const BookmarkNode* url1 = model_->AddURL( 546 const BookmarkNode* url1 = model_->AddURL(
535 folder, 0, ASCIIToUTF16("Internets #1 Pies Site"), 547 folder, 0, ASCIIToUTF16("Internets #1 Pies Site"),
536 GURL("http://www.easypie.com/")); 548 GURL("http://www.easypie.com/"));
537 ExpectSyncerNodeMatching(url1); 549 ExpectSyncerNodeMatching(url1);
538 ExpectModelMatch(); 550 ExpectModelMatch();
539 const BookmarkNode* url2 = model_->AddURL( 551 const BookmarkNode* url2 = model_->AddURL(
540 folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/")); 552 folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/"));
541 ExpectSyncerNodeMatching(url2); 553 ExpectSyncerNodeMatching(url2);
542 ExpectModelMatch(); 554 ExpectModelMatch();
555 // Test addition.
556 const BookmarkNode* synced_folder =
557 model_->AddFolder(model_->synced_node(), 0, ASCIIToUTF16("pie"));
558 ExpectSyncerNodeMatching(synced_folder);
559 ExpectModelMatch();
543 560
544 // Test modification. 561 // Test modification.
545 model_->SetTitle(url2, ASCIIToUTF16("EasyJet")); 562 model_->SetTitle(url2, ASCIIToUTF16("EasyJet"));
546 ExpectModelMatch(); 563 ExpectModelMatch();
547 model_->Move(url1, folder2, 0); 564 model_->Move(url1, folder2, 0);
548 ExpectModelMatch(); 565 ExpectModelMatch();
549 model_->Move(folder2, model_->GetBookmarkBarNode(), 0); 566 model_->Move(folder2, model_->GetBookmarkBarNode(), 0);
550 ExpectModelMatch(); 567 ExpectModelMatch();
551 model_->SetTitle(folder2, ASCIIToUTF16("Not Nested")); 568 model_->SetTitle(folder2, ASCIIToUTF16("Not Nested"));
552 ExpectModelMatch(); 569 ExpectModelMatch();
553 model_->Move(folder, folder2, 0); 570 model_->Move(folder, folder2, 0);
554 ExpectModelMatch(); 571 ExpectModelMatch();
555 model_->SetTitle(folder, ASCIIToUTF16("who's nested now?")); 572 model_->SetTitle(folder, ASCIIToUTF16("who's nested now?"));
556 ExpectModelMatch(); 573 ExpectModelMatch();
557 model_->Copy(url2, model_->GetBookmarkBarNode(), 0); 574 model_->Copy(url2, model_->GetBookmarkBarNode(), 0);
558 ExpectModelMatch(); 575 ExpectModelMatch();
576 model_->SetTitle(synced_folder, ASCIIToUTF16("strawberry"));
577 ExpectModelMatch();
559 578
560 // Test deletion. 579 // Test deletion.
561 // Delete a single item. 580 // Delete a single item.
562 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2)); 581 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2));
563 ExpectModelMatch(); 582 ExpectModelMatch();
564 // Delete an item with several children. 583 // Delete an item with several children.
565 model_->Remove(folder2->parent(), 584 model_->Remove(folder2->parent(),
566 folder2->parent()->GetIndexOf(folder2)); 585 folder2->parent()->GetIndexOf(folder2));
567 ExpectModelMatch(); 586 ExpectModelMatch();
587 model_->Remove(model_->synced_node(), 0);
588 ExpectModelMatch();
568 } 589 }
569 590
570 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) { 591 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
571 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 592 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
572 StartSync(); 593 StartSync();
573 594
574 sync_api::WriteTransaction trans(test_user_share_.user_share()); 595 sync_api::WriteTransaction trans(test_user_share_.user_share());
575 596
576 FakeServerChange adds(&trans); 597 FakeServerChange adds(&trans);
577 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0); 598 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0);
578 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1); 599 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1);
579 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/", 600 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/",
580 bookmark_bar_id(), f2); 601 bookmark_bar_id(), f2);
581 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); 602 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0);
582 // u3 is a duplicate URL 603 // u3 is a duplicate URL
583 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); 604 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2);
584 // u4 is a duplicate title, different URL. 605 // u4 is a duplicate title, different URL.
585 adds.AddURL(L"Some old site", "http://slog.thestranger.com/", 606 adds.AddURL(L"Some old site", "http://slog.thestranger.com/",
586 bookmark_bar_id(), u1); 607 bookmark_bar_id(), u1);
587 // u5 tests an empty-string title. 608 // u5 tests an empty-string title.
588 std::string javascript_url( 609 std::string javascript_url(
589 "javascript:(function(){var w=window.open(" \ 610 "javascript:(function(){var w=window.open(" \
590 "'about:blank','gnotesWin','location=0,menubar=0," \ 611 "'about:blank','gnotesWin','location=0,menubar=0," \
591 "scrollbars=0,status=0,toolbar=0,width=300," \ 612 "scrollbars=0,status=0,toolbar=0,width=300," \
592 "height=300,resizable');});"); 613 "height=300,resizable');});");
593 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0); 614 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0);
615 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/",
616 synced_bookmarks_id(), 0);
594 617
595 std::vector<sync_api::SyncManager::ChangeRecord>::const_iterator it; 618 std::vector<sync_api::SyncManager::ChangeRecord>::const_iterator it;
596 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 619 // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
597 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 620 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
598 ExpectBrowserNodeUnknown(it->id); 621 ExpectBrowserNodeUnknown(it->id);
599 622
600 adds.ApplyPendingChanges(change_processor_.get()); 623 adds.ApplyPendingChanges(change_processor_.get());
601 624
602 // Make sure the bookmark model received all of the nodes in |adds|. 625 // Make sure the bookmark model received all of the nodes in |adds|.
603 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 626 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
604 ExpectBrowserNodeMatching(&trans, it->id); 627 ExpectBrowserNodeMatching(&trans, it->id);
605 ExpectModelMatch(&trans); 628 ExpectModelMatch(&trans);
606 629
607 // Part two: test modifications. 630 // Part two: test modifications.
608 FakeServerChange mods(&trans); 631 FakeServerChange mods(&trans);
609 // Mess with u2, and move it into empty folder f2 632 // Mess with u2, and move it into empty folder f2
610 // TODO(ncarter): Determine if we allow ModifyURL ops or not. 633 // TODO(ncarter): Determine if we allow ModifyURL ops or not.
611 /* std::wstring u2_old_url = mods.ModifyURL(u2, L"http://www.google.com"); */ 634 /* std::wstring u2_old_url = mods.ModifyURL(u2, L"http://www.google.com"); */
612 std::wstring u2_old_title = mods.ModifyTitle(u2, L"The Google"); 635 std::wstring u2_old_title = mods.ModifyTitle(u2, L"The Google");
613 int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0); 636 int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0);
614 637
615 // Now move f1 after u2. 638 // Now move f1 after u2.
616 std::wstring f1_old_title = mods.ModifyTitle(f1, L"Server Folder C"); 639 std::wstring f1_old_title = mods.ModifyTitle(f1, L"Server Folder C");
617 int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2); 640 int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2);
618 641
619 // Then add u3 after f1. 642 // Then add u3 after f1.
620 int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1); 643 int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1);
621 644
645 std::wstring u6_old_title = mods.ModifyTitle(u6, L"Synced Folder A");
646
622 // Test that the property changes have not yet taken effect. 647 // Test that the property changes have not yet taken effect.
623 ExpectBrowserNodeTitle(u2, u2_old_title); 648 ExpectBrowserNodeTitle(u2, u2_old_title);
624 /* ExpectBrowserNodeURL(u2, u2_old_url); */ 649 /* ExpectBrowserNodeURL(u2, u2_old_url); */
625 ExpectBrowserNodeParent(u2, u2_old_parent); 650 ExpectBrowserNodeParent(u2, u2_old_parent);
626 651
627 ExpectBrowserNodeTitle(f1, f1_old_title); 652 ExpectBrowserNodeTitle(f1, f1_old_title);
628 ExpectBrowserNodeParent(f1, f1_old_parent); 653 ExpectBrowserNodeParent(f1, f1_old_parent);
629 654
630 ExpectBrowserNodeParent(u3, u3_old_parent); 655 ExpectBrowserNodeParent(u3, u3_old_parent);
631 656
657 ExpectBrowserNodeTitle(u6, u6_old_title);
658
632 // Apply the changes. 659 // Apply the changes.
633 mods.ApplyPendingChanges(change_processor_.get()); 660 mods.ApplyPendingChanges(change_processor_.get());
634 661
635 // Check for successful application. 662 // Check for successful application.
636 for (it = mods.changes().begin(); it != mods.changes().end(); ++it) 663 for (it = mods.changes().begin(); it != mods.changes().end(); ++it)
637 ExpectBrowserNodeMatching(&trans, it->id); 664 ExpectBrowserNodeMatching(&trans, it->id);
638 ExpectModelMatch(&trans); 665 ExpectModelMatch(&trans);
639 666
640 // Part 3: Test URL deletion. 667 // Part 3: Test URL deletion.
641 FakeServerChange dels(&trans); 668 FakeServerChange dels(&trans);
642 dels.Delete(u2); 669 dels.Delete(u2);
643 dels.Delete(u3); 670 dels.Delete(u3);
671 dels.Delete(u6);
644 672
645 ExpectBrowserNodeKnown(u2); 673 ExpectBrowserNodeKnown(u2);
646 ExpectBrowserNodeKnown(u3); 674 ExpectBrowserNodeKnown(u3);
647 675
648 dels.ApplyPendingChanges(change_processor_.get()); 676 dels.ApplyPendingChanges(change_processor_.get());
649 677
650 ExpectBrowserNodeUnknown(u2); 678 ExpectBrowserNodeUnknown(u2);
651 ExpectBrowserNodeUnknown(u3); 679 ExpectBrowserNodeUnknown(u3);
680 ExpectBrowserNodeUnknown(u6);
652 ExpectModelMatch(&trans); 681 ExpectModelMatch(&trans);
653 } 682 }
654 683
655 // Tests a specific case in ApplyModelChanges where we move the 684 // Tests a specific case in ApplyModelChanges where we move the
656 // children out from under a parent, and then delete the parent 685 // children out from under a parent, and then delete the parent
657 // in the same changelist. The delete shows up first in the changelist, 686 // in the same changelist. The delete shows up first in the changelist,
658 // requiring the children to be moved to a temporary location. 687 // requiring the children to be moved to a temporary location.
659 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) { 688 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) {
660 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 689 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
661 StartSync(); 690 StartSync();
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 // | | |-- f1u2, http://www.f1u2.com/ 957 // | | |-- f1u2, http://www.f1u2.com/
929 // | | |-- f1u3, http://www.f1u3.com/ 958 // | | |-- f1u3, http://www.f1u3.com/
930 // | | +-- f1u1, http://www.f1u1.com/ 959 // | | +-- f1u1, http://www.f1u1.com/
931 // | |-- u1, http://www.u1.com/ 960 // | |-- u1, http://www.u1.com/
932 // | +-- f2 961 // | +-- f2
933 // | |-- f2u2, http://www.f2u2.com/ 962 // | |-- f2u2, http://www.f2u2.com/
934 // | |-- f2u4, http://www.f2u4.com/ 963 // | |-- f2u4, http://www.f2u4.com/
935 // | |-- f2u3, http://www.f2u3.com/ 964 // | |-- f2u3, http://www.f2u3.com/
936 // | +-- f2u1, http://www.f2u1.com/ 965 // | +-- f2u1, http://www.f2u1.com/
937 // +-- Other bookmarks 966 // +-- Other bookmarks
938 // |-- f3 967 // | |-- f3
939 // | |-- f3u4, http://www.f3u4.com/ 968 // | | |-- f3u4, http://www.f3u4.com/
940 // | |-- f3u2, http://www.f3u2.com/ 969 // | | |-- f3u2, http://www.f3u2.com/
941 // | |-- f3u3, http://www.f3u3.com/ 970 // | | |-- f3u3, http://www.f3u3.com/
942 // | +-- f3u1, http://www.f3u1.com/ 971 // | | +-- f3u1, http://www.f3u1.com/
943 // |-- u4, http://www.u4.com/ 972 // | |-- u4, http://www.u4.com/
944 // |-- u3, http://www.u3.com/ 973 // | |-- u3, http://www.u3.com/
945 // --- f4 974 // | --- f4
946 // | |-- f4u1, http://www.f4u1.com/ 975 // | | |-- f4u1, http://www.f4u1.com/
947 // | |-- f4u2, http://www.f4u2.com/ 976 // | | |-- f4u2, http://www.f4u2.com/
948 // | |-- f4u3, http://www.f4u3.com/ 977 // | | |-- f4u3, http://www.f4u3.com/
949 // | +-- f4u4, http://www.f4u4.com/ 978 // | | +-- f4u4, http://www.f4u4.com/
950 // |-- dup 979 // | |-- dup
951 // | +-- dupu1, http://www.dupu1.com/ 980 // | | +-- dupu1, http://www.dupu1.com/
952 // +-- dup 981 // | +-- dup
953 // +-- dupu2, http://www.dupu1.com/ 982 // | +-- dupu2, http://www.dupu1.com/
954 // 983 // |
984 // +-- Synced bookmarks
985 // |-- f5
986 // | |-- f5u1, http://www.f5u1.com/
987 // |-- f6
988 // | |-- f6u1, http://www.f6u1.com/
989 // | |-- f6u2, http://www.f6u2.com/
990 // +-- u5, http://www.u5.com/
991
955 static TestData kBookmarkBarChildren[] = { 992 static TestData kBookmarkBarChildren[] = {
956 { L"u2", "http://www.u2.com/" }, 993 { L"u2", "http://www.u2.com/" },
957 { L"f1", NULL }, 994 { L"f1", NULL },
958 { L"u1", "http://www.u1.com/" }, 995 { L"u1", "http://www.u1.com/" },
959 { L"f2", NULL }, 996 { L"f2", NULL },
960 }; 997 };
961 static TestData kF1Children[] = { 998 static TestData kF1Children[] = {
962 { L"f1u4", "http://www.f1u4.com/" }, 999 { L"f1u4", "http://www.f1u4.com/" },
963 { L"f1u2", "http://www.f1u2.com/" }, 1000 { L"f1u2", "http://www.f1u2.com/" },
964 { L"f1u3", "http://www.f1u3.com/" }, 1001 { L"f1u3", "http://www.f1u3.com/" },
(...skipping 26 matching lines...) Expand all
991 { L"f4u3", "http://www.f4u3.com/" }, 1028 { L"f4u3", "http://www.f4u3.com/" },
992 { L"f4u4", "http://www.f4u4.com/" }, 1029 { L"f4u4", "http://www.f4u4.com/" },
993 }; 1030 };
994 static TestData kDup1Children[] = { 1031 static TestData kDup1Children[] = {
995 { L"dupu1", "http://www.dupu1.com/" }, 1032 { L"dupu1", "http://www.dupu1.com/" },
996 }; 1033 };
997 static TestData kDup2Children[] = { 1034 static TestData kDup2Children[] = {
998 { L"dupu2", "http://www.dupu2.com/" }, 1035 { L"dupu2", "http://www.dupu2.com/" },
999 }; 1036 };
1000 1037
1038 static TestData kSyncedBookmarkChildren[] = {
1039 { L"f5", NULL },
1040 { L"f6", NULL },
1041 { L"u5", "http://www.u5.com/" },
1042 };
1043 static TestData kF5Children[] = {
1044 { L"f5u1", "http://www.f5u1.com/" },
1045 { L"f5u2", "http://www.f5u2.com/" },
1046 };
1047 static TestData kF6Children[] = {
1048 { L"f6u1", "http://www.f6u1.com/" },
1049 { L"f6u2", "http://www.f6u2.com/" },
1050 };
1051
1001 } // anonymous namespace. 1052 } // anonymous namespace.
1002 1053
1003 void ProfileSyncServiceBookmarkTestWithData::PopulateFromTestData( 1054 void ProfileSyncServiceBookmarkTestWithData::PopulateFromTestData(
1004 const BookmarkNode* node, const TestData* data, int size) { 1055 const BookmarkNode* node, const TestData* data, int size) {
1005 DCHECK(node); 1056 DCHECK(node);
1006 DCHECK(data); 1057 DCHECK(data);
1007 DCHECK(node->is_folder()); 1058 DCHECK(node->is_folder());
1008 for (int i = 0; i < size; ++i) { 1059 for (int i = 0; i < size; ++i) {
1009 const TestData& item = data[i]; 1060 const TestData& item = data[i];
1010 if (item.url) { 1061 if (item.url) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 ASSERT_GE(other_bookmarks_node->child_count(), 6); 1109 ASSERT_GE(other_bookmarks_node->child_count(), 6);
1059 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); 1110 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0);
1060 PopulateFromTestData(f3_node, kF3Children, arraysize(kF3Children)); 1111 PopulateFromTestData(f3_node, kF3Children, arraysize(kF3Children));
1061 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); 1112 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3);
1062 PopulateFromTestData(f4_node, kF4Children, arraysize(kF4Children)); 1113 PopulateFromTestData(f4_node, kF4Children, arraysize(kF4Children));
1063 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); 1114 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4);
1064 PopulateFromTestData(dup_node, kDup1Children, arraysize(kDup1Children)); 1115 PopulateFromTestData(dup_node, kDup1Children, arraysize(kDup1Children));
1065 dup_node = other_bookmarks_node->GetChild(5); 1116 dup_node = other_bookmarks_node->GetChild(5);
1066 PopulateFromTestData(dup_node, kDup2Children, arraysize(kDup2Children)); 1117 PopulateFromTestData(dup_node, kDup2Children, arraysize(kDup2Children));
1067 1118
1119 const BookmarkNode* synced_bookmarks_node = model_->synced_node();
1120 PopulateFromTestData(synced_bookmarks_node,
1121 kSyncedBookmarkChildren,
1122 arraysize(kSyncedBookmarkChildren));
1123
1124 ASSERT_GE(synced_bookmarks_node->child_count(), 3);
1125 const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0);
1126 PopulateFromTestData(f5_node, kF5Children, arraysize(kF5Children));
1127 const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1);
1128 PopulateFromTestData(f6_node, kF6Children, arraysize(kF6Children));
1129
1068 ExpectBookmarkModelMatchesTestData(); 1130 ExpectBookmarkModelMatchesTestData();
1069 } 1131 }
1070 1132
1071 void ProfileSyncServiceBookmarkTestWithData:: 1133 void ProfileSyncServiceBookmarkTestWithData::
1072 ExpectBookmarkModelMatchesTestData() { 1134 ExpectBookmarkModelMatchesTestData() {
1073 const BookmarkNode* bookmark_bar_node = model_->GetBookmarkBarNode(); 1135 const BookmarkNode* bookmark_bar_node = model_->GetBookmarkBarNode();
1074 CompareWithTestData(bookmark_bar_node, 1136 CompareWithTestData(bookmark_bar_node,
1075 kBookmarkBarChildren, 1137 kBookmarkBarChildren,
1076 arraysize(kBookmarkBarChildren)); 1138 arraysize(kBookmarkBarChildren));
1077 1139
(...skipping 10 matching lines...) Expand all
1088 1150
1089 ASSERT_GE(other_bookmarks_node->child_count(), 6); 1151 ASSERT_GE(other_bookmarks_node->child_count(), 6);
1090 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); 1152 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0);
1091 CompareWithTestData(f3_node, kF3Children, arraysize(kF3Children)); 1153 CompareWithTestData(f3_node, kF3Children, arraysize(kF3Children));
1092 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); 1154 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3);
1093 CompareWithTestData(f4_node, kF4Children, arraysize(kF4Children)); 1155 CompareWithTestData(f4_node, kF4Children, arraysize(kF4Children));
1094 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); 1156 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4);
1095 CompareWithTestData(dup_node, kDup1Children, arraysize(kDup1Children)); 1157 CompareWithTestData(dup_node, kDup1Children, arraysize(kDup1Children));
1096 dup_node = other_bookmarks_node->GetChild(5); 1158 dup_node = other_bookmarks_node->GetChild(5);
1097 CompareWithTestData(dup_node, kDup2Children, arraysize(kDup2Children)); 1159 CompareWithTestData(dup_node, kDup2Children, arraysize(kDup2Children));
1160
1161 const BookmarkNode* synced_bookmarks_node = model_->synced_node();
1162 CompareWithTestData(synced_bookmarks_node,
1163 kSyncedBookmarkChildren,
1164 arraysize(kSyncedBookmarkChildren));
1165
1166 ASSERT_GE(synced_bookmarks_node->child_count(), 3);
1167 const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0);
1168 CompareWithTestData(f5_node, kF5Children, arraysize(kF5Children));
1169 const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1);
1170 CompareWithTestData(f6_node, kF6Children, arraysize(kF6Children));
1171
1098 } 1172 }
1099 1173
1100 // Tests persistence of the profile sync service by unloading the 1174 // Tests persistence of the profile sync service by unloading the
1101 // database and then reloading it from disk. 1175 // database and then reloading it from disk.
1102 TEST_F(ProfileSyncServiceBookmarkTestWithData, Persistence) { 1176 TEST_F(ProfileSyncServiceBookmarkTestWithData, Persistence) {
1103 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); 1177 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
1104 StartSync(); 1178 StartSync();
1105 1179
1106 WriteTestDataToBookmarkModel(); 1180 WriteTestDataToBookmarkModel();
1107 1181
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 ExpectModelMatch(); 1228 ExpectModelMatch();
1155 1229
1156 // Force the databse to unload and write itself to disk. 1230 // Force the databse to unload and write itself to disk.
1157 StopSync(); 1231 StopSync();
1158 1232
1159 // Blow away the bookmark model -- it should be empty afterwards. 1233 // Blow away the bookmark model -- it should be empty afterwards.
1160 UnloadBookmarkModel(); 1234 UnloadBookmarkModel();
1161 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1235 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1162 EXPECT_EQ(model_->GetBookmarkBarNode()->child_count(), 0); 1236 EXPECT_EQ(model_->GetBookmarkBarNode()->child_count(), 0);
1163 EXPECT_EQ(model_->other_node()->child_count(), 0); 1237 EXPECT_EQ(model_->other_node()->child_count(), 0);
1238 EXPECT_EQ(model_->synced_node()->child_count(), 0);
1164 1239
1165 // Now restart the sync service. Starting it should populate the bookmark 1240 // Now restart the sync service. Starting it should populate the bookmark
1166 // model -- test for consistency. 1241 // model -- test for consistency.
1167 StartSync(); 1242 StartSync();
1168 ExpectBookmarkModelMatchesTestData(); 1243 ExpectBookmarkModelMatchesTestData();
1169 ExpectModelMatch(); 1244 ExpectModelMatch();
1170 } 1245 }
1171 1246
1172 // Tests the merge cases when both the models are expected to be identical 1247 // Tests the merge cases when both the models are expected to be identical
1173 // after the merge. 1248 // after the merge.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 // Make sure we're back in sync. In real life, the user would need 1428 // Make sure we're back in sync. In real life, the user would need
1354 // to reauthenticate before this happens, but in the test, authentication 1429 // to reauthenticate before this happens, but in the test, authentication
1355 // is sidestepped. 1430 // is sidestepped.
1356 ExpectBookmarkModelMatchesTestData(); 1431 ExpectBookmarkModelMatchesTestData();
1357 ExpectModelMatch(); 1432 ExpectModelMatch();
1358 } 1433 }
1359 1434
1360 } // namespace 1435 } // namespace
1361 1436
1362 } // namespace browser_sync 1437 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_model_associator.cc ('k') | chrome/browser/sync/protocol/sync.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698