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

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

Issue 1705813002: Remove //chrome and //content deps from ProfileSyncServiceBookmarkTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@586642_pre-clean-up
Patch Set: Just rebased Created 4 years, 10 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
« no previous file with comments | « no previous file | components/browser_sync.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // 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 <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include <map> 12 #include <map>
13 #include <queue> 13 #include <queue>
14 #include <stack> 14 #include <stack>
15 #include <utility>
15 16
17 #include "base/bind.h"
18 #include "base/bind_helpers.h"
19 #include "base/files/file_util.h"
16 #include "base/location.h" 20 #include "base/location.h"
17 #include "base/macros.h" 21 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
19 #include "base/run_loop.h" 23 #include "base/run_loop.h"
20 #include "base/strings/string16.h" 24 #include "base/strings/string16.h"
21 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 26 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
25 #include "base/time/time.h" 29 #include "base/time/time.h"
26 #include "build/build_config.h" 30 #include "build/build_config.h"
27 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
28 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
29 #include "chrome/browser/favicon/favicon_service_factory.h"
30 #include "chrome/browser/history/history_service_factory.h"
31 #include "chrome/test/base/testing_profile.h"
32 #include "components/bookmarks/browser/base_bookmark_model_observer.h" 31 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
33 #include "components/bookmarks/browser/bookmark_model.h" 32 #include "components/bookmarks/browser/bookmark_model.h"
33 #include "components/bookmarks/browser/bookmark_utils.h"
34 #include "components/bookmarks/managed/managed_bookmark_service.h" 34 #include "components/bookmarks/managed/managed_bookmark_service.h"
35 #include "components/bookmarks/test/bookmark_test_helpers.h" 35 #include "components/bookmarks/test/bookmark_test_helpers.h"
36 #include "components/bookmarks/test/test_bookmark_client.h"
37 #include "components/browser_sync/browser/profile_sync_test_util.h"
36 #include "components/sync_bookmarks/bookmark_change_processor.h" 38 #include "components/sync_bookmarks/bookmark_change_processor.h"
37 #include "components/sync_bookmarks/bookmark_model_associator.h" 39 #include "components/sync_bookmarks/bookmark_model_associator.h"
38 #include "components/sync_driver/data_type_error_handler.h" 40 #include "components/sync_driver/data_type_error_handler.h"
39 #include "components/sync_driver/data_type_error_handler_mock.h" 41 #include "components/sync_driver/data_type_error_handler_mock.h"
40 #include "components/sync_driver/fake_sync_client.h" 42 #include "components/sync_driver/fake_sync_client.h"
41 #include "content/public/test/test_browser_thread_bundle.h"
42 #include "sync/api/sync_error.h" 43 #include "sync/api/sync_error.h"
43 #include "sync/api/sync_merge_result.h" 44 #include "sync/api/sync_merge_result.h"
44 #include "sync/internal_api/public/change_record.h" 45 #include "sync/internal_api/public/change_record.h"
45 #include "sync/internal_api/public/read_node.h" 46 #include "sync/internal_api/public/read_node.h"
46 #include "sync/internal_api/public/read_transaction.h" 47 #include "sync/internal_api/public/read_transaction.h"
47 #include "sync/internal_api/public/test/test_user_share.h" 48 #include "sync/internal_api/public/test/test_user_share.h"
48 #include "sync/internal_api/public/write_node.h" 49 #include "sync/internal_api/public/write_node.h"
49 #include "sync/internal_api/public/write_transaction.h" 50 #include "sync/internal_api/public/write_transaction.h"
50 #include "sync/internal_api/syncapi_internal.h" 51 #include "sync/internal_api/syncapi_internal.h"
51 #include "sync/syncable/mutable_entry.h" 52 #include "sync/syncable/mutable_entry.h"
52 #include "sync/syncable/syncable_id.h" 53 #include "sync/syncable/syncable_id.h"
53 #include "sync/syncable/syncable_util.h" 54 #include "sync/syncable/syncable_util.h"
54 #include "sync/syncable/syncable_write_transaction.h" 55 #include "sync/syncable/syncable_write_transaction.h"
55 #include "testing/gmock/include/gmock/gmock.h" 56 #include "testing/gmock/include/gmock/gmock.h"
56 #include "testing/gtest/include/gtest/gtest.h" 57 #include "testing/gtest/include/gtest/gtest.h"
57 58
58 namespace browser_sync {
59
60 using bookmarks::BookmarkModel; 59 using bookmarks::BookmarkModel;
61 using bookmarks::BookmarkNode; 60 using bookmarks::BookmarkNode;
62 using syncer::BaseNode; 61 using syncer::BaseNode;
63 using testing::_; 62 using testing::_;
64 using testing::Return; 63 using testing::Return;
65 using testing::StrictMock; 64 using testing::StrictMock;
66 65
66 namespace browser_sync {
67
68 namespace {
69
67 #if defined(OS_ANDROID) || defined(OS_IOS) 70 #if defined(OS_ANDROID) || defined(OS_IOS)
68 static const bool kExpectMobileBookmarks = true; 71 static const bool kExpectMobileBookmarks = true;
69 #else 72 #else
70 static const bool kExpectMobileBookmarks = false; 73 static const bool kExpectMobileBookmarks = false;
71 #endif // defined(OS_ANDROID) || defined(OS_IOS) 74 #endif // defined(OS_ANDROID) || defined(OS_IOS)
72 75
73 namespace { 76 std::string ReturnEmptyString() {
77 return std::string();
78 }
74 79
75 void MakeServerUpdate(syncer::WriteTransaction* trans, 80 void MakeServerUpdate(syncer::WriteTransaction* trans,
76 syncer::WriteNode* node) { 81 syncer::WriteNode* node) {
77 syncer::syncable::ChangeEntryIDAndUpdateChildren( 82 syncer::syncable::ChangeEntryIDAndUpdateChildren(
78 trans->GetWrappedWriteTrans(), node->GetMutableEntryForTest(), 83 trans->GetWrappedWriteTrans(), node->GetMutableEntryForTest(),
79 syncer::syncable::Id::CreateFromServerId( 84 syncer::syncable::Id::CreateFromServerId(
80 base::Int64ToString(node->GetId()))); 85 base::Int64ToString(node->GetId())));
81 node->GetMutableEntryForTest()->PutBaseVersion(10); 86 node->GetMutableEntryForTest()->PutBaseVersion(10);
82 node->GetMutableEntryForTest()->PutIsUnappliedUpdate(true); 87 node->GetMutableEntryForTest()->PutIsUnappliedUpdate(true);
83 } 88 }
84 89
85 void MakeServerUpdate(syncer::WriteTransaction* trans, int64_t id) { 90 void MakeServerUpdate(syncer::WriteTransaction* trans, int64_t id) {
86 syncer::WriteNode node(trans); 91 syncer::WriteNode node(trans);
87 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 92 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
88 MakeServerUpdate(trans, &node); 93 MakeServerUpdate(trans, &node);
89 } 94 }
90 95
91 class TestSyncClient : public sync_driver::FakeSyncClient {
92 public:
93 explicit TestSyncClient(Profile* profile) : profile_(profile) {}
94
95 BookmarkModel* GetBookmarkModel() override {
96 return BookmarkModelFactory::GetForProfile(profile_);
97 }
98
99 favicon::FaviconService* GetFaviconService() override {
100 return FaviconServiceFactory::GetForProfile(
101 profile_, ServiceAccessType::EXPLICIT_ACCESS);
102 }
103
104 history::HistoryService* GetHistoryService() override {
105 return HistoryServiceFactory::GetForProfile(
106 profile_, ServiceAccessType::EXPLICIT_ACCESS);
107 }
108
109 private:
110 Profile* profile_;
111 };
112
113 // FakeServerChange constructs a list of syncer::ChangeRecords while modifying 96 // FakeServerChange constructs a list of syncer::ChangeRecords while modifying
114 // the sync model, and can pass the ChangeRecord list to a 97 // the sync model, and can pass the ChangeRecord list to a
115 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client 98 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client
116 // change-application behavior. 99 // change-application behavior.
117 // Tests using FakeServerChange should be careful to avoid back-references, 100 // Tests using FakeServerChange should be careful to avoid back-references,
118 // since FakeServerChange will send the edits in the order specified. 101 // since FakeServerChange will send the edits in the order specified.
119 class FakeServerChange { 102 class FakeServerChange {
120 public: 103 public:
121 explicit FakeServerChange(syncer::WriteTransaction* trans) : trans_(trans) { 104 explicit FakeServerChange(syncer::WriteTransaction* trans) : trans_(trans) {
122 } 105 }
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 344 }
362 345
363 private: 346 private:
364 int started_count_; 347 int started_count_;
365 int completed_count_at_started_; 348 int completed_count_at_started_;
366 int completed_count_; 349 int completed_count_;
367 350
368 DISALLOW_COPY_AND_ASSIGN(ExtensiveChangesBookmarkModelObserver); 351 DISALLOW_COPY_AND_ASSIGN(ExtensiveChangesBookmarkModelObserver);
369 }; 352 };
370 353
371
372 class ProfileSyncServiceBookmarkTest : public testing::Test { 354 class ProfileSyncServiceBookmarkTest : public testing::Test {
373 protected: 355 protected:
374 enum LoadOption { LOAD_FROM_STORAGE, DELETE_EXISTING_STORAGE }; 356 enum LoadOption { LOAD_FROM_STORAGE, DELETE_EXISTING_STORAGE };
375 enum SaveOption { SAVE_TO_STORAGE, DONT_SAVE_TO_STORAGE }; 357 enum SaveOption { SAVE_TO_STORAGE, DONT_SAVE_TO_STORAGE };
376 358
377 ProfileSyncServiceBookmarkTest() 359 ProfileSyncServiceBookmarkTest()
378 : sync_client_(&profile_), 360 : managed_bookmark_service_(new bookmarks::ManagedBookmarkService(
379 model_(NULL), 361 profile_sync_service_bundle_.pref_service(),
362 base::Bind(ReturnEmptyString))),
380 local_merge_result_(syncer::BOOKMARKS), 363 local_merge_result_(syncer::BOOKMARKS),
381 syncer_merge_result_(syncer::BOOKMARKS) {} 364 syncer_merge_result_(syncer::BOOKMARKS) {
365 CHECK(data_dir_.CreateUniqueTempDir());
366 browser_sync::ProfileSyncServiceBundle::SyncClientBuilder builder(
367 &profile_sync_service_bundle_);
368 builder.SetBookmarkModelCallback(base::Bind(
369 &ProfileSyncServiceBookmarkTest::model, base::Unretained(this)));
370 sync_client_ = builder.Build();
371 bookmarks::RegisterProfilePrefs(
372 profile_sync_service_bundle_.pref_service()->registry());
373 }
382 374
383 ~ProfileSyncServiceBookmarkTest() override { 375 ~ProfileSyncServiceBookmarkTest() override {
376 static_cast<KeyedService*>(managed_bookmark_service_.get())->Shutdown();
384 StopSync(); 377 StopSync();
385 UnloadBookmarkModel();
386 } 378 }
387 379
388 void SetUp() override { test_user_share_.SetUp(); } 380 void SetUp() override { test_user_share_.SetUp(); }
389 381
390 void TearDown() override { test_user_share_.TearDown(); } 382 void TearDown() override { test_user_share_.TearDown(); }
391 383
392 bool CanSyncNode(const BookmarkNode* node) { 384 bool CanSyncNode(const BookmarkNode* node) {
393 return model_->client()->CanSyncNode(node); 385 return model_->client()->CanSyncNode(node);
394 } 386 }
395 387
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 433
442 syncer::WriteNode node(trans); 434 syncer::WriteNode node(trans);
443 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); 435 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL));
444 node.SetIsFolder(false); 436 node.SetIsFolder(false);
445 node.SetTitle(title); 437 node.SetTitle(title);
446 node.SetBookmarkSpecifics(specifics); 438 node.SetBookmarkSpecifics(specifics);
447 439
448 return node.GetId(); 440 return node.GetId();
449 } 441 }
450 442
443 // Create a BookmarkModel. If |delete_bookmarks| is true, the bookmarks file
444 // will be deleted before starting up the BookmarkModel.
445 scoped_ptr<BookmarkModel> CreateBookmarkModel(bool delete_bookmarks) {
446 const base::FilePath& data_path = data_dir_.path();
447 auto model = make_scoped_ptr<BookmarkModel>(new BookmarkModel(
448 make_scoped_ptr(new bookmarks::TestBookmarkClient())));
449 managed_bookmark_service_->BookmarkModelCreated(model.get());
450 int64_t next_id = 0;
451 static_cast<bookmarks::TestBookmarkClient*>(model->client())
452 ->SetExtraNodesToLoad(
453 managed_bookmark_service_->GetLoadExtraNodesCallback().Run(
454 &next_id));
455 if (delete_bookmarks) {
456 base::DeleteFile(data_path.Append(FILE_PATH_LITERAL("dummy_bookmarks")),
457 false);
458 }
459
460 model->Load(profile_sync_service_bundle_.pref_service(), std::string(),
461 data_path, base::ThreadTaskRunnerHandle::Get(),
462 base::ThreadTaskRunnerHandle::Get());
463 bookmarks::test::WaitForBookmarkModelToLoad(model.get());
464 return model;
465 }
466
451 // Load (or re-load) the bookmark model. |load| controls use of the 467 // Load (or re-load) the bookmark model. |load| controls use of the
452 // bookmarks file on disk. |save| controls whether the newly loaded 468 // bookmarks file on disk. |save| controls whether the newly loaded
453 // bookmark model will write out a bookmark file as it goes. 469 // bookmark model will write out a bookmark file as it goes.
454 void LoadBookmarkModel(LoadOption load, SaveOption save) { 470 void LoadBookmarkModel(LoadOption load, SaveOption save) {
455 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; 471 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE;
456 profile_.CreateBookmarkModel(delete_bookmarks); 472 model_.reset();
457 model_ = BookmarkModelFactory::GetForProfile(&profile_); 473 model_ = CreateBookmarkModel(delete_bookmarks);
458 bookmarks::test::WaitForBookmarkModelToLoad(model_);
459 // This noticeably speeds up the unit tests that request it. 474 // This noticeably speeds up the unit tests that request it.
460 if (save == DONT_SAVE_TO_STORAGE) 475 if (save == DONT_SAVE_TO_STORAGE)
461 model_->ClearStore(); 476 model_->ClearStore();
462 base::MessageLoop::current()->RunUntilIdle(); 477 base::MessageLoop::current()->RunUntilIdle();
463 } 478 }
464 479
465 int GetSyncBookmarkCount() { 480 int GetSyncBookmarkCount() {
466 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 481 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
467 syncer::ReadNode node(&trans); 482 syncer::ReadNode node(&trans);
468 if (node.InitTypeRoot(syncer::BOOKMARKS) != BaseNode::INIT_OK) 483 if (node.InitTypeRoot(syncer::BOOKMARKS) != BaseNode::INIT_OK)
(...skipping 17 matching lines...) Expand all
486 } 501 }
487 502
488 if (!root_exists) { 503 if (!root_exists) {
489 if (!syncer::TestUserShare::CreateRoot(type, 504 if (!syncer::TestUserShare::CreateRoot(type,
490 test_user_share_.user_share())) 505 test_user_share_.user_share()))
491 return false; 506 return false;
492 } 507 }
493 508
494 const int kNumPermanentNodes = 3; 509 const int kNumPermanentNodes = 3;
495 const std::string permanent_tags[kNumPermanentNodes] = { 510 const std::string permanent_tags[kNumPermanentNodes] = {
496 #if defined(OS_IOS) || defined(OS_ANDROID) 511 "bookmark_bar", "other_bookmarks", "synced_bookmarks",
497 "synced_bookmarks",
498 #endif // defined(OS_IOS) || defined(OS_ANDROID)
499 "bookmark_bar",
500 "other_bookmarks",
501 #if !defined(OS_IOS) && !defined(OS_ANDROID)
502 "synced_bookmarks",
503 #endif // !defined(OS_IOS) && !defined(OS_ANDROID)
504 }; 512 };
505 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 513 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
506 syncer::ReadNode root(&trans); 514 syncer::ReadNode root(&trans);
507 EXPECT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(type)); 515 EXPECT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(type));
508 516
509 // Loop through creating permanent nodes as necessary. 517 // Loop through creating permanent nodes as necessary.
510 int64_t last_child_id = syncer::kInvalidId; 518 int64_t last_child_id = syncer::kInvalidId;
511 for (int i = 0; i < kNumPermanentNodes; ++i) { 519 for (int i = 0; i < kNumPermanentNodes; ++i) {
512 // First check if the node already exists. This is for tests that involve 520 // First check if the node already exists. This is for tests that involve
513 // persistence and set up sync more than once. 521 // persistence and set up sync more than once.
(...skipping 23 matching lines...) Expand all
537 last_child_id = node.GetId(); 545 last_child_id = node.GetId();
538 } 546 }
539 return true; 547 return true;
540 } 548 }
541 549
542 bool AssociateModels() { 550 bool AssociateModels() {
543 DCHECK(!model_associator_); 551 DCHECK(!model_associator_);
544 552
545 // Set up model associator. 553 // Set up model associator.
546 model_associator_.reset(new BookmarkModelAssociator( 554 model_associator_.reset(new BookmarkModelAssociator(
547 BookmarkModelFactory::GetForProfile(&profile_), &sync_client_, 555 model_.get(), sync_client_.get(), test_user_share_.user_share(),
548 test_user_share_.user_share(), &mock_error_handler_, 556 &mock_error_handler_, kExpectMobileBookmarks));
549 kExpectMobileBookmarks));
550 557
551 local_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS); 558 local_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS);
552 syncer_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS); 559 syncer_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS);
553 int local_count_before = model_->root_node()->GetTotalNodeCount(); 560 int local_count_before = model_->root_node()->GetTotalNodeCount();
554 int syncer_count_before = GetSyncBookmarkCount(); 561 int syncer_count_before = GetSyncBookmarkCount();
555 562
556 syncer::SyncError error = model_associator_->AssociateModels( 563 syncer::SyncError error = model_associator_->AssociateModels(
557 &local_merge_result_, 564 &local_merge_result_,
558 &syncer_merge_result_); 565 &syncer_merge_result_);
559 if (error.IsSet()) 566 if (error.IsSet())
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 607 }
601 model_associator_.reset(); 608 model_associator_.reset();
602 609
603 base::RunLoop().RunUntilIdle(); 610 base::RunLoop().RunUntilIdle();
604 611
605 // TODO(akalin): Actually close the database and flush it to disk 612 // TODO(akalin): Actually close the database and flush it to disk
606 // (and make StartSync reload from disk). This would require 613 // (and make StartSync reload from disk). This would require
607 // refactoring TestUserShare. 614 // refactoring TestUserShare.
608 } 615 }
609 616
610 void UnloadBookmarkModel() {
611 profile_.CreateBookmarkModel(false /* delete_bookmarks */);
612 model_ = NULL;
613 base::MessageLoop::current()->RunUntilIdle();
614 }
615
616 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode, 617 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode,
617 BaseNode* sync_node) { 618 BaseNode* sync_node) {
618 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), 619 return model_associator_->InitSyncNodeFromChromeId(bnode->id(),
619 sync_node); 620 sync_node);
620 } 621 }
621 622
622 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans, 623 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans,
623 const BookmarkNode* bnode) { 624 const BookmarkNode* bnode) {
624 std::string truncated_title = base::UTF16ToUTF8(bnode->GetTitle()); 625 std::string truncated_title = base::UTF16ToUTF8(bnode->GetTitle());
625 syncer::SyncAPINameToServerName(truncated_title, &truncated_title); 626 syncer::SyncAPINameToServerName(truncated_title, &truncated_title);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 model_associator_->GetChromeNodeFromSyncId(sync_id); 740 model_associator_->GetChromeNodeFromSyncId(sync_id);
740 ASSERT_TRUE(node); 741 ASSERT_TRUE(node);
741 const BookmarkNode* parent = 742 const BookmarkNode* parent =
742 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); 743 model_associator_->GetChromeNodeFromSyncId(parent_sync_id);
743 EXPECT_TRUE(parent); 744 EXPECT_TRUE(parent);
744 EXPECT_EQ(node->parent(), parent); 745 EXPECT_EQ(node->parent(), parent);
745 } 746 }
746 747
747 void ExpectModelMatch(syncer::BaseTransaction* trans) { 748 void ExpectModelMatch(syncer::BaseTransaction* trans) {
748 const BookmarkNode* root = model_->root_node(); 749 const BookmarkNode* root = model_->root_node();
749 #if defined(OS_IOS) || defined(OS_ANDROID)
750 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 0);
751 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 1);
752 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 2);
753 #else
754 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0); 750 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0);
755 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); 751 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1);
756 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2); 752 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2);
757 #endif // defined(OS_IOS) || defined(OS_ANDROID)
758 753
759 std::stack<int64_t> stack; 754 std::stack<int64_t> stack;
760 stack.push(bookmark_bar_id()); 755 stack.push(bookmark_bar_id());
761 while (!stack.empty()) { 756 while (!stack.empty()) {
762 int64_t id = stack.top(); 757 int64_t id = stack.top();
763 stack.pop(); 758 stack.pop();
764 if (!id) continue; 759 if (!id) continue;
765 760
766 ExpectBrowserNodeMatching(trans, id); 761 ExpectBrowserNodeMatching(trans, id);
767 762
(...skipping 18 matching lines...) Expand all
786 int64_t other_bookmarks_id() { 781 int64_t other_bookmarks_id() {
787 return 782 return
788 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id()); 783 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id());
789 } 784 }
790 785
791 int64_t bookmark_bar_id() { 786 int64_t bookmark_bar_id() {
792 return model_associator_->GetSyncIdFromChromeId( 787 return model_associator_->GetSyncIdFromChromeId(
793 model_->bookmark_bar_node()->id()); 788 model_->bookmark_bar_node()->id());
794 } 789 }
795 790
796 BookmarkModel* model() { return model_; } 791 BookmarkModel* model() { return model_.get(); }
797 792
798 syncer::TestUserShare* test_user_share() { return &test_user_share_; } 793 syncer::TestUserShare* test_user_share() { return &test_user_share_; }
799 794
800 BookmarkChangeProcessor* change_processor() { 795 BookmarkChangeProcessor* change_processor() {
801 return change_processor_.get(); 796 return change_processor_.get();
802 } 797 }
803 798
804 void delete_change_processor() { change_processor_.reset(); } 799 void delete_change_processor() { change_processor_.reset(); }
805 800
806 void ResetChangeProcessor() { 801 void ResetChangeProcessor() {
807 change_processor_ = make_scoped_ptr(new BookmarkChangeProcessor( 802 change_processor_ = make_scoped_ptr(new BookmarkChangeProcessor(
808 &sync_client_, model_associator_.get(), &mock_error_handler_)); 803 sync_client_.get(), model_associator_.get(), &mock_error_handler_));
809 } 804 }
810 805
811 sync_driver::DataTypeErrorHandlerMock* mock_error_handler() { 806 sync_driver::DataTypeErrorHandlerMock* mock_error_handler() {
812 return &mock_error_handler_; 807 return &mock_error_handler_;
813 } 808 }
814 809
815 void delete_model_associator() { model_associator_.reset(); } 810 void delete_model_associator() { model_associator_.reset(); }
816 811
817 BookmarkModelAssociator* model_associator() { 812 BookmarkModelAssociator* model_associator() {
818 return model_associator_.get(); 813 return model_associator_.get();
819 } 814 }
820 815
821 bookmarks::ManagedBookmarkService* GetManagedBookmarkService() { 816 bookmarks::ManagedBookmarkService* managed_bookmark_service() {
822 return ManagedBookmarkServiceFactory::GetForProfile(&profile_); 817 return managed_bookmark_service_.get();
823 } 818 }
824 819
825 private: 820 private:
826 content::TestBrowserThreadBundle thread_bundle_; 821 base::ScopedTempDir data_dir_;
822 base::MessageLoop message_loop_;
823 browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_;
827 824
828 TestingProfile profile_; 825 scoped_ptr<sync_driver::FakeSyncClient> sync_client_;
829 TestSyncClient sync_client_; 826 scoped_ptr<BookmarkModel> model_;
830 BookmarkModel* model_;
831 syncer::TestUserShare test_user_share_; 827 syncer::TestUserShare test_user_share_;
832 scoped_ptr<BookmarkChangeProcessor> change_processor_; 828 scoped_ptr<BookmarkChangeProcessor> change_processor_;
833 StrictMock<sync_driver::DataTypeErrorHandlerMock> mock_error_handler_; 829 StrictMock<sync_driver::DataTypeErrorHandlerMock> mock_error_handler_;
834 scoped_ptr<BookmarkModelAssociator> model_associator_; 830 scoped_ptr<BookmarkModelAssociator> model_associator_;
831 scoped_ptr<bookmarks::ManagedBookmarkService> managed_bookmark_service_;
835 832
836 syncer::SyncMergeResult local_merge_result_; 833 syncer::SyncMergeResult local_merge_result_;
837 syncer::SyncMergeResult syncer_merge_result_; 834 syncer::SyncMergeResult syncer_merge_result_;
838 835
839 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceBookmarkTest); 836 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceBookmarkTest);
840 }; 837 };
841 838
842 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 839 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
843 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 840 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
844 StartSync(); 841 StartSync();
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 StartSync(); 1927 StartSync();
1931 1928
1932 WriteTestDataToBookmarkModel(); 1929 WriteTestDataToBookmarkModel();
1933 1930
1934 ExpectModelMatch(); 1931 ExpectModelMatch();
1935 1932
1936 // Force both models to discard their data and reload from disk. This 1933 // Force both models to discard their data and reload from disk. This
1937 // simulates what would happen if the browser were to shutdown normally, 1934 // simulates what would happen if the browser were to shutdown normally,
1938 // and then relaunch. 1935 // and then relaunch.
1939 StopSync(); 1936 StopSync();
1940 UnloadBookmarkModel();
1941 LoadBookmarkModel(LOAD_FROM_STORAGE, SAVE_TO_STORAGE); 1937 LoadBookmarkModel(LOAD_FROM_STORAGE, SAVE_TO_STORAGE);
1942 StartSync(); 1938 StartSync();
1943 1939
1944 ExpectBookmarkModelMatchesTestData(); 1940 ExpectBookmarkModelMatchesTestData();
1945 1941
1946 // With the BookmarkModel contents verified, ExpectModelMatch will 1942 // With the BookmarkModel contents verified, ExpectModelMatch will
1947 // verify the contents of the sync model. 1943 // verify the contents of the sync model.
1948 ExpectModelMatch(); 1944 ExpectModelMatch();
1949 } 1945 }
1950 1946
(...skipping 25 matching lines...) Expand all
1976 StartSync(); 1972 StartSync();
1977 1973
1978 WriteTestDataToBookmarkModel(); 1974 WriteTestDataToBookmarkModel();
1979 1975
1980 ExpectModelMatch(); 1976 ExpectModelMatch();
1981 1977
1982 // Force the databse to unload and write itself to disk. 1978 // Force the databse to unload and write itself to disk.
1983 StopSync(); 1979 StopSync();
1984 1980
1985 // Blow away the bookmark model -- it should be empty afterwards. 1981 // Blow away the bookmark model -- it should be empty afterwards.
1986 UnloadBookmarkModel();
1987 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1982 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1988 EXPECT_EQ(model()->bookmark_bar_node()->child_count(), 0); 1983 EXPECT_EQ(model()->bookmark_bar_node()->child_count(), 0);
1989 EXPECT_EQ(model()->other_node()->child_count(), 0); 1984 EXPECT_EQ(model()->other_node()->child_count(), 0);
1990 EXPECT_EQ(model()->mobile_node()->child_count(), 0); 1985 EXPECT_EQ(model()->mobile_node()->child_count(), 0);
1991 1986
1992 // Now restart the sync service. Starting it should populate the bookmark 1987 // Now restart the sync service. Starting it should populate the bookmark
1993 // model -- test for consistency. 1988 // model -- test for consistency.
1994 StartSync(); 1989 StartSync();
1995 ExpectBookmarkModelMatchesTestData(); 1990 ExpectBookmarkModelMatchesTestData();
1996 ExpectModelMatch(); 1991 ExpectModelMatch();
1997 } 1992 }
1998 1993
1999 // Tests the merge cases when both the models are expected to be identical 1994 // Tests the merge cases when both the models are expected to be identical
2000 // after the merge. 1995 // after the merge.
2001 TEST_F(ProfileSyncServiceBookmarkTestWithData, MergeExpectedIdenticalModels) { 1996 TEST_F(ProfileSyncServiceBookmarkTestWithData, MergeExpectedIdenticalModels) {
2002 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); 1997 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
2003 StartSync(); 1998 StartSync();
2004 WriteTestDataToBookmarkModel(); 1999 WriteTestDataToBookmarkModel();
2005 ExpectModelMatch(); 2000 ExpectModelMatch();
2006 StopSync(); 2001 StopSync();
2007 UnloadBookmarkModel();
2008 2002
2009 // At this point both the bookmark model and the server should have the 2003 // At this point both the bookmark model and the server should have the
2010 // exact same data and it should match the test data. 2004 // exact same data and it should match the test data.
2011 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE); 2005 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE);
2012 StartSync(); 2006 StartSync();
2013 ExpectBookmarkModelMatchesTestData(); 2007 ExpectBookmarkModelMatchesTestData();
2014 ExpectModelMatch(); 2008 ExpectModelMatch();
2015 StopSync(); 2009 StopSync();
2016 UnloadBookmarkModel();
2017 2010
2018 // Now reorder some bookmarks in the bookmark model and then merge. Make 2011 // Now reorder some bookmarks in the bookmark model and then merge. Make
2019 // sure we get the order of the server after merge. 2012 // sure we get the order of the server after merge.
2020 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE); 2013 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE);
2021 ExpectBookmarkModelMatchesTestData(); 2014 ExpectBookmarkModelMatchesTestData();
2022 const BookmarkNode* bookmark_bar = model()->bookmark_bar_node(); 2015 const BookmarkNode* bookmark_bar = model()->bookmark_bar_node();
2023 ASSERT_TRUE(bookmark_bar); 2016 ASSERT_TRUE(bookmark_bar);
2024 ASSERT_GT(bookmark_bar->child_count(), 1); 2017 ASSERT_GT(bookmark_bar->child_count(), 1);
2025 model()->Move(bookmark_bar->GetChild(0), bookmark_bar, 1); 2018 model()->Move(bookmark_bar->GetChild(0), bookmark_bar, 1);
2026 StartSync(); 2019 StartSync();
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
2608 2601
2609 // Verify operations on native nodes that shouldn't be propagated to Sync. 2602 // Verify operations on native nodes that shouldn't be propagated to Sync.
2610 TEST_F(ProfileSyncServiceBookmarkTest, TestUnsupportedNodes) { 2603 TEST_F(ProfileSyncServiceBookmarkTest, TestUnsupportedNodes) {
2611 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 2604 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
2612 StartSync(); 2605 StartSync();
2613 2606
2614 // Initial number of bookmarks on the sync side. 2607 // Initial number of bookmarks on the sync side.
2615 int sync_bookmark_count = GetSyncBookmarkCount(); 2608 int sync_bookmark_count = GetSyncBookmarkCount();
2616 2609
2617 // Create a bookmark under managed_node() permanent folder. 2610 // Create a bookmark under managed_node() permanent folder.
2618 bookmarks::ManagedBookmarkService* managed_bookmark_service = 2611 const BookmarkNode* folder = managed_bookmark_service()->managed_node();
2619 GetManagedBookmarkService();
2620 const BookmarkNode* folder = managed_bookmark_service->managed_node();
2621 const BookmarkNode* node = model()->AddURL( 2612 const BookmarkNode* node = model()->AddURL(
2622 folder, 0, base::ASCIIToUTF16("node"), GURL("http://www.node.com/")); 2613 folder, 0, base::ASCIIToUTF16("node"), GURL("http://www.node.com/"));
2623 2614
2624 // Verify that these changes are ignored by Sync. 2615 // Verify that these changes are ignored by Sync.
2625 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); 2616 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount());
2626 int64_t sync_id = model_associator()->GetSyncIdFromChromeId(node->id()); 2617 int64_t sync_id = model_associator()->GetSyncIdFromChromeId(node->id());
2627 EXPECT_EQ(syncer::kInvalidId, sync_id); 2618 EXPECT_EQ(syncer::kInvalidId, sync_id);
2628 2619
2629 // Verify that Sync ignores deleting this node. 2620 // Verify that Sync ignores deleting this node.
2630 model()->Remove(node); 2621 model()->Remove(node);
2631 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); 2622 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount());
2632 } 2623 }
2633 2624
2634 } // namespace 2625 } // namespace
2635 2626
2636 } // namespace browser_sync 2627 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | components/browser_sync.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698