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

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

Issue 11636006: WIP: The Bookmark Position Megapatch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Various updates, including switch suffix to unique_client_tag style Created 7 years, 12 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/test_syncable_utils.cc » ('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
(...skipping 14 matching lines...) Expand all
25 using sync_pb::CommitResponse; 25 using sync_pb::CommitResponse;
26 using sync_pb::GetUpdatesMessage; 26 using sync_pb::GetUpdatesMessage;
27 using sync_pb::SyncEnums; 27 using sync_pb::SyncEnums;
28 28
29 namespace syncer { 29 namespace syncer {
30 30
31 using syncable::WriteTransaction; 31 using syncable::WriteTransaction;
32 32
33 static char kValidAuthToken[] = "AuthToken"; 33 static char kValidAuthToken[] = "AuthToken";
34 34
35 static char kCacheGuid[] = "tuiWdG8hV+8y4RT9N5Aikg==";
36
35 MockConnectionManager::MockConnectionManager(syncable::Directory* directory) 37 MockConnectionManager::MockConnectionManager(syncable::Directory* directory)
36 : ServerConnectionManager("unused", 0, false), 38 : ServerConnectionManager("unused", 0, false),
37 server_reachable_(true), 39 server_reachable_(true),
38 conflict_all_commits_(false), 40 conflict_all_commits_(false),
39 conflict_n_commits_(0), 41 conflict_n_commits_(0),
40 next_new_id_(10000), 42 next_new_id_(10000),
41 store_birthday_("Store BDay!"), 43 store_birthday_("Store BDay!"),
42 store_birthday_sent_(false), 44 store_birthday_sent_(false),
43 client_stuck_(false), 45 client_stuck_(false),
44 commit_time_rename_prepended_string_(""), 46 commit_time_rename_prepended_string_(""),
45 countdown_to_postbuffer_fail_(0), 47 countdown_to_postbuffer_fail_(0),
46 directory_(directory), 48 directory_(directory),
47 mid_commit_observer_(NULL), 49 mid_commit_observer_(NULL),
48 throttling_(false), 50 throttling_(false),
49 fail_with_auth_invalid_(false), 51 fail_with_auth_invalid_(false),
50 fail_non_periodic_get_updates_(false), 52 fail_non_periodic_get_updates_(false),
51 gu_client_command_(NULL), 53 gu_client_command_(NULL),
52 commit_client_command_(NULL), 54 commit_client_command_(NULL),
53 next_position_in_parent_(2), 55 next_position_in_parent_(2),
54 use_legacy_bookmarks_protocol_(false), 56 use_legacy_bookmarks_protocol_(false),
55 num_get_updates_requests_(0) { 57 num_get_updates_requests_(0),
58 originator_item_id_(-100000) {
56 SetNewTimestamp(0); 59 SetNewTimestamp(0);
57 set_auth_token(kValidAuthToken); 60 set_auth_token(kValidAuthToken);
58 } 61 }
59 62
60 MockConnectionManager::~MockConnectionManager() { 63 MockConnectionManager::~MockConnectionManager() {
61 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates."; 64 EXPECT_TRUE(update_queue_.empty()) << "Unfetched updates.";
62 } 65 }
63 66
64 void MockConnectionManager::SetCommitTimeRename(string prepend) { 67 void MockConnectionManager::SetCommitTimeRename(string prepend) {
65 commit_time_rename_prepended_string_ = prepend; 68 commit_time_rename_prepended_string_ = prepend;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 sync_pb::SyncEntity* ent = AddUpdateMeta( 240 sync_pb::SyncEntity* ent = AddUpdateMeta(
238 TestIdFactory::FromNumber(id).GetServerId(), 241 TestIdFactory::FromNumber(id).GetServerId(),
239 TestIdFactory::FromNumber(parent_id).GetServerId(), 242 TestIdFactory::FromNumber(parent_id).GetServerId(),
240 name, version, sync_ts); 243 name, version, sync_ts);
241 ent->set_position_in_parent(position); 244 ent->set_position_in_parent(position);
242 ent->mutable_specifics()->CopyFrom(specifics); 245 ent->mutable_specifics()->CopyFrom(specifics);
243 ent->set_folder(is_dir); 246 ent->set_folder(is_dir);
244 return ent; 247 return ent;
245 } 248 }
246 249
250 sync_pb::SyncEntity* MockConnectionManager::AddBookmarkUpdateSpecifics(
251 int id, int parent_id, string name, int64 version, int64 sync_ts,
252 bool is_dir, int64 position, const sync_pb::EntitySpecifics& specifics) {
253 sync_pb::SyncEntity* ent = AddUpdateSpecifics(
254 id, parent_id, name, version, sync_ts, is_dir, position, specifics);
255 ent->set_originator_cache_guid(kCacheGuid);
256 // Not entirely right, but it sure looks like a client ID.
257 syncable::Id client_id =
258 syncable::Id::CreateFromClientString(base::IntToString(id * -1));
259 ent->set_originator_client_item_id(client_id.value());
260 return ent;
261 }
262
263 sync_pb::SyncEntity* MockConnectionManager::AddBookmarkUpdateSpecifics(
264 int id, int parent_id, string name, int64 version, int64 sync_ts,
265 bool is_dir, const syncer::UniquePosition& position,
266 const sync_pb::EntitySpecifics& specifics) {
267 sync_pb::SyncEntity* ent = AddUpdateMeta(
268 TestIdFactory::FromNumber(id).GetServerId(),
269 TestIdFactory::FromNumber(parent_id).GetServerId(),
270 name, version, sync_ts);
271 ent->set_position_in_parent(position.ToInt64());
272 ent->set_unique_position(position.ToInternalValue());
273 ent->mutable_specifics()->CopyFrom(specifics);
274 ent->set_folder(is_dir);
275
276 ent->set_originator_cache_guid(kCacheGuid);
277 // Not entirely right, but it sure looks like a client ID.
278 syncable::Id client_id =
279 syncable::Id::CreateFromClientString(
280 base::Int64ToString(id * -1));
281 ent->set_originator_client_item_id(client_id.value());
282
283 return ent;
284 }
285
247 sync_pb::SyncEntity* MockConnectionManager::SetNigori( 286 sync_pb::SyncEntity* MockConnectionManager::SetNigori(
248 int id, int64 version,int64 sync_ts, 287 int id, int64 version,int64 sync_ts,
249 const sync_pb::EntitySpecifics& specifics) { 288 const sync_pb::EntitySpecifics& specifics) {
250 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); 289 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
251 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId()); 290 ent->set_id_string(TestIdFactory::FromNumber(id).GetServerId());
252 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId()); 291 ent->set_parent_id_string(TestIdFactory::FromNumber(0).GetServerId());
253 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI)); 292 ent->set_server_defined_unique_tag(ModelTypeToRootTag(NIGORI));
254 ent->set_name("Nigori"); 293 ent->set_name("Nigori");
255 ent->set_non_unique_name("Nigori"); 294 ent->set_non_unique_name("Nigori");
256 ent->set_version(version); 295 ent->set_version(version);
257 ent->set_sync_timestamp(sync_ts); 296 ent->set_sync_timestamp(sync_ts);
258 ent->set_mtime(sync_ts); 297 ent->set_mtime(sync_ts);
259 ent->set_ctime(1); 298 ent->set_ctime(1);
260 ent->set_position_in_parent(0); 299 ent->set_position_in_parent(0);
261 ent->set_folder(false); 300 ent->set_folder(false);
262 ent->mutable_specifics()->CopyFrom(specifics); 301 ent->mutable_specifics()->CopyFrom(specifics);
263 return ent; 302 return ent;
264 } 303 }
265 304
266 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFull( 305 sync_pb::SyncEntity* MockConnectionManager::AddUpdateFull(
267 string id, string parent_id, 306 string id, string parent_id,
268 string name, int64 version, 307 string name, int64 version,
269 int64 sync_ts, bool is_dir) { 308 int64 sync_ts, bool is_dir) {
270 sync_pb::SyncEntity* ent = 309 sync_pb::SyncEntity* ent =
271 AddUpdateMeta(id, parent_id, name, version, sync_ts); 310 AddUpdateMeta(id, parent_id, name, version, sync_ts);
272 AddDefaultBookmarkData(ent, is_dir); 311 AddDefaultBookmarkData(ent, is_dir);
312 SetUpdateOriginatorFields(ent);
273 return ent; 313 return ent;
274 } 314 }
275 315
276 sync_pb::SyncEntity* MockConnectionManager::AddUpdateMeta( 316 sync_pb::SyncEntity* MockConnectionManager::AddUpdateMeta(
277 string id, string parent_id, 317 string id, string parent_id,
278 string name, int64 version, 318 string name, int64 version,
279 int64 sync_ts) { 319 int64 sync_ts) {
280 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); 320 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
281 ent->set_id_string(id); 321 ent->set_id_string(id);
282 ent->set_parent_id_string(parent_id); 322 ent->set_parent_id_string(parent_id);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); 360 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
321 ent->CopyFrom(last_sent_commit().entries(0)); 361 ent->CopyFrom(last_sent_commit().entries(0));
322 ent->clear_insert_after_item_id(); 362 ent->clear_insert_after_item_id();
323 ent->clear_old_parent_id(); 363 ent->clear_old_parent_id();
324 ent->set_position_in_parent( 364 ent->set_position_in_parent(
325 last_commit_response().entryresponse(0).position_in_parent()); 365 last_commit_response().entryresponse(0).position_in_parent());
326 ent->set_version( 366 ent->set_version(
327 last_commit_response().entryresponse(0).version()); 367 last_commit_response().entryresponse(0).version());
328 ent->set_id_string( 368 ent->set_id_string(
329 last_commit_response().entryresponse(0).id_string()); 369 last_commit_response().entryresponse(0).id_string());
370 SetUpdateOriginatorFields(ent);
371
330 // Tests don't currently care about the following: 372 // Tests don't currently care about the following:
331 // originator_cache_guid, originator_client_item_id, parent_id_string, 373 // parent_id_string, name, non_unique_name.
332 // name, non_unique_name.
333 } 374 }
334 return GetMutableLastUpdate(); 375 return GetMutableLastUpdate();
335 } 376 }
336 377
337 void MockConnectionManager::AddUpdateTombstone(const syncable::Id& id) { 378 void MockConnectionManager::AddUpdateTombstone(const syncable::Id& id) {
338 // Tombstones have only the ID set and dummy values for the required fields. 379 // Tombstones have only the ID set and dummy values for the required fields.
339 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries(); 380 sync_pb::SyncEntity* ent = GetUpdateResponse()->add_entries();
340 ent->set_id_string(id.GetServerId()); 381 ent->set_id_string(id.GetServerId());
341 ent->set_version(0); 382 ent->set_version(0);
342 ent->set_name(""); 383 ent->set_name("");
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 652 }
612 653
613 void MockConnectionManager::UpdateConnectionStatus() { 654 void MockConnectionManager::UpdateConnectionStatus() {
614 if (!server_reachable_) { 655 if (!server_reachable_) {
615 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE; 656 server_status_ = HttpResponse::CONNECTION_UNAVAILABLE;
616 } else { 657 } else {
617 server_status_ = HttpResponse::SERVER_CONNECTION_OK; 658 server_status_ = HttpResponse::SERVER_CONNECTION_OK;
618 } 659 }
619 } 660 }
620 661
662 void MockConnectionManager::SetUpdateOriginatorFields(
663 sync_pb::SyncEntity* entity) {
664 if (GetModelType(*entity) == BOOKMARKS) {
665 entity->set_originator_cache_guid(kCacheGuid);
666 syncable::Id client_id =
667 syncable::Id::CreateFromClientString(
668 base::Int64ToString(originator_item_id_--));
669 entity->set_originator_client_item_id(client_id.value());
670 }
671 }
672
673
621 } // namespace syncer 674 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/test/engine/mock_connection_manager.h ('k') | sync/test/engine/test_syncable_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698