| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "sync/engine/sync_directory_update_handler.h" | 5 #include "sync/engine/directory_update_handler.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "sync/engine/syncer_proto_util.h" | 10 #include "sync/engine/syncer_proto_util.h" |
| 11 #include "sync/internal_api/public/base/model_type.h" | 11 #include "sync/internal_api/public/base/model_type.h" |
| 12 #include "sync/internal_api/public/test/test_entry_factory.h" | 12 #include "sync/internal_api/public/test/test_entry_factory.h" |
| 13 #include "sync/protocol/sync.pb.h" | 13 #include "sync/protocol/sync.pb.h" |
| 14 #include "sync/sessions/status_controller.h" | 14 #include "sync/sessions/status_controller.h" |
| 15 #include "sync/syncable/directory.h" | 15 #include "sync/syncable/directory.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 namespace syncer { | 28 namespace syncer { |
| 29 | 29 |
| 30 using syncable::UNITTEST; | 30 using syncable::UNITTEST; |
| 31 | 31 |
| 32 // A test harness for tests that focus on processing updates. | 32 // A test harness for tests that focus on processing updates. |
| 33 // | 33 // |
| 34 // Update processing is what occurs when we first download updates. It converts | 34 // Update processing is what occurs when we first download updates. It converts |
| 35 // the received protobuf message into information in the syncable::Directory. | 35 // the received protobuf message into information in the syncable::Directory. |
| 36 // Any invalid or redundant updates will be dropped at this point. | 36 // Any invalid or redundant updates will be dropped at this point. |
| 37 class SyncDirectoryUpdateHandlerProcessUpdateTest : public ::testing::Test { | 37 class DirectoryUpdateHandlerProcessUpdateTest : public ::testing::Test { |
| 38 public: | 38 public: |
| 39 SyncDirectoryUpdateHandlerProcessUpdateTest() | 39 DirectoryUpdateHandlerProcessUpdateTest() |
| 40 : ui_worker_(new FakeModelWorker(GROUP_UI)) { | 40 : ui_worker_(new FakeModelWorker(GROUP_UI)) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual ~SyncDirectoryUpdateHandlerProcessUpdateTest() {} | 43 virtual ~DirectoryUpdateHandlerProcessUpdateTest() {} |
| 44 | 44 |
| 45 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
| 46 dir_maker_.SetUp(); | 46 dir_maker_.SetUp(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual void TearDown() OVERRIDE { | 49 virtual void TearDown() OVERRIDE { |
| 50 dir_maker_.TearDown(); | 50 dir_maker_.TearDown(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 syncable::Directory* dir() { | 53 syncable::Directory* dir() { |
| 54 return dir_maker_.directory(); | 54 return dir_maker_.directory(); |
| 55 } | 55 } |
| 56 protected: | 56 protected: |
| 57 scoped_ptr<sync_pb::SyncEntity> CreateUpdate( | 57 scoped_ptr<sync_pb::SyncEntity> CreateUpdate( |
| 58 const std::string& id, | 58 const std::string& id, |
| 59 const std::string& parent, | 59 const std::string& parent, |
| 60 const ModelType& type); | 60 const ModelType& type); |
| 61 | 61 |
| 62 // This exists mostly to give tests access to the protected member function. | 62 // This exists mostly to give tests access to the protected member function. |
| 63 // Warning: This takes the syncable directory lock. | 63 // Warning: This takes the syncable directory lock. |
| 64 void UpdateSyncEntities( | 64 void UpdateSyncEntities( |
| 65 SyncDirectoryUpdateHandler* handler, | 65 DirectoryUpdateHandler* handler, |
| 66 const SyncEntityList& applicable_updates, | 66 const SyncEntityList& applicable_updates, |
| 67 sessions::StatusController* status); | 67 sessions::StatusController* status); |
| 68 | 68 |
| 69 // Another function to access private member functions. | 69 // Another function to access private member functions. |
| 70 void UpdateProgressMarkers( | 70 void UpdateProgressMarkers( |
| 71 SyncDirectoryUpdateHandler* handler, | 71 DirectoryUpdateHandler* handler, |
| 72 const sync_pb::DataTypeProgressMarker& progress); | 72 const sync_pb::DataTypeProgressMarker& progress); |
| 73 | 73 |
| 74 scoped_refptr<FakeModelWorker> ui_worker() { | 74 scoped_refptr<FakeModelWorker> ui_worker() { |
| 75 return ui_worker_; | 75 return ui_worker_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 base::MessageLoop loop_; // Needed to initialize the directory. | 79 base::MessageLoop loop_; // Needed to initialize the directory. |
| 80 TestDirectorySetterUpper dir_maker_; | 80 TestDirectorySetterUpper dir_maker_; |
| 81 scoped_refptr<FakeModelWorker> ui_worker_; | 81 scoped_refptr<FakeModelWorker> ui_worker_; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 scoped_ptr<sync_pb::SyncEntity> | 84 scoped_ptr<sync_pb::SyncEntity> |
| 85 SyncDirectoryUpdateHandlerProcessUpdateTest::CreateUpdate( | 85 DirectoryUpdateHandlerProcessUpdateTest::CreateUpdate( |
| 86 const std::string& id, | 86 const std::string& id, |
| 87 const std::string& parent, | 87 const std::string& parent, |
| 88 const ModelType& type) { | 88 const ModelType& type) { |
| 89 scoped_ptr<sync_pb::SyncEntity> e(new sync_pb::SyncEntity()); | 89 scoped_ptr<sync_pb::SyncEntity> e(new sync_pb::SyncEntity()); |
| 90 e->set_id_string(id); | 90 e->set_id_string(id); |
| 91 e->set_parent_id_string(parent); | 91 e->set_parent_id_string(parent); |
| 92 e->set_non_unique_name(id); | 92 e->set_non_unique_name(id); |
| 93 e->set_name(id); | 93 e->set_name(id); |
| 94 e->set_version(1000); | 94 e->set_version(1000); |
| 95 AddDefaultFieldValue(type, e->mutable_specifics()); | 95 AddDefaultFieldValue(type, e->mutable_specifics()); |
| 96 return e.Pass(); | 96 return e.Pass(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void SyncDirectoryUpdateHandlerProcessUpdateTest::UpdateSyncEntities( | 99 void DirectoryUpdateHandlerProcessUpdateTest::UpdateSyncEntities( |
| 100 SyncDirectoryUpdateHandler* handler, | 100 DirectoryUpdateHandler* handler, |
| 101 const SyncEntityList& applicable_updates, | 101 const SyncEntityList& applicable_updates, |
| 102 sessions::StatusController* status) { | 102 sessions::StatusController* status) { |
| 103 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, UNITTEST, dir()); | 103 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, UNITTEST, dir()); |
| 104 handler->UpdateSyncEntities(&trans, applicable_updates, status); | 104 handler->UpdateSyncEntities(&trans, applicable_updates, status); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void SyncDirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers( | 107 void DirectoryUpdateHandlerProcessUpdateTest::UpdateProgressMarkers( |
| 108 SyncDirectoryUpdateHandler* handler, | 108 DirectoryUpdateHandler* handler, |
| 109 const sync_pb::DataTypeProgressMarker& progress) { | 109 const sync_pb::DataTypeProgressMarker& progress) { |
| 110 handler->UpdateProgressMarker(progress); | 110 handler->UpdateProgressMarker(progress); |
| 111 } | 111 } |
| 112 | 112 |
| 113 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ=="; | 113 static const char kCacheGuid[] = "IrcjZ2jyzHDV9Io4+zKcXQ=="; |
| 114 | 114 |
| 115 // Test that the bookmark tag is set on newly downloaded items. | 115 // Test that the bookmark tag is set on newly downloaded items. |
| 116 TEST_F(SyncDirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) { | 116 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, NewBookmarkTag) { |
| 117 SyncDirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); | 117 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); |
| 118 sync_pb::GetUpdatesResponse gu_response; | 118 sync_pb::GetUpdatesResponse gu_response; |
| 119 sessions::StatusController status; | 119 sessions::StatusController status; |
| 120 | 120 |
| 121 // Add a bookmark item to the update message. | 121 // Add a bookmark item to the update message. |
| 122 std::string root = syncable::GetNullId().GetServerId(); | 122 std::string root = syncable::GetNullId().GetServerId(); |
| 123 syncable::Id server_id = syncable::Id::CreateFromServerId("b1"); | 123 syncable::Id server_id = syncable::Id::CreateFromServerId("b1"); |
| 124 scoped_ptr<sync_pb::SyncEntity> e = | 124 scoped_ptr<sync_pb::SyncEntity> e = |
| 125 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); | 125 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); |
| 126 e->set_originator_cache_guid( | 126 e->set_originator_cache_guid( |
| 127 std::string(kCacheGuid, arraysize(kCacheGuid)-1)); | 127 std::string(kCacheGuid, arraysize(kCacheGuid)-1)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 143 EXPECT_TRUE(entry.GetServerUniquePosition().IsValid()); | 143 EXPECT_TRUE(entry.GetServerUniquePosition().IsValid()); |
| 144 | 144 |
| 145 // If this assertion fails, that might indicate that the algorithm used to | 145 // If this assertion fails, that might indicate that the algorithm used to |
| 146 // generate bookmark tags has been modified. This could have implications for | 146 // generate bookmark tags has been modified. This could have implications for |
| 147 // bookmark ordering. Please make sure you know what you're doing if you | 147 // bookmark ordering. Please make sure you know what you're doing if you |
| 148 // intend to make such a change. | 148 // intend to make such a change. |
| 149 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag()); | 149 EXPECT_EQ("6wHRAb3kbnXV5GHrejp4/c1y5tw=", entry.GetUniqueBookmarkTag()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Test the receipt of a type root node. | 152 // Test the receipt of a type root node. |
| 153 TEST_F(SyncDirectoryUpdateHandlerProcessUpdateTest, | 153 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, |
| 154 ReceiveServerCreatedBookmarkFolders) { | 154 ReceiveServerCreatedBookmarkFolders) { |
| 155 SyncDirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); | 155 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); |
| 156 sync_pb::GetUpdatesResponse gu_response; | 156 sync_pb::GetUpdatesResponse gu_response; |
| 157 sessions::StatusController status; | 157 sessions::StatusController status; |
| 158 | 158 |
| 159 // Create an update that mimics the bookmark root. | 159 // Create an update that mimics the bookmark root. |
| 160 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); | 160 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); |
| 161 std::string root = syncable::GetNullId().GetServerId(); | 161 std::string root = syncable::GetNullId().GetServerId(); |
| 162 scoped_ptr<sync_pb::SyncEntity> e = | 162 scoped_ptr<sync_pb::SyncEntity> e = |
| 163 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); | 163 CreateUpdate(SyncableIdToProto(server_id), root, BOOKMARKS); |
| 164 e->set_server_defined_unique_tag("google_chrome_bookmarks"); | 164 e->set_server_defined_unique_tag("google_chrome_bookmarks"); |
| 165 e->set_folder(true); | 165 e->set_folder(true); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 178 syncable::Entry entry(&trans, syncable::GET_BY_ID, server_id); | 178 syncable::Entry entry(&trans, syncable::GET_BY_ID, server_id); |
| 179 ASSERT_TRUE(entry.good()); | 179 ASSERT_TRUE(entry.good()); |
| 180 | 180 |
| 181 EXPECT_FALSE(entry.ShouldMaintainPosition()); | 181 EXPECT_FALSE(entry.ShouldMaintainPosition()); |
| 182 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); | 182 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); |
| 183 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); | 183 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); |
| 184 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); | 184 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Test the receipt of a non-bookmark item. | 187 // Test the receipt of a non-bookmark item. |
| 188 TEST_F(SyncDirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { | 188 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { |
| 189 SyncDirectoryUpdateHandler handler(dir(), PREFERENCES, ui_worker()); | 189 DirectoryUpdateHandler handler(dir(), PREFERENCES, ui_worker()); |
| 190 sync_pb::GetUpdatesResponse gu_response; | 190 sync_pb::GetUpdatesResponse gu_response; |
| 191 sessions::StatusController status; | 191 sessions::StatusController status; |
| 192 | 192 |
| 193 std::string root = syncable::GetNullId().GetServerId(); | 193 std::string root = syncable::GetNullId().GetServerId(); |
| 194 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); | 194 syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); |
| 195 scoped_ptr<sync_pb::SyncEntity> e = | 195 scoped_ptr<sync_pb::SyncEntity> e = |
| 196 CreateUpdate(SyncableIdToProto(server_id), root, PREFERENCES); | 196 CreateUpdate(SyncableIdToProto(server_id), root, PREFERENCES); |
| 197 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); | 197 e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); |
| 198 | 198 |
| 199 // Add it to the applicable updates list. | 199 // Add it to the applicable updates list. |
| 200 SyncEntityList autofill_updates; | 200 SyncEntityList autofill_updates; |
| 201 autofill_updates.push_back(e.get()); | 201 autofill_updates.push_back(e.get()); |
| 202 | 202 |
| 203 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); | 203 EXPECT_FALSE(SyncerProtoUtil::ShouldMaintainPosition(*e)); |
| 204 | 204 |
| 205 // Process it. | 205 // Process it. |
| 206 UpdateSyncEntities(&handler, autofill_updates, &status); | 206 UpdateSyncEntities(&handler, autofill_updates, &status); |
| 207 | 207 |
| 208 syncable::ReadTransaction trans(FROM_HERE, dir()); | 208 syncable::ReadTransaction trans(FROM_HERE, dir()); |
| 209 syncable::Entry entry(&trans, syncable::GET_BY_ID, server_id); | 209 syncable::Entry entry(&trans, syncable::GET_BY_ID, server_id); |
| 210 ASSERT_TRUE(entry.good()); | 210 ASSERT_TRUE(entry.good()); |
| 211 | 211 |
| 212 EXPECT_FALSE(entry.ShouldMaintainPosition()); | 212 EXPECT_FALSE(entry.ShouldMaintainPosition()); |
| 213 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); | 213 EXPECT_FALSE(entry.GetUniquePosition().IsValid()); |
| 214 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); | 214 EXPECT_FALSE(entry.GetServerUniquePosition().IsValid()); |
| 215 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); | 215 EXPECT_TRUE(entry.GetUniqueBookmarkTag().empty()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Tests the setting of progress markers. | 218 // Tests the setting of progress markers. |
| 219 TEST_F(SyncDirectoryUpdateHandlerProcessUpdateTest, ProcessNewProgressMarkers) { | 219 TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ProcessNewProgressMarkers) { |
| 220 SyncDirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); | 220 DirectoryUpdateHandler handler(dir(), BOOKMARKS, ui_worker()); |
| 221 | 221 |
| 222 sync_pb::DataTypeProgressMarker progress; | 222 sync_pb::DataTypeProgressMarker progress; |
| 223 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(BOOKMARKS)); | 223 progress.set_data_type_id(GetSpecificsFieldNumberFromModelType(BOOKMARKS)); |
| 224 progress.set_token("token"); | 224 progress.set_token("token"); |
| 225 | 225 |
| 226 UpdateProgressMarkers(&handler, progress); | 226 UpdateProgressMarkers(&handler, progress); |
| 227 | 227 |
| 228 sync_pb::DataTypeProgressMarker saved; | 228 sync_pb::DataTypeProgressMarker saved; |
| 229 dir()->GetDownloadProgress(BOOKMARKS, &saved); | 229 dir()->GetDownloadProgress(BOOKMARKS, &saved); |
| 230 | 230 |
| 231 EXPECT_EQ(progress.token(), saved.token()); | 231 EXPECT_EQ(progress.token(), saved.token()); |
| 232 EXPECT_EQ(progress.data_type_id(), saved.data_type_id()); | 232 EXPECT_EQ(progress.data_type_id(), saved.data_type_id()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 // A test harness for tests that focus on applying updates. | 235 // A test harness for tests that focus on applying updates. |
| 236 // | 236 // |
| 237 // Update application is performed when we want to take updates that were | 237 // Update application is performed when we want to take updates that were |
| 238 // previously downloaded, processed, and stored in our syncable::Directory | 238 // previously downloaded, processed, and stored in our syncable::Directory |
| 239 // and use them to update our local state (both the Directory's local state | 239 // and use them to update our local state (both the Directory's local state |
| 240 // and the model's local state, though these tests focus only on the Directory's | 240 // and the model's local state, though these tests focus only on the Directory's |
| 241 // local state). | 241 // local state). |
| 242 // | 242 // |
| 243 // This is kept separate from the update processing test in part for historical | 243 // This is kept separate from the update processing test in part for historical |
| 244 // reasons, and in part because these tests may require a bit more infrastrcture | 244 // reasons, and in part because these tests may require a bit more infrastrcture |
| 245 // in the future. Update application should happen on a different thread a lot | 245 // in the future. Update application should happen on a different thread a lot |
| 246 // of the time so these tests may end up requiring more infrastructure than the | 246 // of the time so these tests may end up requiring more infrastructure than the |
| 247 // update processing tests. Currently, we're bypassing most of those issues by | 247 // update processing tests. Currently, we're bypassing most of those issues by |
| 248 // using FakeModelWorkers, so there's not much difference between the two test | 248 // using FakeModelWorkers, so there's not much difference between the two test |
| 249 // harnesses. | 249 // harnesses. |
| 250 class SyncDirectoryUpdateHandlerApplyUpdateTest : public ::testing::Test { | 250 class DirectoryUpdateHandlerApplyUpdateTest : public ::testing::Test { |
| 251 public: | 251 public: |
| 252 SyncDirectoryUpdateHandlerApplyUpdateTest() | 252 DirectoryUpdateHandlerApplyUpdateTest() |
| 253 : ui_worker_(new FakeModelWorker(GROUP_UI)), | 253 : ui_worker_(new FakeModelWorker(GROUP_UI)), |
| 254 password_worker_(new FakeModelWorker(GROUP_PASSWORD)), | 254 password_worker_(new FakeModelWorker(GROUP_PASSWORD)), |
| 255 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)), | 255 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)), |
| 256 update_handler_map_deleter_(&update_handler_map_) {} | 256 update_handler_map_deleter_(&update_handler_map_) {} |
| 257 | 257 |
| 258 virtual void SetUp() OVERRIDE { | 258 virtual void SetUp() OVERRIDE { |
| 259 dir_maker_.SetUp(); | 259 dir_maker_.SetUp(); |
| 260 entry_factory_.reset(new TestEntryFactory(directory())); | 260 entry_factory_.reset(new TestEntryFactory(directory())); |
| 261 | 261 |
| 262 update_handler_map_.insert(std::make_pair( | 262 update_handler_map_.insert(std::make_pair( |
| 263 BOOKMARKS, | 263 BOOKMARKS, |
| 264 new SyncDirectoryUpdateHandler(directory(), BOOKMARKS, ui_worker_))); | 264 new DirectoryUpdateHandler(directory(), BOOKMARKS, ui_worker_))); |
| 265 update_handler_map_.insert(std::make_pair( | 265 update_handler_map_.insert(std::make_pair( |
| 266 PASSWORDS, | 266 PASSWORDS, |
| 267 new SyncDirectoryUpdateHandler(directory(), | 267 new DirectoryUpdateHandler(directory(), |
| 268 PASSWORDS, | 268 PASSWORDS, |
| 269 password_worker_))); | 269 password_worker_))); |
| 270 } | 270 } |
| 271 | 271 |
| 272 virtual void TearDown() OVERRIDE { | 272 virtual void TearDown() OVERRIDE { |
| 273 dir_maker_.TearDown(); | 273 dir_maker_.TearDown(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 protected: | 276 protected: |
| 277 void ApplyBookmarkUpdates(sessions::StatusController* status) { | 277 void ApplyBookmarkUpdates(sessions::StatusController* status) { |
| 278 update_handler_map_[BOOKMARKS]->ApplyUpdates(status); | 278 update_handler_map_[BOOKMARKS]->ApplyUpdates(status); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void ApplyPasswordUpdates(sessions::StatusController* status) { | 281 void ApplyPasswordUpdates(sessions::StatusController* status) { |
| 282 update_handler_map_[PASSWORDS]->ApplyUpdates(status); | 282 update_handler_map_[PASSWORDS]->ApplyUpdates(status); |
| 283 } | 283 } |
| 284 | 284 |
| 285 TestEntryFactory* entry_factory() { | 285 TestEntryFactory* entry_factory() { |
| 286 return entry_factory_.get(); | 286 return entry_factory_.get(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 syncable::Directory* directory() { | 289 syncable::Directory* directory() { |
| 290 return dir_maker_.directory(); | 290 return dir_maker_.directory(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 private: | 293 private: |
| 294 typedef std::map<ModelType, SyncDirectoryUpdateHandler*> UpdateHandlerMap; | 294 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; |
| 295 | 295 |
| 296 base::MessageLoop loop_; // Needed to initialize the directory. | 296 base::MessageLoop loop_; // Needed to initialize the directory. |
| 297 TestDirectorySetterUpper dir_maker_; | 297 TestDirectorySetterUpper dir_maker_; |
| 298 scoped_ptr<TestEntryFactory> entry_factory_; | 298 scoped_ptr<TestEntryFactory> entry_factory_; |
| 299 | 299 |
| 300 scoped_refptr<FakeModelWorker> ui_worker_; | 300 scoped_refptr<FakeModelWorker> ui_worker_; |
| 301 scoped_refptr<FakeModelWorker> password_worker_; | 301 scoped_refptr<FakeModelWorker> password_worker_; |
| 302 scoped_refptr<FakeModelWorker> passive_worker_; | 302 scoped_refptr<FakeModelWorker> passive_worker_; |
| 303 | 303 |
| 304 UpdateHandlerMap update_handler_map_; | 304 UpdateHandlerMap update_handler_map_; |
| 305 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; | 305 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_; |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 namespace { | 308 namespace { |
| 309 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { | 309 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { |
| 310 sync_pb::EntitySpecifics result; | 310 sync_pb::EntitySpecifics result; |
| 311 AddDefaultFieldValue(BOOKMARKS, &result); | 311 AddDefaultFieldValue(BOOKMARKS, &result); |
| 312 return result; | 312 return result; |
| 313 } | 313 } |
| 314 } // namespace | 314 } // namespace |
| 315 | 315 |
| 316 // Test update application for a few bookmark items. | 316 // Test update application for a few bookmark items. |
| 317 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) { | 317 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmark) { |
| 318 sessions::StatusController status; | 318 sessions::StatusController status; |
| 319 | 319 |
| 320 std::string root_server_id = syncable::GetNullId().GetServerId(); | 320 std::string root_server_id = syncable::GetNullId().GetServerId(); |
| 321 int64 parent_handle = | 321 int64 parent_handle = |
| 322 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 322 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 323 "parent", DefaultBookmarkSpecifics(), root_server_id); | 323 "parent", DefaultBookmarkSpecifics(), root_server_id); |
| 324 int64 child_handle = | 324 int64 child_handle = |
| 325 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 325 entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 326 "child", DefaultBookmarkSpecifics(), "parent"); | 326 "child", DefaultBookmarkSpecifics(), "parent"); |
| 327 | 327 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 344 ASSERT_TRUE(child.good()); | 344 ASSERT_TRUE(child.good()); |
| 345 | 345 |
| 346 EXPECT_FALSE(parent.GetIsUnsynced()); | 346 EXPECT_FALSE(parent.GetIsUnsynced()); |
| 347 EXPECT_FALSE(parent.GetIsUnappliedUpdate()); | 347 EXPECT_FALSE(parent.GetIsUnappliedUpdate()); |
| 348 EXPECT_FALSE(child.GetIsUnsynced()); | 348 EXPECT_FALSE(child.GetIsUnsynced()); |
| 349 EXPECT_FALSE(child.GetIsUnappliedUpdate()); | 349 EXPECT_FALSE(child.GetIsUnappliedUpdate()); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 | 352 |
| 353 // Test that the applicator can handle updates delivered out of order. | 353 // Test that the applicator can handle updates delivered out of order. |
| 354 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, | 354 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
| 355 BookmarkChildrenBeforeParent) { | 355 BookmarkChildrenBeforeParent) { |
| 356 // Start with some bookmarks whose parents are unknown. | 356 // Start with some bookmarks whose parents are unknown. |
| 357 std::string root_server_id = syncable::GetNullId().GetServerId(); | 357 std::string root_server_id = syncable::GetNullId().GetServerId(); |
| 358 int64 a_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 358 int64 a_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 359 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); | 359 "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); |
| 360 int64 x_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( | 360 int64 x_handle = entry_factory()->CreateUnappliedNewBookmarkItemWithParent( |
| 361 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); | 361 "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); |
| 362 | 362 |
| 363 // Update application will fail. | 363 // Update application will fail. |
| 364 sessions::StatusController status1; | 364 sessions::StatusController status1; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 ASSERT_TRUE(a.good()); | 402 ASSERT_TRUE(a.good()); |
| 403 ASSERT_TRUE(x.good()); | 403 ASSERT_TRUE(x.good()); |
| 404 | 404 |
| 405 EXPECT_FALSE(a.GetIsUnappliedUpdate()); | 405 EXPECT_FALSE(a.GetIsUnappliedUpdate()); |
| 406 EXPECT_FALSE(x.GetIsUnappliedUpdate()); | 406 EXPECT_FALSE(x.GetIsUnappliedUpdate()); |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 | 409 |
| 410 // Try to apply changes on an item that is both IS_UNSYNCED and | 410 // Try to apply changes on an item that is both IS_UNSYNCED and |
| 411 // IS_UNAPPLIED_UPDATE. Conflict resolution should be performed. | 411 // IS_UNAPPLIED_UPDATE. Conflict resolution should be performed. |
| 412 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, SimpleBookmarkConflict) { | 412 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SimpleBookmarkConflict) { |
| 413 int64 handle = entry_factory()->CreateUnappliedAndUnsyncedBookmarkItem("x"); | 413 int64 handle = entry_factory()->CreateUnappliedAndUnsyncedBookmarkItem("x"); |
| 414 | 414 |
| 415 int original_server_version = -10; | 415 int original_server_version = -10; |
| 416 { | 416 { |
| 417 syncable::ReadTransaction trans(FROM_HERE, directory()); | 417 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 418 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); | 418 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); |
| 419 original_server_version = e.GetServerVersion(); | 419 original_server_version = e.GetServerVersion(); |
| 420 ASSERT_NE(original_server_version, e.GetBaseVersion()); | 420 ASSERT_NE(original_server_version, e.GetBaseVersion()); |
| 421 EXPECT_TRUE(e.GetIsUnsynced()); | 421 EXPECT_TRUE(e.GetIsUnsynced()); |
| 422 } | 422 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 438 | 438 |
| 439 // The unsynced flag will remain set until we successfully commit the item. | 439 // The unsynced flag will remain set until we successfully commit the item. |
| 440 EXPECT_TRUE(e.GetIsUnsynced()); | 440 EXPECT_TRUE(e.GetIsUnsynced()); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 // Create a simple conflict that is also a hierarchy conflict. If we were to | 444 // Create a simple conflict that is also a hierarchy conflict. If we were to |
| 445 // follow the normal "server wins" logic, we'd end up violating hierarchy | 445 // follow the normal "server wins" logic, we'd end up violating hierarchy |
| 446 // constraints. The hierarchy conflict must take precedence. We can not allow | 446 // constraints. The hierarchy conflict must take precedence. We can not allow |
| 447 // the update to be applied. The item must remain in the conflict state. | 447 // the update to be applied. The item must remain in the conflict state. |
| 448 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, HierarchyAndSimpleConflict) { | 448 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, HierarchyAndSimpleConflict) { |
| 449 // Create a simply-conflicting item. It will start with valid parent ids. | 449 // Create a simply-conflicting item. It will start with valid parent ids. |
| 450 int64 handle = entry_factory()->CreateUnappliedAndUnsyncedBookmarkItem( | 450 int64 handle = entry_factory()->CreateUnappliedAndUnsyncedBookmarkItem( |
| 451 "orphaned_by_server"); | 451 "orphaned_by_server"); |
| 452 { | 452 { |
| 453 // Manually set the SERVER_PARENT_ID to bad value. | 453 // Manually set the SERVER_PARENT_ID to bad value. |
| 454 // A bad parent indicates a hierarchy conflict. | 454 // A bad parent indicates a hierarchy conflict. |
| 455 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 455 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 456 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); | 456 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); |
| 457 ASSERT_TRUE(entry.good()); | 457 ASSERT_TRUE(entry.good()); |
| 458 | 458 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 469 syncable::ReadTransaction trans(FROM_HERE, directory()); | 469 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 470 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); | 470 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); |
| 471 ASSERT_TRUE(e.good()); | 471 ASSERT_TRUE(e.good()); |
| 472 EXPECT_TRUE(e.GetIsUnappliedUpdate()); | 472 EXPECT_TRUE(e.GetIsUnappliedUpdate()); |
| 473 EXPECT_TRUE(e.GetIsUnsynced()); | 473 EXPECT_TRUE(e.GetIsUnsynced()); |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 // Attempt to apply an udpate that would create a bookmark folder loop. This | 477 // Attempt to apply an udpate that would create a bookmark folder loop. This |
| 478 // application should fail. | 478 // application should fail. |
| 479 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, BookmarkFolderLoop) { | 479 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, BookmarkFolderLoop) { |
| 480 // Item 'X' locally has parent of 'root'. Server is updating it to have | 480 // Item 'X' locally has parent of 'root'. Server is updating it to have |
| 481 // parent of 'Y'. | 481 // parent of 'Y'. |
| 482 | 482 |
| 483 // Create it as a child of root node. | 483 // Create it as a child of root node. |
| 484 int64 handle = entry_factory()->CreateSyncedItem("X", BOOKMARKS, true); | 484 int64 handle = entry_factory()->CreateSyncedItem("X", BOOKMARKS, true); |
| 485 | 485 |
| 486 { | 486 { |
| 487 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 487 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 488 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); | 488 syncable::MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); |
| 489 ASSERT_TRUE(entry.good()); | 489 ASSERT_TRUE(entry.good()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 514 syncable::ReadTransaction trans(FROM_HERE, directory()); | 514 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 515 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); | 515 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); |
| 516 ASSERT_TRUE(e.good()); | 516 ASSERT_TRUE(e.good()); |
| 517 EXPECT_TRUE(e.GetIsUnappliedUpdate()); | 517 EXPECT_TRUE(e.GetIsUnappliedUpdate()); |
| 518 EXPECT_FALSE(e.GetIsUnsynced()); | 518 EXPECT_FALSE(e.GetIsUnsynced()); |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 | 521 |
| 522 // Test update application where the update has been orphaned by a local folder | 522 // Test update application where the update has been orphaned by a local folder |
| 523 // deletion. The update application attempt should fail. | 523 // deletion. The update application attempt should fail. |
| 524 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, | 524 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
| 525 HierarchyConflictDeletedParent) { | 525 HierarchyConflictDeletedParent) { |
| 526 // Create a locally deleted parent item. | 526 // Create a locally deleted parent item. |
| 527 int64 parent_handle; | 527 int64 parent_handle; |
| 528 entry_factory()->CreateUnsyncedItem( | 528 entry_factory()->CreateUnsyncedItem( |
| 529 syncable::Id::CreateFromServerId("parent"), TestIdFactory::root(), | 529 syncable::Id::CreateFromServerId("parent"), TestIdFactory::root(), |
| 530 "parent", true, BOOKMARKS, &parent_handle); | 530 "parent", true, BOOKMARKS, &parent_handle); |
| 531 { | 531 { |
| 532 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 532 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 533 syncable::MutableEntry entry(&trans, | 533 syncable::MutableEntry entry(&trans, |
| 534 syncable::GET_BY_HANDLE, | 534 syncable::GET_BY_HANDLE, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 552 syncable::ReadTransaction trans(FROM_HERE, directory()); | 552 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 553 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle); | 553 syncable::Entry child(&trans, syncable::GET_BY_HANDLE, child_handle); |
| 554 ASSERT_TRUE(child.good()); | 554 ASSERT_TRUE(child.good()); |
| 555 EXPECT_TRUE(child.GetIsUnappliedUpdate()); | 555 EXPECT_TRUE(child.GetIsUnappliedUpdate()); |
| 556 EXPECT_FALSE(child.GetIsUnsynced()); | 556 EXPECT_FALSE(child.GetIsUnsynced()); |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 | 559 |
| 560 // Attempt to apply an update that deletes a folder where the folder has | 560 // Attempt to apply an update that deletes a folder where the folder has |
| 561 // locally-created children. The update application should fail. | 561 // locally-created children. The update application should fail. |
| 562 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, | 562 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
| 563 HierarchyConflictDeleteNonEmptyDirectory) { | 563 HierarchyConflictDeleteNonEmptyDirectory) { |
| 564 // Create a server-deleted folder as a child of root node. | 564 // Create a server-deleted folder as a child of root node. |
| 565 int64 parent_handle = | 565 int64 parent_handle = |
| 566 entry_factory()->CreateSyncedItem("parent", BOOKMARKS, true); | 566 entry_factory()->CreateSyncedItem("parent", BOOKMARKS, true); |
| 567 { | 567 { |
| 568 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 568 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 569 syncable::MutableEntry entry(&trans, | 569 syncable::MutableEntry entry(&trans, |
| 570 syncable::GET_BY_HANDLE, | 570 syncable::GET_BY_HANDLE, |
| 571 parent_handle); | 571 parent_handle); |
| 572 ASSERT_TRUE(entry.good()); | 572 ASSERT_TRUE(entry.good()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 596 syncable::ReadTransaction trans(FROM_HERE, directory()); | 596 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 597 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle); | 597 syncable::Entry parent(&trans, syncable::GET_BY_HANDLE, parent_handle); |
| 598 ASSERT_TRUE(parent.good()); | 598 ASSERT_TRUE(parent.good()); |
| 599 EXPECT_TRUE(parent.GetIsUnappliedUpdate()); | 599 EXPECT_TRUE(parent.GetIsUnappliedUpdate()); |
| 600 EXPECT_FALSE(parent.GetIsUnsynced()); | 600 EXPECT_FALSE(parent.GetIsUnsynced()); |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 | 603 |
| 604 // Attempt to apply updates where the updated item's parent is not known to this | 604 // Attempt to apply updates where the updated item's parent is not known to this |
| 605 // client. The update application attempt should fail. | 605 // client. The update application attempt should fail. |
| 606 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, | 606 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, |
| 607 HierarchyConflictUnknownParent) { | 607 HierarchyConflictUnknownParent) { |
| 608 // We shouldn't be able to do anything with either of these items. | 608 // We shouldn't be able to do anything with either of these items. |
| 609 int64 x_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 609 int64 x_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 610 "some_item", DefaultBookmarkSpecifics(), "unknown_parent"); | 610 "some_item", DefaultBookmarkSpecifics(), "unknown_parent"); |
| 611 int64 y_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 611 int64 y_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 612 "some_other_item", DefaultBookmarkSpecifics(), "some_item"); | 612 "some_other_item", DefaultBookmarkSpecifics(), "some_item"); |
| 613 | 613 |
| 614 sessions::StatusController status; | 614 sessions::StatusController status; |
| 615 ApplyBookmarkUpdates(&status); | 615 ApplyBookmarkUpdates(&status); |
| 616 | 616 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 627 ASSERT_TRUE(y.good()); | 627 ASSERT_TRUE(y.good()); |
| 628 EXPECT_TRUE(x.GetIsUnappliedUpdate()); | 628 EXPECT_TRUE(x.GetIsUnappliedUpdate()); |
| 629 EXPECT_TRUE(y.GetIsUnappliedUpdate()); | 629 EXPECT_TRUE(y.GetIsUnappliedUpdate()); |
| 630 EXPECT_FALSE(x.GetIsUnsynced()); | 630 EXPECT_FALSE(x.GetIsUnsynced()); |
| 631 EXPECT_FALSE(y.GetIsUnsynced()); | 631 EXPECT_FALSE(y.GetIsUnsynced()); |
| 632 } | 632 } |
| 633 } | 633 } |
| 634 | 634 |
| 635 // Attempt application of a mix of items. Some update application attempts will | 635 // Attempt application of a mix of items. Some update application attempts will |
| 636 // fail due to hierarchy conflicts. Others should succeed. | 636 // fail due to hierarchy conflicts. Others should succeed. |
| 637 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, ItemsBothKnownAndUnknown) { | 637 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, ItemsBothKnownAndUnknown) { |
| 638 // See what happens when there's a mixture of good and bad updates. | 638 // See what happens when there's a mixture of good and bad updates. |
| 639 std::string root_server_id = syncable::GetNullId().GetServerId(); | 639 std::string root_server_id = syncable::GetNullId().GetServerId(); |
| 640 int64 u1_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 640 int64 u1_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 641 "first_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); | 641 "first_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); |
| 642 int64 k1_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 642 int64 k1_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 643 "first_known_item", DefaultBookmarkSpecifics(), root_server_id); | 643 "first_known_item", DefaultBookmarkSpecifics(), root_server_id); |
| 644 int64 u2_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 644 int64 u2_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 645 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); | 645 "second_unknown_item", DefaultBookmarkSpecifics(), "unknown_parent"); |
| 646 int64 k2_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 646 int64 k2_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 647 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item"); | 647 "second_known_item", DefaultBookmarkSpecifics(), "first_known_item"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 675 EXPECT_TRUE(u1.GetIsUnappliedUpdate()); | 675 EXPECT_TRUE(u1.GetIsUnappliedUpdate()); |
| 676 EXPECT_TRUE(u2.GetIsUnappliedUpdate()); | 676 EXPECT_TRUE(u2.GetIsUnappliedUpdate()); |
| 677 EXPECT_FALSE(k1.GetIsUnappliedUpdate()); | 677 EXPECT_FALSE(k1.GetIsUnappliedUpdate()); |
| 678 EXPECT_FALSE(k2.GetIsUnappliedUpdate()); | 678 EXPECT_FALSE(k2.GetIsUnappliedUpdate()); |
| 679 EXPECT_FALSE(k3.GetIsUnappliedUpdate()); | 679 EXPECT_FALSE(k3.GetIsUnappliedUpdate()); |
| 680 EXPECT_FALSE(k4.GetIsUnappliedUpdate()); | 680 EXPECT_FALSE(k4.GetIsUnappliedUpdate()); |
| 681 } | 681 } |
| 682 } | 682 } |
| 683 | 683 |
| 684 // Attempt application of password upates where the passphrase is known. | 684 // Attempt application of password upates where the passphrase is known. |
| 685 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, DecryptablePassword) { | 685 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, DecryptablePassword) { |
| 686 // Decryptable password updates should be applied. | 686 // Decryptable password updates should be applied. |
| 687 Cryptographer* cryptographer; | 687 Cryptographer* cryptographer; |
| 688 { | 688 { |
| 689 // Storing the cryptographer separately is bad, but for this test we | 689 // Storing the cryptographer separately is bad, but for this test we |
| 690 // know it's safe. | 690 // know it's safe. |
| 691 syncable::ReadTransaction trans(FROM_HERE, directory()); | 691 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 692 cryptographer = directory()->GetCryptographer(&trans); | 692 cryptographer = directory()->GetCryptographer(&trans); |
| 693 } | 693 } |
| 694 | 694 |
| 695 KeyParams params = {"localhost", "dummy", "foobar"}; | 695 KeyParams params = {"localhost", "dummy", "foobar"}; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 713 { | 713 { |
| 714 syncable::ReadTransaction trans(FROM_HERE, directory()); | 714 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 715 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); | 715 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, handle); |
| 716 ASSERT_TRUE(e.good()); | 716 ASSERT_TRUE(e.good()); |
| 717 EXPECT_FALSE(e.GetIsUnappliedUpdate()); | 717 EXPECT_FALSE(e.GetIsUnappliedUpdate()); |
| 718 EXPECT_FALSE(e.GetIsUnsynced()); | 718 EXPECT_FALSE(e.GetIsUnsynced()); |
| 719 } | 719 } |
| 720 } | 720 } |
| 721 | 721 |
| 722 // Attempt application of encrypted items when the passphrase is not known. | 722 // Attempt application of encrypted items when the passphrase is not known. |
| 723 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, UndecryptableData) { | 723 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, UndecryptableData) { |
| 724 // Undecryptable updates should not be applied. | 724 // Undecryptable updates should not be applied. |
| 725 sync_pb::EntitySpecifics encrypted_bookmark; | 725 sync_pb::EntitySpecifics encrypted_bookmark; |
| 726 encrypted_bookmark.mutable_encrypted(); | 726 encrypted_bookmark.mutable_encrypted(); |
| 727 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); | 727 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); |
| 728 std::string root_server_id = syncable::GetNullId().GetServerId(); | 728 std::string root_server_id = syncable::GetNullId().GetServerId(); |
| 729 int64 folder_handle = entry_factory()->CreateUnappliedNewItemWithParent( | 729 int64 folder_handle = entry_factory()->CreateUnappliedNewItemWithParent( |
| 730 "folder", | 730 "folder", |
| 731 encrypted_bookmark, | 731 encrypted_bookmark, |
| 732 root_server_id); | 732 root_server_id); |
| 733 int64 bookmark_handle = entry_factory()->CreateUnappliedNewItem( | 733 int64 bookmark_handle = entry_factory()->CreateUnappliedNewItem( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 758 ASSERT_TRUE(folder.good()); | 758 ASSERT_TRUE(folder.good()); |
| 759 ASSERT_TRUE(bm.good()); | 759 ASSERT_TRUE(bm.good()); |
| 760 ASSERT_TRUE(pw.good()); | 760 ASSERT_TRUE(pw.good()); |
| 761 EXPECT_TRUE(folder.GetIsUnappliedUpdate()); | 761 EXPECT_TRUE(folder.GetIsUnappliedUpdate()); |
| 762 EXPECT_TRUE(bm.GetIsUnappliedUpdate()); | 762 EXPECT_TRUE(bm.GetIsUnappliedUpdate()); |
| 763 EXPECT_TRUE(pw.GetIsUnappliedUpdate()); | 763 EXPECT_TRUE(pw.GetIsUnappliedUpdate()); |
| 764 } | 764 } |
| 765 } | 765 } |
| 766 | 766 |
| 767 // Test a mix of decryptable and undecryptable updates. | 767 // Test a mix of decryptable and undecryptable updates. |
| 768 TEST_F(SyncDirectoryUpdateHandlerApplyUpdateTest, SomeUndecryptablePassword) { | 768 TEST_F(DirectoryUpdateHandlerApplyUpdateTest, SomeUndecryptablePassword) { |
| 769 Cryptographer* cryptographer; | 769 Cryptographer* cryptographer; |
| 770 | 770 |
| 771 int64 decryptable_handle = -1; | 771 int64 decryptable_handle = -1; |
| 772 int64 undecryptable_handle = -1; | 772 int64 undecryptable_handle = -1; |
| 773 | 773 |
| 774 // Only decryptable password updates should be applied. | 774 // Only decryptable password updates should be applied. |
| 775 { | 775 { |
| 776 sync_pb::EntitySpecifics specifics; | 776 sync_pb::EntitySpecifics specifics; |
| 777 sync_pb::PasswordSpecificsData data; | 777 sync_pb::PasswordSpecificsData data; |
| 778 data.set_origin("http://example.com/1"); | 778 data.set_origin("http://example.com/1"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); | 819 syncable::Entry e1(&trans, syncable::GET_BY_HANDLE, decryptable_handle); |
| 820 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); | 820 syncable::Entry e2(&trans, syncable::GET_BY_HANDLE, undecryptable_handle); |
| 821 ASSERT_TRUE(e1.good()); | 821 ASSERT_TRUE(e1.good()); |
| 822 ASSERT_TRUE(e2.good()); | 822 ASSERT_TRUE(e2.good()); |
| 823 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); | 823 EXPECT_FALSE(e1.GetIsUnappliedUpdate()); |
| 824 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); | 824 EXPECT_TRUE(e2.GetIsUnappliedUpdate()); |
| 825 } | 825 } |
| 826 } | 826 } |
| 827 | 827 |
| 828 } // namespace syncer | 828 } // namespace syncer |
| OLD | NEW |