| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/sync/driver/generic_change_processor.h" | 5 #include "components/sync/driver/generic_change_processor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "components/sync/core/test/test_user_share.h" | 30 #include "components/sync/core/test/test_user_share.h" |
| 31 #include "components/sync/core/user_share.h" | 31 #include "components/sync/core/user_share.h" |
| 32 #include "components/sync/core/write_node.h" | 32 #include "components/sync/core/write_node.h" |
| 33 #include "components/sync/core/write_transaction.h" | 33 #include "components/sync/core/write_transaction.h" |
| 34 #include "components/sync/device_info/local_device_info_provider.h" | 34 #include "components/sync/device_info/local_device_info_provider.h" |
| 35 #include "components/sync/driver/fake_sync_client.h" | 35 #include "components/sync/driver/fake_sync_client.h" |
| 36 #include "components/sync/driver/sync_api_component_factory.h" | 36 #include "components/sync/driver/sync_api_component_factory.h" |
| 37 #include "testing/gmock/include/gmock/gmock.h" | 37 #include "testing/gmock/include/gmock/gmock.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 39 |
| 40 namespace sync_driver { | 40 namespace syncer { |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // A mock that keeps track of attachments passed to UploadAttachments. | 44 // A mock that keeps track of attachments passed to UploadAttachments. |
| 45 class MockAttachmentService : public syncer::AttachmentServiceImpl { | 45 class MockAttachmentService : public AttachmentServiceImpl { |
| 46 public: | 46 public: |
| 47 MockAttachmentService( | 47 MockAttachmentService( |
| 48 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store); | 48 std::unique_ptr<AttachmentStoreForSync> attachment_store); |
| 49 ~MockAttachmentService() override; | 49 ~MockAttachmentService() override; |
| 50 void UploadAttachments( | 50 void UploadAttachments(const AttachmentIdList& attachment_ids) override; |
| 51 const syncer::AttachmentIdList& attachment_ids) override; | 51 std::vector<AttachmentIdList>* attachment_id_lists(); |
| 52 std::vector<syncer::AttachmentIdList>* attachment_id_lists(); | |
| 53 | 52 |
| 54 private: | 53 private: |
| 55 std::vector<syncer::AttachmentIdList> attachment_id_lists_; | 54 std::vector<AttachmentIdList> attachment_id_lists_; |
| 56 }; | 55 }; |
| 57 | 56 |
| 58 MockAttachmentService::MockAttachmentService( | 57 MockAttachmentService::MockAttachmentService( |
| 59 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store) | 58 std::unique_ptr<AttachmentStoreForSync> attachment_store) |
| 60 : AttachmentServiceImpl(std::move(attachment_store), | 59 : AttachmentServiceImpl( |
| 61 std::unique_ptr<syncer::AttachmentUploader>( | 60 std::move(attachment_store), |
| 62 new syncer::FakeAttachmentUploader), | 61 std::unique_ptr<AttachmentUploader>(new FakeAttachmentUploader), |
| 63 std::unique_ptr<syncer::AttachmentDownloader>( | 62 std::unique_ptr<AttachmentDownloader>(new FakeAttachmentDownloader), |
| 64 new syncer::FakeAttachmentDownloader), | 63 NULL, |
| 65 NULL, | 64 base::TimeDelta(), |
| 66 base::TimeDelta(), | 65 base::TimeDelta()) {} |
| 67 base::TimeDelta()) {} | |
| 68 | 66 |
| 69 MockAttachmentService::~MockAttachmentService() {} | 67 MockAttachmentService::~MockAttachmentService() {} |
| 70 | 68 |
| 71 void MockAttachmentService::UploadAttachments( | 69 void MockAttachmentService::UploadAttachments( |
| 72 const syncer::AttachmentIdList& attachment_ids) { | 70 const AttachmentIdList& attachment_ids) { |
| 73 attachment_id_lists_.push_back(attachment_ids); | 71 attachment_id_lists_.push_back(attachment_ids); |
| 74 AttachmentServiceImpl::UploadAttachments(attachment_ids); | 72 AttachmentServiceImpl::UploadAttachments(attachment_ids); |
| 75 } | 73 } |
| 76 | 74 |
| 77 std::vector<syncer::AttachmentIdList>* | 75 std::vector<AttachmentIdList>* MockAttachmentService::attachment_id_lists() { |
| 78 MockAttachmentService::attachment_id_lists() { | |
| 79 return &attachment_id_lists_; | 76 return &attachment_id_lists_; |
| 80 } | 77 } |
| 81 | 78 |
| 82 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and | 79 // MockSyncApiComponentFactory needed to initialize GenericChangeProcessor and |
| 83 // pass MockAttachmentService to it. | 80 // pass MockAttachmentService to it. |
| 84 class MockSyncApiComponentFactory : public SyncApiComponentFactory { | 81 class MockSyncApiComponentFactory : public SyncApiComponentFactory { |
| 85 public: | 82 public: |
| 86 MockSyncApiComponentFactory() {} | 83 MockSyncApiComponentFactory() {} |
| 87 | 84 |
| 88 // SyncApiComponentFactory implementation. | 85 // SyncApiComponentFactory implementation. |
| 89 void RegisterDataTypes( | 86 void RegisterDataTypes( |
| 90 sync_driver::SyncService* sync_service, | 87 SyncService* sync_service, |
| 91 const RegisterDataTypesMethod& register_platform_types_method) override {} | 88 const RegisterDataTypesMethod& register_platform_types_method) override {} |
| 92 sync_driver::DataTypeManager* CreateDataTypeManager( | 89 DataTypeManager* CreateDataTypeManager( |
| 93 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 90 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, |
| 94 debug_info_listener, | 91 const DataTypeController::TypeMap* controllers, |
| 95 const sync_driver::DataTypeController::TypeMap* controllers, | 92 const DataTypeEncryptionHandler* encryption_handler, |
| 96 const sync_driver::DataTypeEncryptionHandler* encryption_handler, | 93 SyncBackendHost* backend, |
| 97 browser_sync::SyncBackendHost* backend, | 94 DataTypeManagerObserver* observer) override { |
| 98 sync_driver::DataTypeManagerObserver* observer) override { | |
| 99 return nullptr; | 95 return nullptr; |
| 100 }; | 96 }; |
| 101 browser_sync::SyncBackendHost* CreateSyncBackendHost( | 97 SyncBackendHost* CreateSyncBackendHost( |
| 102 const std::string& name, | 98 const std::string& name, |
| 103 invalidation::InvalidationService* invalidator, | 99 invalidation::InvalidationService* invalidator, |
| 104 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, | 100 const base::WeakPtr<SyncPrefs>& sync_prefs, |
| 105 const base::FilePath& sync_folder) override { | 101 const base::FilePath& sync_folder) override { |
| 106 return nullptr; | 102 return nullptr; |
| 107 } | 103 } |
| 108 std::unique_ptr<sync_driver::LocalDeviceInfoProvider> | 104 std::unique_ptr<LocalDeviceInfoProvider> CreateLocalDeviceInfoProvider() |
| 109 CreateLocalDeviceInfoProvider() override { | 105 override { |
| 110 return nullptr; | 106 return nullptr; |
| 111 } | 107 } |
| 112 SyncComponents CreateBookmarkSyncComponents( | 108 SyncComponents CreateBookmarkSyncComponents( |
| 113 sync_driver::SyncService* sync_service, | 109 SyncService* sync_service, |
| 114 std::unique_ptr<syncer::DataTypeErrorHandler> error_handler) override { | 110 std::unique_ptr<DataTypeErrorHandler> error_handler) override { |
| 115 return SyncComponents(nullptr, nullptr); | 111 return SyncComponents(nullptr, nullptr); |
| 116 } | 112 } |
| 117 | 113 |
| 118 std::unique_ptr<syncer::AttachmentService> CreateAttachmentService( | 114 std::unique_ptr<AttachmentService> CreateAttachmentService( |
| 119 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store, | 115 std::unique_ptr<AttachmentStoreForSync> attachment_store, |
| 120 const syncer::UserShare& user_share, | 116 const UserShare& user_share, |
| 121 const std::string& store_birthday, | 117 const std::string& store_birthday, |
| 122 syncer::ModelType model_type, | 118 ModelType model_type, |
| 123 syncer::AttachmentService::Delegate* delegate) override { | 119 AttachmentService::Delegate* delegate) override { |
| 124 std::unique_ptr<MockAttachmentService> attachment_service( | 120 std::unique_ptr<MockAttachmentService> attachment_service( |
| 125 new MockAttachmentService(std::move(attachment_store))); | 121 new MockAttachmentService(std::move(attachment_store))); |
| 126 // GenericChangeProcessor takes ownership of the AttachmentService, but we | 122 // GenericChangeProcessor takes ownership of the AttachmentService, but we |
| 127 // need to have a pointer to it so we can see that it was used properly. | 123 // need to have a pointer to it so we can see that it was used properly. |
| 128 // Take a pointer and trust that GenericChangeProcessor does not prematurely | 124 // Take a pointer and trust that GenericChangeProcessor does not prematurely |
| 129 // destroy it. | 125 // destroy it. |
| 130 mock_attachment_service_ = attachment_service.get(); | 126 mock_attachment_service_ = attachment_service.get(); |
| 131 return std::move(attachment_service); | 127 return std::move(attachment_service); |
| 132 } | 128 } |
| 133 | 129 |
| 134 MockAttachmentService* GetMockAttachmentService() { | 130 MockAttachmentService* GetMockAttachmentService() { |
| 135 return mock_attachment_service_; | 131 return mock_attachment_service_; |
| 136 } | 132 } |
| 137 | 133 |
| 138 private: | 134 private: |
| 139 MockAttachmentService* mock_attachment_service_; | 135 MockAttachmentService* mock_attachment_service_; |
| 140 }; | 136 }; |
| 141 | 137 |
| 142 class SyncGenericChangeProcessorTest : public testing::Test { | 138 class SyncGenericChangeProcessorTest : public testing::Test { |
| 143 public: | 139 public: |
| 144 // Most test cases will use this type. For those that need a | 140 // Most test cases will use this type. For those that need a |
| 145 // GenericChangeProcessor for a different type, use |InitializeForType|. | 141 // GenericChangeProcessor for a different type, use |InitializeForType|. |
| 146 static const syncer::ModelType kType = syncer::PREFERENCES; | 142 static const ModelType kType = PREFERENCES; |
| 147 | 143 |
| 148 SyncGenericChangeProcessorTest() | 144 SyncGenericChangeProcessorTest() |
| 149 : syncable_service_ptr_factory_(&fake_syncable_service_), | 145 : syncable_service_ptr_factory_(&fake_syncable_service_), |
| 150 mock_attachment_service_(NULL), | 146 mock_attachment_service_(NULL), |
| 151 sync_client_(&sync_factory_) {} | 147 sync_client_(&sync_factory_) {} |
| 152 | 148 |
| 153 void SetUp() override { | 149 void SetUp() override { |
| 154 // Use kType by default, but allow test cases to re-initialize with whatever | 150 // Use kType by default, but allow test cases to re-initialize with whatever |
| 155 // type they choose. Therefore, it's important that all type dependent | 151 // type they choose. Therefore, it's important that all type dependent |
| 156 // initialization occurs in InitializeForType. | 152 // initialization occurs in InitializeForType. |
| 157 InitializeForType(kType); | 153 InitializeForType(kType); |
| 158 } | 154 } |
| 159 | 155 |
| 160 void TearDown() override { | 156 void TearDown() override { |
| 161 mock_attachment_service_ = NULL; | 157 mock_attachment_service_ = NULL; |
| 162 if (test_user_share_) { | 158 if (test_user_share_) { |
| 163 test_user_share_->TearDown(); | 159 test_user_share_->TearDown(); |
| 164 } | 160 } |
| 165 } | 161 } |
| 166 | 162 |
| 167 // Initialize GenericChangeProcessor and related classes for testing with | 163 // Initialize GenericChangeProcessor and related classes for testing with |
| 168 // model type |type|. | 164 // model type |type|. |
| 169 void InitializeForType(syncer::ModelType type) { | 165 void InitializeForType(ModelType type) { |
| 170 TearDown(); | 166 TearDown(); |
| 171 test_user_share_.reset(new syncer::TestUserShare); | 167 test_user_share_.reset(new TestUserShare); |
| 172 test_user_share_->SetUp(); | 168 test_user_share_->SetUp(); |
| 173 sync_merge_result_.reset(new syncer::SyncMergeResult(type)); | 169 sync_merge_result_.reset(new SyncMergeResult(type)); |
| 174 merge_result_ptr_factory_.reset( | 170 merge_result_ptr_factory_.reset( |
| 175 new base::WeakPtrFactory<syncer::SyncMergeResult>( | 171 new base::WeakPtrFactory<SyncMergeResult>(sync_merge_result_.get())); |
| 176 sync_merge_result_.get())); | |
| 177 | 172 |
| 178 syncer::ModelTypeSet types = syncer::ProtocolTypes(); | 173 ModelTypeSet types = ProtocolTypes(); |
| 179 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); | 174 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
| 180 iter.Inc()) { | 175 TestUserShare::CreateRoot(iter.Get(), test_user_share_->user_share()); |
| 181 syncer::TestUserShare::CreateRoot(iter.Get(), | |
| 182 test_user_share_->user_share()); | |
| 183 } | 176 } |
| 184 test_user_share_->encryption_handler()->Init(); | 177 test_user_share_->encryption_handler()->Init(); |
| 185 ConstructGenericChangeProcessor(type); | 178 ConstructGenericChangeProcessor(type); |
| 186 } | 179 } |
| 187 | 180 |
| 188 void ConstructGenericChangeProcessor(syncer::ModelType type) { | 181 void ConstructGenericChangeProcessor(ModelType type) { |
| 189 std::unique_ptr<syncer::AttachmentStore> attachment_store = | 182 std::unique_ptr<AttachmentStore> attachment_store = |
| 190 syncer::AttachmentStore::CreateInMemoryStore(); | 183 AttachmentStore::CreateInMemoryStore(); |
| 191 change_processor_.reset(new GenericChangeProcessor( | 184 change_processor_.reset(new GenericChangeProcessor( |
| 192 type, base::MakeUnique<syncer::DataTypeErrorHandlerMock>(), | 185 type, base::MakeUnique<DataTypeErrorHandlerMock>(), |
| 193 syncable_service_ptr_factory_.GetWeakPtr(), | 186 syncable_service_ptr_factory_.GetWeakPtr(), |
| 194 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), | 187 merge_result_ptr_factory_->GetWeakPtr(), test_user_share_->user_share(), |
| 195 &sync_client_, attachment_store->CreateAttachmentStoreForSync())); | 188 &sync_client_, attachment_store->CreateAttachmentStoreForSync())); |
| 196 mock_attachment_service_ = sync_factory_.GetMockAttachmentService(); | 189 mock_attachment_service_ = sync_factory_.GetMockAttachmentService(); |
| 197 } | 190 } |
| 198 | 191 |
| 199 void BuildChildNodes(syncer::ModelType type, int n) { | 192 void BuildChildNodes(ModelType type, int n) { |
| 200 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 193 WriteTransaction trans(FROM_HERE, user_share()); |
| 201 for (int i = 0; i < n; ++i) { | 194 for (int i = 0; i < n; ++i) { |
| 202 syncer::WriteNode node(&trans); | 195 WriteNode node(&trans); |
| 203 node.InitUniqueByCreation(type, base::StringPrintf("node%05d", i)); | 196 node.InitUniqueByCreation(type, base::StringPrintf("node%05d", i)); |
| 204 } | 197 } |
| 205 } | 198 } |
| 206 | 199 |
| 207 GenericChangeProcessor* change_processor() { return change_processor_.get(); } | 200 GenericChangeProcessor* change_processor() { return change_processor_.get(); } |
| 208 | 201 |
| 209 syncer::UserShare* user_share() { return test_user_share_->user_share(); } | 202 UserShare* user_share() { return test_user_share_->user_share(); } |
| 210 | 203 |
| 211 MockAttachmentService* mock_attachment_service() { | 204 MockAttachmentService* mock_attachment_service() { |
| 212 return mock_attachment_service_; | 205 return mock_attachment_service_; |
| 213 } | 206 } |
| 214 | 207 |
| 215 void RunLoop() { | 208 void RunLoop() { |
| 216 base::RunLoop run_loop; | 209 base::RunLoop run_loop; |
| 217 run_loop.RunUntilIdle(); | 210 run_loop.RunUntilIdle(); |
| 218 } | 211 } |
| 219 | 212 |
| 220 private: | 213 private: |
| 221 base::MessageLoopForUI loop_; | 214 base::MessageLoopForUI loop_; |
| 222 | 215 |
| 223 std::unique_ptr<syncer::SyncMergeResult> sync_merge_result_; | 216 std::unique_ptr<SyncMergeResult> sync_merge_result_; |
| 224 std::unique_ptr<base::WeakPtrFactory<syncer::SyncMergeResult>> | 217 std::unique_ptr<base::WeakPtrFactory<SyncMergeResult>> |
| 225 merge_result_ptr_factory_; | 218 merge_result_ptr_factory_; |
| 226 | 219 |
| 227 syncer::FakeSyncableService fake_syncable_service_; | 220 FakeSyncableService fake_syncable_service_; |
| 228 base::WeakPtrFactory<syncer::FakeSyncableService> | 221 base::WeakPtrFactory<FakeSyncableService> syncable_service_ptr_factory_; |
| 229 syncable_service_ptr_factory_; | |
| 230 | 222 |
| 231 std::unique_ptr<syncer::TestUserShare> test_user_share_; | 223 std::unique_ptr<TestUserShare> test_user_share_; |
| 232 MockAttachmentService* mock_attachment_service_; | 224 MockAttachmentService* mock_attachment_service_; |
| 233 FakeSyncClient sync_client_; | 225 FakeSyncClient sync_client_; |
| 234 MockSyncApiComponentFactory sync_factory_; | 226 MockSyncApiComponentFactory sync_factory_; |
| 235 | 227 |
| 236 std::unique_ptr<GenericChangeProcessor> change_processor_; | 228 std::unique_ptr<GenericChangeProcessor> change_processor_; |
| 237 }; | 229 }; |
| 238 | 230 |
| 239 // Similar to above, but focused on the method that implements sync/api | 231 // Similar to above, but focused on the method that implements sync/api |
| 240 // interfaces and is hence exposed to datatypes directly. | 232 // interfaces and is hence exposed to datatypes directly. |
| 241 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) { | 233 TEST_F(SyncGenericChangeProcessorTest, StressGetAllSyncData) { |
| 242 const int kNumChildNodes = 1000; | 234 const int kNumChildNodes = 1000; |
| 243 const int kRepeatCount = 1; | 235 const int kRepeatCount = 1; |
| 244 | 236 |
| 245 ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kType, kNumChildNodes)); | 237 ASSERT_NO_FATAL_FAILURE(BuildChildNodes(kType, kNumChildNodes)); |
| 246 | 238 |
| 247 for (int i = 0; i < kRepeatCount; ++i) { | 239 for (int i = 0; i < kRepeatCount; ++i) { |
| 248 syncer::SyncDataList sync_data = change_processor()->GetAllSyncData(kType); | 240 SyncDataList sync_data = change_processor()->GetAllSyncData(kType); |
| 249 | 241 |
| 250 // Start with a simple test. We can add more in-depth testing later. | 242 // Start with a simple test. We can add more in-depth testing later. |
| 251 EXPECT_EQ(static_cast<size_t>(kNumChildNodes), sync_data.size()); | 243 EXPECT_EQ(static_cast<size_t>(kNumChildNodes), sync_data.size()); |
| 252 } | 244 } |
| 253 } | 245 } |
| 254 | 246 |
| 255 TEST_F(SyncGenericChangeProcessorTest, SetGetPasswords) { | 247 TEST_F(SyncGenericChangeProcessorTest, SetGetPasswords) { |
| 256 InitializeForType(syncer::PASSWORDS); | 248 InitializeForType(PASSWORDS); |
| 257 const int kNumPasswords = 10; | 249 const int kNumPasswords = 10; |
| 258 sync_pb::PasswordSpecificsData password_data; | 250 sync_pb::PasswordSpecificsData password_data; |
| 259 password_data.set_username_value("user"); | 251 password_data.set_username_value("user"); |
| 260 | 252 |
| 261 sync_pb::EntitySpecifics password_holder; | 253 sync_pb::EntitySpecifics password_holder; |
| 262 | 254 |
| 263 syncer::SyncChangeList change_list; | 255 SyncChangeList change_list; |
| 264 for (int i = 0; i < kNumPasswords; ++i) { | 256 for (int i = 0; i < kNumPasswords; ++i) { |
| 265 password_data.set_password_value(base::StringPrintf("password%i", i)); | 257 password_data.set_password_value(base::StringPrintf("password%i", i)); |
| 266 password_holder.mutable_password() | 258 password_holder.mutable_password() |
| 267 ->mutable_client_only_encrypted_data() | 259 ->mutable_client_only_encrypted_data() |
| 268 ->CopyFrom(password_data); | 260 ->CopyFrom(password_data); |
| 269 change_list.push_back(syncer::SyncChange( | 261 change_list.push_back( |
| 270 FROM_HERE, syncer::SyncChange::ACTION_ADD, | 262 SyncChange(FROM_HERE, SyncChange::ACTION_ADD, |
| 271 syncer::SyncData::CreateLocalData(base::StringPrintf("tag%i", i), | 263 SyncData::CreateLocalData(base::StringPrintf("tag%i", i), |
| 272 base::StringPrintf("title%i", i), | 264 base::StringPrintf("title%i", i), |
| 273 password_holder))); | 265 password_holder))); |
| 274 } | 266 } |
| 275 | 267 |
| 276 ASSERT_FALSE( | 268 ASSERT_FALSE( |
| 277 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 269 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 278 | 270 |
| 279 syncer::SyncDataList password_list( | 271 SyncDataList password_list(change_processor()->GetAllSyncData(PASSWORDS)); |
| 280 change_processor()->GetAllSyncData(syncer::PASSWORDS)); | |
| 281 | 272 |
| 282 ASSERT_EQ(password_list.size(), change_list.size()); | 273 ASSERT_EQ(password_list.size(), change_list.size()); |
| 283 for (int i = 0; i < kNumPasswords; ++i) { | 274 for (int i = 0; i < kNumPasswords; ++i) { |
| 284 // Verify the password is returned properly. | 275 // Verify the password is returned properly. |
| 285 ASSERT_TRUE(password_list[i].GetSpecifics().has_password()); | 276 ASSERT_TRUE(password_list[i].GetSpecifics().has_password()); |
| 286 ASSERT_TRUE(password_list[i] | 277 ASSERT_TRUE(password_list[i] |
| 287 .GetSpecifics() | 278 .GetSpecifics() |
| 288 .password() | 279 .password() |
| 289 .has_client_only_encrypted_data()); | 280 .has_client_only_encrypted_data()); |
| 290 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted()); | 281 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted()); |
| 291 const sync_pb::PasswordSpecificsData& sync_password = | 282 const sync_pb::PasswordSpecificsData& sync_password = |
| 292 password_list[i].GetSpecifics().password().client_only_encrypted_data(); | 283 password_list[i].GetSpecifics().password().client_only_encrypted_data(); |
| 293 const sync_pb::PasswordSpecificsData& change_password = | 284 const sync_pb::PasswordSpecificsData& change_password = |
| 294 change_list[i] | 285 change_list[i] |
| 295 .sync_data() | 286 .sync_data() |
| 296 .GetSpecifics() | 287 .GetSpecifics() |
| 297 .password() | 288 .password() |
| 298 .client_only_encrypted_data(); | 289 .client_only_encrypted_data(); |
| 299 ASSERT_EQ(sync_password.password_value(), change_password.password_value()); | 290 ASSERT_EQ(sync_password.password_value(), change_password.password_value()); |
| 300 ASSERT_EQ(sync_password.username_value(), change_password.username_value()); | 291 ASSERT_EQ(sync_password.username_value(), change_password.username_value()); |
| 301 | 292 |
| 302 // Verify the raw sync data was stored securely. | 293 // Verify the raw sync data was stored securely. |
| 303 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); | 294 ReadTransaction read_transaction(FROM_HERE, user_share()); |
| 304 syncer::ReadNode node(&read_transaction); | 295 ReadNode node(&read_transaction); |
| 305 ASSERT_EQ(node.InitByClientTagLookup(syncer::PASSWORDS, | 296 ASSERT_EQ( |
| 306 base::StringPrintf("tag%i", i)), | 297 node.InitByClientTagLookup(PASSWORDS, base::StringPrintf("tag%i", i)), |
| 307 syncer::BaseNode::INIT_OK); | 298 BaseNode::INIT_OK); |
| 308 ASSERT_EQ(node.GetTitle(), "encrypted"); | 299 ASSERT_EQ(node.GetTitle(), "encrypted"); |
| 309 const sync_pb::EntitySpecifics& raw_specifics = node.GetEntitySpecifics(); | 300 const sync_pb::EntitySpecifics& raw_specifics = node.GetEntitySpecifics(); |
| 310 ASSERT_TRUE(raw_specifics.has_password()); | 301 ASSERT_TRUE(raw_specifics.has_password()); |
| 311 ASSERT_TRUE(raw_specifics.password().has_encrypted()); | 302 ASSERT_TRUE(raw_specifics.password().has_encrypted()); |
| 312 ASSERT_FALSE(raw_specifics.password().has_client_only_encrypted_data()); | 303 ASSERT_FALSE(raw_specifics.password().has_client_only_encrypted_data()); |
| 313 } | 304 } |
| 314 } | 305 } |
| 315 | 306 |
| 316 TEST_F(SyncGenericChangeProcessorTest, UpdatePasswords) { | 307 TEST_F(SyncGenericChangeProcessorTest, UpdatePasswords) { |
| 317 InitializeForType(syncer::PASSWORDS); | 308 InitializeForType(PASSWORDS); |
| 318 const int kNumPasswords = 10; | 309 const int kNumPasswords = 10; |
| 319 sync_pb::PasswordSpecificsData password_data; | 310 sync_pb::PasswordSpecificsData password_data; |
| 320 password_data.set_username_value("user"); | 311 password_data.set_username_value("user"); |
| 321 | 312 |
| 322 sync_pb::EntitySpecifics password_holder; | 313 sync_pb::EntitySpecifics password_holder; |
| 323 | 314 |
| 324 syncer::SyncChangeList change_list; | 315 SyncChangeList change_list; |
| 325 syncer::SyncChangeList change_list2; | 316 SyncChangeList change_list2; |
| 326 for (int i = 0; i < kNumPasswords; ++i) { | 317 for (int i = 0; i < kNumPasswords; ++i) { |
| 327 password_data.set_password_value(base::StringPrintf("password%i", i)); | 318 password_data.set_password_value(base::StringPrintf("password%i", i)); |
| 328 password_holder.mutable_password() | 319 password_holder.mutable_password() |
| 329 ->mutable_client_only_encrypted_data() | 320 ->mutable_client_only_encrypted_data() |
| 330 ->CopyFrom(password_data); | 321 ->CopyFrom(password_data); |
| 331 change_list.push_back(syncer::SyncChange( | 322 change_list.push_back( |
| 332 FROM_HERE, syncer::SyncChange::ACTION_ADD, | 323 SyncChange(FROM_HERE, SyncChange::ACTION_ADD, |
| 333 syncer::SyncData::CreateLocalData(base::StringPrintf("tag%i", i), | 324 SyncData::CreateLocalData(base::StringPrintf("tag%i", i), |
| 334 base::StringPrintf("title%i", i), | 325 base::StringPrintf("title%i", i), |
| 335 password_holder))); | 326 password_holder))); |
| 336 password_data.set_password_value(base::StringPrintf("password_m%i", i)); | 327 password_data.set_password_value(base::StringPrintf("password_m%i", i)); |
| 337 password_holder.mutable_password() | 328 password_holder.mutable_password() |
| 338 ->mutable_client_only_encrypted_data() | 329 ->mutable_client_only_encrypted_data() |
| 339 ->CopyFrom(password_data); | 330 ->CopyFrom(password_data); |
| 340 change_list2.push_back(syncer::SyncChange( | 331 change_list2.push_back( |
| 341 FROM_HERE, syncer::SyncChange::ACTION_UPDATE, | 332 SyncChange(FROM_HERE, SyncChange::ACTION_UPDATE, |
| 342 syncer::SyncData::CreateLocalData(base::StringPrintf("tag%i", i), | 333 SyncData::CreateLocalData(base::StringPrintf("tag%i", i), |
| 343 base::StringPrintf("title_m%i", i), | 334 base::StringPrintf("title_m%i", i), |
| 344 password_holder))); | 335 password_holder))); |
| 345 } | 336 } |
| 346 | 337 |
| 347 ASSERT_FALSE( | 338 ASSERT_FALSE( |
| 348 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 339 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 349 ASSERT_FALSE( | 340 ASSERT_FALSE( |
| 350 change_processor()->ProcessSyncChanges(FROM_HERE, change_list2).IsSet()); | 341 change_processor()->ProcessSyncChanges(FROM_HERE, change_list2).IsSet()); |
| 351 | 342 |
| 352 syncer::SyncDataList password_list( | 343 SyncDataList password_list(change_processor()->GetAllSyncData(PASSWORDS)); |
| 353 change_processor()->GetAllSyncData(syncer::PASSWORDS)); | |
| 354 | 344 |
| 355 ASSERT_EQ(password_list.size(), change_list2.size()); | 345 ASSERT_EQ(password_list.size(), change_list2.size()); |
| 356 for (int i = 0; i < kNumPasswords; ++i) { | 346 for (int i = 0; i < kNumPasswords; ++i) { |
| 357 // Verify the password is returned properly. | 347 // Verify the password is returned properly. |
| 358 ASSERT_TRUE(password_list[i].GetSpecifics().has_password()); | 348 ASSERT_TRUE(password_list[i].GetSpecifics().has_password()); |
| 359 ASSERT_TRUE(password_list[i] | 349 ASSERT_TRUE(password_list[i] |
| 360 .GetSpecifics() | 350 .GetSpecifics() |
| 361 .password() | 351 .password() |
| 362 .has_client_only_encrypted_data()); | 352 .has_client_only_encrypted_data()); |
| 363 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted()); | 353 ASSERT_FALSE(password_list[i].GetSpecifics().password().has_encrypted()); |
| 364 const sync_pb::PasswordSpecificsData& sync_password = | 354 const sync_pb::PasswordSpecificsData& sync_password = |
| 365 password_list[i].GetSpecifics().password().client_only_encrypted_data(); | 355 password_list[i].GetSpecifics().password().client_only_encrypted_data(); |
| 366 const sync_pb::PasswordSpecificsData& change_password = | 356 const sync_pb::PasswordSpecificsData& change_password = |
| 367 change_list2[i] | 357 change_list2[i] |
| 368 .sync_data() | 358 .sync_data() |
| 369 .GetSpecifics() | 359 .GetSpecifics() |
| 370 .password() | 360 .password() |
| 371 .client_only_encrypted_data(); | 361 .client_only_encrypted_data(); |
| 372 ASSERT_EQ(sync_password.password_value(), change_password.password_value()); | 362 ASSERT_EQ(sync_password.password_value(), change_password.password_value()); |
| 373 ASSERT_EQ(sync_password.username_value(), change_password.username_value()); | 363 ASSERT_EQ(sync_password.username_value(), change_password.username_value()); |
| 374 | 364 |
| 375 // Verify the raw sync data was stored securely. | 365 // Verify the raw sync data was stored securely. |
| 376 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); | 366 ReadTransaction read_transaction(FROM_HERE, user_share()); |
| 377 syncer::ReadNode node(&read_transaction); | 367 ReadNode node(&read_transaction); |
| 378 ASSERT_EQ(node.InitByClientTagLookup(syncer::PASSWORDS, | 368 ASSERT_EQ( |
| 379 base::StringPrintf("tag%i", i)), | 369 node.InitByClientTagLookup(PASSWORDS, base::StringPrintf("tag%i", i)), |
| 380 syncer::BaseNode::INIT_OK); | 370 BaseNode::INIT_OK); |
| 381 ASSERT_EQ(node.GetTitle(), "encrypted"); | 371 ASSERT_EQ(node.GetTitle(), "encrypted"); |
| 382 const sync_pb::EntitySpecifics& raw_specifics = node.GetEntitySpecifics(); | 372 const sync_pb::EntitySpecifics& raw_specifics = node.GetEntitySpecifics(); |
| 383 ASSERT_TRUE(raw_specifics.has_password()); | 373 ASSERT_TRUE(raw_specifics.has_password()); |
| 384 ASSERT_TRUE(raw_specifics.password().has_encrypted()); | 374 ASSERT_TRUE(raw_specifics.password().has_encrypted()); |
| 385 ASSERT_FALSE(raw_specifics.password().has_client_only_encrypted_data()); | 375 ASSERT_FALSE(raw_specifics.password().has_client_only_encrypted_data()); |
| 386 } | 376 } |
| 387 } | 377 } |
| 388 | 378 |
| 389 // Verify that attachments on newly added or updated SyncData are passed to the | 379 // Verify that attachments on newly added or updated SyncData are passed to the |
| 390 // AttachmentService. | 380 // AttachmentService. |
| 391 TEST_F(SyncGenericChangeProcessorTest, | 381 TEST_F(SyncGenericChangeProcessorTest, |
| 392 ProcessSyncChanges_AddUpdateWithAttachment) { | 382 ProcessSyncChanges_AddUpdateWithAttachment) { |
| 393 std::string tag = "client_tag"; | 383 std::string tag = "client_tag"; |
| 394 std::string title = "client_title"; | 384 std::string title = "client_title"; |
| 395 sync_pb::EntitySpecifics specifics; | 385 sync_pb::EntitySpecifics specifics; |
| 396 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); | 386 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); |
| 397 pref_specifics->set_name("test"); | 387 pref_specifics->set_name("test"); |
| 398 | 388 |
| 399 syncer::AttachmentIdList attachment_ids; | 389 AttachmentIdList attachment_ids; |
| 400 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); | 390 attachment_ids.push_back(AttachmentId::Create(0, 0)); |
| 401 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); | 391 attachment_ids.push_back(AttachmentId::Create(0, 0)); |
| 402 | 392 |
| 403 // Add a SyncData with two attachments. | 393 // Add a SyncData with two attachments. |
| 404 syncer::SyncChangeList change_list; | 394 SyncChangeList change_list; |
| 405 change_list.push_back( | 395 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD, |
| 406 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD, | 396 SyncData::CreateLocalDataWithAttachments( |
| 407 syncer::SyncData::CreateLocalDataWithAttachments( | 397 tag, title, specifics, attachment_ids))); |
| 408 tag, title, specifics, attachment_ids))); | |
| 409 ASSERT_FALSE( | 398 ASSERT_FALSE( |
| 410 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 399 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 411 RunLoop(); | 400 RunLoop(); |
| 412 | 401 |
| 413 // Check that the AttachmentService received the new attachments. | 402 // Check that the AttachmentService received the new attachments. |
| 414 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); | 403 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); |
| 415 const syncer::AttachmentIdList& attachments_added = | 404 const AttachmentIdList& attachments_added = |
| 416 mock_attachment_service()->attachment_id_lists()->front(); | 405 mock_attachment_service()->attachment_id_lists()->front(); |
| 417 ASSERT_THAT(attachments_added, testing::UnorderedElementsAre( | 406 ASSERT_THAT(attachments_added, testing::UnorderedElementsAre( |
| 418 attachment_ids[0], attachment_ids[1])); | 407 attachment_ids[0], attachment_ids[1])); |
| 419 | 408 |
| 420 // Update the SyncData, replacing its two attachments with one new attachment. | 409 // Update the SyncData, replacing its two attachments with one new attachment. |
| 421 syncer::AttachmentIdList new_attachment_ids; | 410 AttachmentIdList new_attachment_ids; |
| 422 new_attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); | 411 new_attachment_ids.push_back(AttachmentId::Create(0, 0)); |
| 423 mock_attachment_service()->attachment_id_lists()->clear(); | 412 mock_attachment_service()->attachment_id_lists()->clear(); |
| 424 change_list.clear(); | 413 change_list.clear(); |
| 425 change_list.push_back( | 414 change_list.push_back( |
| 426 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE, | 415 SyncChange(FROM_HERE, SyncChange::ACTION_UPDATE, |
| 427 syncer::SyncData::CreateLocalDataWithAttachments( | 416 SyncData::CreateLocalDataWithAttachments(tag, title, specifics, |
| 428 tag, title, specifics, new_attachment_ids))); | 417 new_attachment_ids))); |
| 429 ASSERT_FALSE( | 418 ASSERT_FALSE( |
| 430 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 419 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 431 RunLoop(); | 420 RunLoop(); |
| 432 | 421 |
| 433 // Check that the AttachmentService received it. | 422 // Check that the AttachmentService received it. |
| 434 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); | 423 ASSERT_EQ(mock_attachment_service()->attachment_id_lists()->size(), 1U); |
| 435 const syncer::AttachmentIdList& new_attachments_added = | 424 const AttachmentIdList& new_attachments_added = |
| 436 mock_attachment_service()->attachment_id_lists()->front(); | 425 mock_attachment_service()->attachment_id_lists()->front(); |
| 437 ASSERT_THAT(new_attachments_added, | 426 ASSERT_THAT(new_attachments_added, |
| 438 testing::UnorderedElementsAre(new_attachment_ids[0])); | 427 testing::UnorderedElementsAre(new_attachment_ids[0])); |
| 439 } | 428 } |
| 440 | 429 |
| 441 // Verify that after attachment is uploaded GenericChangeProcessor updates | 430 // Verify that after attachment is uploaded GenericChangeProcessor updates |
| 442 // corresponding entries | 431 // corresponding entries |
| 443 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { | 432 TEST_F(SyncGenericChangeProcessorTest, AttachmentUploaded) { |
| 444 std::string tag = "client_tag"; | 433 std::string tag = "client_tag"; |
| 445 std::string title = "client_title"; | 434 std::string title = "client_title"; |
| 446 sync_pb::EntitySpecifics specifics; | 435 sync_pb::EntitySpecifics specifics; |
| 447 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); | 436 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); |
| 448 pref_specifics->set_name("test"); | 437 pref_specifics->set_name("test"); |
| 449 | 438 |
| 450 syncer::AttachmentIdList attachment_ids; | 439 AttachmentIdList attachment_ids; |
| 451 attachment_ids.push_back(syncer::AttachmentId::Create(0, 0)); | 440 attachment_ids.push_back(AttachmentId::Create(0, 0)); |
| 452 | 441 |
| 453 // Add a SyncData with two attachments. | 442 // Add a SyncData with two attachments. |
| 454 syncer::SyncChangeList change_list; | 443 SyncChangeList change_list; |
| 455 change_list.push_back( | 444 change_list.push_back(SyncChange(FROM_HERE, SyncChange::ACTION_ADD, |
| 456 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD, | 445 SyncData::CreateLocalDataWithAttachments( |
| 457 syncer::SyncData::CreateLocalDataWithAttachments( | 446 tag, title, specifics, attachment_ids))); |
| 458 tag, title, specifics, attachment_ids))); | |
| 459 ASSERT_FALSE( | 447 ASSERT_FALSE( |
| 460 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 448 change_processor()->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); |
| 461 | 449 |
| 462 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto(); | 450 sync_pb::AttachmentIdProto attachment_id_proto = attachment_ids[0].GetProto(); |
| 463 syncer::AttachmentId attachment_id = | 451 AttachmentId attachment_id = |
| 464 syncer::AttachmentId::CreateFromProto(attachment_id_proto); | 452 AttachmentId::CreateFromProto(attachment_id_proto); |
| 465 | 453 |
| 466 change_processor()->OnAttachmentUploaded(attachment_id); | 454 change_processor()->OnAttachmentUploaded(attachment_id); |
| 467 syncer::ReadTransaction read_transaction(FROM_HERE, user_share()); | 455 ReadTransaction read_transaction(FROM_HERE, user_share()); |
| 468 syncer::ReadNode node(&read_transaction); | 456 ReadNode node(&read_transaction); |
| 469 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), syncer::BaseNode::INIT_OK); | 457 ASSERT_EQ(node.InitByClientTagLookup(kType, tag), BaseNode::INIT_OK); |
| 470 attachment_ids = node.GetAttachmentIds(); | 458 attachment_ids = node.GetAttachmentIds(); |
| 471 EXPECT_EQ(1U, attachment_ids.size()); | 459 EXPECT_EQ(1U, attachment_ids.size()); |
| 472 } | 460 } |
| 473 | 461 |
| 474 // Verify that upon construction, all attachments not yet on the server are | 462 // Verify that upon construction, all attachments not yet on the server are |
| 475 // scheduled for upload. | 463 // scheduled for upload. |
| 476 TEST_F(SyncGenericChangeProcessorTest, UploadAllAttachmentsNotOnServer) { | 464 TEST_F(SyncGenericChangeProcessorTest, UploadAllAttachmentsNotOnServer) { |
| 477 // Create two attachment ids. id2 will be marked as "on server". | 465 // Create two attachment ids. id2 will be marked as "on server". |
| 478 syncer::AttachmentId id1 = syncer::AttachmentId::Create(0, 0); | 466 AttachmentId id1 = AttachmentId::Create(0, 0); |
| 479 syncer::AttachmentId id2 = syncer::AttachmentId::Create(0, 0); | 467 AttachmentId id2 = AttachmentId::Create(0, 0); |
| 480 { | 468 { |
| 481 // Write an entry containing these two attachment ids. | 469 // Write an entry containing these two attachment ids. |
| 482 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 470 WriteTransaction trans(FROM_HERE, user_share()); |
| 483 syncer::ReadNode root(&trans); | 471 ReadNode root(&trans); |
| 484 ASSERT_EQ(syncer::BaseNode::INIT_OK, root.InitTypeRoot(kType)); | 472 ASSERT_EQ(BaseNode::INIT_OK, root.InitTypeRoot(kType)); |
| 485 syncer::WriteNode node(&trans); | 473 WriteNode node(&trans); |
| 486 node.InitUniqueByCreation(kType, root, "some node"); | 474 node.InitUniqueByCreation(kType, root, "some node"); |
| 487 sync_pb::AttachmentMetadata metadata; | 475 sync_pb::AttachmentMetadata metadata; |
| 488 sync_pb::AttachmentMetadataRecord* record1 = metadata.add_record(); | 476 sync_pb::AttachmentMetadataRecord* record1 = metadata.add_record(); |
| 489 *record1->mutable_id() = id1.GetProto(); | 477 *record1->mutable_id() = id1.GetProto(); |
| 490 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); | 478 sync_pb::AttachmentMetadataRecord* record2 = metadata.add_record(); |
| 491 *record2->mutable_id() = id2.GetProto(); | 479 *record2->mutable_id() = id2.GetProto(); |
| 492 record2->set_is_on_server(true); | 480 record2->set_is_on_server(true); |
| 493 node.SetAttachmentMetadata(metadata); | 481 node.SetAttachmentMetadata(metadata); |
| 494 } | 482 } |
| 495 | 483 |
| 496 // Construct the GenericChangeProcessor and see that it asks the | 484 // Construct the GenericChangeProcessor and see that it asks the |
| 497 // AttachmentService to upload id1 only. | 485 // AttachmentService to upload id1 only. |
| 498 ConstructGenericChangeProcessor(kType); | 486 ConstructGenericChangeProcessor(kType); |
| 499 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_lists()->size()); | 487 ASSERT_EQ(1U, mock_attachment_service()->attachment_id_lists()->size()); |
| 500 ASSERT_THAT(mock_attachment_service()->attachment_id_lists()->front(), | 488 ASSERT_THAT(mock_attachment_service()->attachment_id_lists()->front(), |
| 501 testing::UnorderedElementsAre(id1)); | 489 testing::UnorderedElementsAre(id1)); |
| 502 } | 490 } |
| 503 | 491 |
| 504 // Test that attempting to add an entry that already exists still works. | 492 // Test that attempting to add an entry that already exists still works. |
| 505 TEST_F(SyncGenericChangeProcessorTest, AddExistingEntry) { | 493 TEST_F(SyncGenericChangeProcessorTest, AddExistingEntry) { |
| 506 InitializeForType(syncer::SESSIONS); | 494 InitializeForType(SESSIONS); |
| 507 sync_pb::EntitySpecifics sessions_specifics; | 495 sync_pb::EntitySpecifics sessions_specifics; |
| 508 sessions_specifics.mutable_session()->set_session_tag("session tag"); | 496 sessions_specifics.mutable_session()->set_session_tag("session tag"); |
| 509 syncer::SyncChangeList changes; | 497 SyncChangeList changes; |
| 510 | 498 |
| 511 // First add it normally. | 499 // First add it normally. |
| 512 changes.push_back(syncer::SyncChange( | 500 changes.push_back( |
| 513 FROM_HERE, syncer::SyncChange::ACTION_ADD, | 501 SyncChange(FROM_HERE, SyncChange::ACTION_ADD, |
| 514 syncer::SyncData::CreateLocalData(base::StringPrintf("tag"), | 502 SyncData::CreateLocalData(base::StringPrintf("tag"), |
| 515 base::StringPrintf("title"), | 503 base::StringPrintf("title"), |
| 516 sessions_specifics))); | 504 sessions_specifics))); |
| 517 ASSERT_FALSE( | 505 ASSERT_FALSE( |
| 518 change_processor()->ProcessSyncChanges(FROM_HERE, changes).IsSet()); | 506 change_processor()->ProcessSyncChanges(FROM_HERE, changes).IsSet()); |
| 519 | 507 |
| 520 // Now attempt to add it again, but with different specifics. Should not | 508 // Now attempt to add it again, but with different specifics. Should not |
| 521 // result in an error and should still update the specifics. | 509 // result in an error and should still update the specifics. |
| 522 sessions_specifics.mutable_session()->set_session_tag("session tag 2"); | 510 sessions_specifics.mutable_session()->set_session_tag("session tag 2"); |
| 523 changes[0] = | 511 changes[0] = SyncChange(FROM_HERE, SyncChange::ACTION_ADD, |
| 524 syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_ADD, | 512 SyncData::CreateLocalData(base::StringPrintf("tag"), |
| 525 syncer::SyncData::CreateLocalData( | 513 base::StringPrintf("title"), |
| 526 base::StringPrintf("tag"), | 514 sessions_specifics)); |
| 527 base::StringPrintf("title"), sessions_specifics)); | |
| 528 ASSERT_FALSE( | 515 ASSERT_FALSE( |
| 529 change_processor()->ProcessSyncChanges(FROM_HERE, changes).IsSet()); | 516 change_processor()->ProcessSyncChanges(FROM_HERE, changes).IsSet()); |
| 530 | 517 |
| 531 // Verify the data was updated properly. | 518 // Verify the data was updated properly. |
| 532 syncer::SyncDataList sync_data = | 519 SyncDataList sync_data = change_processor()->GetAllSyncData(SESSIONS); |
| 533 change_processor()->GetAllSyncData(syncer::SESSIONS); | |
| 534 ASSERT_EQ(sync_data.size(), 1U); | 520 ASSERT_EQ(sync_data.size(), 1U); |
| 535 ASSERT_EQ("session tag 2", | 521 ASSERT_EQ("session tag 2", |
| 536 sync_data[0].GetSpecifics().session().session_tag()); | 522 sync_data[0].GetSpecifics().session().session_tag()); |
| 537 EXPECT_FALSE(syncer::SyncDataRemote(sync_data[0]).GetClientTagHash().empty()); | 523 EXPECT_FALSE(SyncDataRemote(sync_data[0]).GetClientTagHash().empty()); |
| 538 } | 524 } |
| 539 | 525 |
| 540 } // namespace | 526 } // namespace |
| 541 | 527 |
| 542 } // namespace sync_driver | 528 } // namespace syncer |
| OLD | NEW |