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

Side by Side Diff: sync/internal_api/sync_rollback_manager_unittest.cc

Issue 1545553003: Switch to standard integer types in sync/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « sync/internal_api/sync_rollback_manager_base.cc ('k') | sync/internal_api/syncapi_internal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/internal_api/sync_rollback_manager.h" 5 #include "sync/internal_api/sync_rollback_manager.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <set> 10 #include <set>
8 11
9 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
10 #include "base/run_loop.h" 13 #include "base/run_loop.h"
11 #include "sync/internal_api/public/read_node.h" 14 #include "sync/internal_api/public/read_node.h"
12 #include "sync/internal_api/public/read_transaction.h" 15 #include "sync/internal_api/public/read_transaction.h"
13 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 16 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
14 #include "sync/internal_api/public/test/test_internal_components_factory.h" 17 #include "sync/internal_api/public/test/test_internal_components_factory.h"
15 #include "sync/internal_api/public/write_node.h" 18 #include "sync/internal_api/public/write_node.h"
16 #include "sync/internal_api/public/write_transaction.h" 19 #include "sync/internal_api/public/write_transaction.h"
(...skipping 17 matching lines...) Expand all
34 37
35 class TestChangeDelegate : public SyncManager::ChangeDelegate { 38 class TestChangeDelegate : public SyncManager::ChangeDelegate {
36 public: 39 public:
37 TestChangeDelegate() { 40 TestChangeDelegate() {
38 ON_CALL(*this, OnChangesApplied(_, _, _, _)) 41 ON_CALL(*this, OnChangesApplied(_, _, _, _))
39 .WillByDefault( 42 .WillByDefault(
40 WithArgs<3>(Invoke(this, 43 WithArgs<3>(Invoke(this,
41 &TestChangeDelegate::VerifyDeletes))); 44 &TestChangeDelegate::VerifyDeletes)));
42 } 45 }
43 46
44 void add_expected_delete(int64 v) { 47 void add_expected_delete(int64_t v) { expected_deletes_.insert(v); }
45 expected_deletes_.insert(v);
46 }
47 48
48 MOCK_METHOD4(OnChangesApplied, 49 MOCK_METHOD4(OnChangesApplied,
49 void(ModelType model_type, 50 void(ModelType model_type,
50 int64 model_version, 51 int64_t model_version,
51 const BaseTransaction* trans, 52 const BaseTransaction* trans,
52 const ImmutableChangeRecordList& changes)); 53 const ImmutableChangeRecordList& changes));
53 MOCK_METHOD1(OnChangesComplete, void(ModelType model_type)); 54 MOCK_METHOD1(OnChangesComplete, void(ModelType model_type));
54 55
55 private: 56 private:
56 void VerifyDeletes(const ImmutableChangeRecordList& changes) { 57 void VerifyDeletes(const ImmutableChangeRecordList& changes) {
57 std::set<int64> deleted; 58 std::set<int64_t> deleted;
58 for (size_t i = 0; i < changes.Get().size(); ++i) { 59 for (size_t i = 0; i < changes.Get().size(); ++i) {
59 const ChangeRecord& change = (changes.Get())[i]; 60 const ChangeRecord& change = (changes.Get())[i];
60 EXPECT_EQ(ChangeRecord::ACTION_DELETE, change.action); 61 EXPECT_EQ(ChangeRecord::ACTION_DELETE, change.action);
61 EXPECT_TRUE(deleted.find(change.id) == deleted.end()); 62 EXPECT_TRUE(deleted.find(change.id) == deleted.end());
62 deleted.insert(change.id); 63 deleted.insert(change.id);
63 } 64 }
64 EXPECT_TRUE(expected_deletes_ == deleted); 65 EXPECT_TRUE(expected_deletes_ == deleted);
65 } 66 }
66 67
67 std::set<int64> expected_deletes_; 68 std::set<int64_t> expected_deletes_;
68 }; 69 };
69 70
70 class SyncRollbackManagerTest : public testing::Test, 71 class SyncRollbackManagerTest : public testing::Test,
71 public SyncManager::Observer { 72 public SyncManager::Observer {
72 protected: 73 protected:
73 void SetUp() override { 74 void SetUp() override {
74 CHECK(temp_dir_.CreateUniqueTempDir()); 75 CHECK(temp_dir_.CreateUniqueTempDir());
75 76
76 worker_ = new FakeModelWorker(GROUP_UI); 77 worker_ = new FakeModelWorker(GROUP_UI);
77 } 78 }
78 79
79 MOCK_METHOD1(OnSyncCycleCompleted, 80 MOCK_METHOD1(OnSyncCycleCompleted,
80 void(const sessions::SyncSessionSnapshot&)); 81 void(const sessions::SyncSessionSnapshot&));
81 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); 82 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus));
82 MOCK_METHOD4(OnInitializationComplete, 83 MOCK_METHOD4(OnInitializationComplete,
83 void(const WeakHandle<JsBackend>&, 84 void(const WeakHandle<JsBackend>&,
84 const WeakHandle<DataTypeDebugInfoListener>&, 85 const WeakHandle<DataTypeDebugInfoListener>&,
85 bool, ModelTypeSet)); 86 bool, ModelTypeSet));
86 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&)); 87 MOCK_METHOD1(OnActionableError, void(const SyncProtocolError&));
87 MOCK_METHOD1(OnMigrationRequested, void(ModelTypeSet));; 88 MOCK_METHOD1(OnMigrationRequested, void(ModelTypeSet));;
88 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&)); 89 MOCK_METHOD1(OnProtocolEvent, void(const ProtocolEvent&));
89 90
90 void OnConfigDone(bool success) { 91 void OnConfigDone(bool success) {
91 EXPECT_TRUE(success); 92 EXPECT_TRUE(success);
92 } 93 }
93 94
94 int64 CreateEntry(UserShare* user_share, ModelType type, 95 int64_t CreateEntry(UserShare* user_share,
95 const std::string& client_tag) { 96 ModelType type,
97 const std::string& client_tag) {
96 WriteTransaction trans(FROM_HERE, user_share); 98 WriteTransaction trans(FROM_HERE, user_share);
97 WriteNode node(&trans); 99 WriteNode node(&trans);
98 EXPECT_EQ(WriteNode::INIT_SUCCESS, 100 EXPECT_EQ(WriteNode::INIT_SUCCESS,
99 node.InitUniqueByCreation(type, client_tag)); 101 node.InitUniqueByCreation(type, client_tag));
100 return node.GetId(); 102 return node.GetId();
101 } 103 }
102 104
103 void InitManager(SyncManager* manager, ModelTypeSet types, 105 void InitManager(SyncManager* manager, ModelTypeSet types,
104 TestChangeDelegate* delegate, 106 TestChangeDelegate* delegate,
105 InternalComponentsFactory::StorageOption storage_option) { 107 InternalComponentsFactory::StorageOption storage_option) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 184
183 TEST_F(SyncRollbackManagerTest, RollbackBasic) { 185 TEST_F(SyncRollbackManagerTest, RollbackBasic) {
184 PrepopulateDb(PREFERENCES, "pref1"); 186 PrepopulateDb(PREFERENCES, "pref1");
185 187
186 TestChangeDelegate delegate; 188 TestChangeDelegate delegate;
187 SyncRollbackManager rollback_manager; 189 SyncRollbackManager rollback_manager;
188 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES), &delegate, 190 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES), &delegate,
189 InternalComponentsFactory::STORAGE_ON_DISK); 191 InternalComponentsFactory::STORAGE_ON_DISK);
190 192
191 // Simulate a new entry added during type initialization. 193 // Simulate a new entry added during type initialization.
192 int64 new_pref_id = 194 int64_t new_pref_id =
193 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2"); 195 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2");
194 196
195 delegate.add_expected_delete(new_pref_id); 197 delegate.add_expected_delete(new_pref_id);
196 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _)) 198 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _))
197 .Times(1) 199 .Times(1)
198 .WillOnce(DoDefault()); 200 .WillOnce(DoDefault());
199 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1); 201 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1);
200 EXPECT_CALL(*this, OnActionableError(Truly(IsRollbackDoneAction))).Times(1); 202 EXPECT_CALL(*this, OnActionableError(Truly(IsRollbackDoneAction))).Times(1);
201 203
202 ModelSafeRoutingInfo routing_info; 204 ModelSafeRoutingInfo routing_info;
203 routing_info[PREFERENCES] = GROUP_UI; 205 routing_info[PREFERENCES] = GROUP_UI;
204 rollback_manager.StartSyncingNormally(routing_info, base::Time()); 206 rollback_manager.StartSyncingNormally(routing_info, base::Time());
205 } 207 }
206 208
207 TEST_F(SyncRollbackManagerTest, NoRollbackOfTypesNotBackedUp) { 209 TEST_F(SyncRollbackManagerTest, NoRollbackOfTypesNotBackedUp) {
208 PrepopulateDb(PREFERENCES, "pref1"); 210 PrepopulateDb(PREFERENCES, "pref1");
209 211
210 TestChangeDelegate delegate; 212 TestChangeDelegate delegate;
211 SyncRollbackManager rollback_manager; 213 SyncRollbackManager rollback_manager;
212 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES, APPS), &delegate, 214 InitManager(&rollback_manager, ModelTypeSet(PREFERENCES, APPS), &delegate,
213 InternalComponentsFactory::STORAGE_ON_DISK); 215 InternalComponentsFactory::STORAGE_ON_DISK);
214 216
215 // Simulate new entry added during type initialization. 217 // Simulate new entry added during type initialization.
216 int64 new_pref_id = 218 int64_t new_pref_id =
217 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2"); 219 CreateEntry(rollback_manager.GetUserShare(), PREFERENCES, "pref2");
218 CreateEntry(rollback_manager.GetUserShare(), APPS, "app1"); 220 CreateEntry(rollback_manager.GetUserShare(), APPS, "app1");
219 221
220 delegate.add_expected_delete(new_pref_id); 222 delegate.add_expected_delete(new_pref_id);
221 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _)) 223 EXPECT_CALL(delegate, OnChangesApplied(_, _, _, _))
222 .Times(1) 224 .Times(1)
223 .WillOnce(DoDefault()); 225 .WillOnce(DoDefault());
224 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1); 226 EXPECT_CALL(delegate, OnChangesComplete(_)).Times(1);
225 227
226 ModelSafeRoutingInfo routing_info; 228 ModelSafeRoutingInfo routing_info;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // Test graceful shutdown on initialization failure. 260 // Test graceful shutdown on initialization failure.
259 scoped_ptr<SyncRollbackManager> rollback_manager( 261 scoped_ptr<SyncRollbackManager> rollback_manager(
260 new SyncRollbackManager); 262 new SyncRollbackManager);
261 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), NULL, 263 InitManager(rollback_manager.get(), ModelTypeSet(PREFERENCES), NULL,
262 InternalComponentsFactory::STORAGE_ON_DISK); 264 InternalComponentsFactory::STORAGE_ON_DISK);
263 } 265 }
264 266
265 } // anonymous namespace 267 } // anonymous namespace
266 268
267 } // namespace syncer 269 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_rollback_manager_base.cc ('k') | sync/internal_api/syncapi_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698