Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Side by Side Diff: sync/test/engine/mock_connection_manager.cc

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/test/engine/mock_connection_manager.h ('k') | sync/test/engine/syncer_command_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "sync/engine/syncer_proto_util.h" 13 #include "sync/engine/syncer_proto_util.h"
14 #include "sync/protocol/bookmark_specifics.pb.h" 14 #include "sync/protocol/bookmark_specifics.pb.h"
15 #include "sync/syncable/directory.h" 15 #include "sync/syncable/directory.h"
16 #include "sync/syncable/write_transaction.h" 16 #include "sync/syncable/write_transaction.h"
17 #include "sync/test/engine/test_id_factory.h" 17 #include "sync/test/engine/test_id_factory.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using std::map; 20 using std::map;
21 using std::string; 21 using std::string;
22 using sync_pb::CommitMessage; 22 using sync_pb::CommitMessage;
23 using sync_pb::CommitResponse; 23 using sync_pb::CommitResponse;
24 using sync_pb::GetUpdatesMessage; 24 using sync_pb::GetUpdatesMessage;
25 using sync_pb::SyncEnums; 25 using sync_pb::SyncEnums;
26 26
27 namespace syncer { 27 namespace syncer {
28 28
29 using syncable::FIRST_REAL_MODEL_TYPE;
30 using syncable::MODEL_TYPE_COUNT;
31 using syncable::ModelType;
32 using syncable::WriteTransaction; 29 using syncable::WriteTransaction;
33 30
34 static char kValidAuthToken[] = "AuthToken"; 31 static char kValidAuthToken[] = "AuthToken";
35 32
36 MockConnectionManager::MockConnectionManager(syncable::Directory* directory) 33 MockConnectionManager::MockConnectionManager(syncable::Directory* directory)
37 : ServerConnectionManager("unused", 0, false), 34 : ServerConnectionManager("unused", 0, false),
38 server_reachable_(true), 35 server_reachable_(true),
39 conflict_all_commits_(false), 36 conflict_all_commits_(false),
40 conflict_n_commits_(0), 37 conflict_n_commits_(0),
41 next_new_id_(10000), 38 next_new_id_(10000),
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ent->set_folder(is_dir); 237 ent->set_folder(is_dir);
241 return ent; 238 return ent;
242 } 239 }
243 240
244 sync_pb::SyncEntity* MockConnectionManager::SetNigori( 241 sync_pb::SyncEntity* MockConnectionManager::SetNigori(
245 int id, int64 version,int64 sync_ts, 242 int id, int64 version,int64 sync_ts,
246 const sync_pb::EntitySpecifics& specifics) { 243 const sync_pb::EntitySpecifics& specifics) {
247 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); 244 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
248 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId()); 245 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId());
249 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId()); 246 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId());
250 ent->set_server_defined_unique_tag(syncable::ModelTypeToRootTag( 247 ent->set_server_defined_unique_tag(syncer::ModelTypeToRootTag(
251 syncable::NIGORI)); 248 syncer::NIGORI));
252 ent->set_name("Nigori"); 249 ent->set_name("Nigori");
253 ent->set_non_unique_name("Nigori"); 250 ent->set_non_unique_name("Nigori");
254 ent->set_version(version); 251 ent->set_version(version);
255 ent->set_sync_timestamp(sync_ts); 252 ent->set_sync_timestamp(sync_ts);
256 ent->set_mtime(sync_ts); 253 ent->set_mtime(sync_ts);
257 ent->set_ctime(1); 254 ent->set_ctime(1);
258 ent->set_position_in_parent(0); 255 ent->set_position_in_parent(0);
259 ent->set_folder(false); 256 ent->set_folder(false);
260 ent->mutable_specifics()->CopyFrom(specifics); 257 ent->mutable_specifics()->CopyFrom(specifics);
261 return ent; 258 return ent;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 EXPECT_FALSE(gu.has_requested_types()); 394 EXPECT_FALSE(gu.has_requested_types());
398 395
399 if (fail_non_periodic_get_updates_) { 396 if (fail_non_periodic_get_updates_) {
400 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, 397 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC,
401 gu.caller_info().source()); 398 gu.caller_info().source());
402 } 399 }
403 400
404 // 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
405 // expectation. 402 // expectation.
406 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) {
407 ModelType model_type = syncable::ModelTypeFromInt(i); 404 ModelType model_type = syncer::ModelTypeFromInt(i);
408 sync_pb::DataTypeProgressMarker const* progress_marker = 405 sync_pb::DataTypeProgressMarker const* progress_marker =
409 GetProgressMarkerForType(gu.from_progress_marker(), model_type); 406 GetProgressMarkerForType(gu.from_progress_marker(), model_type);
410 EXPECT_EQ(expected_filter_.Has(model_type), (progress_marker != NULL)) 407 EXPECT_EQ(expected_filter_.Has(model_type), (progress_marker != NULL))
411 << "Syncer requested_types differs from test expectation."; 408 << "Syncer requested_types differs from test expectation.";
412 if (progress_marker) { 409 if (progress_marker) {
413 EXPECT_EQ((expected_payloads_.count(model_type) > 0 ? 410 EXPECT_EQ((expected_payloads_.count(model_type) > 0 ?
414 expected_payloads_[model_type] : 411 expected_payloads_[model_type] :
415 std::string()), 412 std::string()),
416 progress_marker->notification_hint()); 413 progress_marker->notification_hint());
417 } 414 }
418 } 415 }
419 416
420 // 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
421 // 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
422 // a test bug. 419 // a test bug.
423 EXPECT_TRUE(gu.fetch_folders()); 420 EXPECT_TRUE(gu.fetch_folders());
424 EXPECT_FALSE(gu.has_requested_types()); 421 EXPECT_FALSE(gu.has_requested_types());
425 if (update_queue_.empty()) { 422 if (update_queue_.empty()) {
426 GetUpdateResponse(); 423 GetUpdateResponse();
427 } 424 }
428 sync_pb::GetUpdatesResponse* updates = &update_queue_.front(); 425 sync_pb::GetUpdatesResponse* updates = &update_queue_.front();
429 for (int i = 0; i < updates->entries_size(); ++i) { 426 for (int i = 0; i < updates->entries_size(); ++i) {
430 if (!updates->entries(i).deleted()) { 427 if (!updates->entries(i).deleted()) {
431 ModelType entry_type = syncable::GetModelType(updates->entries(i)); 428 ModelType entry_type = syncer::GetModelType(updates->entries(i));
432 EXPECT_TRUE( 429 EXPECT_TRUE(
433 IsModelTypePresentInSpecifics(gu.from_progress_marker(), entry_type)) 430 IsModelTypePresentInSpecifics(gu.from_progress_marker(), entry_type))
434 << "Syncer did not request updates being provided by the test."; 431 << "Syncer did not request updates being provided by the test.";
435 } 432 }
436 } 433 }
437 434
438 response->mutable_get_updates()->CopyFrom(*updates); 435 response->mutable_get_updates()->CopyFrom(*updates);
439 436
440 // Set appropriate progress markers, overriding the value squirreled 437 // Set appropriate progress markers, overriding the value squirreled
441 // away by ApplyToken(). 438 // away by ApplyToken().
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 547 }
551 548
552 const CommitResponse& MockConnectionManager::last_commit_response() const { 549 const CommitResponse& MockConnectionManager::last_commit_response() const {
553 EXPECT_TRUE(!commit_responses_.empty()); 550 EXPECT_TRUE(!commit_responses_.empty());
554 return *commit_responses_.back(); 551 return *commit_responses_.back();
555 } 552 }
556 553
557 bool MockConnectionManager::IsModelTypePresentInSpecifics( 554 bool MockConnectionManager::IsModelTypePresentInSpecifics(
558 const google::protobuf::RepeatedPtrField< 555 const google::protobuf::RepeatedPtrField<
559 sync_pb::DataTypeProgressMarker>& filter, 556 sync_pb::DataTypeProgressMarker>& filter,
560 syncable::ModelType value) { 557 syncer::ModelType value) {
561 int data_type_id = syncable::GetSpecificsFieldNumberFromModelType(value); 558 int data_type_id = syncer::GetSpecificsFieldNumberFromModelType(value);
562 for (int i = 0; i < filter.size(); ++i) { 559 for (int i = 0; i < filter.size(); ++i) {
563 if (filter.Get(i).data_type_id() == data_type_id) { 560 if (filter.Get(i).data_type_id() == data_type_id) {
564 return true; 561 return true;
565 } 562 }
566 } 563 }
567 return false; 564 return false;
568 } 565 }
569 566
570 sync_pb::DataTypeProgressMarker const* 567 sync_pb::DataTypeProgressMarker const*
571 MockConnectionManager::GetProgressMarkerForType( 568 MockConnectionManager::GetProgressMarkerForType(
572 const google::protobuf::RepeatedPtrField< 569 const google::protobuf::RepeatedPtrField<
573 sync_pb::DataTypeProgressMarker>& filter, 570 sync_pb::DataTypeProgressMarker>& filter,
574 syncable::ModelType value) { 571 syncer::ModelType value) {
575 int data_type_id = syncable::GetSpecificsFieldNumberFromModelType(value); 572 int data_type_id = syncer::GetSpecificsFieldNumberFromModelType(value);
576 for (int i = 0; i < filter.size(); ++i) { 573 for (int i = 0; i < filter.size(); ++i) {
577 if (filter.Get(i).data_type_id() == data_type_id) { 574 if (filter.Get(i).data_type_id() == data_type_id) {
578 return &(filter.Get(i)); 575 return &(filter.Get(i));
579 } 576 }
580 } 577 }
581 return NULL; 578 return NULL;
582 } 579 }
583 580
584 void MockConnectionManager::SetServerReachable() { 581 void MockConnectionManager::SetServerReachable() {
585 server_reachable_ = true; 582 server_reachable_ = true;
586 } 583 }
587 584
588 void MockConnectionManager::SetServerNotReachable() { 585 void MockConnectionManager::SetServerNotReachable() {
589 server_reachable_ = false; 586 server_reachable_ = false;
590 } 587 }
591 588
592 void MockConnectionManager::UpdateConnectionStatus() { 589 void MockConnectionManager::UpdateConnectionStatus() {
593 if (!server_reachable_) { 590 if (!server_reachable_) {
594 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; 591 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE;
595 } else { 592 } else {
596 server_status_ = HttpResponse::SERVER_CONNECTION_OK; 593 server_status_ = HttpResponse::SERVER_CONNECTION_OK;
597 } 594 }
598 } 595 }
599 596
600 } // namespace syncer 597 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/test/engine/mock_connection_manager.h ('k') | sync/test/engine/syncer_command_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698