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

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

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

Powered by Google App Engine
This is Rietveld 408576698