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