OLD | NEW |
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> |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 model_(NULL) { | 289 model_(NULL) { |
290 } | 290 } |
291 | 291 |
292 virtual ~ProfileSyncServiceBookmarkTest() { | 292 virtual ~ProfileSyncServiceBookmarkTest() { |
293 StopSync(); | 293 StopSync(); |
294 UnloadBookmarkModel(); | 294 UnloadBookmarkModel(); |
295 } | 295 } |
296 | 296 |
297 virtual void SetUp() { | 297 virtual void SetUp() { |
298 test_user_share_.SetUp(); | 298 test_user_share_.SetUp(); |
299 CommandLine::ForCurrentProcess()->AppendSwitch( | |
300 switches::kEnableSyncedBookmarksFolder); | |
301 } | 299 } |
302 | 300 |
303 virtual void TearDown() { | 301 virtual void TearDown() { |
304 test_user_share_.TearDown(); | 302 test_user_share_.TearDown(); |
305 } | 303 } |
306 | 304 |
307 // Load (or re-load) the bookmark model. |load| controls use of the | 305 // Load (or re-load) the bookmark model. |load| controls use of the |
308 // bookmarks file on disk. |save| controls whether the newly loaded | 306 // bookmarks file on disk. |save| controls whether the newly loaded |
309 // bookmark model will write out a bookmark file as it goes. | 307 // bookmark model will write out a bookmark file as it goes. |
310 void LoadBookmarkModel(LoadOption load, SaveOption save) { | 308 void LoadBookmarkModel(LoadOption load, SaveOption save) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 const BookmarkNode* parent = | 456 const BookmarkNode* parent = |
459 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); | 457 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); |
460 EXPECT_TRUE(parent); | 458 EXPECT_TRUE(parent); |
461 EXPECT_EQ(node->parent(), parent); | 459 EXPECT_EQ(node->parent(), parent); |
462 } | 460 } |
463 | 461 |
464 void ExpectModelMatch(sync_api::BaseTransaction* trans) { | 462 void ExpectModelMatch(sync_api::BaseTransaction* trans) { |
465 const BookmarkNode* root = model_->root_node(); | 463 const BookmarkNode* root = model_->root_node(); |
466 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0); | 464 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0); |
467 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); | 465 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); |
468 EXPECT_EQ(root->GetIndexOf(model_->synced_node()), 2); | 466 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2); |
469 | 467 |
470 std::stack<int64> stack; | 468 std::stack<int64> stack; |
471 stack.push(bookmark_bar_id()); | 469 stack.push(bookmark_bar_id()); |
472 while (!stack.empty()) { | 470 while (!stack.empty()) { |
473 int64 id = stack.top(); | 471 int64 id = stack.top(); |
474 stack.pop(); | 472 stack.pop(); |
475 if (!id) continue; | 473 if (!id) continue; |
476 | 474 |
477 ExpectBrowserNodeMatching(trans, id); | 475 ExpectBrowserNodeMatching(trans, id); |
478 | 476 |
479 sync_api::ReadNode gnode(trans); | 477 sync_api::ReadNode gnode(trans); |
480 ASSERT_TRUE(gnode.InitByIdLookup(id)); | 478 ASSERT_TRUE(gnode.InitByIdLookup(id)); |
481 stack.push(gnode.GetFirstChildId()); | 479 stack.push(gnode.GetFirstChildId()); |
482 stack.push(gnode.GetSuccessorId()); | 480 stack.push(gnode.GetSuccessorId()); |
483 } | 481 } |
484 } | 482 } |
485 | 483 |
486 void ExpectModelMatch() { | 484 void ExpectModelMatch() { |
487 sync_api::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 485 sync_api::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
488 ExpectModelMatch(&trans); | 486 ExpectModelMatch(&trans); |
489 } | 487 } |
490 | 488 |
491 int64 synced_bookmarks_id() { | 489 int64 mobile_bookmarks_id() { |
492 return | 490 return |
493 model_associator_->GetSyncIdFromChromeId(model_->synced_node()->id()); | 491 model_associator_->GetSyncIdFromChromeId(model_->mobile_node()->id()); |
494 } | 492 } |
495 | 493 |
496 int64 other_bookmarks_id() { | 494 int64 other_bookmarks_id() { |
497 return | 495 return |
498 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id()); | 496 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id()); |
499 } | 497 } |
500 | 498 |
501 int64 bookmark_bar_id() { | 499 int64 bookmark_bar_id() { |
502 return model_associator_->GetSyncIdFromChromeId( | 500 return model_associator_->GetSyncIdFromChromeId( |
503 model_->bookmark_bar_node()->id()); | 501 model_->bookmark_bar_node()->id()); |
(...skipping 15 matching lines...) Expand all Loading... |
519 scoped_ptr<BookmarkChangeProcessor> change_processor_; | 517 scoped_ptr<BookmarkChangeProcessor> change_processor_; |
520 StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_; | 518 StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_; |
521 }; | 519 }; |
522 | 520 |
523 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { | 521 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { |
524 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 522 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
525 StartSync(); | 523 StartSync(); |
526 | 524 |
527 EXPECT_TRUE(other_bookmarks_id()); | 525 EXPECT_TRUE(other_bookmarks_id()); |
528 EXPECT_TRUE(bookmark_bar_id()); | 526 EXPECT_TRUE(bookmark_bar_id()); |
529 EXPECT_TRUE(synced_bookmarks_id()); | 527 EXPECT_TRUE(mobile_bookmarks_id()); |
530 | 528 |
531 ExpectModelMatch(); | 529 ExpectModelMatch(); |
532 } | 530 } |
533 | 531 |
534 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { | 532 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { |
535 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 533 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
536 StartSync(); | 534 StartSync(); |
537 | 535 |
538 // Test addition. | 536 // Test addition. |
539 const BookmarkNode* folder = | 537 const BookmarkNode* folder = |
540 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); | 538 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); |
541 ExpectSyncerNodeMatching(folder); | 539 ExpectSyncerNodeMatching(folder); |
542 ExpectModelMatch(); | 540 ExpectModelMatch(); |
543 const BookmarkNode* folder2 = | 541 const BookmarkNode* folder2 = |
544 model_->AddFolder(folder, 0, ASCIIToUTF16("nested")); | 542 model_->AddFolder(folder, 0, ASCIIToUTF16("nested")); |
545 ExpectSyncerNodeMatching(folder2); | 543 ExpectSyncerNodeMatching(folder2); |
546 ExpectModelMatch(); | 544 ExpectModelMatch(); |
547 const BookmarkNode* url1 = model_->AddURL( | 545 const BookmarkNode* url1 = model_->AddURL( |
548 folder, 0, ASCIIToUTF16("Internets #1 Pies Site"), | 546 folder, 0, ASCIIToUTF16("Internets #1 Pies Site"), |
549 GURL("http://www.easypie.com/")); | 547 GURL("http://www.easypie.com/")); |
550 ExpectSyncerNodeMatching(url1); | 548 ExpectSyncerNodeMatching(url1); |
551 ExpectModelMatch(); | 549 ExpectModelMatch(); |
552 const BookmarkNode* url2 = model_->AddURL( | 550 const BookmarkNode* url2 = model_->AddURL( |
553 folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/")); | 551 folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/")); |
554 ExpectSyncerNodeMatching(url2); | 552 ExpectSyncerNodeMatching(url2); |
555 ExpectModelMatch(); | 553 ExpectModelMatch(); |
556 // Test addition. | 554 // Test addition. |
557 const BookmarkNode* synced_folder = | 555 const BookmarkNode* mobile_folder = |
558 model_->AddFolder(model_->synced_node(), 0, ASCIIToUTF16("pie")); | 556 model_->AddFolder(model_->mobile_node(), 0, ASCIIToUTF16("pie")); |
559 ExpectSyncerNodeMatching(synced_folder); | 557 ExpectSyncerNodeMatching(mobile_folder); |
560 ExpectModelMatch(); | 558 ExpectModelMatch(); |
561 | 559 |
562 // Test modification. | 560 // Test modification. |
563 model_->SetTitle(url2, ASCIIToUTF16("EasyJet")); | 561 model_->SetTitle(url2, ASCIIToUTF16("EasyJet")); |
564 ExpectModelMatch(); | 562 ExpectModelMatch(); |
565 model_->Move(url1, folder2, 0); | 563 model_->Move(url1, folder2, 0); |
566 ExpectModelMatch(); | 564 ExpectModelMatch(); |
567 model_->Move(folder2, model_->bookmark_bar_node(), 0); | 565 model_->Move(folder2, model_->bookmark_bar_node(), 0); |
568 ExpectModelMatch(); | 566 ExpectModelMatch(); |
569 model_->SetTitle(folder2, ASCIIToUTF16("Not Nested")); | 567 model_->SetTitle(folder2, ASCIIToUTF16("Not Nested")); |
570 ExpectModelMatch(); | 568 ExpectModelMatch(); |
571 model_->Move(folder, folder2, 0); | 569 model_->Move(folder, folder2, 0); |
572 ExpectModelMatch(); | 570 ExpectModelMatch(); |
573 model_->SetTitle(folder, ASCIIToUTF16("who's nested now?")); | 571 model_->SetTitle(folder, ASCIIToUTF16("who's nested now?")); |
574 ExpectModelMatch(); | 572 ExpectModelMatch(); |
575 model_->Copy(url2, model_->bookmark_bar_node(), 0); | 573 model_->Copy(url2, model_->bookmark_bar_node(), 0); |
576 ExpectModelMatch(); | 574 ExpectModelMatch(); |
577 model_->SetTitle(synced_folder, ASCIIToUTF16("strawberry")); | 575 model_->SetTitle(mobile_folder, ASCIIToUTF16("strawberry")); |
578 ExpectModelMatch(); | 576 ExpectModelMatch(); |
579 | 577 |
580 // Test deletion. | 578 // Test deletion. |
581 // Delete a single item. | 579 // Delete a single item. |
582 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2)); | 580 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2)); |
583 ExpectModelMatch(); | 581 ExpectModelMatch(); |
584 // Delete an item with several children. | 582 // Delete an item with several children. |
585 model_->Remove(folder2->parent(), | 583 model_->Remove(folder2->parent(), |
586 folder2->parent()->GetIndexOf(folder2)); | 584 folder2->parent()->GetIndexOf(folder2)); |
587 ExpectModelMatch(); | 585 ExpectModelMatch(); |
588 model_->Remove(model_->synced_node(), 0); | 586 model_->Remove(model_->mobile_node(), 0); |
589 ExpectModelMatch(); | 587 ExpectModelMatch(); |
590 } | 588 } |
591 | 589 |
592 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) { | 590 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) { |
593 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 591 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
594 StartSync(); | 592 StartSync(); |
595 | 593 |
596 sync_api::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 594 sync_api::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
597 | 595 |
598 FakeServerChange adds(&trans); | 596 FakeServerChange adds(&trans); |
599 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0); | 597 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0); |
600 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1); | 598 int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1); |
601 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/", | 599 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/", |
602 bookmark_bar_id(), f2); | 600 bookmark_bar_id(), f2); |
603 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); | 601 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); |
604 // u3 is a duplicate URL | 602 // u3 is a duplicate URL |
605 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); | 603 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); |
606 // u4 is a duplicate title, different URL. | 604 // u4 is a duplicate title, different URL. |
607 adds.AddURL(L"Some old site", "http://slog.thestranger.com/", | 605 adds.AddURL(L"Some old site", "http://slog.thestranger.com/", |
608 bookmark_bar_id(), u1); | 606 bookmark_bar_id(), u1); |
609 // u5 tests an empty-string title. | 607 // u5 tests an empty-string title. |
610 std::string javascript_url( | 608 std::string javascript_url( |
611 "javascript:(function(){var w=window.open(" \ | 609 "javascript:(function(){var w=window.open(" \ |
612 "'about:blank','gnotesWin','location=0,menubar=0," \ | 610 "'about:blank','gnotesWin','location=0,menubar=0," \ |
613 "scrollbars=0,status=0,toolbar=0,width=300," \ | 611 "scrollbars=0,status=0,toolbar=0,width=300," \ |
614 "height=300,resizable');});"); | 612 "height=300,resizable');});"); |
615 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0); | 613 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0); |
616 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/", | 614 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/", |
617 synced_bookmarks_id(), 0); | 615 mobile_bookmarks_id(), 0); |
618 | 616 |
619 sync_api::ChangeRecordList::const_iterator it; | 617 sync_api::ChangeRecordList::const_iterator it; |
620 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. | 618 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. |
621 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) | 619 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) |
622 ExpectBrowserNodeUnknown(it->id); | 620 ExpectBrowserNodeUnknown(it->id); |
623 | 621 |
624 adds.ApplyPendingChanges(change_processor_.get()); | 622 adds.ApplyPendingChanges(change_processor_.get()); |
625 | 623 |
626 // Make sure the bookmark model received all of the nodes in |adds|. | 624 // Make sure the bookmark model received all of the nodes in |adds|. |
627 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) | 625 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) |
628 ExpectBrowserNodeMatching(&trans, it->id); | 626 ExpectBrowserNodeMatching(&trans, it->id); |
629 ExpectModelMatch(&trans); | 627 ExpectModelMatch(&trans); |
630 | 628 |
631 // Part two: test modifications. | 629 // Part two: test modifications. |
632 FakeServerChange mods(&trans); | 630 FakeServerChange mods(&trans); |
633 // Mess with u2, and move it into empty folder f2 | 631 // Mess with u2, and move it into empty folder f2 |
634 // TODO(ncarter): Determine if we allow ModifyURL ops or not. | 632 // TODO(ncarter): Determine if we allow ModifyURL ops or not. |
635 /* std::wstring u2_old_url = mods.ModifyURL(u2, L"http://www.google.com"); */ | 633 /* std::wstring u2_old_url = mods.ModifyURL(u2, L"http://www.google.com"); */ |
636 std::wstring u2_old_title = mods.ModifyTitle(u2, L"The Google"); | 634 std::wstring u2_old_title = mods.ModifyTitle(u2, L"The Google"); |
637 int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0); | 635 int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0); |
638 | 636 |
639 // Now move f1 after u2. | 637 // Now move f1 after u2. |
640 std::wstring f1_old_title = mods.ModifyTitle(f1, L"Server Folder C"); | 638 std::wstring f1_old_title = mods.ModifyTitle(f1, L"Server Folder C"); |
641 int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2); | 639 int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2); |
642 | 640 |
643 // Then add u3 after f1. | 641 // Then add u3 after f1. |
644 int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1); | 642 int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1); |
645 | 643 |
646 std::wstring u6_old_title = mods.ModifyTitle(u6, L"Synced Folder A"); | 644 std::wstring u6_old_title = mods.ModifyTitle(u6, L"Mobile Folder A"); |
647 | 645 |
648 // Test that the property changes have not yet taken effect. | 646 // Test that the property changes have not yet taken effect. |
649 ExpectBrowserNodeTitle(u2, u2_old_title); | 647 ExpectBrowserNodeTitle(u2, u2_old_title); |
650 /* ExpectBrowserNodeURL(u2, u2_old_url); */ | 648 /* ExpectBrowserNodeURL(u2, u2_old_url); */ |
651 ExpectBrowserNodeParent(u2, u2_old_parent); | 649 ExpectBrowserNodeParent(u2, u2_old_parent); |
652 | 650 |
653 ExpectBrowserNodeTitle(f1, f1_old_title); | 651 ExpectBrowserNodeTitle(f1, f1_old_title); |
654 ExpectBrowserNodeParent(f1, f1_old_parent); | 652 ExpectBrowserNodeParent(f1, f1_old_parent); |
655 | 653 |
656 ExpectBrowserNodeParent(u3, u3_old_parent); | 654 ExpectBrowserNodeParent(u3, u3_old_parent); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 // | --- f4 | 973 // | --- f4 |
976 // | | |-- f4u1, http://www.f4u1.com/ | 974 // | | |-- f4u1, http://www.f4u1.com/ |
977 // | | |-- f4u2, http://www.f4u2.com/ | 975 // | | |-- f4u2, http://www.f4u2.com/ |
978 // | | |-- f4u3, http://www.f4u3.com/ | 976 // | | |-- f4u3, http://www.f4u3.com/ |
979 // | | +-- f4u4, http://www.f4u4.com/ | 977 // | | +-- f4u4, http://www.f4u4.com/ |
980 // | |-- dup | 978 // | |-- dup |
981 // | | +-- dupu1, http://www.dupu1.com/ | 979 // | | +-- dupu1, http://www.dupu1.com/ |
982 // | +-- dup | 980 // | +-- dup |
983 // | +-- dupu2, http://www.dupu1.com/ | 981 // | +-- dupu2, http://www.dupu1.com/ |
984 // | | 982 // | |
985 // +-- Synced bookmarks | 983 // +-- Mobile bookmarks |
986 // |-- f5 | 984 // |-- f5 |
987 // | |-- f5u1, http://www.f5u1.com/ | 985 // | |-- f5u1, http://www.f5u1.com/ |
988 // |-- f6 | 986 // |-- f6 |
989 // | |-- f6u1, http://www.f6u1.com/ | 987 // | |-- f6u1, http://www.f6u1.com/ |
990 // | |-- f6u2, http://www.f6u2.com/ | 988 // | |-- f6u2, http://www.f6u2.com/ |
991 // +-- u5, http://www.u5.com/ | 989 // +-- u5, http://www.u5.com/ |
992 | 990 |
993 static TestData kBookmarkBarChildren[] = { | 991 static TestData kBookmarkBarChildren[] = { |
994 { L"u2", "http://www.u2.com/" }, | 992 { L"u2", "http://www.u2.com/" }, |
995 { L"f1", NULL }, | 993 { L"f1", NULL }, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 { L"f4u3", "http://www.f4u3.com/" }, | 1027 { L"f4u3", "http://www.f4u3.com/" }, |
1030 { L"f4u4", "http://www.f4u4.com/" }, | 1028 { L"f4u4", "http://www.f4u4.com/" }, |
1031 }; | 1029 }; |
1032 static TestData kDup1Children[] = { | 1030 static TestData kDup1Children[] = { |
1033 { L"dupu1", "http://www.dupu1.com/" }, | 1031 { L"dupu1", "http://www.dupu1.com/" }, |
1034 }; | 1032 }; |
1035 static TestData kDup2Children[] = { | 1033 static TestData kDup2Children[] = { |
1036 { L"dupu2", "http://www.dupu2.com/" }, | 1034 { L"dupu2", "http://www.dupu2.com/" }, |
1037 }; | 1035 }; |
1038 | 1036 |
1039 static TestData kSyncedBookmarkChildren[] = { | 1037 static TestData kMobileBookmarkChildren[] = { |
1040 { L"f5", NULL }, | 1038 { L"f5", NULL }, |
1041 { L"f6", NULL }, | 1039 { L"f6", NULL }, |
1042 { L"u5", "http://www.u5.com/" }, | 1040 { L"u5", "http://www.u5.com/" }, |
1043 }; | 1041 }; |
1044 static TestData kF5Children[] = { | 1042 static TestData kF5Children[] = { |
1045 { L"f5u1", "http://www.f5u1.com/" }, | 1043 { L"f5u1", "http://www.f5u1.com/" }, |
1046 { L"f5u2", "http://www.f5u2.com/" }, | 1044 { L"f5u2", "http://www.f5u2.com/" }, |
1047 }; | 1045 }; |
1048 static TestData kF6Children[] = { | 1046 static TestData kF6Children[] = { |
1049 { L"f6u1", "http://www.f6u1.com/" }, | 1047 { L"f6u1", "http://www.f6u1.com/" }, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 ASSERT_GE(other_bookmarks_node->child_count(), 6); | 1108 ASSERT_GE(other_bookmarks_node->child_count(), 6); |
1111 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); | 1109 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); |
1112 PopulateFromTestData(f3_node, kF3Children, arraysize(kF3Children)); | 1110 PopulateFromTestData(f3_node, kF3Children, arraysize(kF3Children)); |
1113 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); | 1111 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); |
1114 PopulateFromTestData(f4_node, kF4Children, arraysize(kF4Children)); | 1112 PopulateFromTestData(f4_node, kF4Children, arraysize(kF4Children)); |
1115 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); | 1113 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); |
1116 PopulateFromTestData(dup_node, kDup1Children, arraysize(kDup1Children)); | 1114 PopulateFromTestData(dup_node, kDup1Children, arraysize(kDup1Children)); |
1117 dup_node = other_bookmarks_node->GetChild(5); | 1115 dup_node = other_bookmarks_node->GetChild(5); |
1118 PopulateFromTestData(dup_node, kDup2Children, arraysize(kDup2Children)); | 1116 PopulateFromTestData(dup_node, kDup2Children, arraysize(kDup2Children)); |
1119 | 1117 |
1120 const BookmarkNode* synced_bookmarks_node = model_->synced_node(); | 1118 const BookmarkNode* mobile_bookmarks_node = model_->mobile_node(); |
1121 PopulateFromTestData(synced_bookmarks_node, | 1119 PopulateFromTestData(mobile_bookmarks_node, |
1122 kSyncedBookmarkChildren, | 1120 kMobileBookmarkChildren, |
1123 arraysize(kSyncedBookmarkChildren)); | 1121 arraysize(kMobileBookmarkChildren)); |
1124 | 1122 |
1125 ASSERT_GE(synced_bookmarks_node->child_count(), 3); | 1123 ASSERT_GE(mobile_bookmarks_node->child_count(), 3); |
1126 const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0); | 1124 const BookmarkNode* f5_node = mobile_bookmarks_node->GetChild(0); |
1127 PopulateFromTestData(f5_node, kF5Children, arraysize(kF5Children)); | 1125 PopulateFromTestData(f5_node, kF5Children, arraysize(kF5Children)); |
1128 const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1); | 1126 const BookmarkNode* f6_node = mobile_bookmarks_node->GetChild(1); |
1129 PopulateFromTestData(f6_node, kF6Children, arraysize(kF6Children)); | 1127 PopulateFromTestData(f6_node, kF6Children, arraysize(kF6Children)); |
1130 | 1128 |
1131 ExpectBookmarkModelMatchesTestData(); | 1129 ExpectBookmarkModelMatchesTestData(); |
1132 } | 1130 } |
1133 | 1131 |
1134 void ProfileSyncServiceBookmarkTestWithData:: | 1132 void ProfileSyncServiceBookmarkTestWithData:: |
1135 ExpectBookmarkModelMatchesTestData() { | 1133 ExpectBookmarkModelMatchesTestData() { |
1136 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); | 1134 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); |
1137 CompareWithTestData(bookmark_bar_node, | 1135 CompareWithTestData(bookmark_bar_node, |
1138 kBookmarkBarChildren, | 1136 kBookmarkBarChildren, |
(...skipping 13 matching lines...) Expand all Loading... |
1152 ASSERT_GE(other_bookmarks_node->child_count(), 6); | 1150 ASSERT_GE(other_bookmarks_node->child_count(), 6); |
1153 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); | 1151 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); |
1154 CompareWithTestData(f3_node, kF3Children, arraysize(kF3Children)); | 1152 CompareWithTestData(f3_node, kF3Children, arraysize(kF3Children)); |
1155 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); | 1153 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); |
1156 CompareWithTestData(f4_node, kF4Children, arraysize(kF4Children)); | 1154 CompareWithTestData(f4_node, kF4Children, arraysize(kF4Children)); |
1157 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); | 1155 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); |
1158 CompareWithTestData(dup_node, kDup1Children, arraysize(kDup1Children)); | 1156 CompareWithTestData(dup_node, kDup1Children, arraysize(kDup1Children)); |
1159 dup_node = other_bookmarks_node->GetChild(5); | 1157 dup_node = other_bookmarks_node->GetChild(5); |
1160 CompareWithTestData(dup_node, kDup2Children, arraysize(kDup2Children)); | 1158 CompareWithTestData(dup_node, kDup2Children, arraysize(kDup2Children)); |
1161 | 1159 |
1162 const BookmarkNode* synced_bookmarks_node = model_->synced_node(); | 1160 const BookmarkNode* mobile_bookmarks_node = model_->mobile_node(); |
1163 CompareWithTestData(synced_bookmarks_node, | 1161 CompareWithTestData(mobile_bookmarks_node, |
1164 kSyncedBookmarkChildren, | 1162 kMobileBookmarkChildren, |
1165 arraysize(kSyncedBookmarkChildren)); | 1163 arraysize(kMobileBookmarkChildren)); |
1166 | 1164 |
1167 ASSERT_GE(synced_bookmarks_node->child_count(), 3); | 1165 ASSERT_GE(mobile_bookmarks_node->child_count(), 3); |
1168 const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0); | 1166 const BookmarkNode* f5_node = mobile_bookmarks_node->GetChild(0); |
1169 CompareWithTestData(f5_node, kF5Children, arraysize(kF5Children)); | 1167 CompareWithTestData(f5_node, kF5Children, arraysize(kF5Children)); |
1170 const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1); | 1168 const BookmarkNode* f6_node = mobile_bookmarks_node->GetChild(1); |
1171 CompareWithTestData(f6_node, kF6Children, arraysize(kF6Children)); | 1169 CompareWithTestData(f6_node, kF6Children, arraysize(kF6Children)); |
1172 | 1170 |
1173 } | 1171 } |
1174 | 1172 |
1175 // Tests persistence of the profile sync service by unloading the | 1173 // Tests persistence of the profile sync service by unloading the |
1176 // database and then reloading it from disk. | 1174 // database and then reloading it from disk. |
1177 TEST_F(ProfileSyncServiceBookmarkTestWithData, Persistence) { | 1175 TEST_F(ProfileSyncServiceBookmarkTestWithData, Persistence) { |
1178 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); | 1176 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); |
1179 StartSync(); | 1177 StartSync(); |
1180 | 1178 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 ExpectModelMatch(); | 1227 ExpectModelMatch(); |
1230 | 1228 |
1231 // Force the databse to unload and write itself to disk. | 1229 // Force the databse to unload and write itself to disk. |
1232 StopSync(); | 1230 StopSync(); |
1233 | 1231 |
1234 // Blow away the bookmark model -- it should be empty afterwards. | 1232 // Blow away the bookmark model -- it should be empty afterwards. |
1235 UnloadBookmarkModel(); | 1233 UnloadBookmarkModel(); |
1236 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 1234 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
1237 EXPECT_EQ(model_->bookmark_bar_node()->child_count(), 0); | 1235 EXPECT_EQ(model_->bookmark_bar_node()->child_count(), 0); |
1238 EXPECT_EQ(model_->other_node()->child_count(), 0); | 1236 EXPECT_EQ(model_->other_node()->child_count(), 0); |
1239 EXPECT_EQ(model_->synced_node()->child_count(), 0); | 1237 EXPECT_EQ(model_->mobile_node()->child_count(), 0); |
1240 | 1238 |
1241 // Now restart the sync service. Starting it should populate the bookmark | 1239 // Now restart the sync service. Starting it should populate the bookmark |
1242 // model -- test for consistency. | 1240 // model -- test for consistency. |
1243 StartSync(); | 1241 StartSync(); |
1244 ExpectBookmarkModelMatchesTestData(); | 1242 ExpectBookmarkModelMatchesTestData(); |
1245 ExpectModelMatch(); | 1243 ExpectModelMatch(); |
1246 } | 1244 } |
1247 | 1245 |
1248 // Tests the merge cases when both the models are expected to be identical | 1246 // Tests the merge cases when both the models are expected to be identical |
1249 // after the merge. | 1247 // after the merge. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 // Make sure we're back in sync. In real life, the user would need | 1427 // Make sure we're back in sync. In real life, the user would need |
1430 // to reauthenticate before this happens, but in the test, authentication | 1428 // to reauthenticate before this happens, but in the test, authentication |
1431 // is sidestepped. | 1429 // is sidestepped. |
1432 ExpectBookmarkModelMatchesTestData(); | 1430 ExpectBookmarkModelMatchesTestData(); |
1433 ExpectModelMatch(); | 1431 ExpectModelMatch(); |
1434 } | 1432 } |
1435 | 1433 |
1436 } // namespace | 1434 } // namespace |
1437 | 1435 |
1438 } // namespace browser_sync | 1436 } // namespace browser_sync |
OLD | NEW |