| OLD | NEW |
| 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 #include "sync/engine/syncer_proto_util.h" | 5 #include "components/sync/engine_impl/syncer_proto_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "sync/internal_api/public/base/cancelation_signal.h" | 12 #include "components/sync/base/cancelation_signal.h" |
| 13 #include "sync/internal_api/public/base/model_type_test_util.h" | 13 #include "components/sync/base/model_type_test_util.h" |
| 14 #include "sync/protocol/bookmark_specifics.pb.h" | 14 #include "components/sync/protocol/bookmark_specifics.pb.h" |
| 15 #include "sync/protocol/password_specifics.pb.h" | 15 #include "components/sync/protocol/password_specifics.pb.h" |
| 16 #include "sync/protocol/sync.pb.h" | 16 #include "components/sync/protocol/sync.pb.h" |
| 17 #include "sync/protocol/sync_enums.pb.h" | 17 #include "components/sync/protocol/sync_enums.pb.h" |
| 18 #include "sync/sessions/sync_session_context.h" | 18 #include "components/sync/sessions_impl/sync_session_context.h" |
| 19 #include "sync/syncable/directory.h" | 19 #include "components/sync/syncable/directory.h" |
| 20 #include "sync/test/engine/mock_connection_manager.h" | 20 #include "components/sync/test/engine/mock_connection_manager.h" |
| 21 #include "sync/test/engine/test_directory_setter_upper.h" | 21 #include "components/sync/test/engine/test_directory_setter_upper.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 using ::testing::_; | 24 using ::testing::_; |
| 25 | 25 |
| 26 using sync_pb::ClientToServerMessage; | 26 using sync_pb::ClientToServerMessage; |
| 27 using sync_pb::CommitResponse_EntryResponse; | 27 using sync_pb::CommitResponse_EntryResponse; |
| 28 using sync_pb::SyncEntity; | 28 using sync_pb::SyncEntity; |
| 29 | 29 |
| 30 namespace syncer { | 30 namespace syncer { |
| 31 | 31 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 SyncerProtoUtil::NameFromSyncEntity(two_name_entity); | 122 SyncerProtoUtil::NameFromSyncEntity(two_name_entity); |
| 123 EXPECT_EQ(neuro, name_a); | 123 EXPECT_EQ(neuro, name_a); |
| 124 } | 124 } |
| 125 | 125 |
| 126 class SyncerProtoUtilTest : public testing::Test { | 126 class SyncerProtoUtilTest : public testing::Test { |
| 127 public: | 127 public: |
| 128 void SetUp() override { dir_maker_.SetUp(); } | 128 void SetUp() override { dir_maker_.SetUp(); } |
| 129 | 129 |
| 130 void TearDown() override { dir_maker_.TearDown(); } | 130 void TearDown() override { dir_maker_.TearDown(); } |
| 131 | 131 |
| 132 syncable::Directory* directory() { | 132 syncable::Directory* directory() { return dir_maker_.directory(); } |
| 133 return dir_maker_.directory(); | |
| 134 } | |
| 135 | 133 |
| 136 // Helper function to call GetProtocolErrorFromResponse. Allows not adding | 134 // Helper function to call GetProtocolErrorFromResponse. Allows not adding |
| 137 // individual tests as friends to SyncerProtoUtil. | 135 // individual tests as friends to SyncerProtoUtil. |
| 138 static SyncProtocolError CallGetProtocolErrorFromResponse( | 136 static SyncProtocolError CallGetProtocolErrorFromResponse( |
| 139 const sync_pb::ClientToServerResponse& response, | 137 const sync_pb::ClientToServerResponse& response, |
| 140 syncable::Directory* directory) { | 138 syncable::Directory* directory) { |
| 141 return SyncerProtoUtil::GetProtocolErrorFromResponse(response, directory); | 139 return SyncerProtoUtil::GetProtocolErrorFromResponse(response, directory); |
| 142 } | 140 } |
| 143 | 141 |
| 144 protected: | 142 protected: |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (send_error_) { | 229 if (send_error_) { |
| 232 return false; | 230 return false; |
| 233 } | 231 } |
| 234 | 232 |
| 235 sync_pb::ClientToServerResponse response; | 233 sync_pb::ClientToServerResponse response; |
| 236 response.SerializeToString(¶ms->buffer_out); | 234 response.SerializeToString(¶ms->buffer_out); |
| 237 | 235 |
| 238 return true; | 236 return true; |
| 239 } | 237 } |
| 240 | 238 |
| 241 void set_send_error(bool send) { | 239 void set_send_error(bool send) { send_error_ = send; } |
| 242 send_error_ = send; | |
| 243 } | |
| 244 | 240 |
| 245 private: | 241 private: |
| 246 bool send_error_; | 242 bool send_error_; |
| 247 }; | 243 }; |
| 248 | 244 |
| 249 TEST_F(SyncerProtoUtilTest, PostAndProcessHeaders) { | 245 TEST_F(SyncerProtoUtilTest, PostAndProcessHeaders) { |
| 250 CancelationSignal signal; | 246 CancelationSignal signal; |
| 251 DummyConnectionManager dcm(&signal); | 247 DummyConnectionManager dcm(&signal); |
| 252 ClientToServerMessage msg; | 248 ClientToServerMessage msg; |
| 253 SyncerProtoUtil::SetProtocolVersion(&msg); | 249 SyncerProtoUtil::SetProtocolVersion(&msg); |
| 254 msg.set_share("required"); | 250 msg.set_share("required"); |
| 255 msg.set_message_contents(ClientToServerMessage::GET_UPDATES); | 251 msg.set_message_contents(ClientToServerMessage::GET_UPDATES); |
| 256 sync_pb::ClientToServerResponse response; | 252 sync_pb::ClientToServerResponse response; |
| 257 | 253 |
| 258 dcm.set_send_error(true); | 254 dcm.set_send_error(true); |
| 259 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 255 EXPECT_FALSE( |
| 260 msg, &response)); | 256 SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, msg, &response)); |
| 261 | 257 |
| 262 dcm.set_send_error(false); | 258 dcm.set_send_error(false); |
| 263 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 259 EXPECT_TRUE( |
| 264 msg, &response)); | 260 SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, msg, &response)); |
| 265 } | 261 } |
| 266 | 262 |
| 267 } // namespace syncer | 263 } // namespace syncer |
| OLD | NEW |