OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/syncer_proto_util.h" | 5 #include "chrome/browser/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 "chrome/browser/sync/engine/syncproto.h" | 13 #include "chrome/browser/sync/engine/syncproto.h" |
| 14 #include "chrome/browser/sync/sessions/session_state.h" |
| 15 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 16 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 17 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 18 #include "chrome/browser/sync/protocol/sync.pb.h" |
13 #include "chrome/browser/sync/syncable/blob.h" | 19 #include "chrome/browser/sync/syncable/blob.h" |
14 #include "chrome/browser/sync/syncable/directory_manager.h" | 20 #include "chrome/browser/sync/syncable/directory_manager.h" |
15 #include "chrome/browser/sync/syncable/syncable.h" | 21 #include "chrome/browser/sync/syncable/syncable.h" |
16 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" | 22 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" |
17 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" | 23 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" |
18 | 24 |
19 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
20 | 26 |
21 using syncable::Blob; | 27 using syncable::Blob; |
22 using syncable::ScopedDirLookup; | 28 using syncable::ScopedDirLookup; |
| 29 using syncable::ModelTypeSet; |
| 30 using ::testing::_; |
23 | 31 |
24 namespace browser_sync { | 32 namespace browser_sync { |
| 33 using sessions::SyncSessionContext; |
| 34 |
| 35 class MockSyncSessionContext : public SyncSessionContext { |
| 36 public: |
| 37 MockSyncSessionContext() {} |
| 38 ~MockSyncSessionContext() {} |
| 39 MOCK_METHOD2(SetUnthrottleTime, void(const ModelTypeSet&, |
| 40 const base::TimeTicks&)); |
| 41 }; |
| 42 |
| 43 class MockDelegate : public sessions::SyncSession::Delegate { |
| 44 public: |
| 45 MockDelegate() {} |
| 46 ~MockDelegate() {} |
| 47 |
| 48 MOCK_METHOD0(IsSyncingCurrentlySilenced, bool()); |
| 49 MOCK_METHOD1(OnReceivedShortPollIntervalUpdate, void(const base::TimeDelta&)); |
| 50 MOCK_METHOD1(OnReceivedLongPollIntervalUpdate ,void(const base::TimeDelta&)); |
| 51 MOCK_METHOD1(OnReceivedSessionsCommitDelay, void(const base::TimeDelta&)); |
| 52 MOCK_METHOD1(OnSyncProtocolError, void(const sessions::SyncSessionSnapshot&)); |
| 53 MOCK_METHOD0(OnShouldStopSyncingPermanently, void()); |
| 54 MOCK_METHOD1(OnSilencedUntil, void(const base::TimeTicks&)); |
| 55 }; |
25 | 56 |
26 TEST(SyncerProtoUtil, TestBlobToProtocolBufferBytesUtilityFunctions) { | 57 TEST(SyncerProtoUtil, TestBlobToProtocolBufferBytesUtilityFunctions) { |
27 unsigned char test_data1[] = {1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 4, 2, 9}; | 58 unsigned char test_data1[] = {1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 4, 2, 9}; |
28 unsigned char test_data2[] = {1, 99, 3, 4, 5, 6, 7, 8, 0, 1, 4, 2, 9}; | 59 unsigned char test_data2[] = {1, 99, 3, 4, 5, 6, 7, 8, 0, 1, 4, 2, 9}; |
29 unsigned char test_data3[] = {99, 2, 3, 4, 5, 6, 7, 8}; | 60 unsigned char test_data3[] = {99, 2, 3, 4, 5, 6, 7, 8}; |
30 | 61 |
31 syncable::Blob test_blob1, test_blob2, test_blob3; | 62 syncable::Blob test_blob1, test_blob2, test_blob3; |
32 for (size_t i = 0; i < arraysize(test_data1); ++i) | 63 for (size_t i = 0; i < arraysize(test_data1); ++i) |
33 test_blob1.push_back(test_data1[i]); | 64 test_blob1.push_back(test_data1[i]); |
34 for (size_t i = 0; i < arraysize(test_data2); ++i) | 65 for (size_t i = 0; i < arraysize(test_data2); ++i) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 264 |
234 dcm.set_send_error(false); | 265 dcm.set_send_error(false); |
235 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 266 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
236 msg, &response)); | 267 msg, &response)); |
237 | 268 |
238 dcm.set_access_denied(true); | 269 dcm.set_access_denied(true); |
239 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 270 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
240 msg, &response)); | 271 msg, &response)); |
241 } | 272 } |
242 | 273 |
| 274 TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) { |
| 275 MockSyncSessionContext context; |
| 276 SyncProtocolError error; |
| 277 error.error_type = browser_sync::THROTTLED; |
| 278 syncable::ModelTypeSet types; |
| 279 types.insert(syncable::BOOKMARKS); |
| 280 types.insert(syncable::PASSWORDS); |
| 281 error.error_data_types = types; |
| 282 |
| 283 base::TimeTicks ticks = base::TimeTicks::Now(); |
| 284 |
| 285 EXPECT_CALL(context, SetUnthrottleTime(types, ticks)); |
| 286 |
| 287 SyncerProtoUtil::HandleThrottleError(error, ticks, &context, NULL); |
| 288 } |
| 289 |
| 290 TEST_F(SyncerProtoUtilTest, HandleThrottlingNoDatatypes) { |
| 291 MockDelegate delegate; |
| 292 SyncProtocolError error; |
| 293 error.error_type = browser_sync::THROTTLED; |
| 294 |
| 295 base::TimeTicks ticks = base::TimeTicks::Now(); |
| 296 |
| 297 EXPECT_CALL(delegate, OnSilencedUntil(ticks)); |
| 298 |
| 299 SyncerProtoUtil::HandleThrottleError(error, ticks, NULL, &delegate); |
| 300 } |
243 } // namespace browser_sync | 301 } // namespace browser_sync |
OLD | NEW |