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

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 pass #2 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 const ModelEnumSet initial_types(BOOKMARKS, NIGORI, PASSWORDS);
92 initial_types.insert(BOOKMARKS);
93 initial_types.insert(NIGORI);
94 initial_types.insert(PASSWORDS);
95 SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_); 92 SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_);
96 EXPECT_TRUE(registrar.IsNigoriEnabled()); 93 EXPECT_TRUE(registrar.IsNigoriEnabled());
97 { 94 {
98 std::vector<ModelSafeWorker*> workers; 95 std::vector<ModelSafeWorker*> workers;
99 registrar.GetWorkers(&workers); 96 registrar.GetWorkers(&workers);
100 EXPECT_EQ(4u, workers.size()); 97 EXPECT_EQ(4u, workers.size());
101 } 98 }
102 { 99 {
103 ModelSafeRoutingInfo expected_routing_info; 100 ModelSafeRoutingInfo expected_routing_info;
104 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE; 101 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE;
105 expected_routing_info[NIGORI] = GROUP_PASSIVE; 102 expected_routing_info[NIGORI] = GROUP_PASSIVE;
106 // Passwords dropped because of no password store. 103 // Passwords dropped because of no password store.
107 ExpectRoutingInfo(&registrar, expected_routing_info); 104 ExpectRoutingInfo(&registrar, expected_routing_info);
108 } 105 }
109 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 106 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
110 registrar.OnSyncerShutdownComplete(); 107 registrar.OnSyncerShutdownComplete();
111 registrar.StopOnUIThread(); 108 registrar.StopOnUIThread();
112 } 109 }
113 110
114 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { 111 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) {
115 TestingProfile profile; 112 TestingProfile profile;
116 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 113 SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
117 114
118 // Add. 115 // Add.
119 ModelTypeSet types1; 116 const ModelEnumSet types1(BOOKMARKS, NIGORI, AUTOFILL);
120 types1.insert(BOOKMARKS); 117 EXPECT_TRUE(
121 types1.insert(NIGORI); 118 registrar.ConfigureDataTypes(types1, ModelEnumSet()).Equals(types1));
122 types1.insert(AUTOFILL);
123 EXPECT_EQ(types1, registrar.ConfigureDataTypes(types1, ModelTypeSet()));
124 { 119 {
125 ModelSafeRoutingInfo expected_routing_info; 120 ModelSafeRoutingInfo expected_routing_info;
126 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE; 121 expected_routing_info[BOOKMARKS] = GROUP_PASSIVE;
127 expected_routing_info[NIGORI] = GROUP_PASSIVE; 122 expected_routing_info[NIGORI] = GROUP_PASSIVE;
128 expected_routing_info[AUTOFILL] = GROUP_PASSIVE; 123 expected_routing_info[AUTOFILL] = GROUP_PASSIVE;
129 ExpectRoutingInfo(&registrar, expected_routing_info); 124 ExpectRoutingInfo(&registrar, expected_routing_info);
130 } 125 }
131 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 126 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
132 127
133 // Add and remove. 128 // Add and remove.
134 ModelTypeSet types2; 129 const ModelEnumSet types2(PREFERENCES, THEMES);
135 types2.insert(PREFERENCES); 130 EXPECT_TRUE(registrar.ConfigureDataTypes(types2, types1).Equals(types2));
136 types2.insert(THEMES);
137 EXPECT_EQ(types2, registrar.ConfigureDataTypes(types2, types1));
138 { 131 {
139 ModelSafeRoutingInfo expected_routing_info; 132 ModelSafeRoutingInfo expected_routing_info;
140 expected_routing_info[PREFERENCES] = GROUP_PASSIVE; 133 expected_routing_info[PREFERENCES] = GROUP_PASSIVE;
141 expected_routing_info[THEMES] = GROUP_PASSIVE; 134 expected_routing_info[THEMES] = GROUP_PASSIVE;
142 ExpectRoutingInfo(&registrar, expected_routing_info); 135 ExpectRoutingInfo(&registrar, expected_routing_info);
143 } 136 }
144 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 137 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
145 138
146 // Remove. 139 // Remove.
147 EXPECT_TRUE(registrar.ConfigureDataTypes(ModelTypeSet(), types2).empty()); 140 EXPECT_TRUE(registrar.ConfigureDataTypes(ModelEnumSet(), types2).Empty());
148 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo()); 141 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
149 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 142 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
150 143
151 registrar.OnSyncerShutdownComplete(); 144 registrar.OnSyncerShutdownComplete();
152 registrar.StopOnUIThread(); 145 registrar.StopOnUIThread();
153 } 146 }
154 147
155 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { 148 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) {
156 registrar->OnChangesApplied(type, NULL, 149 registrar->OnChangesApplied(type, NULL,
157 sync_api::ImmutableChangeRecordList()); 150 sync_api::ImmutableChangeRecordList());
158 registrar->OnChangesComplete(type); 151 registrar->OnChangesComplete(type);
159 } 152 }
160 153
161 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { 154 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) {
162 InSequence in_sequence; 155 InSequence in_sequence;
163 TestingProfile profile; 156 TestingProfile profile;
164 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 157 SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
165 158
166 // Should do nothing. 159 // Should do nothing.
167 TriggerChanges(&registrar, BOOKMARKS); 160 TriggerChanges(&registrar, BOOKMARKS);
168 161
169 StrictMock<ChangeProcessorMock> change_processor_mock; 162 StrictMock<ChangeProcessorMock> change_processor_mock;
170 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); 163 EXPECT_CALL(change_processor_mock, StartImpl(&profile));
171 EXPECT_CALL(change_processor_mock, IsRunning()) 164 EXPECT_CALL(change_processor_mock, IsRunning())
172 .WillRepeatedly(Return(true)); 165 .WillRepeatedly(Return(true));
173 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); 166 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _));
174 EXPECT_CALL(change_processor_mock, IsRunning()) 167 EXPECT_CALL(change_processor_mock, IsRunning())
175 .WillRepeatedly(Return(true)); 168 .WillRepeatedly(Return(true));
176 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); 169 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel());
177 EXPECT_CALL(change_processor_mock, StopImpl()); 170 EXPECT_CALL(change_processor_mock, StopImpl());
178 EXPECT_CALL(change_processor_mock, IsRunning()) 171 EXPECT_CALL(change_processor_mock, IsRunning())
179 .WillRepeatedly(Return(false)); 172 .WillRepeatedly(Return(false));
180 173
181 ModelTypeSet types; 174 const ModelEnumSet types(BOOKMARKS);
182 types.insert(BOOKMARKS); 175 EXPECT_TRUE(
183 EXPECT_EQ(types, registrar.ConfigureDataTypes(types, ModelTypeSet())); 176 registrar.ConfigureDataTypes(types, ModelEnumSet()).Equals(types));
184 registrar.ActivateDataType(BOOKMARKS, GROUP_UI, 177 registrar.ActivateDataType(BOOKMARKS, GROUP_UI,
185 &change_processor_mock, 178 &change_processor_mock,
186 test_user_share_.user_share()); 179 test_user_share_.user_share());
187 { 180 {
188 ModelSafeRoutingInfo expected_routing_info; 181 ModelSafeRoutingInfo expected_routing_info;
189 expected_routing_info[BOOKMARKS] = GROUP_UI; 182 expected_routing_info[BOOKMARKS] = GROUP_UI;
190 ExpectRoutingInfo(&registrar, expected_routing_info); 183 ExpectRoutingInfo(&registrar, expected_routing_info);
191 } 184 }
192 ExpectHasProcessorsForTypes(registrar, types); 185 ExpectHasProcessorsForTypes(registrar, types);
193 186
194 TriggerChanges(&registrar, BOOKMARKS); 187 TriggerChanges(&registrar, BOOKMARKS);
195 188
196 registrar.DeactivateDataType(BOOKMARKS); 189 registrar.DeactivateDataType(BOOKMARKS);
197 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo()); 190 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
198 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 191 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
199 192
200 // Should do nothing. 193 // Should do nothing.
201 TriggerChanges(&registrar, BOOKMARKS); 194 TriggerChanges(&registrar, BOOKMARKS);
202 195
203 registrar.OnSyncerShutdownComplete(); 196 registrar.OnSyncerShutdownComplete();
204 registrar.StopOnUIThread(); 197 registrar.StopOnUIThread();
205 } 198 }
206 199
207 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { 200 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) {
208 content::TestBrowserThread db_thread(BrowserThread::DB, &loop_); 201 content::TestBrowserThread db_thread(BrowserThread::DB, &loop_);
209 InSequence in_sequence; 202 InSequence in_sequence;
210 TestingProfile profile; 203 TestingProfile profile;
211 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); 204 SyncBackendRegistrar registrar(ModelEnumSet(), "test", &profile, &loop_);
212 205
213 // Should do nothing. 206 // Should do nothing.
214 TriggerChanges(&registrar, AUTOFILL); 207 TriggerChanges(&registrar, AUTOFILL);
215 208
216 StrictMock<ChangeProcessorMock> change_processor_mock; 209 StrictMock<ChangeProcessorMock> change_processor_mock;
217 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); 210 EXPECT_CALL(change_processor_mock, StartImpl(&profile));
218 EXPECT_CALL(change_processor_mock, IsRunning()) 211 EXPECT_CALL(change_processor_mock, IsRunning())
219 .WillRepeatedly(Return(true)); 212 .WillRepeatedly(Return(true));
220 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); 213 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _));
221 EXPECT_CALL(change_processor_mock, IsRunning()) 214 EXPECT_CALL(change_processor_mock, IsRunning())
222 .WillRepeatedly(Return(true)); 215 .WillRepeatedly(Return(true));
223 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); 216 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel());
224 EXPECT_CALL(change_processor_mock, StopImpl()); 217 EXPECT_CALL(change_processor_mock, StopImpl());
225 EXPECT_CALL(change_processor_mock, IsRunning()) 218 EXPECT_CALL(change_processor_mock, IsRunning())
226 .WillRepeatedly(Return(false)); 219 .WillRepeatedly(Return(false));
227 220
228 ModelTypeSet types; 221 const ModelEnumSet types(AUTOFILL);
229 types.insert(AUTOFILL); 222 EXPECT_TRUE(
230 EXPECT_EQ(types, registrar.ConfigureDataTypes(types, ModelTypeSet())); 223 registrar.ConfigureDataTypes(types, ModelEnumSet()).Equals(types));
231 registrar.ActivateDataType(AUTOFILL, GROUP_DB, 224 registrar.ActivateDataType(AUTOFILL, GROUP_DB,
232 &change_processor_mock, 225 &change_processor_mock,
233 test_user_share_.user_share()); 226 test_user_share_.user_share());
234 { 227 {
235 ModelSafeRoutingInfo expected_routing_info; 228 ModelSafeRoutingInfo expected_routing_info;
236 expected_routing_info[AUTOFILL] = GROUP_DB; 229 expected_routing_info[AUTOFILL] = GROUP_DB;
237 ExpectRoutingInfo(&registrar, expected_routing_info); 230 ExpectRoutingInfo(&registrar, expected_routing_info);
238 } 231 }
239 ExpectHasProcessorsForTypes(registrar, types); 232 ExpectHasProcessorsForTypes(registrar, types);
240 233
241 TriggerChanges(&registrar, AUTOFILL); 234 TriggerChanges(&registrar, AUTOFILL);
242 235
243 registrar.DeactivateDataType(AUTOFILL); 236 registrar.DeactivateDataType(AUTOFILL);
244 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo()); 237 ExpectRoutingInfo(&registrar, ModelSafeRoutingInfo());
245 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); 238 ExpectHasProcessorsForTypes(registrar, ModelEnumSet());
246 239
247 // Should do nothing. 240 // Should do nothing.
248 TriggerChanges(&registrar, AUTOFILL); 241 TriggerChanges(&registrar, AUTOFILL);
249 242
250 registrar.OnSyncerShutdownComplete(); 243 registrar.OnSyncerShutdownComplete();
251 registrar.StopOnUIThread(); 244 registrar.StopOnUIThread();
252 } 245 }
253 246
254 } // namespace 247 } // namespace
255 248
256 } // namespace browser_sync 249 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_registrar.cc ('k') | chrome/browser/sync/glue/theme_model_associator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698