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

Side by Side Diff: chrome/test/sync/engine/mock_server_connection.cc

Issue 214033: Use chrome/base synchronization primitives and threads instead of... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/test/sync/engine/mock_server_connection.h" 7 #include "chrome/test/sync/engine/mock_server_connection.h"
8 8
9 #include "chrome/browser/sync/engine/syncer_proto_util.h" 9 #include "chrome/browser/sync/engine/syncer_proto_util.h"
10 #include "chrome/browser/sync/util/character_set_converters.h" 10 #include "chrome/browser/sync/util/character_set_converters.h"
11 #include "chrome/test/sync/engine/test_id_factory.h" 11 #include "chrome/test/sync/engine/test_id_factory.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using browser_sync::HttpResponse; 14 using browser_sync::HttpResponse;
15 using browser_sync::ServerConnectionManager; 15 using browser_sync::ServerConnectionManager;
16 using browser_sync::SyncerProtoUtil; 16 using browser_sync::SyncerProtoUtil;
17 using browser_sync::TestIdFactory; 17 using browser_sync::TestIdFactory;
18 using std::map; 18 using std::map;
19 using std::string; 19 using std::string;
20 using sync_pb::ClientToServerMessage; 20 using sync_pb::ClientToServerMessage;
21 using sync_pb::ClientToServerResponse; 21 using sync_pb::ClientToServerResponse;
22 using sync_pb::CommitMessage; 22 using sync_pb::CommitMessage;
23 using sync_pb::CommitResponse; 23 using sync_pb::CommitResponse;
24 using sync_pb::CommitResponse_EntryResponse; 24 using sync_pb::CommitResponse_EntryResponse;
25 using sync_pb::GetUpdatesMessage; 25 using sync_pb::GetUpdatesMessage;
26 using sync_pb::SyncEntity; 26 using sync_pb::SyncEntity;
27 using syncable::DirectoryManager; 27 using syncable::DirectoryManager;
28 using syncable::ScopedDirLookup;
28 using syncable::WriteTransaction; 29 using syncable::WriteTransaction;
29 30
30 MockConnectionManager::MockConnectionManager(DirectoryManager* dirmgr, 31 MockConnectionManager::MockConnectionManager(DirectoryManager* dirmgr,
31 PathString name) 32 PathString name)
32 : ServerConnectionManager("unused", 0, false, "version", "id"), 33 : ServerConnectionManager("unused", 0, false, "version", "id"),
33 conflict_all_commits_(false), 34 conflict_all_commits_(false),
34 conflict_n_commits_(0), 35 conflict_n_commits_(0),
35 next_new_id_(10000), 36 next_new_id_(10000),
36 store_birthday_("Store BDay!"), 37 store_birthday_("Store BDay!"),
37 store_birthday_sent_(false), 38 store_birthday_sent_(false),
38 client_stuck_(false), 39 client_stuck_(false),
39 commit_time_rename_prepended_string_(""), 40 commit_time_rename_prepended_string_(""),
40 fail_next_postbuffer_(false), 41 fail_next_postbuffer_(false),
41 directory_(dirmgr, name), 42 directory_manager_(dirmgr),
43 directory_name_(name),
42 mid_commit_callback_function_(NULL), 44 mid_commit_callback_function_(NULL),
45 mid_commit_observer_(NULL),
43 client_command_(NULL), 46 client_command_(NULL),
44 next_position_in_parent_(2) { 47 next_position_in_parent_(2) {
45 server_reachable_ = true; 48 server_reachable_ = true;
46 CHECK(directory_.good());
47 }; 49 };
48 50
49 MockConnectionManager::~MockConnectionManager() { 51 MockConnectionManager::~MockConnectionManager() {
50 for (size_t i = 0; i < commit_messages_.size(); i++) 52 for (size_t i = 0; i < commit_messages_.size(); i++)
51 delete commit_messages_[i]; 53 delete commit_messages_[i];
52 } 54 }
53 55
54 void MockConnectionManager::SetCommitTimeRename(string prepend) { 56 void MockConnectionManager::SetCommitTimeRename(string prepend) {
55 commit_time_rename_prepended_string_ = prepend; 57 commit_time_rename_prepended_string_ = prepend;
56 } 58 }
57 59
58 void MockConnectionManager::SetMidCommitCallbackFunction( 60 void MockConnectionManager::SetMidCommitCallbackFunction(
59 MockConnectionManager::TestCallbackFunction callback) { 61 MockConnectionManager::TestCallbackFunction callback) {
60 mid_commit_callback_function_ = callback; 62 mid_commit_callback_function_ = callback;
61 } 63 }
62 64
65 void MockConnectionManager::SetMidCommitObserver(
66 MockConnectionManager::MidCommitObserver* observer) {
67 mid_commit_observer_ = observer;
68 }
69
63 bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params, 70 bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
64 const string& path, 71 const string& path,
65 const string& auth_token) { 72 const string& auth_token) {
73
74 ScopedDirLookup directory(directory_manager_, directory_name_);
75 CHECK(directory.good());
76
66 ClientToServerMessage post; 77 ClientToServerMessage post;
67 CHECK(post.ParseFromString(params->buffer_in)); 78 CHECK(post.ParseFromString(params->buffer_in));
68 client_stuck_ = post.sync_problem_detected(); 79 client_stuck_ = post.sync_problem_detected();
69 ClientToServerResponse response; 80 ClientToServerResponse response;
70 response.Clear(); 81 response.Clear();
71 // If the Directory's locked when we do this, it's a problem as in normal 82 // If the Directory's locked when we do this, it's a problem as in normal
72 // use this function could take a while to return because it accesses the 83 // use this function could take a while to return because it accesses the
73 // network. As we can't test this we do the next best thing and hang here 84 // network. As we can't test this we do the next best thing and hang here
74 // when there's an issue. 85 // when there's an issue.
75 { 86 {
76 WriteTransaction wt(directory_, syncable::UNITTEST, __FILE__, __LINE__); 87 WriteTransaction wt(directory, syncable::UNITTEST, __FILE__, __LINE__);
77 } 88 }
78 if (fail_next_postbuffer_) { 89 if (fail_next_postbuffer_) {
79 fail_next_postbuffer_ = false; 90 fail_next_postbuffer_ = false;
80 return false; 91 return false;
81 } 92 }
82 // Default to an ok connection. 93 // Default to an ok connection.
83 params->response->server_status = HttpResponse::SERVER_CONNECTION_OK; 94 params->response->server_status = HttpResponse::SERVER_CONNECTION_OK;
84 response.set_store_birthday(store_birthday_); 95 response.set_store_birthday(store_birthday_);
85 if (post.has_store_birthday() && post.store_birthday() != store_birthday_) { 96 if (post.has_store_birthday() && post.store_birthday() != store_birthday_) {
86 response.set_error_code(ClientToServerResponse::NOT_MY_BIRTHDAY); 97 response.set_error_code(ClientToServerResponse::NOT_MY_BIRTHDAY);
(...skipping 11 matching lines...) Expand all
98 ProcessGetUpdates(&post, &response); 109 ProcessGetUpdates(&post, &response);
99 } else { 110 } else {
100 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage"; 111 EXPECT_TRUE(false) << "Unknown/unsupported ClientToServerMessage";
101 return false; 112 return false;
102 } 113 }
103 if (client_command_.get()) { 114 if (client_command_.get()) {
104 response.mutable_client_command()->CopyFrom(*client_command_.get()); 115 response.mutable_client_command()->CopyFrom(*client_command_.get());
105 } 116 }
106 response.SerializeToString(params->buffer_out); 117 response.SerializeToString(params->buffer_out);
107 if (mid_commit_callback_function_) { 118 if (mid_commit_callback_function_) {
108 if (mid_commit_callback_function_(directory_)) 119 if (mid_commit_callback_function_(directory))
109 mid_commit_callback_function_ = 0; 120 mid_commit_callback_function_ = 0;
110 } 121 }
122 if (mid_commit_observer_) {
123 mid_commit_observer_->Observe();
124 }
111 return result; 125 return result;
112 } 126 }
113 127
114 bool MockConnectionManager::IsServerReachable() { 128 bool MockConnectionManager::IsServerReachable() {
115 return true; 129 return true;
116 } 130 }
117 131
118 bool MockConnectionManager::IsUserAuthenticated() { 132 bool MockConnectionManager::IsUserAuthenticated() {
119 return true; 133 return true;
120 } 134 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 342
329 SyncEntity* MockConnectionManager::GetMutableLastUpdate() { 343 SyncEntity* MockConnectionManager::GetMutableLastUpdate() {
330 DCHECK(updates_.entries_size() > 0); 344 DCHECK(updates_.entries_size() > 0);
331 return updates_.mutable_entries()->Mutable(updates_.entries_size() - 1); 345 return updates_.mutable_entries()->Mutable(updates_.entries_size() - 1);
332 } 346 }
333 347
334 const CommitMessage& MockConnectionManager::last_sent_commit() const { 348 const CommitMessage& MockConnectionManager::last_sent_commit() const {
335 DCHECK(!commit_messages_.empty()); 349 DCHECK(!commit_messages_.empty());
336 return *commit_messages_.back(); 350 return *commit_messages_.back();
337 } 351 }
OLDNEW
« no previous file with comments | « chrome/test/sync/engine/mock_server_connection.h ('k') | chrome/test/sync/engine/test_directory_setter_upper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698