| OLD | NEW |
| 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 <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
| 49 | 49 |
| 50 namespace browser_sync { | 50 namespace browser_sync { |
| 51 | 51 |
| 52 using syncer::BaseNode; | 52 using syncer::BaseNode; |
| 53 using testing::_; | 53 using testing::_; |
| 54 using testing::InvokeWithoutArgs; | 54 using testing::InvokeWithoutArgs; |
| 55 using testing::Mock; | 55 using testing::Mock; |
| 56 using testing::StrictMock; | 56 using testing::StrictMock; |
| 57 | 57 |
| 58 #if defined(OS_ANDROID) | 58 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 59 static const bool kExpectMobileBookmarks = true; | 59 static const bool kExpectMobileBookmarks = true; |
| 60 #else | 60 #else |
| 61 static const bool kExpectMobileBookmarks = false; | 61 static const bool kExpectMobileBookmarks = false; |
| 62 #endif // defined(OS_ANDROID) | 62 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
| 63 | 63 |
| 64 namespace { | 64 namespace { |
| 65 | 65 |
| 66 // FakeServerChange constructs a list of syncer::ChangeRecords while modifying | 66 // FakeServerChange constructs a list of syncer::ChangeRecords while modifying |
| 67 // the sync model, and can pass the ChangeRecord list to a | 67 // the sync model, and can pass the ChangeRecord list to a |
| 68 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client | 68 // syncer::SyncObserver (i.e., the ProfileSyncService) to test the client |
| 69 // change-application behavior. | 69 // change-application behavior. |
| 70 // Tests using FakeServerChange should be careful to avoid back-references, | 70 // Tests using FakeServerChange should be careful to avoid back-references, |
| 71 // since FakeServerChange will send the edits in the order specified. | 71 // since FakeServerChange will send the edits in the order specified. |
| 72 class FakeServerChange { | 72 class FakeServerChange { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 431 } |
| 432 | 432 |
| 433 if (!root_exists) { | 433 if (!root_exists) { |
| 434 if (!syncer::TestUserShare::CreateRoot(type, | 434 if (!syncer::TestUserShare::CreateRoot(type, |
| 435 test_user_share_.user_share())) | 435 test_user_share_.user_share())) |
| 436 return false; | 436 return false; |
| 437 } | 437 } |
| 438 | 438 |
| 439 const int kNumPermanentNodes = 3; | 439 const int kNumPermanentNodes = 3; |
| 440 const std::string permanent_tags[kNumPermanentNodes] = { | 440 const std::string permanent_tags[kNumPermanentNodes] = { |
| 441 "bookmark_bar", "other_bookmarks", "synced_bookmarks" | 441 #if defined(OS_IOS) |
| 442 "synced_bookmarks", |
| 443 #endif |
| 444 "bookmark_bar", |
| 445 "other_bookmarks", |
| 446 #if !defined(OS_IOS) |
| 447 "synced_bookmarks", |
| 448 #endif |
| 442 }; | 449 }; |
| 443 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 450 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 444 syncer::ReadNode root(&trans); | 451 syncer::ReadNode root(&trans); |
| 445 EXPECT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(type)); | 452 EXPECT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(type)); |
| 446 | 453 |
| 447 // Loop through creating permanent nodes as necessary. | 454 // Loop through creating permanent nodes as necessary. |
| 448 int64 last_child_id = syncer::kInvalidId; | 455 int64 last_child_id = syncer::kInvalidId; |
| 449 for (int i = 0; i < kNumPermanentNodes; ++i) { | 456 for (int i = 0; i < kNumPermanentNodes; ++i) { |
| 450 // First check if the node already exists. This is for tests that involve | 457 // First check if the node already exists. This is for tests that involve |
| 451 // persistence and set up sync more than once. | 458 // persistence and set up sync more than once. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 model_associator_->GetChromeNodeFromSyncId(sync_id); | 689 model_associator_->GetChromeNodeFromSyncId(sync_id); |
| 683 ASSERT_TRUE(node); | 690 ASSERT_TRUE(node); |
| 684 const BookmarkNode* parent = | 691 const BookmarkNode* parent = |
| 685 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); | 692 model_associator_->GetChromeNodeFromSyncId(parent_sync_id); |
| 686 EXPECT_TRUE(parent); | 693 EXPECT_TRUE(parent); |
| 687 EXPECT_EQ(node->parent(), parent); | 694 EXPECT_EQ(node->parent(), parent); |
| 688 } | 695 } |
| 689 | 696 |
| 690 void ExpectModelMatch(syncer::BaseTransaction* trans) { | 697 void ExpectModelMatch(syncer::BaseTransaction* trans) { |
| 691 const BookmarkNode* root = model_->root_node(); | 698 const BookmarkNode* root = model_->root_node(); |
| 699 #if defined(OS_IOS) |
| 700 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 0); |
| 701 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 1); |
| 702 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 2); |
| 703 #else |
| 692 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0); | 704 EXPECT_EQ(root->GetIndexOf(model_->bookmark_bar_node()), 0); |
| 693 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); | 705 EXPECT_EQ(root->GetIndexOf(model_->other_node()), 1); |
| 694 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2); | 706 EXPECT_EQ(root->GetIndexOf(model_->mobile_node()), 2); |
| 707 #endif |
| 695 | 708 |
| 696 std::stack<int64> stack; | 709 std::stack<int64> stack; |
| 697 stack.push(bookmark_bar_id()); | 710 stack.push(bookmark_bar_id()); |
| 698 while (!stack.empty()) { | 711 while (!stack.empty()) { |
| 699 int64 id = stack.top(); | 712 int64 id = stack.top(); |
| 700 stack.pop(); | 713 stack.pop(); |
| 701 if (!id) continue; | 714 if (!id) continue; |
| 702 | 715 |
| 703 ExpectBrowserNodeMatching(trans, id); | 716 ExpectBrowserNodeMatching(trans, id); |
| 704 | 717 |
| (...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2172 ExpectModelMatch(); | 2185 ExpectModelMatch(); |
| 2173 | 2186 |
| 2174 // Then simulate the add call arriving late. | 2187 // Then simulate the add call arriving late. |
| 2175 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); | 2188 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); |
| 2176 ExpectModelMatch(); | 2189 ExpectModelMatch(); |
| 2177 } | 2190 } |
| 2178 | 2191 |
| 2179 } // namespace | 2192 } // namespace |
| 2180 | 2193 |
| 2181 } // namespace browser_sync | 2194 } // namespace browser_sync |
| OLD | NEW |