Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/sync/engine/syncer_proto_util_unittest.cc

Issue 8595023: [Sync] Parse and save per-data type throttle data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
19 #include "chrome/browser/sync/sessions/sync_session_unittest.cc"
13 #include "chrome/browser/sync/syncable/blob.h" 20 #include "chrome/browser/sync/syncable/blob.h"
14 #include "chrome/browser/sync/syncable/directory_manager.h" 21 #include "chrome/browser/sync/syncable/directory_manager.h"
15 #include "chrome/browser/sync/syncable/syncable.h" 22 #include "chrome/browser/sync/syncable/syncable.h"
16 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" 23 #include "chrome/browser/sync/test/engine/mock_connection_manager.h"
17 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" 24 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h"
18 25
19 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
20 27
21 using syncable::Blob; 28 using syncable::Blob;
22 using syncable::ScopedDirLookup; 29 using syncable::ScopedDirLookup;
30 using syncable::ModelTypeSet;
31 using ::testing::_;
23 32
24 namespace browser_sync { 33 namespace browser_sync {
34 using sessions::SyncSessionContext;
35
36 class MockSyncSessionContext : public SyncSessionContext {
37 public:
38 MockSyncSessionContext() {}
39 ~MockSyncSessionContext() {}
40 MOCK_METHOD2(AddUnthrottleTime, void(const ModelTypeSet&,
41 const base::TimeTicks&));
42 };
43
44 class MockDelegate : public sessions::SyncSession::Delegate {
45 public:
46 MockDelegate() {}
47 ~MockDelegate() {}
48
49 MOCK_METHOD0(IsSyncingCurrentlySilenced, bool());
50 MOCK_METHOD1(OnReceivedShortPollIntervalUpdate, void(const base::TimeDelta&));
51 MOCK_METHOD1(OnReceivedLongPollIntervalUpdate ,void(const base::TimeDelta&));
52 MOCK_METHOD1(OnReceivedSessionsCommitDelay, void(const base::TimeDelta&));
53 MOCK_METHOD1(OnSyncProtocolError, void(const sessions::SyncSessionSnapshot&));
54 MOCK_METHOD0(OnShouldStopSyncingPermanently, void());
55 MOCK_METHOD1(OnSilencedUntil, void(const base::TimeTicks&));
56 };
25 57
26 TEST(SyncerProtoUtil, TestBlobToProtocolBufferBytesUtilityFunctions) { 58 TEST(SyncerProtoUtil, TestBlobToProtocolBufferBytesUtilityFunctions) {
27 unsigned char test_data1[] = {1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 4, 2, 9}; 59 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}; 60 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}; 61 unsigned char test_data3[] = {99, 2, 3, 4, 5, 6, 7, 8};
30 62
31 syncable::Blob test_blob1, test_blob2, test_blob3; 63 syncable::Blob test_blob1, test_blob2, test_blob3;
32 for (size_t i = 0; i < arraysize(test_data1); ++i) 64 for (size_t i = 0; i < arraysize(test_data1); ++i)
33 test_blob1.push_back(test_data1[i]); 65 test_blob1.push_back(test_data1[i]);
34 for (size_t i = 0; i < arraysize(test_data2); ++i) 66 for (size_t i = 0; i < arraysize(test_data2); ++i)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 265
234 dcm.set_send_error(false); 266 dcm.set_send_error(false);
235 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, 267 EXPECT_TRUE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL,
236 msg, &response)); 268 msg, &response));
237 269
238 dcm.set_access_denied(true); 270 dcm.set_access_denied(true);
239 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL, 271 EXPECT_FALSE(SyncerProtoUtil::PostAndProcessHeaders(&dcm, NULL,
240 msg, &response)); 272 msg, &response));
241 } 273 }
242 274
275 TEST_F(SyncerProtoUtilTest, HandleThrottlingWithDatatypes) {
276 MockSyncSessionContext context;
277 SyncProtocolError error;
278 error.error_type = browser_sync::THROTTLED;
279 syncable::ModelTypeSet types;
280 types.insert(syncable::BOOKMARKS);
281 types.insert(syncable::PASSWORDS);
282 error.error_data_types = types;
283
284 base::TimeTicks ticks = base::TimeTicks::Now();
285
286 EXPECT_CALL(context, AddUnthrottleTime(types, ticks));
287
288 SyncerProtoUtil::HandleThrottleError(error, ticks, &context, NULL);
289 }
290
291 TEST_F(SyncerProtoUtilTest, HandleThrottlingNoDatatypes) {
292 MockDelegate delegate;
293 SyncProtocolError error;
294 error.error_type = browser_sync::THROTTLED;
295
296 base::TimeTicks ticks = base::TimeTicks::Now();
297
298 EXPECT_CALL(delegate, OnSilencedUntil(ticks));
299
300 SyncerProtoUtil::HandleThrottleError(error, ticks, NULL, &delegate);
301 }
243 } // namespace browser_sync 302 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698