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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_registrar_unittest.cc

Issue 8851006: [Sync] Replace all instances of ModelTypeSet with ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 9 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 | 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/glue/sync_backend_registrar.h" 5 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
6 6
7 #include "chrome/browser/sync/glue/change_processor_mock.h" 7 #include "chrome/browser/sync/glue/change_processor_mock.h"
8 #include "chrome/browser/sync/glue/ui_model_worker.h" 8 #include "chrome/browser/sync/glue/ui_model_worker.h"
9 #include "chrome/browser/sync/syncable/model_type.h" 9 #include "chrome/browser/sync/syncable/model_type.h"
10 #include "chrome/browser/sync/test/engine/test_user_share.h" 10 #include "chrome/browser/sync/test/engine/test_user_share.h"
(...skipping 12 matching lines...) Expand all
23 using ::testing::StrictMock; 23 using ::testing::StrictMock;
24 using content::BrowserThread; 24 using content::BrowserThread;
25 using syncable::FIRST_REAL_MODEL_TYPE; 25 using syncable::FIRST_REAL_MODEL_TYPE;
26 using syncable::AUTOFILL; 26 using syncable::AUTOFILL;
27 using syncable::BOOKMARKS; 27 using syncable::BOOKMARKS;
28 using syncable::PREFERENCES; 28 using syncable::PREFERENCES;
29 using syncable::THEMES; 29 using syncable::THEMES;
30 using syncable::NIGORI; 30 using syncable::NIGORI;
31 using syncable::PASSWORDS; 31 using syncable::PASSWORDS;
32 using syncable::MODEL_TYPE_COUNT; 32 using syncable::MODEL_TYPE_COUNT;
33 using syncable::ModelEnumSet;
33 using syncable::ModelType; 34 using syncable::ModelType;
34 using syncable::ModelTypeFromInt; 35 using syncable::ModelTypeFromInt;
35 using syncable::ModelTypeSet;
36 36
37 class SyncBackendRegistrarTest : public testing::Test { 37 class SyncBackendRegistrarTest : public testing::Test {
38 protected: 38 protected:
39 SyncBackendRegistrarTest() : ui_thread_(BrowserThread::UI, &loop_) {} 39 SyncBackendRegistrarTest() : ui_thread_(BrowserThread::UI, &loop_) {}
40 40
41 virtual ~SyncBackendRegistrarTest() {} 41 virtual ~SyncBackendRegistrarTest() {}
42 42
43 virtual void SetUp() { 43 virtual void SetUp() {
44 test_user_share_.SetUp(); 44 test_user_share_.SetUp();
45 } 45 }
46 46
47 virtual void TearDown() { 47 virtual void TearDown() {
48 test_user_share_.TearDown(); 48 test_user_share_.TearDown();
49 } 49 }
50 50
51 void ExpectRoutingInfo(SyncBackendRegistrar* registrar, 51 void ExpectRoutingInfo(SyncBackendRegistrar* registrar,
52 const ModelSafeRoutingInfo& expected_routing_info) { 52 const ModelSafeRoutingInfo& expected_routing_info) {
53 ModelSafeRoutingInfo routing_info; 53 ModelSafeRoutingInfo routing_info;
54 registrar->GetModelSafeRoutingInfo(&routing_info); 54 registrar->GetModelSafeRoutingInfo(&routing_info);
55 EXPECT_EQ(expected_routing_info, routing_info); 55 EXPECT_EQ(expected_routing_info, routing_info);
56 } 56 }
57 57
58 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar, 58 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar,
59 const ModelTypeSet& types) { 59 ModelEnumSet types) {
60 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 60 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
61 ModelType model_type = ModelTypeFromInt(i); 61 ModelType model_type = ModelTypeFromInt(i);
62 EXPECT_EQ(types.count(model_type) > 0, 62 EXPECT_EQ(types.Has(model_type),
63 registrar.IsTypeActivatedForTest(model_type)); 63 registrar.IsTypeActivatedForTest(model_type));
64 } 64 }
65 } 65 }
66 66
67 MessageLoop loop_; 67 MessageLoop loop_;
68 TestUserShare test_user_share_; 68 TestUserShare test_user_share_;
69 69
70 private: 70 private:
71 content::TestBrowserThread ui_thread_; 71 content::TestBrowserThread ui_thread_;
72 }; 72 };
73 73
74 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { 74 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) {
75 TestingProfile profile; 75 TestingProfile profile;
76 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 76 SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
77 EXPECT_FALSE(registrar.IsNigoriEnabled()); 77 EXPECT_FALSE(registrar.IsNigoriEnabled());
78 { 78 {
79 std::vector<ModelSafeWorker*> workers; 79 std::vector<ModelSafeWorker*> workers;
80 registrar.GetWorkers(&workers); 80 registrar.GetWorkers(&workers);
81 EXPECT_EQ(4u, workers.size()); 81 EXPECT_EQ(4u, workers.size());
82 } 82 }
83 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo()); 83 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
84 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 84 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
85 registrar.OnSyncerShutdownComplete(); 85 registrar.OnSyncerShutdownComplete();
86 registrar.StopOnUIThread(); 86 registrar.StopOnUIThread();
87 } 87 }
88 88
89 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { 89 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) {
90 TestingProfile profile; 90 TestingProfile profile;
91 ModelTypeSet initial_types; 91 ModelEnumSet initial_types;
92 initial_types.insert(BOOKMARKS); 92 initial_types.Put(BOOKMARKS);
93 initial_types.insert(NIGORI); 93 initial_types.Put(NIGORI);
94 initial_types.insert(PASSWORDS); 94 initial_types.Put(PASSWORDS);
95 SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_); 95 SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_);
96 EXPECT_TRUE(registrar.IsNigoriEnabled()); 96 EXPECT_TRUE(registrar.IsNigoriEnabled());
97 { 97 {
98 std::vector<ModelSafeWorker*> workers; 98 std::vector<ModelSafeWorker*> workers;
99 registrar.GetWorkers(&workers); 99 registrar.GetWorkers(&workers);
100 EXPECT_EQ(4u, workers.size()); 100 EXPECT_EQ(4u, workers.size());
101 } 101 }
102 { 102 {
103 ModelSafeRoutingInfo expected_routing_info; 103 ModelSafeRoutingInfo expected_routing_info;
104 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE; 104 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE;
105 expected_routing_info[NIGORI] = GROUP_PASSIVE; 105 expected_routing_info[NIGORI] = GROUP_PASSIVE;
106 // Passwords dropped because of no password store. 106 // Passwords dropped because of no password store.
107 ExpectRoutingInfo(&registrar, expected_routing_info); 107 ExpectRoutingInfo(&registrar, expected_routing_info);
108 } 108 }
109 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 109 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
110 registrar.OnSyncerShutdownComplete(); 110 registrar.OnSyncerShutdownComplete();
111 registrar.StopOnUIThread(); 111 registrar.StopOnUIThread();
112 } 112 }
113 113
114 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { 114 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) {
115 TestingProfile profile; 115 TestingProfile profile;
116 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 116 SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
117 117
118 // Add. 118 // Add.
119 ModelTypeSet types1; 119 ModelEnumSet types1;
120 types1.insert(BOOKMARKS); 120 types1.Put(BOOKMARKS);
121 types1.insert(NIGORI); 121 types1.Put(NIGORI);
122 types1.insert(AUTOFILL); 122 types1.Put(AUTOFILL);
123 EXPECT_EQ(types1, registrar.ConfigureDataTypes(types1, ModelTypeSet())); 123 EXPECT_TRUE(types1.Equals(
124 registrar.ConfigureDataTypes(types1, ModelEnumSet())));
124 { 125 {
125 ModelSafeRoutingInfo expected_routing_info; 126 ModelSafeRoutingInfo expected_routing_info;
126 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE; 127 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE;
127 expected_routing_info[NIGORI] = GROUP_PASSIVE; 128 expected_routing_info[NIGORI] = GROUP_PASSIVE;
128 expected_routing_info[AUTOFILL] = GROUP_PASSIVE; 129 expected_routing_info[AUTOFILL] = GROUP_PASSIVE;
129 ExpectRoutingInfo(&registrar, expected_routing_info); 130 ExpectRoutingInfo(&registrar, expected_routing_info);
130 } 131 }
131 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 132 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
132 133
133 // Add and remove. 134 // Add and remove.
134 ModelTypeSet types2; 135 ModelEnumSet types2;
135 types2.insert(PREFERENCES); 136 types2.Put(PREFERENCES);
136 types2.insert(THEMES); 137 types2.Put(THEMES);
137 EXPECT_EQ(types2, registrar.ConfigureDataTypes(types2, types1)); 138 EXPECT_TRUE(types2.Equals(registrar.ConfigureDataTypes(types2, types1)));
138 { 139 {
139 ModelSafeRoutingInfo expected_routing_info; 140 ModelSafeRoutingInfo expected_routing_info;
140 expected_routing_info[PREFERENCES] = GROUP_PASSIVE; 141 expected_routing_info[PREFERENCES] = GROUP_PASSIVE;
141 expected_routing_info[THEMES] = GROUP_PASSIVE; 142 expected_routing_info[THEMES] = GROUP_PASSIVE;
142 ExpectRoutingInfo(&registrar, expected_routing_info); 143 ExpectRoutingInfo(&registrar, expected_routing_info);
143 } 144 }
144 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 145 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
145 146
146 // Remove. 147 // Remove.
147 EXPECT_TRUE(registrar.ConfigureDataTypes(ModelTypeSet(), types2).empty()); 148 EXPECT_TRUE(registrar.ConfigureDataTypes(ModelEnumSet(), types2).Empty());
148 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo()); 149 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
149 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 150 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
150 151
151 registrar.OnSyncerShutdownComplete(); 152 registrar.OnSyncerShutdownComplete();
152 registrar.StopOnUIThread(); 153 registrar.StopOnUIThread();
153 } 154 }
154 155
155 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { 156 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) {
156 registrar->OnChangesApplied(type, NULL, 157 registrar->OnChangesApplied(type, NULL,
157 sync_api::ImmutableChangeRecordList()); 158 sync_api::ImmutableChangeRecordList());
158 registrar->OnChangesComplete(type); 159 registrar->OnChangesComplete(type);
159 } 160 }
160 161
161 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { 162 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) {
162 InSequence in_sequence; 163 InSequence in_sequence;
163 TestingProfile profile; 164 TestingProfile profile;
164 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 165 SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
165 166
166 // Should do nothing. 167 // Should do nothing.
167 TriggerChanges(&registrar, BOOKMARKS); 168 TriggerChanges(&registrar, BOOKMARKS);
168 169
169 StrictMock<ChangeProcessorMock> change_processor_mock; 170 StrictMock<ChangeProcessorMock> change_processor_mock;
170 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); 171 EXPECT_CALL(change_processor_mock, StartImpl(&profile));
171 EXPECT_CALL(change_processor_mock, IsRunning()) 172 EXPECT_CALL(change_processor_mock, IsRunning())
172 .WillRepeatedly(Return(true)); 173 .WillRepeatedly(Return(true));
173 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); 174 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _));
174 EXPECT_CALL(change_processor_mock, IsRunning()) 175 EXPECT_CALL(change_processor_mock, IsRunning())
175 .WillRepeatedly(Return(true)); 176 .WillRepeatedly(Return(true));
176 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); 177 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel());
177 EXPECT_CALL(change_processor_mock, StopImpl()); 178 EXPECT_CALL(change_processor_mock, StopImpl());
178 EXPECT_CALL(change_processor_mock, IsRunning()) 179 EXPECT_CALL(change_processor_mock, IsRunning())
179 .WillRepeatedly(Return(false)); 180 .WillRepeatedly(Return(false));
180 181
181 ModelTypeSet types; 182 ModelEnumSet types;
182 types.insert(BOOKMARKS); 183 types.Put(BOOKMARKS);
183 EXPECT_EQ(types, registrar.ConfigureDataTypes(types, ModelTypeSet())); 184 EXPECT_TRUE(types.Equals(
185 registrar.ConfigureDataTypes(types, ModelEnumSet())));
184 registrar.ActivateDataType(BOOKMARKS, GROUP_UI, 186 registrar.ActivateDataType(BOOKMARKS, GROUP_UI,
185 &change_processor_mock, 187 &change_processor_mock,
186 test_user_share_.user_share()); 188 test_user_share_.user_share());
187 { 189 {
188 ModelSafeRoutingInfo expected_routing_info; 190 ModelSafeRoutingInfo expected_routing_info;
189 expected_routing_info[BOOKMARKS] = GROUP_UI; 191 expected_routing_info[BOOKMARKS] = GROUP_UI;
190 ExpectRoutingInfo(&registrar, expected_routing_info); 192 ExpectRoutingInfo(&registrar, expected_routing_info);
191 } 193 }
192 ExpectHasProcessorsForTypes(registrar, types); 194 ExpectHasProcessorsForTypes(registrar, types);
193 195
194 TriggerChanges(&registrar, BOOKMARKS); 196 TriggerChanges(&registrar, BOOKMARKS);
195 197
196 registrar.DeactivateDataType(BOOKMARKS); 198 registrar.DeactivateDataType(BOOKMARKS);
197 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo()); 199 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
198 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 200 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
199 201
200 // Should do nothing. 202 // Should do nothing.
201 TriggerChanges(&registrar, BOOKMARKS); 203 TriggerChanges(&registrar, BOOKMARKS);
202 204
203 registrar.OnSyncerShutdownComplete(); 205 registrar.OnSyncerShutdownComplete();
204 registrar.StopOnUIThread(); 206 registrar.StopOnUIThread();
205 } 207 }
206 208
207 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { 209 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) {
208 content::TestBrowserThread db_thread(BrowserThread::DB, &loop_); 210 content::TestBrowserThread db_thread(BrowserThread::DB, &loop_);
209 InSequence in_sequence; 211 InSequence in_sequence;
210 TestingProfile profile; 212 TestingProfile profile;
211 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 213 SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
212 214
213 // Should do nothing. 215 // Should do nothing.
214 TriggerChanges(&registrar, AUTOFILL); 216 TriggerChanges(&registrar, AUTOFILL);
215 217
216 StrictMock<ChangeProcessorMock> change_processor_mock; 218 StrictMock<ChangeProcessorMock> change_processor_mock;
217 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); 219 EXPECT_CALL(change_processor_mock, StartImpl(&profile));
218 EXPECT_CALL(change_processor_mock, IsRunning()) 220 EXPECT_CALL(change_processor_mock, IsRunning())
219 .WillRepeatedly(Return(true)); 221 .WillRepeatedly(Return(true));
220 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); 222 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _));
221 EXPECT_CALL(change_processor_mock, IsRunning()) 223 EXPECT_CALL(change_processor_mock, IsRunning())
222 .WillRepeatedly(Return(true)); 224 .WillRepeatedly(Return(true));
223 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); 225 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel());
224 EXPECT_CALL(change_processor_mock, StopImpl()); 226 EXPECT_CALL(change_processor_mock, StopImpl());
225 EXPECT_CALL(change_processor_mock, IsRunning()) 227 EXPECT_CALL(change_processor_mock, IsRunning())
226 .WillRepeatedly(Return(false)); 228 .WillRepeatedly(Return(false));
227 229
228 ModelTypeSet types; 230 ModelEnumSet types;
229 types.insert(AUTOFILL); 231 types.Put(AUTOFILL);
230 EXPECT_EQ(types, registrar.ConfigureDataTypes(types, ModelTypeSet())); 232 EXPECT_TRUE(types.Equals(
233 registrar.ConfigureDataTypes(types, ModelEnumSet())));
231 registrar.ActivateDataType(AUTOFILL, GROUP_DB, 234 registrar.ActivateDataType(AUTOFILL, GROUP_DB,
232 &change_processor_mock, 235 &change_processor_mock,
233 test_user_share_.user_share()); 236 test_user_share_.user_share());
234 { 237 {
235 ModelSafeRoutingInfo expected_routing_info; 238 ModelSafeRoutingInfo expected_routing_info;
236 expected_routing_info[AUTOFILL] = GROUP_DB; 239 expected_routing_info[AUTOFILL] = GROUP_DB;
237 ExpectRoutingInfo(&registrar, expected_routing_info); 240 ExpectRoutingInfo(&registrar, expected_routing_info);
238 } 241 }
239 ExpectHasProcessorsForTypes(registrar, types); 242 ExpectHasProcessorsForTypes(registrar, types);
240 243
241 TriggerChanges(&registrar, AUTOFILL); 244 TriggerChanges(&registrar, AUTOFILL);
242 245
243 registrar.DeactivateDataType(AUTOFILL); 246 registrar.DeactivateDataType(AUTOFILL);
244 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo()); 247 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
245 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 248 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
246 249
247 // Should do nothing. 250 // Should do nothing.
248 TriggerChanges(&registrar, AUTOFILL); 251 TriggerChanges(&registrar, AUTOFILL);
249 252
250 registrar.OnSyncerShutdownComplete(); 253 registrar.OnSyncerShutdownComplete();
251 registrar.StopOnUIThread(); 254 registrar.StopOnUIThread();
252 } 255 }
253 256
254 } // namespace 257 } // namespace
255 258
256 } // namespace browser_sync 259 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698