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

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

Issue 7012005: Revert "Revert 84829 - Initial implementation of "Synced Bookmarks" folder." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trying to set .json eol-style 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 }; 276 };
275 277
276 class ProfileSyncServiceBookmarkTest : public testing::Test { 278 class ProfileSyncServiceBookmarkTest : public testing::Test {
277 protected: 279 protected:
278 enum LoadOption { LOAD_FROM_STORAGE, DELETE_EXISTING_STORAGE }; 280 enum LoadOption { LOAD_FROM_STORAGE, DELETE_EXISTING_STORAGE };
279 enum SaveOption { SAVE_TO_STORAGE, DONT_SAVE_TO_STORAGE }; 281 enum SaveOption { SAVE_TO_STORAGE, DONT_SAVE_TO_STORAGE };
280 282
281 ProfileSyncServiceBookmarkTest() 283 ProfileSyncServiceBookmarkTest()
282 : ui_thread_(BrowserThread::UI, &message_loop_), 284 : ui_thread_(BrowserThread::UI, &message_loop_),
283 file_thread_(BrowserThread::FILE, &message_loop_), 285 file_thread_(BrowserThread::FILE, &message_loop_),
284 model_(NULL) { 286 model_(NULL),
287 original_command_line_(*CommandLine::ForCurrentProcess()) {
285 } 288 }
286 289
287 virtual ~ProfileSyncServiceBookmarkTest() { 290 virtual ~ProfileSyncServiceBookmarkTest() {
288 StopSync(); 291 StopSync();
289 UnloadBookmarkModel(); 292 UnloadBookmarkModel();
290 } 293 }
291 294
292 virtual void SetUp() { 295 virtual void SetUp() {
293 test_user_share_.SetUp(); 296 test_user_share_.SetUp();
297 CommandLine::ForCurrentProcess()->AppendSwitch(
298 switches::kEnableSyncedBookmarksFolder);
294 } 299 }
295 300
296 virtual void TearDown() { 301 virtual void TearDown() {
297 test_user_share_.TearDown(); 302 test_user_share_.TearDown();
303 *CommandLine::ForCurrentProcess() = original_command_line_;
298 } 304 }
299 305
300 // Load (or re-load) the bookmark model. |load| controls use of the 306 // Load (or re-load) the bookmark model. |load| controls use of the
301 // bookmarks file on disk. |save| controls whether the newly loaded 307 // bookmarks file on disk. |save| controls whether the newly loaded
302 // bookmark model will write out a bookmark file as it goes. 308 // bookmark model will write out a bookmark file as it goes.
303 void LoadBookmarkModel(LoadOption load, SaveOption save) { 309 void LoadBookmarkModel(LoadOption load, SaveOption save) {
304 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; 310 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE;
305 profile_.CreateBookmarkModel(delete_bookmarks); 311 profile_.CreateBookmarkModel(delete_bookmarks);
306 model_ = profile_.GetBookmarkModel(); 312 model_ = profile_.GetBookmarkModel();
307 // Wait for the bookmarks model to load. 313 // Wait for the bookmarks model to load.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 sync_api::BaseNode* sync_node) { 358 sync_api::BaseNode* sync_node) {
353 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), 359 return model_associator_->InitSyncNodeFromChromeId(bnode->id(),
354 sync_node); 360 sync_node);
355 } 361 }
356 362
357 void ExpectSyncerNodeMatching(sync_api::BaseTransaction* trans, 363 void ExpectSyncerNodeMatching(sync_api::BaseTransaction* trans,
358 const BookmarkNode* bnode) { 364 const BookmarkNode* bnode) {
359 sync_api::ReadNode gnode(trans); 365 sync_api::ReadNode gnode(trans);
360 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode)); 366 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnode, &gnode));
361 // Non-root node titles and parents must match. 367 // Non-root node titles and parents must match.
362 if (bnode != model_->GetBookmarkBarNode() && 368 if (!model_->is_permanent_node(bnode)) {
363 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
373 // Check for position matches. 378 // Check for position matches.
(...skipping 78 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
494 private: 505 private:
495 // Used by both |ui_thread_| and |file_thread_|. 506 // Used by both |ui_thread_| and |file_thread_|.
496 MessageLoop message_loop_; 507 MessageLoop message_loop_;
497 BrowserThread ui_thread_; 508 BrowserThread ui_thread_;
498 // Needed by |model_|. 509 // Needed by |model_|.
499 BrowserThread file_thread_; 510 BrowserThread file_thread_;
500 511
501 TestingProfile profile_; 512 TestingProfile profile_;
502 scoped_ptr<TestBookmarkModelAssociator> model_associator_; 513 scoped_ptr<TestBookmarkModelAssociator> model_associator_;
503 514
504 protected: 515 protected:
505 BookmarkModel* model_; 516 BookmarkModel* model_;
517 CommandLine original_command_line_;
506 TestUserShare test_user_share_; 518 TestUserShare test_user_share_;
507 scoped_ptr<BookmarkChangeProcessor> change_processor_; 519 scoped_ptr<BookmarkChangeProcessor> change_processor_;
508 StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_; 520 StrictMock<MockUnrecoverableErrorHandler> mock_unrecoverable_error_handler_;
509 }; 521 };
510 522
511 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 523 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
512 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 524 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
513 StartSync(); 525 StartSync();
514 526
515 EXPECT_TRUE(other_bookmarks_id()); 527 EXPECT_TRUE(other_bookmarks_id());
516 EXPECT_TRUE(bookmark_bar_id()); 528 EXPECT_TRUE(bookmark_bar_id());
529 EXPECT_TRUE(synced_bookmarks_id());
517 530
518 ExpectModelMatch(); 531 ExpectModelMatch();
519 } 532 }
520 533
521 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) { 534 TEST_F(ProfileSyncServiceBookmarkTest, BookmarkModelOperations) {
522 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 535 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
523 StartSync(); 536 StartSync();
524 537
525 // Test addition. 538 // Test addition.
526 const BookmarkNode* folder = 539 const BookmarkNode* folder =
527 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar")); 540 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foobar"));
528 ExpectSyncerNodeMatching(folder); 541 ExpectSyncerNodeMatching(folder);
529 ExpectModelMatch(); 542 ExpectModelMatch();
530 const BookmarkNode* folder2 = 543 const BookmarkNode* folder2 =
531 model_->AddFolder(folder, 0, ASCIIToUTF16("nested")); 544 model_->AddFolder(folder, 0, ASCIIToUTF16("nested"));
532 ExpectSyncerNodeMatching(folder2); 545 ExpectSyncerNodeMatching(folder2);
533 ExpectModelMatch(); 546 ExpectModelMatch();
534 const BookmarkNode* url1 = model_->AddURL( 547 const BookmarkNode* url1 = model_->AddURL(
535 folder, 0, ASCIIToUTF16("Internets #1 Pies Site"), 548 folder, 0, ASCIIToUTF16("Internets #1 Pies Site"),
536 GURL("http://www.easypie.com/")); 549 GURL("http://www.easypie.com/"));
537 ExpectSyncerNodeMatching(url1); 550 ExpectSyncerNodeMatching(url1);
538 ExpectModelMatch(); 551 ExpectModelMatch();
539 const BookmarkNode* url2 = model_->AddURL( 552 const BookmarkNode* url2 = model_->AddURL(
540 folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/")); 553 folder, 1, ASCIIToUTF16("Airplanes"), GURL("http://www.easyjet.com/"));
541 ExpectSyncerNodeMatching(url2); 554 ExpectSyncerNodeMatching(url2);
542 ExpectModelMatch(); 555 ExpectModelMatch();
556 // Test addition.
557 const BookmarkNode* synced_folder =
558 model_->AddFolder(model_->synced_node(), 0, ASCIIToUTF16("pie"));
559 ExpectSyncerNodeMatching(synced_folder);
560 ExpectModelMatch();
543 561
544 // Test modification. 562 // Test modification.
545 model_->SetTitle(url2, ASCIIToUTF16("EasyJet")); 563 model_->SetTitle(url2, ASCIIToUTF16("EasyJet"));
546 ExpectModelMatch(); 564 ExpectModelMatch();
547 model_->Move(url1, folder2, 0); 565 model_->Move(url1, folder2, 0);
548 ExpectModelMatch(); 566 ExpectModelMatch();
549 model_->Move(folder2, model_->GetBookmarkBarNode(), 0); 567 model_->Move(folder2, model_->GetBookmarkBarNode(), 0);
550 ExpectModelMatch(); 568 ExpectModelMatch();
551 model_->SetTitle(folder2, ASCIIToUTF16("Not Nested")); 569 model_->SetTitle(folder2, ASCIIToUTF16("Not Nested"));
552 ExpectModelMatch(); 570 ExpectModelMatch();
553 model_->Move(folder, folder2, 0); 571 model_->Move(folder, folder2, 0);
554 ExpectModelMatch(); 572 ExpectModelMatch();
555 model_->SetTitle(folder, ASCIIToUTF16("who's nested now?")); 573 model_->SetTitle(folder, ASCIIToUTF16("who's nested now?"));
556 ExpectModelMatch(); 574 ExpectModelMatch();
557 model_->Copy(url2, model_->GetBookmarkBarNode(), 0); 575 model_->Copy(url2, model_->GetBookmarkBarNode(), 0);
558 ExpectModelMatch(); 576 ExpectModelMatch();
577 model_->SetTitle(synced_folder, ASCIIToUTF16("strawberry"));
578 ExpectModelMatch();
559 579
560 // Test deletion. 580 // Test deletion.
561 // Delete a single item. 581 // Delete a single item.
562 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2)); 582 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2));
563 ExpectModelMatch(); 583 ExpectModelMatch();
564 // Delete an item with several children. 584 // Delete an item with several children.
565 model_->Remove(folder2->parent(), 585 model_->Remove(folder2->parent(),
566 folder2->parent()->GetIndexOf(folder2)); 586 folder2->parent()->GetIndexOf(folder2));
567 ExpectModelMatch(); 587 ExpectModelMatch();
588 model_->Remove(model_->synced_node(), 0);
589 ExpectModelMatch();
568 } 590 }
569 591
570 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) { 592 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
571 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 593 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
572 StartSync(); 594 StartSync();
573 595
574 sync_api::WriteTransaction trans(test_user_share_.user_share()); 596 sync_api::WriteTransaction trans(test_user_share_.user_share());
575 597
576 FakeServerChange adds(&trans); 598 FakeServerChange adds(&trans);
577 int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0); 599 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); 600 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/", 601 int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/",
580 bookmark_bar_id(), f2); 602 bookmark_bar_id(), f2);
581 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0); 603 int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0);
582 // u3 is a duplicate URL 604 // u3 is a duplicate URL
583 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2); 605 int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2);
584 // u4 is a duplicate title, different URL. 606 // u4 is a duplicate title, different URL.
585 adds.AddURL(L"Some old site", "http://slog.thestranger.com/", 607 adds.AddURL(L"Some old site", "http://slog.thestranger.com/",
586 bookmark_bar_id(), u1); 608 bookmark_bar_id(), u1);
587 // u5 tests an empty-string title. 609 // u5 tests an empty-string title.
588 std::string javascript_url( 610 std::string javascript_url(
589 "javascript:(function(){var w=window.open(" \ 611 "javascript:(function(){var w=window.open(" \
590 "'about:blank','gnotesWin','location=0,menubar=0," \ 612 "'about:blank','gnotesWin','location=0,menubar=0," \
591 "scrollbars=0,status=0,toolbar=0,width=300," \ 613 "scrollbars=0,status=0,toolbar=0,width=300," \
592 "height=300,resizable');});"); 614 "height=300,resizable');});");
593 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0); 615 adds.AddURL(L"", javascript_url, other_bookmarks_id(), 0);
616 int64 u6 = adds.AddURL(L"Sync1", "http://www.syncable.edu/",
617 synced_bookmarks_id(), 0);
594 618
595 std::vector<sync_api::SyncManager::ChangeRecord>::const_iterator it; 619 std::vector<sync_api::SyncManager::ChangeRecord>::const_iterator it;
596 // The bookmark model shouldn't yet have seen any of the nodes of |adds|. 620 // 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) 621 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
598 ExpectBrowserNodeUnknown(it->id); 622 ExpectBrowserNodeUnknown(it->id);
599 623
600 adds.ApplyPendingChanges(change_processor_.get()); 624 adds.ApplyPendingChanges(change_processor_.get());
601 625
602 // Make sure the bookmark model received all of the nodes in |adds|. 626 // Make sure the bookmark model received all of the nodes in |adds|.
603 for (it = adds.changes().begin(); it != adds.changes().end(); ++it) 627 for (it = adds.changes().begin(); it != adds.changes().end(); ++it)
604 ExpectBrowserNodeMatching(&trans, it->id); 628 ExpectBrowserNodeMatching(&trans, it->id);
605 ExpectModelMatch(&trans); 629 ExpectModelMatch(&trans);
606 630
607 // Part two: test modifications. 631 // Part two: test modifications.
608 FakeServerChange mods(&trans); 632 FakeServerChange mods(&trans);
609 // Mess with u2, and move it into empty folder f2 633 // Mess with u2, and move it into empty folder f2
610 // TODO(ncarter): Determine if we allow ModifyURL ops or not. 634 // TODO(ncarter): Determine if we allow ModifyURL ops or not.
611 /* std::wstring u2_old_url = mods.ModifyURL(u2, L"http://www.google.com"); */ 635 /* 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"); 636 std::wstring u2_old_title = mods.ModifyTitle(u2, L"The Google");
613 int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0); 637 int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0);
614 638
615 // Now move f1 after u2. 639 // Now move f1 after u2.
616 std::wstring f1_old_title = mods.ModifyTitle(f1, L"Server Folder C"); 640 std::wstring f1_old_title = mods.ModifyTitle(f1, L"Server Folder C");
617 int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2); 641 int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2);
618 642
619 // Then add u3 after f1. 643 // Then add u3 after f1.
620 int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1); 644 int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1);
621 645
646 std::wstring u6_old_title = mods.ModifyTitle(u6, L"Synced Folder A");
647
622 // Test that the property changes have not yet taken effect. 648 // Test that the property changes have not yet taken effect.
623 ExpectBrowserNodeTitle(u2, u2_old_title); 649 ExpectBrowserNodeTitle(u2, u2_old_title);
624 /* ExpectBrowserNodeURL(u2, u2_old_url); */ 650 /* ExpectBrowserNodeURL(u2, u2_old_url); */
625 ExpectBrowserNodeParent(u2, u2_old_parent); 651 ExpectBrowserNodeParent(u2, u2_old_parent);
626 652
627 ExpectBrowserNodeTitle(f1, f1_old_title); 653 ExpectBrowserNodeTitle(f1, f1_old_title);
628 ExpectBrowserNodeParent(f1, f1_old_parent); 654 ExpectBrowserNodeParent(f1, f1_old_parent);
629 655
630 ExpectBrowserNodeParent(u3, u3_old_parent); 656 ExpectBrowserNodeParent(u3, u3_old_parent);
631 657
658 ExpectBrowserNodeTitle(u6, u6_old_title);
659
632 // Apply the changes. 660 // Apply the changes.
633 mods.ApplyPendingChanges(change_processor_.get()); 661 mods.ApplyPendingChanges(change_processor_.get());
634 662
635 // Check for successful application. 663 // Check for successful application.
636 for (it = mods.changes().begin(); it != mods.changes().end(); ++it) 664 for (it = mods.changes().begin(); it != mods.changes().end(); ++it)
637 ExpectBrowserNodeMatching(&trans, it->id); 665 ExpectBrowserNodeMatching(&trans, it->id);
638 ExpectModelMatch(&trans); 666 ExpectModelMatch(&trans);
639 667
640 // Part 3: Test URL deletion. 668 // Part 3: Test URL deletion.
641 FakeServerChange dels(&trans); 669 FakeServerChange dels(&trans);
642 dels.Delete(u2); 670 dels.Delete(u2);
643 dels.Delete(u3); 671 dels.Delete(u3);
672 dels.Delete(u6);
644 673
645 ExpectBrowserNodeKnown(u2); 674 ExpectBrowserNodeKnown(u2);
646 ExpectBrowserNodeKnown(u3); 675 ExpectBrowserNodeKnown(u3);
647 676
648 dels.ApplyPendingChanges(change_processor_.get()); 677 dels.ApplyPendingChanges(change_processor_.get());
649 678
650 ExpectBrowserNodeUnknown(u2); 679 ExpectBrowserNodeUnknown(u2);
651 ExpectBrowserNodeUnknown(u3); 680 ExpectBrowserNodeUnknown(u3);
681 ExpectBrowserNodeUnknown(u6);
652 ExpectModelMatch(&trans); 682 ExpectModelMatch(&trans);
653 } 683 }
654 684
655 // Tests a specific case in ApplyModelChanges where we move the 685 // Tests a specific case in ApplyModelChanges where we move the
656 // children out from under a parent, and then delete the parent 686 // children out from under a parent, and then delete the parent
657 // in the same changelist. The delete shows up first in the changelist, 687 // in the same changelist. The delete shows up first in the changelist,
658 // requiring the children to be moved to a temporary location. 688 // requiring the children to be moved to a temporary location.
659 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) { 689 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) {
660 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 690 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
661 StartSync(); 691 StartSync();
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 // | | |-- f1u2, http://www.f1u2.com/ 958 // | | |-- f1u2, http://www.f1u2.com/
929 // | | |-- f1u3, http://www.f1u3.com/ 959 // | | |-- f1u3, http://www.f1u3.com/
930 // | | +-- f1u1, http://www.f1u1.com/ 960 // | | +-- f1u1, http://www.f1u1.com/
931 // | |-- u1, http://www.u1.com/ 961 // | |-- u1, http://www.u1.com/
932 // | +-- f2 962 // | +-- f2
933 // | |-- f2u2, http://www.f2u2.com/ 963 // | |-- f2u2, http://www.f2u2.com/
934 // | |-- f2u4, http://www.f2u4.com/ 964 // | |-- f2u4, http://www.f2u4.com/
935 // | |-- f2u3, http://www.f2u3.com/ 965 // | |-- f2u3, http://www.f2u3.com/
936 // | +-- f2u1, http://www.f2u1.com/ 966 // | +-- f2u1, http://www.f2u1.com/
937 // +-- Other bookmarks 967 // +-- Other bookmarks
938 // |-- f3 968 // | |-- f3
939 // | |-- f3u4, http://www.f3u4.com/ 969 // | | |-- f3u4, http://www.f3u4.com/
940 // | |-- f3u2, http://www.f3u2.com/ 970 // | | |-- f3u2, http://www.f3u2.com/
941 // | |-- f3u3, http://www.f3u3.com/ 971 // | | |-- f3u3, http://www.f3u3.com/
942 // | +-- f3u1, http://www.f3u1.com/ 972 // | | +-- f3u1, http://www.f3u1.com/
943 // |-- u4, http://www.u4.com/ 973 // | |-- u4, http://www.u4.com/
944 // |-- u3, http://www.u3.com/ 974 // | |-- u3, http://www.u3.com/
945 // --- f4 975 // | --- f4
946 // | |-- f4u1, http://www.f4u1.com/ 976 // | | |-- f4u1, http://www.f4u1.com/
947 // | |-- f4u2, http://www.f4u2.com/ 977 // | | |-- f4u2, http://www.f4u2.com/
948 // | |-- f4u3, http://www.f4u3.com/ 978 // | | |-- f4u3, http://www.f4u3.com/
949 // | +-- f4u4, http://www.f4u4.com/ 979 // | | +-- f4u4, http://www.f4u4.com/
950 // |-- dup 980 // | |-- dup
951 // | +-- dupu1, http://www.dupu1.com/ 981 // | | +-- dupu1, http://www.dupu1.com/
952 // +-- dup 982 // | +-- dup
953 // +-- dupu2, http://www.dupu1.com/ 983 // | +-- dupu2, http://www.dupu1.com/
954 // 984 // |
985 // +-- Synced bookmarks
986 // |-- f5
987 // | |-- f5u1, http://www.f5u1.com/
988 // |-- f6
989 // | |-- f6u1, http://www.f6u1.com/
990 // | |-- f6u2, http://www.f6u2.com/
991 // +-- u5, http://www.u5.com/
992
955 static TestData kBookmarkBarChildren[] = { 993 static TestData kBookmarkBarChildren[] = {
956 { L"u2", "http://www.u2.com/" }, 994 { L"u2", "http://www.u2.com/" },
957 { L"f1", NULL }, 995 { L"f1", NULL },
958 { L"u1", "http://www.u1.com/" }, 996 { L"u1", "http://www.u1.com/" },
959 { L"f2", NULL }, 997 { L"f2", NULL },
960 }; 998 };
961 static TestData kF1Children[] = { 999 static TestData kF1Children[] = {
962 { L"f1u4", "http://www.f1u4.com/" }, 1000 { L"f1u4", "http://www.f1u4.com/" },
963 { L"f1u2", "http://www.f1u2.com/" }, 1001 { L"f1u2", "http://www.f1u2.com/" },
964 { L"f1u3", "http://www.f1u3.com/" }, 1002 { L"f1u3", "http://www.f1u3.com/" },
(...skipping 26 matching lines...) Expand all
991 { L"f4u3", "http://www.f4u3.com/" }, 1029 { L"f4u3", "http://www.f4u3.com/" },
992 { L"f4u4", "http://www.f4u4.com/" }, 1030 { L"f4u4", "http://www.f4u4.com/" },
993 }; 1031 };
994 static TestData kDup1Children[] = { 1032 static TestData kDup1Children[] = {
995 { L"dupu1", "http://www.dupu1.com/" }, 1033 { L"dupu1", "http://www.dupu1.com/" },
996 }; 1034 };
997 static TestData kDup2Children[] = { 1035 static TestData kDup2Children[] = {
998 { L"dupu2", "http://www.dupu2.com/" }, 1036 { L"dupu2", "http://www.dupu2.com/" },
999 }; 1037 };
1000 1038
1039 static TestData kSyncedBookmarkChildren[] = {
1040 { L"f5", NULL },
1041 { L"f6", NULL },
1042 { L"u5", "http://www.u5.com/" },
1043 };
1044 static TestData kF5Children[] = {
1045 { L"f5u1", "http://www.f5u1.com/" },
1046 { L"f5u2", "http://www.f5u2.com/" },
1047 };
1048 static TestData kF6Children[] = {
1049 { L"f6u1", "http://www.f6u1.com/" },
1050 { L"f6u2", "http://www.f6u2.com/" },
1051 };
1052
1001 } // anonymous namespace. 1053 } // anonymous namespace.
1002 1054
1003 void ProfileSyncServiceBookmarkTestWithData::PopulateFromTestData( 1055 void ProfileSyncServiceBookmarkTestWithData::PopulateFromTestData(
1004 const BookmarkNode* node, const TestData* data, int size) { 1056 const BookmarkNode* node, const TestData* data, int size) {
1005 DCHECK(node); 1057 DCHECK(node);
1006 DCHECK(data); 1058 DCHECK(data);
1007 DCHECK(node->is_folder()); 1059 DCHECK(node->is_folder());
1008 for (int i = 0; i < size; ++i) { 1060 for (int i = 0; i < size; ++i) {
1009 const TestData& item = data[i]; 1061 const TestData& item = data[i];
1010 if (item.url) { 1062 if (item.url) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 ASSERT_GE(other_bookmarks_node->child_count(), 6); 1110 ASSERT_GE(other_bookmarks_node->child_count(), 6);
1059 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); 1111 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0);
1060 PopulateFromTestData(f3_node, kF3Children, arraysize(kF3Children)); 1112 PopulateFromTestData(f3_node, kF3Children, arraysize(kF3Children));
1061 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); 1113 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3);
1062 PopulateFromTestData(f4_node, kF4Children, arraysize(kF4Children)); 1114 PopulateFromTestData(f4_node, kF4Children, arraysize(kF4Children));
1063 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); 1115 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4);
1064 PopulateFromTestData(dup_node, kDup1Children, arraysize(kDup1Children)); 1116 PopulateFromTestData(dup_node, kDup1Children, arraysize(kDup1Children));
1065 dup_node = other_bookmarks_node->GetChild(5); 1117 dup_node = other_bookmarks_node->GetChild(5);
1066 PopulateFromTestData(dup_node, kDup2Children, arraysize(kDup2Children)); 1118 PopulateFromTestData(dup_node, kDup2Children, arraysize(kDup2Children));
1067 1119
1120 const BookmarkNode* synced_bookmarks_node = model_->synced_node();
1121 PopulateFromTestData(synced_bookmarks_node,
1122 kSyncedBookmarkChildren,
1123 arraysize(kSyncedBookmarkChildren));
1124
1125 ASSERT_GE(synced_bookmarks_node->child_count(), 3);
1126 const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0);
1127 PopulateFromTestData(f5_node, kF5Children, arraysize(kF5Children));
1128 const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1);
1129 PopulateFromTestData(f6_node, kF6Children, arraysize(kF6Children));
1130
1068 ExpectBookmarkModelMatchesTestData(); 1131 ExpectBookmarkModelMatchesTestData();
1069 } 1132 }
1070 1133
1071 void ProfileSyncServiceBookmarkTestWithData:: 1134 void ProfileSyncServiceBookmarkTestWithData::
1072 ExpectBookmarkModelMatchesTestData() { 1135 ExpectBookmarkModelMatchesTestData() {
1073 const BookmarkNode* bookmark_bar_node = model_->GetBookmarkBarNode(); 1136 const BookmarkNode* bookmark_bar_node = model_->GetBookmarkBarNode();
1074 CompareWithTestData(bookmark_bar_node, 1137 CompareWithTestData(bookmark_bar_node,
1075 kBookmarkBarChildren, 1138 kBookmarkBarChildren,
1076 arraysize(kBookmarkBarChildren)); 1139 arraysize(kBookmarkBarChildren));
1077 1140
(...skipping 10 matching lines...) Expand all
1088 1151
1089 ASSERT_GE(other_bookmarks_node->child_count(), 6); 1152 ASSERT_GE(other_bookmarks_node->child_count(), 6);
1090 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0); 1153 const BookmarkNode* f3_node = other_bookmarks_node->GetChild(0);
1091 CompareWithTestData(f3_node, kF3Children, arraysize(kF3Children)); 1154 CompareWithTestData(f3_node, kF3Children, arraysize(kF3Children));
1092 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3); 1155 const BookmarkNode* f4_node = other_bookmarks_node->GetChild(3);
1093 CompareWithTestData(f4_node, kF4Children, arraysize(kF4Children)); 1156 CompareWithTestData(f4_node, kF4Children, arraysize(kF4Children));
1094 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4); 1157 const BookmarkNode* dup_node = other_bookmarks_node->GetChild(4);
1095 CompareWithTestData(dup_node, kDup1Children, arraysize(kDup1Children)); 1158 CompareWithTestData(dup_node, kDup1Children, arraysize(kDup1Children));
1096 dup_node = other_bookmarks_node->GetChild(5); 1159 dup_node = other_bookmarks_node->GetChild(5);
1097 CompareWithTestData(dup_node, kDup2Children, arraysize(kDup2Children)); 1160 CompareWithTestData(dup_node, kDup2Children, arraysize(kDup2Children));
1161
1162 const BookmarkNode* synced_bookmarks_node = model_->synced_node();
1163 CompareWithTestData(synced_bookmarks_node,
1164 kSyncedBookmarkChildren,
1165 arraysize(kSyncedBookmarkChildren));
1166
1167 ASSERT_GE(synced_bookmarks_node->child_count(), 3);
1168 const BookmarkNode* f5_node = synced_bookmarks_node->GetChild(0);
1169 CompareWithTestData(f5_node, kF5Children, arraysize(kF5Children));
1170 const BookmarkNode* f6_node = synced_bookmarks_node->GetChild(1);
1171 CompareWithTestData(f6_node, kF6Children, arraysize(kF6Children));
1172
1098 } 1173 }
1099 1174
1100 // Tests persistence of the profile sync service by unloading the 1175 // Tests persistence of the profile sync service by unloading the
1101 // database and then reloading it from disk. 1176 // database and then reloading it from disk.
1102 TEST_F(ProfileSyncServiceBookmarkTestWithData, Persistence) { 1177 TEST_F(ProfileSyncServiceBookmarkTestWithData, Persistence) {
1103 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); 1178 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
1104 StartSync(); 1179 StartSync();
1105 1180
1106 WriteTestDataToBookmarkModel(); 1181 WriteTestDataToBookmarkModel();
1107 1182
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 ExpectModelMatch(); 1229 ExpectModelMatch();
1155 1230
1156 // Force the databse to unload and write itself to disk. 1231 // Force the databse to unload and write itself to disk.
1157 StopSync(); 1232 StopSync();
1158 1233
1159 // Blow away the bookmark model -- it should be empty afterwards. 1234 // Blow away the bookmark model -- it should be empty afterwards.
1160 UnloadBookmarkModel(); 1235 UnloadBookmarkModel();
1161 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1236 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1162 EXPECT_EQ(model_->GetBookmarkBarNode()->child_count(), 0); 1237 EXPECT_EQ(model_->GetBookmarkBarNode()->child_count(), 0);
1163 EXPECT_EQ(model_->other_node()->child_count(), 0); 1238 EXPECT_EQ(model_->other_node()->child_count(), 0);
1239 EXPECT_EQ(model_->synced_node()->child_count(), 0);
1164 1240
1165 // Now restart the sync service. Starting it should populate the bookmark 1241 // Now restart the sync service. Starting it should populate the bookmark
1166 // model -- test for consistency. 1242 // model -- test for consistency.
1167 StartSync(); 1243 StartSync();
1168 ExpectBookmarkModelMatchesTestData(); 1244 ExpectBookmarkModelMatchesTestData();
1169 ExpectModelMatch(); 1245 ExpectModelMatch();
1170 } 1246 }
1171 1247
1172 // Tests the merge cases when both the models are expected to be identical 1248 // Tests the merge cases when both the models are expected to be identical
1173 // after the merge. 1249 // 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 1429 // 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 1430 // to reauthenticate before this happens, but in the test, authentication
1355 // is sidestepped. 1431 // is sidestepped.
1356 ExpectBookmarkModelMatchesTestData(); 1432 ExpectBookmarkModelMatchesTestData();
1357 ExpectModelMatch(); 1433 ExpectModelMatch();
1358 } 1434 }
1359 1435
1360 } // namespace 1436 } // namespace
1361 1437
1362 } // namespace browser_sync 1438 } // 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