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

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

Powered by Google App Engine
This is Rietveld 408576698