| 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 "sync/engine/syncer_proto_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 using sync_pb::ClientToServerMessage; | 27 using sync_pb::ClientToServerMessage; |
| 28 using sync_pb::CommitResponse_EntryResponse; | 28 using sync_pb::CommitResponse_EntryResponse; |
| 29 using sync_pb::SyncEntity; | 29 using sync_pb::SyncEntity; |
| 30 | 30 |
| 31 namespace syncer { | 31 namespace syncer { |
| 32 | 32 |
| 33 using sessions::SyncSessionContext; | 33 using sessions::SyncSessionContext; |
| 34 | 34 |
| 35 class MockDelegate : public sessions::SyncSession::Delegate { | 35 class MockDelegate : public sessions::SyncSession::Delegate { |
| 36 public: | 36 public: |
| 37 MockDelegate() {} | 37 MockDelegate() {} |
| 38 ~MockDelegate() {} | 38 ~MockDelegate() {} |
| 39 | 39 |
| 40 MOCK_METHOD1(OnReceivedShortPollIntervalUpdate, void(const base::TimeDelta&)); | 40 MOCK_METHOD1(OnReceivedShortPollIntervalUpdate, void(const base::TimeDelta&)); |
| 41 MOCK_METHOD1(OnReceivedLongPollIntervalUpdate ,void(const base::TimeDelta&)); | 41 MOCK_METHOD1(OnReceivedLongPollIntervalUpdate, void(const base::TimeDelta&)); |
| 42 MOCK_METHOD1(OnReceivedSessionsCommitDelay, void(const base::TimeDelta&)); | 42 MOCK_METHOD1(OnReceivedSessionsCommitDelay, void(const base::TimeDelta&)); |
| 43 MOCK_METHOD1(OnReceivedClientInvalidationHintBufferSize, void(int)); | 43 MOCK_METHOD1(OnReceivedClientInvalidationHintBufferSize, void(int)); |
| 44 MOCK_METHOD1(OnSyncProtocolError, void(const SyncProtocolError&)); | 44 MOCK_METHOD1(OnSyncProtocolError, void(const SyncProtocolError&)); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // Builds a ClientToServerResponse with some data type ids, including | 47 // Builds a ClientToServerResponse with some data type ids, including |
| 48 // invalid ones. GetTypesToMigrate() should return only the valid | 48 // invalid ones. GetTypesToMigrate() should return only the valid |
| 49 // model types. | 49 // model types. |
| 50 TEST(SyncerProtoUtil, GetTypesToMigrate) { | 50 TEST(SyncerProtoUtil, GetTypesToMigrate) { |
| 51 sync_pb::ClientToServerResponse response; | 51 sync_pb::ClientToServerResponse response; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 SyncerProtoUtil::AddRequestBirthday(directory(), &msg); | 218 SyncerProtoUtil::AddRequestBirthday(directory(), &msg); |
| 219 EXPECT_FALSE(msg.has_store_birthday()); | 219 EXPECT_FALSE(msg.has_store_birthday()); |
| 220 | 220 |
| 221 directory()->set_store_birthday("meat"); | 221 directory()->set_store_birthday("meat"); |
| 222 SyncerProtoUtil::AddRequestBirthday(directory(), &msg); | 222 SyncerProtoUtil::AddRequestBirthday(directory(), &msg); |
| 223 EXPECT_EQ(msg.store_birthday(), "meat"); | 223 EXPECT_EQ(msg.store_birthday(), "meat"); |
| 224 } | 224 } |
| 225 | 225 |
| 226 class DummyConnectionManager : public ServerConnectionManager { | 226 class DummyConnectionManager : public ServerConnectionManager { |
| 227 public: | 227 public: |
| 228 DummyConnectionManager(CancelationSignal* signal) | 228 explicit DummyConnectionManager(CancelationSignal* signal) |
| 229 : ServerConnectionManager("unused", 0, false, signal), | 229 : ServerConnectionManager("unused", 0, false, signal), |
| 230 send_error_(false), | 230 send_error_(false) {} |
| 231 access_denied_(false) {} | |
| 232 | 231 |
| 233 ~DummyConnectionManager() override {} | 232 ~DummyConnectionManager() override {} |
| 234 bool PostBufferWithCachedAuth(PostBufferParams* params, | 233 bool PostBufferWithCachedAuth(PostBufferParams* params) override { |
| 235 ScopedServerStatusWatcher* watcher) override { | |
| 236 if (send_error_) { | 234 if (send_error_) { |
| 237 return false; | 235 return false; |
| 238 } | 236 } |
| 239 | 237 |
| 240 sync_pb::ClientToServerResponse response; | 238 sync_pb::ClientToServerResponse response; |
| 241 if (access_denied_) { | |
| 242 response.set_error_code(sync_pb::SyncEnums::ACCESS_DENIED); | |
| 243 } | |
| 244 response.SerializeToString(¶ms->buffer_out); | 239 response.SerializeToString(¶ms->buffer_out); |
| 245 | 240 |
| 246 return true; | 241 return true; |
| 247 } | 242 } |
| 248 | 243 |
| 249 void set_send_error(bool send) { | 244 void set_send_error(bool send) { |
| 250 send_error_ = send; | 245 send_error_ = send; |
| 251 } | 246 } |
| 252 | 247 |
| 253 void set_access_denied(bool denied) { | |
| 254 access_denied_ = denied; | |
| 255 } | |
| 256 | |
| 257 private: | 248 private: |
| 258 bool send_error_; | 249 bool send_error_; |
| 259 bool access_denied_; | |
| 260 }; | 250 }; |
| 261 | 251 |
| 262 TEST_F(SyncerProtoUtilTest, PostAndProcessHeaders) { | 252 TEST_F(SyncerProtoUtilTest, PostAndProcessHeaders) { |
| 263 CancelationSignal signal; | 253 CancelationSignal signal; |
| 264 DummyConnectionManager dcm(&signal); | 254 DummyConnectionManager dcm(&signal); |
| 265 ClientToServerMessage msg; | 255 ClientToServerMessage msg; |
| 266 SyncerProtoUtil::SetProtocolVersion(&msg); | 256 SyncerProtoUtil::SetProtocolVersion(&msg); |
| 267 msg.set_share("required"); | 257 msg.set_share("required"); |
| 268 msg.set_message_contents(ClientToServerMessage::GET_UPDATES); | 258 msg.set_message_contents(ClientToServerMessage::GET_UPDATES); |
| 269 sync_pb::ClientToServerResponse response; | 259 sync_pb::ClientToServerResponse response; |
| 270 | 260 |
| 271 dcm.set_send_error(true); | 261 dcm.set_send_error(true); |
| 272 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 262 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
| 273 msg, &response)); | 263 msg, &response)); |
| 274 | 264 |
| 275 dcm.set_send_error(false); | 265 dcm.set_send_error(false); |
| 276 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 266 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
| 277 msg, &response)); | 267 msg, &response)); |
| 278 | |
| 279 dcm.set_access_denied(true); | |
| 280 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | |
| 281 msg, &response)); | |
| 282 } | 268 } |
| 283 | 269 |
| 284 } // namespace syncer | 270 } // namespace syncer |
| OLD | NEW |