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

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

Issue 11341048: Populate versions on individual nodes in sync model and native bookmark model. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tests Created 8 years, 1 month 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) 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 <queue>
9 #include <stack> 10 #include <stack>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/file_path.h" 14 #include "base/file_path.h"
14 #include "base/file_util.h" 15 #include "base/file_util.h"
15 #include "base/location.h" 16 #include "base/location.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop.h" 18 #include "base/message_loop.h"
18 #include "base/string16.h" 19 #include "base/string16.h"
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 553 }
553 554
554 private: 555 private:
555 // Used by both |ui_thread_| and |file_thread_|. 556 // Used by both |ui_thread_| and |file_thread_|.
556 MessageLoop message_loop_; 557 MessageLoop message_loop_;
557 content::TestBrowserThread ui_thread_; 558 content::TestBrowserThread ui_thread_;
558 // Needed by |model_|. 559 // Needed by |model_|.
559 content::TestBrowserThread file_thread_; 560 content::TestBrowserThread file_thread_;
560 561
561 TestingProfile profile_; 562 TestingProfile profile_;
562 scoped_ptr<TestBookmarkModelAssociator> model_associator_;
563 563
564 protected: 564 protected:
565 BookmarkModel* model_; 565 BookmarkModel* model_;
566 syncer::TestUserShare test_user_share_; 566 syncer::TestUserShare test_user_share_;
567 scoped_ptr<BookmarkChangeProcessor> change_processor_; 567 scoped_ptr<BookmarkChangeProcessor> change_processor_;
568 scoped_ptr<TestBookmarkModelAssociator> model_associator_;
568 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; 569 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_;
569 }; 570 };
570 571
571 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 572 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
572 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 573 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
573 StartSync(); 574 StartSync();
574 575
575 EXPECT_TRUE(other_bookmarks_id()); 576 EXPECT_TRUE(other_bookmarks_id());
576 EXPECT_TRUE(bookmark_bar_id()); 577 EXPECT_TRUE(bookmark_bar_id());
577 EXPECT_TRUE(mobile_bookmarks_id()); 578 EXPECT_TRUE(mobile_bookmarks_id());
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 int size, 996 int size,
996 int* running_count); 997 int* running_count);
997 void CompareWithTestData(const BookmarkNode* node, 998 void CompareWithTestData(const BookmarkNode* node,
998 const TestData* data, 999 const TestData* data,
999 int size, 1000 int size,
1000 int* running_count); 1001 int* running_count);
1001 1002
1002 void ExpectBookmarkModelMatchesTestData(); 1003 void ExpectBookmarkModelMatchesTestData();
1003 void WriteTestDataToBookmarkModel(); 1004 void WriteTestDataToBookmarkModel();
1004 1005
1006 // Verify transaction versions of bookmark nodes and sync nodes are equal
1007 // recursively.
1008 void ExpectTransactionVersionMatch(const BookmarkNode* node);
1009
1005 private: 1010 private:
1006 const base::Time start_time_; 1011 const base::Time start_time_;
1007 1012
1008 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceBookmarkTestWithData); 1013 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceBookmarkTestWithData);
1009 }; 1014 };
1010 1015
1011 namespace { 1016 namespace {
1012 1017
1013 // Constants for bookmark model that looks like: 1018 // Constants for bookmark model that looks like:
1014 // |-- Bookmark bar 1019 // |-- Bookmark bar
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 DCHECK(node); 1132 DCHECK(node);
1128 DCHECK(data); 1133 DCHECK(data);
1129 DCHECK(node->is_folder()); 1134 DCHECK(node->is_folder());
1130 for (int i = 0; i < size; ++i) { 1135 for (int i = 0; i < size; ++i) {
1131 const TestData& item = data[i]; 1136 const TestData& item = data[i];
1132 if (item.url) { 1137 if (item.url) {
1133 const base::Time add_time = 1138 const base::Time add_time =
1134 start_time_ + base::TimeDelta::FromMinutes(*running_count); 1139 start_time_ + base::TimeDelta::FromMinutes(*running_count);
1135 model_->AddURLWithCreationTime(node, i, WideToUTF16Hack(item.title), 1140 model_->AddURLWithCreationTime(node, i, WideToUTF16Hack(item.title),
1136 GURL(item.url), add_time); 1141 GURL(item.url), add_time);
1137 (*running_count)++;
1138 } else { 1142 } else {
1139 model_->AddFolder(node, i, WideToUTF16Hack(item.title)); 1143 model_->AddFolder(node, i, WideToUTF16Hack(item.title));
1140 } 1144 }
1145 (*running_count)++;
1141 } 1146 }
1142 } 1147 }
1143 1148
1144 void ProfileSyncServiceBookmarkTestWithData::CompareWithTestData( 1149 void ProfileSyncServiceBookmarkTestWithData::CompareWithTestData(
1145 const BookmarkNode* node, 1150 const BookmarkNode* node,
1146 const TestData* data, 1151 const TestData* data,
1147 int size, 1152 int size,
1148 int* running_count) { 1153 int* running_count) {
1149 DCHECK(node); 1154 DCHECK(node);
1150 DCHECK(data); 1155 DCHECK(data);
1151 DCHECK(node->is_folder()); 1156 DCHECK(node->is_folder());
1152 ASSERT_EQ(size, node->child_count()); 1157 ASSERT_EQ(size, node->child_count());
1153 for (int i = 0; i < size; ++i) { 1158 for (int i = 0; i < size; ++i) {
1154 const BookmarkNode* child_node = node->GetChild(i); 1159 const BookmarkNode* child_node = node->GetChild(i);
1155 const TestData& item = data[i]; 1160 const TestData& item = data[i];
1156 GURL url = GURL(item.url == NULL ? "" : item.url); 1161 GURL url = GURL(item.url == NULL ? "" : item.url);
1157 BookmarkNode test_node(url); 1162 BookmarkNode test_node(url);
1158 test_node.SetTitle(WideToUTF16Hack(item.title)); 1163 test_node.SetTitle(WideToUTF16Hack(item.title));
1159 EXPECT_EQ(child_node->GetTitle(), test_node.GetTitle()); 1164 EXPECT_EQ(child_node->GetTitle(), test_node.GetTitle());
1160 if (item.url) { 1165 if (item.url) {
1161 EXPECT_FALSE(child_node->is_folder()); 1166 EXPECT_FALSE(child_node->is_folder());
1162 EXPECT_TRUE(child_node->is_url()); 1167 EXPECT_TRUE(child_node->is_url());
1163 EXPECT_EQ(child_node->url(), test_node.url()); 1168 EXPECT_EQ(child_node->url(), test_node.url());
1164 const base::Time expected_time = 1169 const base::Time expected_time =
1165 start_time_ + base::TimeDelta::FromMinutes(*running_count); 1170 start_time_ + base::TimeDelta::FromMinutes(*running_count);
1166 EXPECT_EQ(expected_time.ToInternalValue(), 1171 EXPECT_EQ(expected_time.ToInternalValue(),
1167 child_node->date_added().ToInternalValue()); 1172 child_node->date_added().ToInternalValue());
1168 (*running_count)++;
1169 } else { 1173 } else {
1170 EXPECT_TRUE(child_node->is_folder()); 1174 EXPECT_TRUE(child_node->is_folder());
1171 EXPECT_FALSE(child_node->is_url()); 1175 EXPECT_FALSE(child_node->is_url());
1172 } 1176 }
1177 (*running_count)++;
1173 } 1178 }
1174 } 1179 }
1175 1180
1176 // TODO(munjal): We should implement some way of generating random data and can 1181 // TODO(munjal): We should implement some way of generating random data and can
1177 // use the same seed to generate the same sequence. 1182 // use the same seed to generate the same sequence.
1178 void ProfileSyncServiceBookmarkTestWithData::WriteTestDataToBookmarkModel() { 1183 void ProfileSyncServiceBookmarkTestWithData::WriteTestDataToBookmarkModel() {
1179 const BookmarkNode* bookmarks_bar_node = model_->bookmark_bar_node(); 1184 const BookmarkNode* bookmarks_bar_node = model_->bookmark_bar_node();
1180 int count = 0; 1185 int count = 0;
1181 PopulateFromTestData(bookmarks_bar_node, 1186 PopulateFromTestData(bookmarks_bar_node,
1182 kBookmarkBarChildren, 1187 kBookmarkBarChildren,
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 updates.ApplyPendingChanges(change_processor_.get()); 1593 updates.ApplyPendingChanges(change_processor_.get());
1589 1594
1590 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(0); 1595 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(0);
1591 ASSERT_TRUE(node); 1596 ASSERT_TRUE(node);
1592 EXPECT_TRUE(node->is_url()); 1597 EXPECT_TRUE(node->is_url());
1593 EXPECT_EQ(WideToUTF16Hack(kTitle), node->GetTitle()); 1598 EXPECT_EQ(WideToUTF16Hack(kTitle), node->GetTitle());
1594 EXPECT_EQ(kUrl, node->url().possibly_invalid_spec()); 1599 EXPECT_EQ(kUrl, node->url().possibly_invalid_spec());
1595 EXPECT_EQ(node->date_added(), base::Time::FromInternalValue(30)); 1600 EXPECT_EQ(node->date_added(), base::Time::FromInternalValue(30));
1596 } 1601 }
1597 1602
1603 int64 GetTransactionVersion(const BookmarkNode* node) {
1604 std::string version_str;
1605 int64 version;
1606 EXPECT_TRUE(node->GetMetaInfo(kBookmarkTransactionVersionKey, &version_str));
1607 EXPECT_TRUE(base::StringToInt64(version_str, &version));
1608 return version;
1609 }
1610
1611 void ProfileSyncServiceBookmarkTestWithData::ExpectTransactionVersionMatch(
1612 const BookmarkNode* node) {
1613 std::queue<const BookmarkNode*> nodes;
1614 nodes.push(node);
1615 while (!nodes.empty()) {
1616 const BookmarkNode* n = nodes.front();
1617 nodes.pop();
1618
1619 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
1620 syncer::ReadNode sync_node(&trans);
1621 ASSERT_TRUE(model_associator_->InitSyncNodeFromChromeId(n->id(),
1622 &sync_node));
1623 EXPECT_EQ(sync_node.GetEntry()->Get(syncer::syncable::TRANSACTION_VERSION),
1624 GetTransactionVersion(n));
1625 for (int i = 0; i < n->child_count(); ++i)
1626 nodes.push(n->GetChild(i));
1627 }
1628 }
1629
1630 // Test transaction versions of model and nodes are incremented after changes
1631 // are applied.
1632 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateTransactionVersion) {
1633 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1634 StartSync();
1635 WriteTestDataToBookmarkModel();
1636 MessageLoop::current()->RunUntilIdle();
1637
1638 // Verify model versions are equal.
1639 {
1640 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
1641 EXPECT_EQ(trans.GetModelVersion(syncer::BOOKMARKS),
1642 GetTransactionVersion(model_->root_node()));
1643 }
1644
1645 // Verify node versions are equal.
1646 ExpectTransactionVersionMatch(model_->bookmark_bar_node());
1647 ExpectTransactionVersionMatch(model_->other_node());
1648 ExpectTransactionVersionMatch(model_->mobile_node());
1649
1650 // verify version is incremented when bookmark is removed.
1651 int64 old_model_version = GetTransactionVersion(model_->root_node());
1652 model_->Remove(model_->bookmark_bar_node(), 0);
1653 MessageLoop::current()->RunUntilIdle();
1654 EXPECT_EQ(old_model_version + 1, GetTransactionVersion(model_->root_node()));
1655
1656 // Verify version is updated when bookmark is changed.
1657 old_model_version = GetTransactionVersion(model_->root_node());
1658 model_->SetTitle(model_->bookmark_bar_node()->GetChild(0),
1659 WideToUTF16Hack(L"test"));
1660 MessageLoop::current()->RunUntilIdle();
1661 EXPECT_EQ(old_model_version + 1, GetTransactionVersion(model_->root_node()));
1662 EXPECT_EQ(old_model_version + 1,
1663 GetTransactionVersion(model_->bookmark_bar_node()->GetChild(0)));
1664 ExpectTransactionVersionMatch(model_->bookmark_bar_node()->GetChild(0));
1665 }
1666
Nicolas Zea 2012/11/07 00:20:31 do children get updated when a parent is modified?
haitaol1 2012/11/07 22:20:25 Parent is not updated but siblings do because of N
1598 } // namespace 1667 } // namespace
1599 1668
1600 } // namespace browser_sync 1669 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698