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

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

Issue 896073002: Prevent Meta Info from being overwritten due to reordering of entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback Created 5 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 | « chrome/browser/sync/glue/bookmark_change_processor.cc ('k') | no next file » | 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 <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); 93 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id));
94 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); 94 EXPECT_EQ(predecessor.GetParentId(), parent.GetId());
95 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); 95 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor));
96 } 96 }
97 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); 97 EXPECT_EQ(node.GetPredecessorId(), predecessor_id);
98 EXPECT_EQ(node.GetParentId(), parent_id); 98 EXPECT_EQ(node.GetParentId(), parent_id);
99 node.SetIsFolder(is_folder); 99 node.SetIsFolder(is_folder);
100 node.SetTitle(title); 100 node.SetTitle(title);
101 101
102 sync_pb::BookmarkSpecifics specifics(node.GetBookmarkSpecifics()); 102 sync_pb::BookmarkSpecifics specifics(node.GetBookmarkSpecifics());
103 const base::Time creation_time(base::Time::Now());
104 specifics.set_creation_time_us(creation_time.ToInternalValue());
103 if (!is_folder) 105 if (!is_folder)
104 specifics.set_url(url); 106 specifics.set_url(url);
105 if (meta_info_map) 107 if (meta_info_map)
106 SetNodeMetaInfo(*meta_info_map, &specifics); 108 SetNodeMetaInfo(*meta_info_map, &specifics);
107 node.SetBookmarkSpecifics(specifics); 109 node.SetBookmarkSpecifics(specifics);
108 110
109 syncer::ChangeRecord record; 111 syncer::ChangeRecord record;
110 record.action = syncer::ChangeRecord::ACTION_ADD; 112 record.action = syncer::ChangeRecord::ACTION_ADD;
111 record.id = node.GetId(); 113 record.id = node.GetId();
112 changes_.push_back(record); 114 changes_.push_back(record);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 return; 253 return;
252 syncer::ChangeRecord record; 254 syncer::ChangeRecord record;
253 record.action = syncer::ChangeRecord::ACTION_UPDATE; 255 record.action = syncer::ChangeRecord::ACTION_UPDATE;
254 record.id = id; 256 record.id = id;
255 changes_.push_back(record); 257 changes_.push_back(record);
256 } 258 }
257 259
258 void SetNodeMetaInfo(const BookmarkNode::MetaInfoMap& meta_info_map, 260 void SetNodeMetaInfo(const BookmarkNode::MetaInfoMap& meta_info_map,
259 sync_pb::BookmarkSpecifics* specifics) { 261 sync_pb::BookmarkSpecifics* specifics) {
260 specifics->clear_meta_info(); 262 specifics->clear_meta_info();
261 for (BookmarkNode::MetaInfoMap::const_iterator it = 263 // Deliberatly set MetaInfoMap entries in opposite order (compared
262 meta_info_map.begin(); it != meta_info_map.end(); ++it) { 264 // to the implementation in BookmarkChangeProcessor) to ensure that
265 // (a) the implementation isn't sensitive to the order and
266 // (b) the original meta info isn't blindly overwritten by
267 // BookmarkChangeProcessor unless there is a real change.
268 BookmarkNode::MetaInfoMap::const_iterator it = meta_info_map.end();
269 while (it != meta_info_map.begin()) {
270 --it;
263 sync_pb::MetaInfo* meta_info = specifics->add_meta_info(); 271 sync_pb::MetaInfo* meta_info = specifics->add_meta_info();
264 meta_info->set_key(it->first); 272 meta_info->set_key(it->first);
265 meta_info->set_value(it->second); 273 meta_info->set_value(it->second);
266 } 274 }
267 } 275 }
268 276
269
270 // The transaction on which everything happens. 277 // The transaction on which everything happens.
271 syncer::WriteTransaction *trans_; 278 syncer::WriteTransaction *trans_;
272 279
273 // The change list we construct. 280 // The change list we construct.
274 syncer::ChangeRecordList changes_; 281 syncer::ChangeRecordList changes_;
275 }; 282 };
276 283
277 class ExtensiveChangesBookmarkModelObserver 284 class ExtensiveChangesBookmarkModelObserver
278 : public bookmarks::BaseBookmarkModelObserver { 285 : public bookmarks::BaseBookmarkModelObserver {
279 public: 286 public:
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 ExpectModelMatch(); 2023 ExpectModelMatch();
2017 2024
2018 // Change/delete existing meta info and verify. 2025 // Change/delete existing meta info and verify.
2019 model_->DeleteNodeMetaInfo(folder_node, "folder"); 2026 model_->DeleteNodeMetaInfo(folder_node, "folder");
2020 model_->SetNodeMetaInfo(node, "node", "changednodevalue"); 2027 model_->SetNodeMetaInfo(node, "node", "changednodevalue");
2021 model_->DeleteNodeMetaInfo(node, "other"); 2028 model_->DeleteNodeMetaInfo(node, "other");
2022 model_->SetNodeMetaInfo(node, "newkey", "newkeyvalue"); 2029 model_->SetNodeMetaInfo(node, "newkey", "newkeyvalue");
2023 ExpectModelMatch(); 2030 ExpectModelMatch();
2024 } 2031 }
2025 2032
2033 // Tests that node's specifics doesn't get unnecessarily overwritten (causing
2034 // a subsequent commit) when BookmarkChangeProcessor handles a notification
2035 // (such as BookmarkMetaInfoChanged) without an actual data change.
2036 TEST_F(ProfileSyncServiceBookmarkTestWithData, MetaInfoPreservedOnNonChange) {
2037 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
2038 WriteTestDataToBookmarkModel();
2039 StartSync();
2040
2041 std::string orig_specifics;
2042 int64 sync_id;
2043 const BookmarkNode* bookmark;
2044
2045 // Create bookmark folder node containing meta info.
2046 {
2047 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
2048 FakeServerChange adds(&trans);
2049
2050 int64 folder_id = adds.AddFolder("folder title", bookmark_bar_id(), 0);
2051
2052 BookmarkNode::MetaInfoMap node_meta_info;
2053 node_meta_info["one"] = "1";
2054 node_meta_info["two"] = "2";
2055 node_meta_info["three"] = "3";
2056
2057 sync_id = adds.AddURLWithMetaInfo("node title", "http://www.foo.com/",
2058 &node_meta_info, folder_id, 0);
2059
2060 // Verify that the node propagates to the bookmark model
2061 adds.ApplyPendingChanges(change_processor_.get());
2062
2063 bookmark = model_->bookmark_bar_node()->GetChild(0)->GetChild(0);
2064 EXPECT_EQ(node_meta_info, *bookmark->GetMetaInfoMap());
2065
2066 syncer::ReadNode sync_node(&trans);
2067 EXPECT_EQ(BaseNode::INIT_OK, sync_node.InitByIdLookup(sync_id));
2068 orig_specifics = sync_node.GetBookmarkSpecifics().SerializeAsString();
2069 }
2070
2071 // Force change processor to update the sync node.
2072 change_processor_->BookmarkMetaInfoChanged(model_, bookmark);
2073
2074 // Read bookmark specifics again and verify that there is no change.
2075 {
2076 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
2077 syncer::ReadNode sync_node(&trans);
2078 EXPECT_EQ(BaseNode::INIT_OK, sync_node.InitByIdLookup(sync_id));
2079 std::string new_specifics =
2080 sync_node.GetBookmarkSpecifics().SerializeAsString();
2081 ASSERT_EQ(orig_specifics, new_specifics);
2082 }
2083 }
2084
2026 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions( 2085 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions(
2027 const BookmarkNode* root, 2086 const BookmarkNode* root,
2028 BookmarkNodeVersionMap* node_versions) { 2087 BookmarkNodeVersionMap* node_versions) {
2029 node_versions->clear(); 2088 node_versions->clear();
2030 std::queue<const BookmarkNode*> nodes; 2089 std::queue<const BookmarkNode*> nodes;
2031 nodes.push(root); 2090 nodes.push(root);
2032 while (!nodes.empty()) { 2091 while (!nodes.empty()) {
2033 const BookmarkNode* n = nodes.front(); 2092 const BookmarkNode* n = nodes.front();
2034 nodes.pop(); 2093 nodes.pop();
2035 2094
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 ExpectModelMatch(); 2246 ExpectModelMatch();
2188 2247
2189 // Then simulate the add call arriving late. 2248 // Then simulate the add call arriving late.
2190 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); 2249 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0);
2191 ExpectModelMatch(); 2250 ExpectModelMatch();
2192 } 2251 }
2193 2252
2194 } // namespace 2253 } // namespace
2195 2254
2196 } // namespace browser_sync 2255 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_change_processor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698