Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); | 92 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); |
| 93 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); | 93 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); |
| 94 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); | 94 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); |
| 95 } | 95 } |
| 96 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); | 96 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); |
| 97 EXPECT_EQ(node.GetParentId(), parent_id); | 97 EXPECT_EQ(node.GetParentId(), parent_id); |
| 98 node.SetIsFolder(is_folder); | 98 node.SetIsFolder(is_folder); |
| 99 node.SetTitle(title); | 99 node.SetTitle(title); |
| 100 | 100 |
| 101 sync_pb::BookmarkSpecifics specifics(node.GetBookmarkSpecifics()); | 101 sync_pb::BookmarkSpecifics specifics(node.GetBookmarkSpecifics()); |
| 102 const base::Time creation_time(base::Time::Now()); | |
| 103 specifics.set_creation_time_us(creation_time.ToInternalValue()); | |
| 102 if (!is_folder) | 104 if (!is_folder) |
| 103 specifics.set_url(url); | 105 specifics.set_url(url); |
| 104 if (meta_info_map) | 106 if (meta_info_map) |
| 105 SetNodeMetaInfo(*meta_info_map, &specifics); | 107 SetNodeMetaInfo(*meta_info_map, &specifics); |
| 106 node.SetBookmarkSpecifics(specifics); | 108 node.SetBookmarkSpecifics(specifics); |
| 107 | 109 |
| 108 syncer::ChangeRecord record; | 110 syncer::ChangeRecord record; |
| 109 record.action = syncer::ChangeRecord::ACTION_ADD; | 111 record.action = syncer::ChangeRecord::ACTION_ADD; |
| 110 record.id = node.GetId(); | 112 record.id = node.GetId(); |
| 111 changes_.push_back(record); | 113 changes_.push_back(record); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 return; | 252 return; |
| 251 syncer::ChangeRecord record; | 253 syncer::ChangeRecord record; |
| 252 record.action = syncer::ChangeRecord::ACTION_UPDATE; | 254 record.action = syncer::ChangeRecord::ACTION_UPDATE; |
| 253 record.id = id; | 255 record.id = id; |
| 254 changes_.push_back(record); | 256 changes_.push_back(record); |
| 255 } | 257 } |
| 256 | 258 |
| 257 void SetNodeMetaInfo(const BookmarkNode::MetaInfoMap& meta_info_map, | 259 void SetNodeMetaInfo(const BookmarkNode::MetaInfoMap& meta_info_map, |
| 258 sync_pb::BookmarkSpecifics* specifics) { | 260 sync_pb::BookmarkSpecifics* specifics) { |
| 259 specifics->clear_meta_info(); | 261 specifics->clear_meta_info(); |
| 260 for (BookmarkNode::MetaInfoMap::const_iterator it = | 262 // Deliberatly set MetaInfoMap entries in opposite order (compared |
| 261 meta_info_map.begin(); it != meta_info_map.end(); ++it) { | 263 // to the implementation in BookmarkChangeProcessor) to ensure that |
| 264 // (a) the implementation isn't sensitive to the order and | |
| 265 // (b) the original meta info isn't blindly overwritten by | |
| 266 // BookmarkChangeProcessor unless there is a real change. | |
| 267 BookmarkNode::MetaInfoMap::const_iterator it = meta_info_map.end(); | |
|
Nicolas Zea
2015/02/04 22:46:21
nit: leave as for loop?
stanisc
2015/02/05 01:40:15
I have considered the for loop, but couldn't find
| |
| 268 while (it != meta_info_map.begin()) { | |
| 269 --it; | |
| 262 sync_pb::MetaInfo* meta_info = specifics->add_meta_info(); | 270 sync_pb::MetaInfo* meta_info = specifics->add_meta_info(); |
| 263 meta_info->set_key(it->first); | 271 meta_info->set_key(it->first); |
| 264 meta_info->set_value(it->second); | 272 meta_info->set_value(it->second); |
| 265 } | 273 } |
| 266 } | 274 } |
| 267 | 275 |
| 268 | |
| 269 // The transaction on which everything happens. | 276 // The transaction on which everything happens. |
| 270 syncer::WriteTransaction *trans_; | 277 syncer::WriteTransaction *trans_; |
| 271 | 278 |
| 272 // The change list we construct. | 279 // The change list we construct. |
| 273 syncer::ChangeRecordList changes_; | 280 syncer::ChangeRecordList changes_; |
| 274 }; | 281 }; |
| 275 | 282 |
| 276 class ExtensiveChangesBookmarkModelObserver | 283 class ExtensiveChangesBookmarkModelObserver |
| 277 : public bookmarks::BaseBookmarkModelObserver { | 284 : public bookmarks::BaseBookmarkModelObserver { |
| 278 public: | 285 public: |
| (...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2015 ExpectModelMatch(); | 2022 ExpectModelMatch(); |
| 2016 | 2023 |
| 2017 // Change/delete existing meta info and verify. | 2024 // Change/delete existing meta info and verify. |
| 2018 model_->DeleteNodeMetaInfo(folder_node, "folder"); | 2025 model_->DeleteNodeMetaInfo(folder_node, "folder"); |
| 2019 model_->SetNodeMetaInfo(node, "node", "changednodevalue"); | 2026 model_->SetNodeMetaInfo(node, "node", "changednodevalue"); |
| 2020 model_->DeleteNodeMetaInfo(node, "other"); | 2027 model_->DeleteNodeMetaInfo(node, "other"); |
| 2021 model_->SetNodeMetaInfo(node, "newkey", "newkeyvalue"); | 2028 model_->SetNodeMetaInfo(node, "newkey", "newkeyvalue"); |
| 2022 ExpectModelMatch(); | 2029 ExpectModelMatch(); |
| 2023 } | 2030 } |
| 2024 | 2031 |
| 2032 // Tests that | |
|
Nicolas Zea
2015/02/04 22:46:21
Finish comment?
stanisc
2015/02/05 01:40:15
Done.
| |
| 2033 TEST_F(ProfileSyncServiceBookmarkTestWithData, MetaInfoPreservedOnNonChange) { | |
| 2034 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | |
| 2035 WriteTestDataToBookmarkModel(); | |
| 2036 StartSync(); | |
| 2037 | |
| 2038 std::string orig_specifics; | |
| 2039 int64 sync_id; | |
| 2040 const BookmarkNode* bookmark; | |
| 2041 | |
| 2042 // Create bookmark folder node containing meta info. | |
| 2043 { | |
| 2044 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | |
| 2045 FakeServerChange adds(&trans); | |
| 2046 | |
| 2047 int64 folder_id = adds.AddFolder("folder title", bookmark_bar_id(), 0); | |
| 2048 | |
| 2049 BookmarkNode::MetaInfoMap node_meta_info; | |
| 2050 node_meta_info["one"] = "1"; | |
| 2051 node_meta_info["two"] = "2"; | |
| 2052 node_meta_info["three"] = "3"; | |
| 2053 | |
| 2054 sync_id = adds.AddURLWithMetaInfo("node title", "http://www.foo.com/", | |
| 2055 &node_meta_info, folder_id, 0); | |
| 2056 | |
| 2057 // Verify that the node propagates to the bookmark model | |
| 2058 adds.ApplyPendingChanges(change_processor_.get()); | |
| 2059 | |
| 2060 bookmark = model_->bookmark_bar_node()->GetChild(0)->GetChild(0); | |
| 2061 EXPECT_EQ(node_meta_info, *bookmark->GetMetaInfoMap()); | |
| 2062 | |
| 2063 syncer::ReadNode sync_node(&trans); | |
| 2064 EXPECT_EQ(BaseNode::INIT_OK, sync_node.InitByIdLookup(sync_id)); | |
| 2065 orig_specifics = sync_node.GetBookmarkSpecifics().SerializeAsString(); | |
| 2066 } | |
| 2067 | |
| 2068 // Force change processor to update the sync node. | |
| 2069 change_processor_->BookmarkMetaInfoChanged(model_, bookmark); | |
| 2070 | |
| 2071 // Read bookmark specifics again and verify that there is no change. | |
| 2072 { | |
| 2073 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | |
| 2074 syncer::ReadNode sync_node(&trans); | |
| 2075 EXPECT_EQ(BaseNode::INIT_OK, sync_node.InitByIdLookup(sync_id)); | |
| 2076 std::string new_specifics = | |
| 2077 sync_node.GetBookmarkSpecifics().SerializeAsString(); | |
| 2078 ASSERT_EQ(orig_specifics, new_specifics); | |
| 2079 } | |
| 2080 } | |
| 2081 | |
| 2025 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions( | 2082 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions( |
| 2026 const BookmarkNode* root, | 2083 const BookmarkNode* root, |
| 2027 BookmarkNodeVersionMap* node_versions) { | 2084 BookmarkNodeVersionMap* node_versions) { |
| 2028 node_versions->clear(); | 2085 node_versions->clear(); |
| 2029 std::queue<const BookmarkNode*> nodes; | 2086 std::queue<const BookmarkNode*> nodes; |
| 2030 nodes.push(root); | 2087 nodes.push(root); |
| 2031 while (!nodes.empty()) { | 2088 while (!nodes.empty()) { |
| 2032 const BookmarkNode* n = nodes.front(); | 2089 const BookmarkNode* n = nodes.front(); |
| 2033 nodes.pop(); | 2090 nodes.pop(); |
| 2034 | 2091 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2186 ExpectModelMatch(); | 2243 ExpectModelMatch(); |
| 2187 | 2244 |
| 2188 // Then simulate the add call arriving late. | 2245 // Then simulate the add call arriving late. |
| 2189 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); | 2246 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); |
| 2190 ExpectModelMatch(); | 2247 ExpectModelMatch(); |
| 2191 } | 2248 } |
| 2192 | 2249 |
| 2193 } // namespace | 2250 } // namespace |
| 2194 | 2251 |
| 2195 } // namespace browser_sync | 2252 } // namespace browser_sync |
| OLD | NEW |