summaryrefslogtreecommitdiffstats
path: root/sync/test
diff options
context:
space:
mode:
authorpvalenzuela <pvalenzuela@chromium.org>2014-10-07 16:21:42 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-07 23:21:55 +0000
commit9411c4682723604e6b5975e48e7f1a5c46e9bed2 (patch)
tree9dd12a1a6b94764fb99f9cb0af0993ae950e301b /sync/test
parent2087fb8402cbd9512aab3936661d15c80b62b543 (diff)
downloadchromium_src-9411c4682723604e6b5975e48e7f1a5c46e9bed2.zip
chromium_src-9411c4682723604e6b5975e48e7f1a5c46e9bed2.tar.gz
chromium_src-9411c4682723604e6b5975e48e7f1a5c46e9bed2.tar.bz2
Convert two sync tests to use FakeServer
This CL converts two tests in sync_errors_test.cc, ActionableErrorTest and DisableDatatypeWhileRunning, to use FakeServer. The first required the addition of a TriggerActionableError method to FakeServer. The second works without any changes. BUG=406545 Review URL: https://codereview.chromium.org/605733005 Cr-Commit-Position: refs/heads/master@{#298607}
Diffstat (limited to 'sync/test')
-rw-r--r--sync/test/fake_server/fake_server.cc39
-rw-r--r--sync/test/fake_server/fake_server.h21
2 files changed, 49 insertions, 11 deletions
diff --git a/sync/test/fake_server/fake_server.cc b/sync/test/fake_server/fake_server.cc
index ea4abfd..7626073 100644
--- a/sync/test/fake_server/fake_server.cc
+++ b/sync/test/fake_server/fake_server.cc
@@ -227,14 +227,17 @@ void FakeServer::HandleCommand(const string& request,
bool parsed = message.ParseFromString(request);
CHECK(parsed) << "Unable to parse the ClientToServerMessage.";
- sync_pb::SyncEnums_ErrorType error_code;
sync_pb::ClientToServerResponse response_proto;
if (message.has_store_birthday() &&
message.store_birthday() != store_birthday_) {
- error_code = sync_pb::SyncEnums::NOT_MY_BIRTHDAY;
+ response_proto.set_error_code(sync_pb::SyncEnums::NOT_MY_BIRTHDAY);
} else if (error_type_ != sync_pb::SyncEnums::SUCCESS) {
- error_code = error_type_;
+ response_proto.set_error_code(error_type_);
+ } else if (triggered_actionable_error_.get()) {
+ sync_pb::ClientToServerResponse_Error* error =
+ response_proto.mutable_error();
+ error->CopyFrom(*(triggered_actionable_error_.get()));
} else {
bool success = false;
switch (message.message_contents()) {
@@ -259,10 +262,9 @@ void FakeServer::HandleCommand(const string& request,
return;
}
- error_code = sync_pb::SyncEnums::SUCCESS;
+ response_proto.set_error_code(sync_pb::SyncEnums::SUCCESS);
}
- response_proto.set_error_code(error_code);
response_proto.set_store_birthday(store_birthday_);
callback.Run(0, net::HTTP_OK, response_proto.SerializeAsString());
}
@@ -503,15 +505,32 @@ void FakeServer::SetUnauthenticated() {
authenticated_ = false;
}
-// TODO(pvalenzuela): comments from Richard: we should look at
-// mock_connection_manager.cc and take it as a warning. This style of injecting
-// errors works when there's one or two conditions we care about, but it can
-// eventually lead to a hairball once we have many different conditions and
-// triggering logic.
void FakeServer::TriggerError(const sync_pb::SyncEnums::ErrorType& error_type) {
+ CHECK(!triggered_actionable_error_.get())
+ << "Only one type of error can be triggered at any given time.";
error_type_ = error_type;
}
+bool FakeServer::TriggerActionableError(
+ const sync_pb::SyncEnums::ErrorType& error_type,
+ const string& description,
+ const string& url,
+ const sync_pb::SyncEnums::Action& action) {
+ if (error_type_ != sync_pb::SyncEnums::SUCCESS) {
+ DVLOG(1) << "Only one type of error can be triggered at any given time.";
+ return false;
+ }
+
+ sync_pb::ClientToServerResponse_Error* error =
+ new sync_pb::ClientToServerResponse_Error();
+ error->set_error_type(error_type);
+ error->set_error_description(description);
+ error->set_url(url);
+ error->set_action(action);
+ triggered_actionable_error_.reset(error);
+ return true;
+}
+
void FakeServer::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
diff --git a/sync/test/fake_server/fake_server.h b/sync/test/fake_server/fake_server.h
index fa1b4d5..15ad0e0 100644
--- a/sync/test/fake_server/fake_server.h
+++ b/sync/test/fake_server/fake_server.h
@@ -70,9 +70,22 @@ class FakeServer {
// authentication error.
void SetUnauthenticated();
- // Return |error_type| on next sync request.
+ // Force the server to return |error_type| in the error_code field of
+ // ClientToServerResponse on all subsequent sync requests. This method should
+ // not be called if TriggerActionableError has previously been called.
+ // TODO(pvalenzuela): Return a bool here to indicate whether the call
+ // succeeded.
void TriggerError(const sync_pb::SyncEnums::ErrorType& error_type);
+ // Force the server to return the given data as part of the error field of
+ // ClientToServerResponse on all subsequent sync requests. This method should
+ // not be called if TriggerError has previously been called.
+ bool TriggerActionableError(
+ const sync_pb::SyncEnums::ErrorType& error_type,
+ const std::string& description,
+ const std::string& url,
+ const sync_pb::SyncEnums::Action& action);
+
// Adds |observer| to FakeServer's observer list. This should be called
// before the Profile associated with |observer| is connected to the server.
void AddObserver(Observer* observer);
@@ -145,8 +158,14 @@ class FakeServer {
// All Keystore keys known to the server.
std::vector<std::string> keystore_keys_;
+ // Used as the error_code field of ClientToServerResponse on all responses
+ // except when |triggered_actionable_error_| is set.
sync_pb::SyncEnums::ErrorType error_type_;
+ // Used as the error field of ClientToServerResponse when its pointer is not
+ // NULL.
+ scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_;
+
// FakeServer's observers.
ObserverList<Observer, true> observers_;
};