| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "sync/engine/syncproto.h" | 13 #include "sync/engine/syncproto.h" |
| 14 #include "sync/engine/throttled_data_type_tracker.h" |
| 14 #include "sync/internal_api/public/syncable/model_type_test_util.h" | 15 #include "sync/internal_api/public/syncable/model_type_test_util.h" |
| 15 #include "sync/protocol/bookmark_specifics.pb.h" | 16 #include "sync/protocol/bookmark_specifics.pb.h" |
| 16 #include "sync/protocol/password_specifics.pb.h" | 17 #include "sync/protocol/password_specifics.pb.h" |
| 17 #include "sync/protocol/sync.pb.h" | 18 #include "sync/protocol/sync.pb.h" |
| 18 #include "sync/protocol/sync_enums.pb.h" | 19 #include "sync/protocol/sync_enums.pb.h" |
| 19 #include "sync/sessions/session_state.h" | 20 #include "sync/sessions/session_state.h" |
| 20 #include "sync/sessions/sync_session_context.h" | 21 #include "sync/sessions/sync_session_context.h" |
| 21 #include "sync/syncable/blob.h" | 22 #include "sync/syncable/blob.h" |
| 22 #include "sync/syncable/syncable.h" | 23 #include "sync/syncable/syncable.h" |
| 23 #include "sync/test/engine/mock_connection_manager.h" | 24 #include "sync/test/engine/mock_connection_manager.h" |
| 24 #include "sync/test/engine/test_directory_setter_upper.h" | 25 #include "sync/test/engine/test_directory_setter_upper.h" |
| 25 | 26 |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 using syncable::Blob; | 29 using syncable::Blob; |
| 29 using ::testing::_; | 30 using ::testing::_; |
| 30 | 31 |
| 31 namespace browser_sync { | 32 namespace browser_sync { |
| 32 using sessions::SyncSessionContext; | 33 using sessions::SyncSessionContext; |
| 33 | 34 |
| 34 class MockSyncSessionContext : public SyncSessionContext { | |
| 35 public: | |
| 36 MockSyncSessionContext() {} | |
| 37 ~MockSyncSessionContext() {} | |
| 38 MOCK_METHOD2(SetUnthrottleTime, void(syncable::ModelTypeSet, | |
| 39 const base::TimeTicks&)); | |
| 40 }; | |
| 41 | |
| 42 class MockDelegate : public sessions::SyncSession::Delegate { | 35 class MockDelegate : public sessions::SyncSession::Delegate { |
| 43 public: | 36 public: |
| 44 MockDelegate() {} | 37 MockDelegate() {} |
| 45 ~MockDelegate() {} | 38 ~MockDelegate() {} |
| 46 | 39 |
| 47 MOCK_METHOD0(IsSyncingCurrentlySilenced, bool()); | 40 MOCK_METHOD0(IsSyncingCurrentlySilenced, bool()); |
| 48 MOCK_METHOD1(OnReceivedShortPollIntervalUpdate, void(const base::TimeDelta&)); | 41 MOCK_METHOD1(OnReceivedShortPollIntervalUpdate, void(const base::TimeDelta&)); |
| 49 MOCK_METHOD1(OnReceivedLongPollIntervalUpdate ,void(const base::TimeDelta&)); | 42 MOCK_METHOD1(OnReceivedLongPollIntervalUpdate ,void(const base::TimeDelta&)); |
| 50 MOCK_METHOD1(OnReceivedSessionsCommitDelay, void(const base::TimeDelta&)); | 43 MOCK_METHOD1(OnReceivedSessionsCommitDelay, void(const base::TimeDelta&)); |
| 51 MOCK_METHOD1(OnSyncProtocolError, void(const sessions::SyncSessionSnapshot&)); | 44 MOCK_METHOD1(OnSyncProtocolError, void(const sessions::SyncSessionSnapshot&)); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 dcm.set_send_error(false); | 255 dcm.set_send_error(false); |
| 263 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 256 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
| 264 msg, &response)); | 257 msg, &response)); |
| 265 | 258 |
| 266 dcm.set_access_denied(true); | 259 dcm.set_access_denied(true); |
| 267 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 260 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
| 268 msg, &response)); | 261 msg, &response)); |
| 269 } | 262 } |
| 270 | 263 |
| 271 TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) { | 264 TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) { |
| 272 MockSyncSessionContext context; | 265 ThrottledDataTypeTracker tracker(NULL); |
| 273 SyncProtocolError error; | 266 SyncProtocolError error; |
| 274 error.error_type = browser_sync::THROTTLED; | 267 error.error_type = browser_sync::THROTTLED; |
| 275 syncable::ModelTypeSet types; | 268 syncable::ModelTypeSet types; |
| 276 types.Put(syncable::BOOKMARKS); | 269 types.Put(syncable::BOOKMARKS); |
| 277 types.Put(syncable::PASSWORDS); | 270 types.Put(syncable::PASSWORDS); |
| 278 error.error_data_types = types; | 271 error.error_data_types = types; |
| 279 | 272 |
| 280 base::TimeTicks ticks = base::TimeTicks::Now(); | 273 base::TimeTicks ticks = base::TimeTicks::FromInternalValue(1); |
| 281 | 274 SyncerProtoUtil::HandleThrottleError(error, ticks, &tracker, NULL); |
| 282 EXPECT_CALL(context, SetUnthrottleTime(HasModelTypes(types), ticks)); | 275 EXPECT_TRUE(tracker.GetThrottledTypes().Equals(types)); |
| 283 | |
| 284 SyncerProtoUtil::HandleThrottleError(error, ticks, &context, NULL); | |
| 285 } | 276 } |
| 286 | 277 |
| 287 TEST_F(SyncerProtoUtilTest, HandleThrottlingNoDatatypes) { | 278 TEST_F(SyncerProtoUtilTest, HandleThrottlingNoDatatypes) { |
| 279 ThrottledDataTypeTracker tracker(NULL); |
| 288 MockDelegate delegate; | 280 MockDelegate delegate; |
| 289 SyncProtocolError error; | 281 SyncProtocolError error; |
| 290 error.error_type = browser_sync::THROTTLED; | 282 error.error_type = browser_sync::THROTTLED; |
| 291 | 283 |
| 292 base::TimeTicks ticks = base::TimeTicks::Now(); | 284 base::TimeTicks ticks = base::TimeTicks::FromInternalValue(1); |
| 293 | 285 |
| 294 EXPECT_CALL(delegate, OnSilencedUntil(ticks)); | 286 EXPECT_CALL(delegate, OnSilencedUntil(ticks)); |
| 295 | 287 |
| 296 SyncerProtoUtil::HandleThrottleError(error, ticks, NULL, &delegate); | 288 SyncerProtoUtil::HandleThrottleError(error, ticks, &tracker, &delegate); |
| 289 EXPECT_TRUE(tracker.GetThrottledTypes().Empty()); |
| 297 } | 290 } |
| 298 } // namespace browser_sync | 291 } // namespace browser_sync |
| OLD | NEW |