| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/tracked.h" | 9 #include "base/tracked.h" |
| 10 #include "chrome/browser/sync/engine/apply_updates_command.h" | 10 #include "chrome/browser/sync/engine/apply_updates_command.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 bool is_unique) { | 85 bool is_unique) { |
| 86 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 86 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 87 ASSERT_TRUE(dir.good()); | 87 ASSERT_TRUE(dir.good()); |
| 88 WriteTransaction trans(FROM_HERE, UNITTEST, dir); | 88 WriteTransaction trans(FROM_HERE, UNITTEST, dir); |
| 89 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 89 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 90 Id::CreateFromServerId(item_id)); | 90 Id::CreateFromServerId(item_id)); |
| 91 ASSERT_TRUE(entry.good()); | 91 ASSERT_TRUE(entry.good()); |
| 92 entry.Put(syncable::SERVER_VERSION, next_revision_++); | 92 entry.Put(syncable::SERVER_VERSION, next_revision_++); |
| 93 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 93 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 94 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); | 94 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); |
| 95 entry.Put(syncable::SERVER_PARENT_ID, syncable::kNullId); | 95 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); |
| 96 entry.Put(syncable::SERVER_IS_DIR, false); | 96 entry.Put(syncable::SERVER_IS_DIR, false); |
| 97 entry.Put(syncable::SERVER_SPECIFICS, specifics); | 97 entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| 98 if (is_unique) // For top-level nodes. | 98 if (is_unique) // For top-level nodes. |
| 99 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); | 99 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Create an unsynced item in the database. If item_id is a local ID, it | 102 // Create an unsynced item in the database. If item_id is a local ID, it |
| 103 // will be treated as a create-new. Otherwise, if it's a server ID, we'll | 103 // will be treated as a create-new. Otherwise, if it's a server ID, we'll |
| 104 // fake the server data so that it looks like it exists on the server. | 104 // fake the server data so that it looks like it exists on the server. |
| 105 // Returns the methandle of the created item in |metahandle_out| if not NULL. | 105 // Returns the methandle of the created item in |metahandle_out| if not NULL. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 137 } |
| 138 | 138 |
| 139 ApplyUpdatesCommand apply_updates_command_; | 139 ApplyUpdatesCommand apply_updates_command_; |
| 140 TestIdFactory id_factory_; | 140 TestIdFactory id_factory_; |
| 141 private: | 141 private: |
| 142 int64 next_revision_; | 142 int64 next_revision_; |
| 143 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest); | 143 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 TEST_F(ApplyUpdatesCommandTest, Simple) { | 146 TEST_F(ApplyUpdatesCommandTest, Simple) { |
| 147 string root_server_id = syncable::kNullId.GetServerId(); | 147 string root_server_id = syncable::GetNullId().GetServerId(); |
| 148 CreateUnappliedNewItemWithParent("parent", | 148 CreateUnappliedNewItemWithParent("parent", |
| 149 DefaultBookmarkSpecifics(), | 149 DefaultBookmarkSpecifics(), |
| 150 root_server_id); | 150 root_server_id); |
| 151 CreateUnappliedNewItemWithParent("child", | 151 CreateUnappliedNewItemWithParent("child", |
| 152 DefaultBookmarkSpecifics(), | 152 DefaultBookmarkSpecifics(), |
| 153 "parent"); | 153 "parent"); |
| 154 | 154 |
| 155 apply_updates_command_.ExecuteImpl(session()); | 155 apply_updates_command_.ExecuteImpl(session()); |
| 156 | 156 |
| 157 sessions::StatusController* status = session()->status_controller(); | 157 sessions::StatusController* status = session()->status_controller(); |
| 158 | 158 |
| 159 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 159 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
| 160 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) | 160 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) |
| 161 << "All updates should have been attempted"; | 161 << "All updates should have been attempted"; |
| 162 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) | 162 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize()) |
| 163 << "Simple update shouldn't result in conflicts"; | 163 << "Simple update shouldn't result in conflicts"; |
| 164 EXPECT_EQ(2, status->update_progress().SuccessfullyAppliedUpdateCount()) | 164 EXPECT_EQ(2, status->update_progress().SuccessfullyAppliedUpdateCount()) |
| 165 << "All items should have been successfully applied"; | 165 << "All items should have been successfully applied"; |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) { | 168 TEST_F(ApplyUpdatesCommandTest, UpdateWithChildrenBeforeParents) { |
| 169 // Set a bunch of updates which are difficult to apply in the order | 169 // Set a bunch of updates which are difficult to apply in the order |
| 170 // they're received due to dependencies on other unseen items. | 170 // they're received due to dependencies on other unseen items. |
| 171 string root_server_id = syncable::kNullId.GetServerId(); | 171 string root_server_id = syncable::GetNullId().GetServerId(); |
| 172 CreateUnappliedNewItemWithParent("a_child_created_first", | 172 CreateUnappliedNewItemWithParent("a_child_created_first", |
| 173 DefaultBookmarkSpecifics(), | 173 DefaultBookmarkSpecifics(), |
| 174 "parent"); | 174 "parent"); |
| 175 CreateUnappliedNewItemWithParent("x_child_created_first", | 175 CreateUnappliedNewItemWithParent("x_child_created_first", |
| 176 DefaultBookmarkSpecifics(), | 176 DefaultBookmarkSpecifics(), |
| 177 "parent"); | 177 "parent"); |
| 178 CreateUnappliedNewItemWithParent("parent", | 178 CreateUnappliedNewItemWithParent("parent", |
| 179 DefaultBookmarkSpecifics(), | 179 DefaultBookmarkSpecifics(), |
| 180 root_server_id); | 180 root_server_id); |
| 181 CreateUnappliedNewItemWithParent("a_child_created_second", | 181 CreateUnappliedNewItemWithParent("a_child_created_second", |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) | 213 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize()) |
| 214 << "All updates should have been attempted"; | 214 << "All updates should have been attempted"; |
| 215 EXPECT_EQ(2, status->conflict_progress().ConflictingItemsSize()) | 215 EXPECT_EQ(2, status->conflict_progress().ConflictingItemsSize()) |
| 216 << "All updates with an unknown ancestors should be in conflict"; | 216 << "All updates with an unknown ancestors should be in conflict"; |
| 217 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) | 217 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount()) |
| 218 << "No item with an unknown ancestor should be applied"; | 218 << "No item with an unknown ancestor should be applied"; |
| 219 } | 219 } |
| 220 | 220 |
| 221 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) { | 221 TEST_F(ApplyUpdatesCommandTest, ItemsBothKnownAndUnknown) { |
| 222 // See what happens when there's a mixture of good and bad updates. | 222 // See what happens when there's a mixture of good and bad updates. |
| 223 string root_server_id = syncable::kNullId.GetServerId(); | 223 string root_server_id = syncable::GetNullId().GetServerId(); |
| 224 CreateUnappliedNewItemWithParent("first_unknown_item", | 224 CreateUnappliedNewItemWithParent("first_unknown_item", |
| 225 DefaultBookmarkSpecifics(), | 225 DefaultBookmarkSpecifics(), |
| 226 "unknown_parent"); | 226 "unknown_parent"); |
| 227 CreateUnappliedNewItemWithParent("first_known_item", | 227 CreateUnappliedNewItemWithParent("first_known_item", |
| 228 DefaultBookmarkSpecifics(), | 228 DefaultBookmarkSpecifics(), |
| 229 root_server_id); | 229 root_server_id); |
| 230 CreateUnappliedNewItemWithParent("second_unknown_item", | 230 CreateUnappliedNewItemWithParent("second_unknown_item", |
| 231 DefaultBookmarkSpecifics(), | 231 DefaultBookmarkSpecifics(), |
| 232 "unknown_parent"); | 232 "unknown_parent"); |
| 233 CreateUnappliedNewItemWithParent("second_known_item", | 233 CreateUnappliedNewItemWithParent("second_known_item", |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 << "No update should be in conflict because they're all decryptable"; | 286 << "No update should be in conflict because they're all decryptable"; |
| 287 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) | 287 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount()) |
| 288 << "The updates that can be decrypted should be applied"; | 288 << "The updates that can be decrypted should be applied"; |
| 289 } | 289 } |
| 290 | 290 |
| 291 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) { | 291 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) { |
| 292 // Undecryptable updates should not be applied. | 292 // Undecryptable updates should not be applied. |
| 293 sync_pb::EntitySpecifics encrypted_bookmark; | 293 sync_pb::EntitySpecifics encrypted_bookmark; |
| 294 encrypted_bookmark.mutable_encrypted(); | 294 encrypted_bookmark.mutable_encrypted(); |
| 295 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | 295 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); |
| 296 string root_server_id = syncable::kNullId.GetServerId(); | 296 string root_server_id = syncable::GetNullId().GetServerId(); |
| 297 CreateUnappliedNewItemWithParent("folder", | 297 CreateUnappliedNewItemWithParent("folder", |
| 298 encrypted_bookmark, | 298 encrypted_bookmark, |
| 299 root_server_id); | 299 root_server_id); |
| 300 CreateUnappliedNewItem("item2", encrypted_bookmark, false); | 300 CreateUnappliedNewItem("item2", encrypted_bookmark, false); |
| 301 sync_pb::EntitySpecifics encrypted_password; | 301 sync_pb::EntitySpecifics encrypted_password; |
| 302 encrypted_password.MutableExtension(sync_pb::password); | 302 encrypted_password.MutableExtension(sync_pb::password); |
| 303 CreateUnappliedNewItem("item3", encrypted_password, false); | 303 CreateUnappliedNewItem("item3", encrypted_password, false); |
| 304 | 304 |
| 305 apply_updates_command_.ExecuteImpl(session()); | 305 apply_updates_command_.ExecuteImpl(session()); |
| 306 | 306 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 encrypted_types.insert(syncable::BOOKMARKS); | 671 encrypted_types.insert(syncable::BOOKMARKS); |
| 672 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); | 672 EXPECT_EQ(encrypted_types, cryptographer->GetEncryptedTypes()); |
| 673 | 673 |
| 674 Syncer::UnsyncedMetaHandles handles; | 674 Syncer::UnsyncedMetaHandles handles; |
| 675 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 675 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| 676 EXPECT_EQ(2*batch_s+1, handles.size()); | 676 EXPECT_EQ(2*batch_s+1, handles.size()); |
| 677 } | 677 } |
| 678 } | 678 } |
| 679 | 679 |
| 680 } // namespace browser_sync | 680 } // namespace browser_sync |
| OLD | NEW |