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

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

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