| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Mock ServerConnectionManager class for use in client regression tests. | 5 // Mock ServerConnectionManager class for use in client regression tests. |
| 6 | 6 |
| 7 #include "sync/test/engine/mock_connection_manager.h" | 7 #include "sync/test/engine/mock_connection_manager.h" |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 void MockConnectionManager::SetMidCommitObserver( | 71 void MockConnectionManager::SetMidCommitObserver( |
| 72 MockConnectionManager::MidCommitObserver* observer) { | 72 MockConnectionManager::MidCommitObserver* observer) { |
| 73 mid_commit_observer_ = observer; | 73 mid_commit_observer_ = observer; |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, | 76 bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, |
| 77 const string& path, | 77 const string& path, |
| 78 const string& auth_token, | 78 const string& auth_token, |
| 79 syncer::ScopedServerStatusWatcher* watcher) { | 79 ScopedServerStatusWatcher* watcher) { |
| 80 ClientToServerMessage post; | 80 ClientToServerMessage post; |
| 81 CHECK(post.ParseFromString(params->buffer_in)); | 81 CHECK(post.ParseFromString(params->buffer_in)); |
| 82 CHECK(post.has_protocol_version()); | 82 CHECK(post.has_protocol_version()); |
| 83 last_request_.CopyFrom(post); | 83 last_request_.CopyFrom(post); |
| 84 client_stuck_ = post.sync_problem_detected(); | 84 client_stuck_ = post.sync_problem_detected(); |
| 85 sync_pb::ClientToServerResponse response; | 85 sync_pb::ClientToServerResponse response; |
| 86 response.Clear(); | 86 response.Clear(); |
| 87 | 87 |
| 88 if (directory_) { | 88 if (directory_) { |
| 89 // If the Directory's locked when we do this, it's a problem as in normal | 89 // If the Directory's locked when we do this, it's a problem as in normal |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 ent->set_folder(is_dir); | 238 ent->set_folder(is_dir); |
| 239 return ent; | 239 return ent; |
| 240 } | 240 } |
| 241 | 241 |
| 242 sync_pb::SyncEntity* MockConnectionManager::SetNigori( | 242 sync_pb::SyncEntity* MockConnectionManager::SetNigori( |
| 243 int id, int64 version,int64 sync_ts, | 243 int id, int64 version,int64 sync_ts, |
| 244 const sync_pb::EntitySpecifics& specifics) { | 244 const sync_pb::EntitySpecifics& specifics) { |
| 245 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); | 245 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); |
| 246 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId()); | 246 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId()); |
| 247 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId()); | 247 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId()); |
| 248 ent->set_server_defined_unique_tag(syncer::ModelTypeToRootTag( | 248 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI)); |
| 249 syncer::NIGORI)); | |
| 250 ent->set_name("Nigori"); | 249 ent->set_name("Nigori"); |
| 251 ent->set_non_unique_name("Nigori"); | 250 ent->set_non_unique_name("Nigori"); |
| 252 ent->set_version(version); | 251 ent->set_version(version); |
| 253 ent->set_sync_timestamp(sync_ts); | 252 ent->set_sync_timestamp(sync_ts); |
| 254 ent->set_mtime(sync_ts); | 253 ent->set_mtime(sync_ts); |
| 255 ent->set_ctime(1); | 254 ent->set_ctime(1); |
| 256 ent->set_position_in_parent(0); | 255 ent->set_position_in_parent(0); |
| 257 ent->set_folder(false); | 256 ent->set_folder(false); |
| 258 ent->mutable_specifics()->CopyFrom(specifics); | 257 ent->mutable_specifics()->CopyFrom(specifics); |
| 259 return ent; | 258 return ent; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 EXPECT_FALSE(gu.has_requested_types()); | 394 EXPECT_FALSE(gu.has_requested_types()); |
| 396 | 395 |
| 397 if (fail_non_periodic_get_updates_) { | 396 if (fail_non_periodic_get_updates_) { |
| 398 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, | 397 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, |
| 399 gu.caller_info().source()); | 398 gu.caller_info().source()); |
| 400 } | 399 } |
| 401 | 400 |
| 402 // Verify that the GetUpdates filter sent by the Syncer matches the test | 401 // Verify that the GetUpdates filter sent by the Syncer matches the test |
| 403 // expectation. | 402 // expectation. |
| 404 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 403 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
| 405 ModelType model_type = syncer::ModelTypeFromInt(i); | 404 ModelType model_type = ModelTypeFromInt(i); |
| 406 sync_pb::DataTypeProgressMarker const* progress_marker = | 405 sync_pb::DataTypeProgressMarker const* progress_marker = |
| 407 GetProgressMarkerForType(gu.from_progress_marker(), model_type); | 406 GetProgressMarkerForType(gu.from_progress_marker(), model_type); |
| 408 EXPECT_EQ(expected_filter_.Has(model_type), (progress_marker != NULL)) | 407 EXPECT_EQ(expected_filter_.Has(model_type), (progress_marker != NULL)) |
| 409 << "Syncer requested_types differs from test expectation."; | 408 << "Syncer requested_types differs from test expectation."; |
| 410 if (progress_marker) { | 409 if (progress_marker) { |
| 411 EXPECT_EQ((expected_payloads_.count(model_type) > 0 ? | 410 EXPECT_EQ((expected_payloads_.count(model_type) > 0 ? |
| 412 expected_payloads_[model_type] : | 411 expected_payloads_[model_type] : |
| 413 std::string()), | 412 std::string()), |
| 414 progress_marker->notification_hint()); | 413 progress_marker->notification_hint()); |
| 415 } | 414 } |
| 416 } | 415 } |
| 417 | 416 |
| 418 // Verify that the items we're about to send back to the client are of | 417 // Verify that the items we're about to send back to the client are of |
| 419 // the types requested by the client. If this fails, it probably indicates | 418 // the types requested by the client. If this fails, it probably indicates |
| 420 // a test bug. | 419 // a test bug. |
| 421 EXPECT_TRUE(gu.fetch_folders()); | 420 EXPECT_TRUE(gu.fetch_folders()); |
| 422 EXPECT_FALSE(gu.has_requested_types()); | 421 EXPECT_FALSE(gu.has_requested_types()); |
| 423 if (update_queue_.empty()) { | 422 if (update_queue_.empty()) { |
| 424 GetUpdateResponse(); | 423 GetUpdateResponse(); |
| 425 } | 424 } |
| 426 sync_pb::GetUpdatesResponse* updates = &update_queue_.front(); | 425 sync_pb::GetUpdatesResponse* updates = &update_queue_.front(); |
| 427 for (int i = 0; i < updates->entries_size(); ++i) { | 426 for (int i = 0; i < updates->entries_size(); ++i) { |
| 428 if (!updates->entries(i).deleted()) { | 427 if (!updates->entries(i).deleted()) { |
| 429 ModelType entry_type = syncer::GetModelType(updates->entries(i)); | 428 ModelType entry_type = GetModelType(updates->entries(i)); |
| 430 EXPECT_TRUE( | 429 EXPECT_TRUE( |
| 431 IsModelTypePresentInSpecifics(gu.from_progress_marker(), entry_type)) | 430 IsModelTypePresentInSpecifics(gu.from_progress_marker(), entry_type)) |
| 432 << "Syncer did not request updates being provided by the test."; | 431 << "Syncer did not request updates being provided by the test."; |
| 433 } | 432 } |
| 434 } | 433 } |
| 435 | 434 |
| 436 response->mutable_get_updates()->CopyFrom(*updates); | 435 response->mutable_get_updates()->CopyFrom(*updates); |
| 437 | 436 |
| 438 // Set appropriate progress markers, overriding the value squirreled | 437 // Set appropriate progress markers, overriding the value squirreled |
| 439 // away by ApplyToken(). | 438 // away by ApplyToken(). |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 547 } |
| 549 | 548 |
| 550 const CommitResponse& MockConnectionManager::last_commit_response() const { | 549 const CommitResponse& MockConnectionManager::last_commit_response() const { |
| 551 EXPECT_TRUE(!commit_responses_.empty()); | 550 EXPECT_TRUE(!commit_responses_.empty()); |
| 552 return *commit_responses_.back(); | 551 return *commit_responses_.back(); |
| 553 } | 552 } |
| 554 | 553 |
| 555 bool MockConnectionManager::IsModelTypePresentInSpecifics( | 554 bool MockConnectionManager::IsModelTypePresentInSpecifics( |
| 556 const google::protobuf::RepeatedPtrField< | 555 const google::protobuf::RepeatedPtrField< |
| 557 sync_pb::DataTypeProgressMarker>& filter, | 556 sync_pb::DataTypeProgressMarker>& filter, |
| 558 syncer::ModelType value) { | 557 ModelType value) { |
| 559 int data_type_id = syncer::GetSpecificsFieldNumberFromModelType(value); | 558 int data_type_id = GetSpecificsFieldNumberFromModelType(value); |
| 560 for (int i = 0; i < filter.size(); ++i) { | 559 for (int i = 0; i < filter.size(); ++i) { |
| 561 if (filter.Get(i).data_type_id() == data_type_id) { | 560 if (filter.Get(i).data_type_id() == data_type_id) { |
| 562 return true; | 561 return true; |
| 563 } | 562 } |
| 564 } | 563 } |
| 565 return false; | 564 return false; |
| 566 } | 565 } |
| 567 | 566 |
| 568 sync_pb::DataTypeProgressMarker const* | 567 sync_pb::DataTypeProgressMarker const* |
| 569 MockConnectionManager::GetProgressMarkerForType( | 568 MockConnectionManager::GetProgressMarkerForType( |
| 570 const google::protobuf::RepeatedPtrField< | 569 const google::protobuf::RepeatedPtrField< |
| 571 sync_pb::DataTypeProgressMarker>& filter, | 570 sync_pb::DataTypeProgressMarker>& filter, |
| 572 syncer::ModelType value) { | 571 ModelType value) { |
| 573 int data_type_id = syncer::GetSpecificsFieldNumberFromModelType(value); | 572 int data_type_id = GetSpecificsFieldNumberFromModelType(value); |
| 574 for (int i = 0; i < filter.size(); ++i) { | 573 for (int i = 0; i < filter.size(); ++i) { |
| 575 if (filter.Get(i).data_type_id() == data_type_id) { | 574 if (filter.Get(i).data_type_id() == data_type_id) { |
| 576 return &(filter.Get(i)); | 575 return &(filter.Get(i)); |
| 577 } | 576 } |
| 578 } | 577 } |
| 579 return NULL; | 578 return NULL; |
| 580 } | 579 } |
| 581 | 580 |
| 582 void MockConnectionManager::SetServerReachable() { | 581 void MockConnectionManager::SetServerReachable() { |
| 583 server_reachable_ = true; | 582 server_reachable_ = true; |
| 584 } | 583 } |
| 585 | 584 |
| 586 void MockConnectionManager::SetServerNotReachable() { | 585 void MockConnectionManager::SetServerNotReachable() { |
| 587 server_reachable_ = false; | 586 server_reachable_ = false; |
| 588 } | 587 } |
| 589 | 588 |
| 590 void MockConnectionManager::UpdateConnectionStatus() { | 589 void MockConnectionManager::UpdateConnectionStatus() { |
| 591 if (!server_reachable_) { | 590 if (!server_reachable_) { |
| 592 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; | 591 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; |
| 593 } else { | 592 } else { |
| 594 server_status_ = HttpResponse::SERVER_CONNECTION_OK; | 593 server_status_ = HttpResponse::SERVER_CONNECTION_OK; |
| 595 } | 594 } |
| 596 } | 595 } |
| 597 | 596 |
| 598 } // namespace syncer | 597 } // namespace syncer |
| OLD | NEW |