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/time.h" |
11 #include "chrome/browser/sync/engine/syncproto.h" | 12 #include "chrome/browser/sync/engine/syncproto.h" |
| 13 #include "chrome/browser/sync/sessions/session_state.h" |
| 14 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 15 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 16 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 17 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 18 #include "chrome/browser/sync/sessions/sync_session_unittest.cc" |
12 #include "chrome/browser/sync/syncable/blob.h" | 19 #include "chrome/browser/sync/syncable/blob.h" |
13 #include "chrome/browser/sync/syncable/directory_manager.h" | 20 #include "chrome/browser/sync/syncable/directory_manager.h" |
14 #include "chrome/browser/sync/syncable/syncable.h" | 21 #include "chrome/browser/sync/syncable/syncable.h" |
15 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" | 22 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" |
16 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" | 23 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" |
17 | 24 |
18 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
19 | 26 |
20 using syncable::Blob; | 27 using syncable::Blob; |
21 using syncable::ScopedDirLookup; | 28 using syncable::ScopedDirLookup; |
| 29 using syncable::ModelTypeSet; |
| 30 using ::testing::_; |
22 | 31 |
23 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(AddUnthrottleTime, 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 }; |
24 | 56 |
25 TEST(SyncerProtoUtil, TestBlobToProtocolBufferBytesUtilityFunctions) { | 57 TEST(SyncerProtoUtil, TestBlobToProtocolBufferBytesUtilityFunctions) { |
26 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}; |
27 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}; |
28 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}; |
29 | 61 |
30 syncable::Blob test_blob1, test_blob2, test_blob3; | 62 syncable::Blob test_blob1, test_blob2, test_blob3; |
31 for (size_t i = 0; i < arraysize(test_data1); ++i) | 63 for (size_t i = 0; i < arraysize(test_data1); ++i) |
32 test_blob1.push_back(test_data1[i]); | 64 test_blob1.push_back(test_data1[i]); |
33 for (size_t i = 0; i < arraysize(test_data2); ++i) | 65 for (size_t i = 0; i < arraysize(test_data2); ++i) |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 263 |
232 dcm.set_send_error(false); | 264 dcm.set_send_error(false); |
233 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 265 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
234 msg, &response)); | 266 msg, &response)); |
235 | 267 |
236 dcm.set_access_denied(true); | 268 dcm.set_access_denied(true); |
237 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, | 269 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, |
238 msg, &response)); | 270 msg, &response)); |
239 } | 271 } |
240 | 272 |
| 273 TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) { |
| 274 MockSyncSessionContext context; |
| 275 SyncProtocolError error; |
| 276 error.error_type = browser_sync::THROTTLED; |
| 277 syncable::ModelTypeSet types; |
| 278 types.insert(syncable::BOOKMARKS); |
| 279 types.insert(syncable::PASSWORDS); |
| 280 error.error_data_types = types; |
| 281 |
| 282 base::TimeTicks ticks = base::TimeTicks::Now(); |
| 283 |
| 284 EXPECT_CALL(context, AddUnthrottleTime(types, ticks)); |
| 285 |
| 286 SyncerProtoUtil::HandleThrottling(error, ticks, &context, NULL); |
| 287 } |
| 288 |
| 289 TEST_F(SyncerProtoUtilTest, HandleThrottlingNoDatatypes) { |
| 290 MockDelegate delegate; |
| 291 SyncProtocolError error; |
| 292 error.error_type = browser_sync::THROTTLED; |
| 293 |
| 294 base::TimeTicks ticks = base::TimeTicks::Now(); |
| 295 |
| 296 EXPECT_CALL(delegate, OnSilencedUntil(ticks)); |
| 297 |
| 298 SyncerProtoUtil::HandleThrottling(error, ticks, NULL, &delegate); |
| 299 } |
241 } // namespace browser_sync | 300 } // namespace browser_sync |
OLD | NEW |