summaryrefslogtreecommitdiffstats
path: root/sync/engine/syncer_proto_util_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sync/engine/syncer_proto_util_unittest.cc')
-rw-r--r--sync/engine/syncer_proto_util_unittest.cc59
1 files changed, 46 insertions, 13 deletions
diff --git a/sync/engine/syncer_proto_util_unittest.cc b/sync/engine/syncer_proto_util_unittest.cc
index 35cc2c7..0bc745f 100644
--- a/sync/engine/syncer_proto_util_unittest.cc
+++ b/sync/engine/syncer_proto_util_unittest.cc
@@ -60,9 +60,9 @@ TEST(SyncerProtoUtil, GetTypesToMigrate) {
}
// Builds a ClientToServerResponse_Error with some error data type
-// ids, including invalid ones. ConvertErrorPBToLocalType() should
+// ids, including invalid ones. ConvertErrorPBToSyncProtocolError() should
// return a SyncProtocolError with only the valid model types.
-TEST(SyncerProtoUtil, ConvertErrorPBToLocalType) {
+TEST(SyncerProtoUtil, ConvertErrorPBToSyncProtocolError) {
sync_pb::ClientToServerResponse_Error error_pb;
error_pb.set_error_type(sync_pb::SyncEnums::THROTTLED);
error_pb.add_error_data_type_ids(
@@ -70,7 +70,7 @@ TEST(SyncerProtoUtil, ConvertErrorPBToLocalType) {
error_pb.add_error_data_type_ids(
GetSpecificsFieldNumberFromModelType(HISTORY_DELETE_DIRECTIVES));
error_pb.add_error_data_type_ids(-1);
- SyncProtocolError error = ConvertErrorPBToLocalType(error_pb);
+ SyncProtocolError error = ConvertErrorPBToSyncProtocolError(error_pb);
EXPECT_TRUE(
error.error_data_types.Equals(
ModelTypeSet(BOOKMARKS, HISTORY_DELETE_DIRECTIVES)));
@@ -136,6 +136,14 @@ class SyncerProtoUtilTest : public testing::Test {
return dir_maker_.directory();
}
+ // Helper function to call GetProtocolErrorFromResponse. Allows not adding
+ // individual tests as friends to SyncerProtoUtil.
+ static SyncProtocolError CallGetProtocolErrorFromResponse(
+ const sync_pb::ClientToServerResponse& response,
+ syncable::Directory* directory) {
+ return SyncerProtoUtil::GetProtocolErrorFromResponse(response, directory);
+ }
+
protected:
base::MessageLoop message_loop_;
TestDirectorySetterUpper dir_maker_;
@@ -145,38 +153,63 @@ TEST_F(SyncerProtoUtilTest, VerifyResponseBirthday) {
// Both sides empty
EXPECT_TRUE(directory()->store_birthday().empty());
sync_pb::ClientToServerResponse response;
- EXPECT_FALSE(SyncerProtoUtil::VerifyResponseBirthday(response, directory()));
+ SyncProtocolError sync_protocol_error;
+ response.set_error_code(sync_pb::SyncEnums::SUCCESS);
+
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(NOT_MY_BIRTHDAY, sync_protocol_error.error_type);
+ EXPECT_EQ(DISABLE_SYNC_ON_CLIENT, sync_protocol_error.action);
// Remote set, local empty
response.set_store_birthday("flan");
- EXPECT_TRUE(SyncerProtoUtil::VerifyResponseBirthday(response, directory()));
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(SYNC_SUCCESS, sync_protocol_error.error_type);
+ EXPECT_EQ(UNKNOWN_ACTION, sync_protocol_error.action);
EXPECT_EQ(directory()->store_birthday(), "flan");
// Remote empty, local set.
response.clear_store_birthday();
- EXPECT_TRUE(SyncerProtoUtil::VerifyResponseBirthday(response, directory()));
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(SYNC_SUCCESS, sync_protocol_error.error_type);
+ EXPECT_EQ(UNKNOWN_ACTION, sync_protocol_error.action);
EXPECT_EQ(directory()->store_birthday(), "flan");
// Doesn't match
response.set_store_birthday("meat");
- EXPECT_FALSE(SyncerProtoUtil::VerifyResponseBirthday(response, directory()));
-
- response.set_error_code(sync_pb::SyncEnums::CLEAR_PENDING);
- EXPECT_FALSE(SyncerProtoUtil::VerifyResponseBirthday(response, directory()));
+ response.set_error_code(sync_pb::SyncEnums::NOT_MY_BIRTHDAY);
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(NOT_MY_BIRTHDAY, sync_protocol_error.error_type);
+ EXPECT_EQ(DISABLE_SYNC_ON_CLIENT, sync_protocol_error.action);
+
+ // Doesn't match. CLIENT_DATA_OBSOLETE error is set.
+ response.set_error_code(sync_pb::SyncEnums::CLIENT_DATA_OBSOLETE);
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(CLIENT_DATA_OBSOLETE, sync_protocol_error.error_type);
+ EXPECT_EQ(RESET_LOCAL_SYNC_DATA, sync_protocol_error.action);
}
TEST_F(SyncerProtoUtilTest, VerifyDisabledByAdmin) {
// No error code
sync_pb::ClientToServerResponse response;
- EXPECT_FALSE(SyncerProtoUtil::IsSyncDisabledByAdmin(response));
+ SyncProtocolError sync_protocol_error;
+ directory()->set_store_birthday("flan");
+ response.set_error_code(sync_pb::SyncEnums::SUCCESS);
+
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(SYNC_SUCCESS, sync_protocol_error.error_type);
+ EXPECT_EQ(UNKNOWN_ACTION, sync_protocol_error.action);
// Has error code, but not disabled
response.set_error_code(sync_pb::SyncEnums::NOT_MY_BIRTHDAY);
- EXPECT_FALSE(SyncerProtoUtil::IsSyncDisabledByAdmin(response));
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(NOT_MY_BIRTHDAY, sync_protocol_error.error_type);
+ EXPECT_NE(UNKNOWN_ACTION, sync_protocol_error.action);
// Has error code, and is disabled by admin
response.set_error_code(sync_pb::SyncEnums::DISABLED_BY_ADMIN);
- EXPECT_TRUE(SyncerProtoUtil::IsSyncDisabledByAdmin(response));
+ sync_protocol_error = CallGetProtocolErrorFromResponse(response, directory());
+ EXPECT_EQ(DISABLED_BY_ADMIN, sync_protocol_error.error_type);
+ EXPECT_EQ(STOP_SYNC_FOR_DISABLED_ACCOUNT, sync_protocol_error.action);
}
TEST_F(SyncerProtoUtilTest, AddRequestBirthday) {