| 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/core/shared_model_type_processor.h" | 5 #include "components/sync/core/shared_model_type_processor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "components/sync/core/simple_metadata_change_list.h" | 25 #include "components/sync/core/simple_metadata_change_list.h" |
| 26 #include "components/sync/engine/commit_queue.h" | 26 #include "components/sync/engine/commit_queue.h" |
| 27 #include "components/sync/protocol/sync.pb.h" | 27 #include "components/sync/protocol/sync.pb.h" |
| 28 #include "components/sync/test/engine/mock_model_type_worker.h" | 28 #include "components/sync/test/engine/mock_model_type_worker.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using sync_pb::EntitySpecifics; | 31 using sync_pb::EntitySpecifics; |
| 32 using sync_pb::EntityMetadata; | 32 using sync_pb::EntityMetadata; |
| 33 using sync_pb::DataTypeState; | 33 using sync_pb::DataTypeState; |
| 34 | 34 |
| 35 namespace syncer { | 35 namespace syncer_v2 { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const char kKey1[] = "key1"; | 39 const char kKey1[] = "key1"; |
| 40 const char kKey2[] = "key2"; | 40 const char kKey2[] = "key2"; |
| 41 const char kKey3[] = "key3"; | 41 const char kKey3[] = "key3"; |
| 42 const char kKey4[] = "key4"; | 42 const char kKey4[] = "key4"; |
| 43 const char kKey5[] = "key5"; | 43 const char kKey5[] = "key5"; |
| 44 const char kValue1[] = "value1"; | 44 const char kValue1[] = "value1"; |
| 45 const char kValue2[] = "value2"; | 45 const char kValue2[] = "value2"; |
| 46 const char kValue3[] = "value3"; | 46 const char kValue3[] = "value3"; |
| 47 const std::string kHash1(FakeModelTypeService::TagHashFromKey(kKey1)); | 47 const std::string kHash1(FakeModelTypeService::TagHashFromKey(kKey1)); |
| 48 const std::string kHash2(FakeModelTypeService::TagHashFromKey(kKey2)); | 48 const std::string kHash2(FakeModelTypeService::TagHashFromKey(kKey2)); |
| 49 const std::string kHash3(FakeModelTypeService::TagHashFromKey(kKey3)); | 49 const std::string kHash3(FakeModelTypeService::TagHashFromKey(kKey3)); |
| 50 const std::string kHash4(FakeModelTypeService::TagHashFromKey(kKey4)); | 50 const std::string kHash4(FakeModelTypeService::TagHashFromKey(kKey4)); |
| 51 const std::string kHash5(FakeModelTypeService::TagHashFromKey(kKey5)); | 51 const std::string kHash5(FakeModelTypeService::TagHashFromKey(kKey5)); |
| 52 | 52 |
| 53 // Typically used for verification after a delete. The specifics given to the | 53 // Typically used for verification after a delete. The specifics given to the |
| 54 // worker/processor will not have been initialized and thus empty. | 54 // worker/processor will not have been initialized and thus empty. |
| 55 const EntitySpecifics kEmptySpecifics; | 55 const EntitySpecifics kEmptySpecifics; |
| 56 | 56 |
| 57 SyncError CreateSyncError(SyncError::ErrorType error_type) { | 57 syncer::SyncError CreateSyncError(syncer::SyncError::ErrorType error_type) { |
| 58 return SyncError(FROM_HERE, error_type, "TestError", PREFERENCES); | 58 return syncer::SyncError(FROM_HERE, error_type, "TestError", |
| 59 syncer::PREFERENCES); |
| 59 } | 60 } |
| 60 | 61 |
| 61 } // namespace | 62 } // namespace |
| 62 | 63 |
| 63 // Tests the various functionality of SharedModelTypeProcessor. | 64 // Tests the various functionality of SharedModelTypeProcessor. |
| 64 // | 65 // |
| 65 // The processor sits between the service (implemented by this test class) and | 66 // The processor sits between the service (implemented by this test class) and |
| 66 // the worker, which is represented by a MockModelTypeWorker. This test suite | 67 // the worker, which is represented by a MockModelTypeWorker. This test suite |
| 67 // exercises the initialization flows (whether initial sync is done, performing | 68 // exercises the initialization flows (whether initial sync is done, performing |
| 68 // the initial merge, etc) as well as normal functionality: | 69 // the initial merge, etc) as well as normal functionality: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 // Initialize to a "ready-to-commit" state. | 94 // Initialize to a "ready-to-commit" state. |
| 94 void InitializeToReadyState() { | 95 void InitializeToReadyState() { |
| 95 InitializeToMetadataLoaded(); | 96 InitializeToMetadataLoaded(); |
| 96 if (!data_callback_.is_null()) { | 97 if (!data_callback_.is_null()) { |
| 97 OnPendingCommitDataLoaded(); | 98 OnPendingCommitDataLoaded(); |
| 98 } | 99 } |
| 99 OnSyncStarting(); | 100 OnSyncStarting(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void OnMetadataLoaded() { | 103 void OnMetadataLoaded() { |
| 103 type_processor()->OnMetadataLoaded(SyncError(), db_.CreateMetadataBatch()); | 104 type_processor()->OnMetadataLoaded(syncer::SyncError(), |
| 105 db_.CreateMetadataBatch()); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void OnPendingCommitDataLoaded() { | 108 void OnPendingCommitDataLoaded() { |
| 107 DCHECK(!data_callback_.is_null()); | 109 DCHECK(!data_callback_.is_null()); |
| 108 data_callback_.Run(); | 110 data_callback_.Run(); |
| 109 data_callback_.Reset(); | 111 data_callback_.Reset(); |
| 110 } | 112 } |
| 111 | 113 |
| 112 void OnSyncStarting() { | 114 void OnSyncStarting() { |
| 113 std::unique_ptr<DataTypeErrorHandlerMock> error_handler = | 115 std::unique_ptr<syncer::DataTypeErrorHandlerMock> error_handler = |
| 114 base::MakeUnique<DataTypeErrorHandlerMock>(); | 116 base::MakeUnique<syncer::DataTypeErrorHandlerMock>(); |
| 115 error_handler_ = error_handler.get(); | 117 error_handler_ = error_handler.get(); |
| 116 type_processor()->OnSyncStarting( | 118 type_processor()->OnSyncStarting( |
| 117 std::move(error_handler), | 119 std::move(error_handler), |
| 118 base::Bind(&SharedModelTypeProcessorTest::OnReadyToConnect, | 120 base::Bind(&SharedModelTypeProcessorTest::OnReadyToConnect, |
| 119 base::Unretained(this))); | 121 base::Unretained(this))); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void DisconnectSync() { | 124 void DisconnectSync() { |
| 123 type_processor()->DisconnectSync(); | 125 type_processor()->DisconnectSync(); |
| 124 worker_ = nullptr; | 126 worker_ = nullptr; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 171 } |
| 170 | 172 |
| 171 // Return the number of entities the processor has metadata for. | 173 // Return the number of entities the processor has metadata for. |
| 172 size_t ProcessorEntityCount() const { | 174 size_t ProcessorEntityCount() const { |
| 173 DCHECK(type_processor()); | 175 DCHECK(type_processor()); |
| 174 return type_processor()->entities_.size(); | 176 return type_processor()->entities_.size(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 // Sets the error type that OnReadyToConnect (our StartCallback) expects to | 179 // Sets the error type that OnReadyToConnect (our StartCallback) expects to |
| 178 // receive. | 180 // receive. |
| 179 void ExpectStartError(SyncError::ErrorType error_type) { | 181 void ExpectStartError(syncer::SyncError::ErrorType error_type) { |
| 180 DCHECK(expected_start_error_ == SyncError::UNSET); | 182 DCHECK(expected_start_error_ == syncer::SyncError::UNSET); |
| 181 expected_start_error_ = error_type; | 183 expected_start_error_ = error_type; |
| 182 } | 184 } |
| 183 | 185 |
| 184 MockModelTypeWorker* worker() { return worker_; } | 186 MockModelTypeWorker* worker() { return worker_; } |
| 185 | 187 |
| 186 SharedModelTypeProcessor* type_processor() const { | 188 SharedModelTypeProcessor* type_processor() const { |
| 187 return static_cast<SharedModelTypeProcessor*>(change_processor()); | 189 return static_cast<SharedModelTypeProcessor*>(change_processor()); |
| 188 } | 190 } |
| 189 | 191 |
| 190 DataTypeErrorHandlerMock* error_handler() { | 192 syncer::DataTypeErrorHandlerMock* error_handler() { |
| 191 DCHECK(error_handler_); | 193 DCHECK(error_handler_); |
| 192 return error_handler_; | 194 return error_handler_; |
| 193 } | 195 } |
| 194 | 196 |
| 195 int merge_call_count() const { return merge_call_count_; } | 197 int merge_call_count() const { return merge_call_count_; } |
| 196 | 198 |
| 197 private: | 199 private: |
| 198 void CheckPostConditions() override { | 200 void CheckPostConditions() override { |
| 199 FakeModelTypeService::CheckPostConditions(); | 201 FakeModelTypeService::CheckPostConditions(); |
| 200 DCHECK(data_callback_.is_null()); | 202 DCHECK(data_callback_.is_null()); |
| 201 DCHECK_EQ(SyncError::UNSET, expected_start_error_); | 203 DCHECK_EQ(syncer::SyncError::UNSET, expected_start_error_); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void OnReadyToConnect(SyncError error, | 206 void OnReadyToConnect(syncer::SyncError error, |
| 205 std::unique_ptr<ActivationContext> context) { | 207 std::unique_ptr<ActivationContext> context) { |
| 206 if (expected_start_error_ != SyncError::UNSET) { | 208 if (expected_start_error_ != syncer::SyncError::UNSET) { |
| 207 EXPECT_TRUE(error.IsSet()); | 209 EXPECT_TRUE(error.IsSet()); |
| 208 EXPECT_EQ(expected_start_error_, error.error_type()); | 210 EXPECT_EQ(expected_start_error_, error.error_type()); |
| 209 EXPECT_EQ(nullptr, context); | 211 EXPECT_EQ(nullptr, context); |
| 210 expected_start_error_ = SyncError::UNSET; | 212 expected_start_error_ = syncer::SyncError::UNSET; |
| 211 return; | 213 return; |
| 212 } | 214 } |
| 213 | 215 |
| 214 std::unique_ptr<MockModelTypeWorker> worker( | 216 std::unique_ptr<MockModelTypeWorker> worker( |
| 215 new MockModelTypeWorker(context->data_type_state, type_processor())); | 217 new MockModelTypeWorker(context->data_type_state, type_processor())); |
| 216 // Keep an unsafe pointer to the commit queue the processor will use. | 218 // Keep an unsafe pointer to the commit queue the processor will use. |
| 217 worker_ = worker.get(); | 219 worker_ = worker.get(); |
| 218 // The context contains a proxy to the processor, but this call is | 220 // The context contains a proxy to the processor, but this call is |
| 219 // side-stepping that completely and connecting directly to the real | 221 // side-stepping that completely and connecting directly to the real |
| 220 // processor, since these tests are single-threaded and don't need proxies. | 222 // processor, since these tests are single-threaded and don't need proxies. |
| 221 type_processor()->ConnectSync(std::move(worker)); | 223 type_processor()->ConnectSync(std::move(worker)); |
| 222 } | 224 } |
| 223 | 225 |
| 224 // FakeModelTypeService overrides. | 226 // FakeModelTypeService overrides. |
| 225 | 227 |
| 226 SyncError MergeSyncData(std::unique_ptr<MetadataChangeList> mcl, | 228 syncer::SyncError MergeSyncData(std::unique_ptr<MetadataChangeList> mcl, |
| 227 EntityDataMap entity_data_map) override { | 229 EntityDataMap entity_data_map) override { |
| 228 merge_call_count_++; | 230 merge_call_count_++; |
| 229 return FakeModelTypeService::MergeSyncData(std::move(mcl), entity_data_map); | 231 return FakeModelTypeService::MergeSyncData(std::move(mcl), entity_data_map); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void CaptureDataCallback(DataCallback callback, | 234 void CaptureDataCallback(DataCallback callback, |
| 233 SyncError error, | 235 syncer::SyncError error, |
| 234 std::unique_ptr<DataBatch> data) { | 236 std::unique_ptr<DataBatch> data) { |
| 235 data_callback_ = base::Bind(callback, error, base::Passed(std::move(data))); | 237 data_callback_ = base::Bind(callback, error, base::Passed(std::move(data))); |
| 236 } | 238 } |
| 237 | 239 |
| 238 void GetData(StorageKeyList keys, DataCallback callback) override { | 240 void GetData(StorageKeyList keys, DataCallback callback) override { |
| 239 FakeModelTypeService::GetData( | 241 FakeModelTypeService::GetData( |
| 240 keys, base::Bind(&SharedModelTypeProcessorTest::CaptureDataCallback, | 242 keys, base::Bind(&SharedModelTypeProcessorTest::CaptureDataCallback, |
| 241 base::Unretained(this), callback)); | 243 base::Unretained(this), callback)); |
| 242 } | 244 } |
| 243 | 245 |
| 244 // This sets ThreadTaskRunnerHandle on the current thread, which the type | 246 // This sets ThreadTaskRunnerHandle on the current thread, which the type |
| 245 // processor will pick up as the sync task runner. | 247 // processor will pick up as the sync task runner. |
| 246 base::MessageLoop sync_loop_; | 248 base::MessageLoop sync_loop_; |
| 247 | 249 |
| 248 // The current mock queue, which is owned by |type_processor()|. | 250 // The current mock queue, which is owned by |type_processor()|. |
| 249 MockModelTypeWorker* worker_; | 251 MockModelTypeWorker* worker_; |
| 250 | 252 |
| 251 // Stores the data callback between GetData() and OnPendingCommitDataLoaded(). | 253 // Stores the data callback between GetData() and OnPendingCommitDataLoaded(). |
| 252 base::Closure data_callback_; | 254 base::Closure data_callback_; |
| 253 | 255 |
| 254 // The processor's error handler. | 256 // The processor's error handler. |
| 255 DataTypeErrorHandlerMock* error_handler_; | 257 syncer::DataTypeErrorHandlerMock* error_handler_; |
| 256 | 258 |
| 257 // The error to expect in OnReadyToConnect(). | 259 // The error to expect in OnReadyToConnect(). |
| 258 SyncError::ErrorType expected_start_error_ = SyncError::UNSET; | 260 syncer::SyncError::ErrorType expected_start_error_ = syncer::SyncError::UNSET; |
| 259 | 261 |
| 260 // The number of times MergeSyncData has been called. | 262 // The number of times MergeSyncData has been called. |
| 261 int merge_call_count_ = 0; | 263 int merge_call_count_ = 0; |
| 262 }; | 264 }; |
| 263 | 265 |
| 264 // Test that an initial sync handles local and remote items properly. | 266 // Test that an initial sync handles local and remote items properly. |
| 265 TEST_F(SharedModelTypeProcessorTest, InitialSync) { | 267 TEST_F(SharedModelTypeProcessorTest, InitialSync) { |
| 266 CreateChangeProcessor(); | 268 CreateChangeProcessor(); |
| 267 OnMetadataLoaded(); | 269 OnMetadataLoaded(); |
| 268 OnSyncStarting(); | 270 OnSyncStarting(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 EXPECT_EQ(2U, db().data_count()); | 310 EXPECT_EQ(2U, db().data_count()); |
| 309 EXPECT_EQ(2U, db().metadata_count()); | 311 EXPECT_EQ(2U, db().metadata_count()); |
| 310 } | 312 } |
| 311 | 313 |
| 312 // Test that an error during the merge is propagated to the error handler. | 314 // Test that an error during the merge is propagated to the error handler. |
| 313 TEST_F(SharedModelTypeProcessorTest, InitialSyncError) { | 315 TEST_F(SharedModelTypeProcessorTest, InitialSyncError) { |
| 314 CreateChangeProcessor(); | 316 CreateChangeProcessor(); |
| 315 OnMetadataLoaded(); | 317 OnMetadataLoaded(); |
| 316 OnSyncStarting(); | 318 OnSyncStarting(); |
| 317 | 319 |
| 318 SetServiceError(SyncError::DATATYPE_ERROR); | 320 SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
| 319 error_handler()->ExpectError(SyncError::DATATYPE_ERROR); | 321 error_handler()->ExpectError(syncer::SyncError::DATATYPE_ERROR); |
| 320 worker()->UpdateFromServer(); | 322 worker()->UpdateFromServer(); |
| 321 } | 323 } |
| 322 | 324 |
| 323 // Test that errors before it's called are passed to |start_callback| correctly. | 325 // Test that errors before it's called are passed to |start_callback| correctly. |
| 324 TEST_F(SharedModelTypeProcessorTest, StartErrors) { | 326 TEST_F(SharedModelTypeProcessorTest, StartErrors) { |
| 325 CreateChangeProcessor(); | 327 CreateChangeProcessor(); |
| 326 type_processor()->OnMetadataLoaded(CreateSyncError(SyncError::DATATYPE_ERROR), | 328 type_processor()->OnMetadataLoaded( |
| 327 nullptr); | 329 CreateSyncError(syncer::SyncError::DATATYPE_ERROR), nullptr); |
| 328 ExpectStartError(SyncError::DATATYPE_ERROR); | 330 ExpectStartError(syncer::SyncError::DATATYPE_ERROR); |
| 329 OnSyncStarting(); | 331 OnSyncStarting(); |
| 330 | 332 |
| 331 // Test OnSyncStarting happening first. | 333 // Test OnSyncStarting happening first. |
| 332 ResetState(); | 334 ResetState(); |
| 333 CreateChangeProcessor(); | 335 CreateChangeProcessor(); |
| 334 OnSyncStarting(); | 336 OnSyncStarting(); |
| 335 ExpectStartError(SyncError::DATATYPE_ERROR); | 337 ExpectStartError(syncer::SyncError::DATATYPE_ERROR); |
| 336 type_processor()->OnMetadataLoaded(CreateSyncError(SyncError::DATATYPE_ERROR), | 338 type_processor()->OnMetadataLoaded( |
| 337 nullptr); | 339 CreateSyncError(syncer::SyncError::DATATYPE_ERROR), nullptr); |
| 338 | 340 |
| 339 // Test an error loading pending data. | 341 // Test an error loading pending data. |
| 340 ResetStateWriteItem(kKey1, kValue1); | 342 ResetStateWriteItem(kKey1, kValue1); |
| 341 SetServiceError(SyncError::DATATYPE_ERROR); | 343 SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
| 342 InitializeToMetadataLoaded(); | 344 InitializeToMetadataLoaded(); |
| 343 OnPendingCommitDataLoaded(); | 345 OnPendingCommitDataLoaded(); |
| 344 ExpectStartError(SyncError::DATATYPE_ERROR); | 346 ExpectStartError(syncer::SyncError::DATATYPE_ERROR); |
| 345 OnSyncStarting(); | 347 OnSyncStarting(); |
| 346 } | 348 } |
| 347 | 349 |
| 348 // This test covers race conditions during loading pending data. All cases | 350 // This test covers race conditions during loading pending data. All cases |
| 349 // start with no processor and one acked (committed to the server) item with a | 351 // start with no processor and one acked (committed to the server) item with a |
| 350 // pending commit. There are three different events that can occur in any order | 352 // pending commit. There are three different events that can occur in any order |
| 351 // once metadata is loaded: | 353 // once metadata is loaded: |
| 352 // | 354 // |
| 353 // - Pending commit data is loaded. | 355 // - Pending commit data is loaded. |
| 354 // - Sync gets connected. | 356 // - Sync gets connected. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 EXPECT_EQ(1, acked_metadata.sequence_number()); | 601 EXPECT_EQ(1, acked_metadata.sequence_number()); |
| 600 EXPECT_EQ(1, acked_metadata.acked_sequence_number()); | 602 EXPECT_EQ(1, acked_metadata.acked_sequence_number()); |
| 601 EXPECT_EQ(1, acked_metadata.server_version()); | 603 EXPECT_EQ(1, acked_metadata.server_version()); |
| 602 } | 604 } |
| 603 | 605 |
| 604 // Test that an error applying metadata changes from a commit response is | 606 // Test that an error applying metadata changes from a commit response is |
| 605 // propagated to the error handler. | 607 // propagated to the error handler. |
| 606 TEST_F(SharedModelTypeProcessorTest, ErrorApplyingAck) { | 608 TEST_F(SharedModelTypeProcessorTest, ErrorApplyingAck) { |
| 607 InitializeToReadyState(); | 609 InitializeToReadyState(); |
| 608 WriteItem(kKey1, kValue1); | 610 WriteItem(kKey1, kValue1); |
| 609 SetServiceError(SyncError::DATATYPE_ERROR); | 611 SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
| 610 error_handler()->ExpectError(SyncError::DATATYPE_ERROR); | 612 error_handler()->ExpectError(syncer::SyncError::DATATYPE_ERROR); |
| 611 worker()->AckOnePendingCommit(); | 613 worker()->AckOnePendingCommit(); |
| 612 } | 614 } |
| 613 | 615 |
| 614 // The purpose of this test case is to test setting |client_tag_hash| and |id| | 616 // The purpose of this test case is to test setting |client_tag_hash| and |id| |
| 615 // on the EntityData object as we pass it into the Put method of the processor. | 617 // on the EntityData object as we pass it into the Put method of the processor. |
| 616 TEST_F(SharedModelTypeProcessorTest, LocalUpdateItemWithOverrides) { | 618 TEST_F(SharedModelTypeProcessorTest, LocalUpdateItemWithOverrides) { |
| 617 const std::string kId1 = "cid1"; | 619 const std::string kId1 = "cid1"; |
| 618 const std::string kId2 = "cid2"; | 620 const std::string kId2 = "cid2"; |
| 619 | 621 |
| 620 InitializeToReadyState(); | 622 InitializeToReadyState(); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 EXPECT_EQ(1, metadata.server_version()); | 766 EXPECT_EQ(1, metadata.server_version()); |
| 765 EXPECT_TRUE(metadata.has_creation_time()); | 767 EXPECT_TRUE(metadata.has_creation_time()); |
| 766 EXPECT_TRUE(metadata.has_modification_time()); | 768 EXPECT_TRUE(metadata.has_modification_time()); |
| 767 EXPECT_TRUE(metadata.has_specifics_hash()); | 769 EXPECT_TRUE(metadata.has_specifics_hash()); |
| 768 } | 770 } |
| 769 | 771 |
| 770 // Test that an error applying changes from a server update is | 772 // Test that an error applying changes from a server update is |
| 771 // propagated to the error handler. | 773 // propagated to the error handler. |
| 772 TEST_F(SharedModelTypeProcessorTest, ErrorApplyingUpdate) { | 774 TEST_F(SharedModelTypeProcessorTest, ErrorApplyingUpdate) { |
| 773 InitializeToReadyState(); | 775 InitializeToReadyState(); |
| 774 SetServiceError(SyncError::DATATYPE_ERROR); | 776 SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
| 775 error_handler()->ExpectError(SyncError::DATATYPE_ERROR); | 777 error_handler()->ExpectError(syncer::SyncError::DATATYPE_ERROR); |
| 776 worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue1)); | 778 worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue1)); |
| 777 } | 779 } |
| 778 | 780 |
| 779 // Thoroughly tests the data generated by a server item creation. | 781 // Thoroughly tests the data generated by a server item creation. |
| 780 TEST_F(SharedModelTypeProcessorTest, ServerUpdateItem) { | 782 TEST_F(SharedModelTypeProcessorTest, ServerUpdateItem) { |
| 781 InitializeToReadyState(); | 783 InitializeToReadyState(); |
| 782 | 784 |
| 783 // Local add writes data and metadata; ack writes metadata again. | 785 // Local add writes data and metadata; ack writes metadata again. |
| 784 WriteItemAndAck(kKey1, kValue1); | 786 WriteItemAndAck(kKey1, kValue1); |
| 785 EXPECT_EQ(1U, db().data_change_count()); | 787 EXPECT_EQ(1U, db().data_change_count()); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 OnPendingCommitDataLoaded(); | 1107 OnPendingCommitDataLoaded(); |
| 1106 ASSERT_EQ(3U, worker()->GetNumPendingCommits()); | 1108 ASSERT_EQ(3U, worker()->GetNumPendingCommits()); |
| 1107 worker()->ExpectNthPendingCommit(2, kHash1, specifics1); | 1109 worker()->ExpectNthPendingCommit(2, kHash1, specifics1); |
| 1108 } | 1110 } |
| 1109 | 1111 |
| 1110 // Test that an error loading pending commit data for re-encryption is | 1112 // Test that an error loading pending commit data for re-encryption is |
| 1111 // propagated to the error handler. | 1113 // propagated to the error handler. |
| 1112 TEST_F(SharedModelTypeProcessorTest, ReEncryptErrorLoadingData) { | 1114 TEST_F(SharedModelTypeProcessorTest, ReEncryptErrorLoadingData) { |
| 1113 InitializeToReadyState(); | 1115 InitializeToReadyState(); |
| 1114 WriteItemAndAck(kKey1, kValue1); | 1116 WriteItemAndAck(kKey1, kValue1); |
| 1115 SetServiceError(SyncError::DATATYPE_ERROR); | 1117 SetServiceError(syncer::SyncError::DATATYPE_ERROR); |
| 1116 worker()->UpdateWithEncryptionKey("k1"); | 1118 worker()->UpdateWithEncryptionKey("k1"); |
| 1117 error_handler()->ExpectError(SyncError::DATATYPE_ERROR); | 1119 error_handler()->ExpectError(syncer::SyncError::DATATYPE_ERROR); |
| 1118 OnPendingCommitDataLoaded(); | 1120 OnPendingCommitDataLoaded(); |
| 1119 } | 1121 } |
| 1120 | 1122 |
| 1121 // Test receipt of updates with new and old keys. | 1123 // Test receipt of updates with new and old keys. |
| 1122 TEST_F(SharedModelTypeProcessorTest, ReEncryptUpdatesWithNewKey) { | 1124 TEST_F(SharedModelTypeProcessorTest, ReEncryptUpdatesWithNewKey) { |
| 1123 InitializeToReadyState(); | 1125 InitializeToReadyState(); |
| 1124 | 1126 |
| 1125 // Receive an unencrypted update. | 1127 // Receive an unencrypted update. |
| 1126 worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue1)); | 1128 worker()->UpdateFromServer(kHash1, GenerateSpecifics(kKey1, kValue1)); |
| 1127 ASSERT_EQ(0U, worker()->GetNumPendingCommits()); | 1129 ASSERT_EQ(0U, worker()->GetNumPendingCommits()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 worker()->ExpectNthPendingCommit(0, kHash1, specifics2); | 1269 worker()->ExpectNthPendingCommit(0, kHash1, specifics2); |
| 1268 | 1270 |
| 1269 UpdateResponseDataList update; | 1271 UpdateResponseDataList update; |
| 1270 update.push_back(worker()->GenerateUpdateData(kHash1, specifics1, 1, "k1")); | 1272 update.push_back(worker()->GenerateUpdateData(kHash1, specifics1, 1, "k1")); |
| 1271 worker()->UpdateWithEncryptionKey("k1", update); | 1273 worker()->UpdateWithEncryptionKey("k1", update); |
| 1272 | 1274 |
| 1273 EXPECT_EQ(2U, worker()->GetNumPendingCommits()); | 1275 EXPECT_EQ(2U, worker()->GetNumPendingCommits()); |
| 1274 worker()->ExpectNthPendingCommit(1, kHash1, specifics2); | 1276 worker()->ExpectNthPendingCommit(1, kHash1, specifics2); |
| 1275 } | 1277 } |
| 1276 | 1278 |
| 1277 } // namespace syncer | 1279 } // namespace syncer_v2 |
| OLD | NEW |