OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 MessageLoop loop_; | 68 MessageLoop loop_; |
69 syncer::TestUserShare test_user_share_; | 69 syncer::TestUserShare test_user_share_; |
70 | 70 |
71 private: | 71 private: |
72 content::TestBrowserThread ui_thread_; | 72 content::TestBrowserThread ui_thread_; |
73 }; | 73 }; |
74 | 74 |
75 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { | 75 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { |
76 TestingProfile profile; | 76 TestingProfile profile; |
77 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); | 77 SyncBackendRegistrar registrar("test", &profile, &loop_); |
| 78 registrar.SetInitialTypes(ModelTypeSet()); |
78 EXPECT_FALSE(registrar.IsNigoriEnabled()); | 79 EXPECT_FALSE(registrar.IsNigoriEnabled()); |
79 { | 80 { |
80 std::vector<syncer::ModelSafeWorker*> workers; | 81 std::vector<syncer::ModelSafeWorker*> workers; |
81 registrar.GetWorkers(&workers); | 82 registrar.GetWorkers(&workers); |
82 EXPECT_EQ(4u, workers.size()); | 83 EXPECT_EQ(4u, workers.size()); |
83 } | 84 } |
84 ExpectRoutingInfo(®istrar, syncer::ModelSafeRoutingInfo()); | 85 ExpectRoutingInfo(®istrar, syncer::ModelSafeRoutingInfo()); |
85 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); | 86 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
86 registrar.OnSyncerShutdownComplete(); | 87 registrar.OnSyncerShutdownComplete(); |
87 registrar.StopOnUIThread(); | 88 registrar.StopOnUIThread(); |
88 } | 89 } |
89 | 90 |
90 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { | 91 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { |
91 TestingProfile profile; | 92 TestingProfile profile; |
92 const ModelTypeSet initial_types(BOOKMARKS, NIGORI, PASSWORDS); | 93 const ModelTypeSet initial_types(BOOKMARKS, NIGORI, PASSWORDS); |
93 SyncBackendRegistrar registrar(initial_types, "test", &profile, &loop_); | 94 SyncBackendRegistrar registrar("test", &profile, &loop_); |
| 95 registrar.SetInitialTypes(initial_types); |
94 EXPECT_TRUE(registrar.IsNigoriEnabled()); | 96 EXPECT_TRUE(registrar.IsNigoriEnabled()); |
95 { | 97 { |
96 std::vector<syncer::ModelSafeWorker*> workers; | 98 std::vector<syncer::ModelSafeWorker*> workers; |
97 registrar.GetWorkers(&workers); | 99 registrar.GetWorkers(&workers); |
98 EXPECT_EQ(4u, workers.size()); | 100 EXPECT_EQ(4u, workers.size()); |
99 } | 101 } |
100 { | 102 { |
101 syncer::ModelSafeRoutingInfo expected_routing_info; | 103 syncer::ModelSafeRoutingInfo expected_routing_info; |
102 expected_routing_info[BOOKMARKS] = syncer::GROUP_PASSIVE; | 104 expected_routing_info[BOOKMARKS] = syncer::GROUP_PASSIVE; |
103 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE; | 105 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE; |
104 // Passwords dropped because of no password store. | 106 // Passwords dropped because of no password store. |
105 ExpectRoutingInfo(®istrar, expected_routing_info); | 107 ExpectRoutingInfo(®istrar, expected_routing_info); |
106 } | 108 } |
107 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); | 109 ExpectHasProcessorsForTypes(registrar, ModelTypeSet()); |
108 registrar.OnSyncerShutdownComplete(); | 110 registrar.OnSyncerShutdownComplete(); |
109 registrar.StopOnUIThread(); | 111 registrar.StopOnUIThread(); |
110 } | 112 } |
111 | 113 |
112 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { | 114 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { |
113 TestingProfile profile; | 115 TestingProfile profile; |
114 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); | 116 SyncBackendRegistrar registrar("test", &profile, &loop_); |
| 117 registrar.SetInitialTypes(ModelTypeSet()); |
115 | 118 |
116 // Add. | 119 // Add. |
117 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL); | 120 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL); |
118 EXPECT_TRUE( | 121 EXPECT_TRUE( |
119 registrar.ConfigureDataTypes(types1, ModelTypeSet()).Equals(types1)); | 122 registrar.ConfigureDataTypes(types1, ModelTypeSet()).Equals(types1)); |
120 { | 123 { |
121 syncer::ModelSafeRoutingInfo expected_routing_info; | 124 syncer::ModelSafeRoutingInfo expected_routing_info; |
122 expected_routing_info[BOOKMARKS] = syncer::GROUP_PASSIVE; | 125 expected_routing_info[BOOKMARKS] = syncer::GROUP_PASSIVE; |
123 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE; | 126 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE; |
124 expected_routing_info[AUTOFILL] = syncer::GROUP_PASSIVE; | 127 expected_routing_info[AUTOFILL] = syncer::GROUP_PASSIVE; |
(...skipping 23 matching lines...) Expand all Loading... |
148 | 151 |
149 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { | 152 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { |
150 registrar->OnChangesApplied(type, NULL, | 153 registrar->OnChangesApplied(type, NULL, |
151 syncer::ImmutableChangeRecordList()); | 154 syncer::ImmutableChangeRecordList()); |
152 registrar->OnChangesComplete(type); | 155 registrar->OnChangesComplete(type); |
153 } | 156 } |
154 | 157 |
155 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { | 158 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { |
156 InSequence in_sequence; | 159 InSequence in_sequence; |
157 TestingProfile profile; | 160 TestingProfile profile; |
158 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); | 161 SyncBackendRegistrar registrar("test", &profile, &loop_); |
| 162 registrar.SetInitialTypes(ModelTypeSet()); |
159 | 163 |
160 // Should do nothing. | 164 // Should do nothing. |
161 TriggerChanges(®istrar, BOOKMARKS); | 165 TriggerChanges(®istrar, BOOKMARKS); |
162 | 166 |
163 StrictMock<ChangeProcessorMock> change_processor_mock; | 167 StrictMock<ChangeProcessorMock> change_processor_mock; |
164 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); | 168 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); |
165 EXPECT_CALL(change_processor_mock, IsRunning()) | 169 EXPECT_CALL(change_processor_mock, IsRunning()) |
166 .WillRepeatedly(Return(true)); | 170 .WillRepeatedly(Return(true)); |
167 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); | 171 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); |
168 EXPECT_CALL(change_processor_mock, IsRunning()) | 172 EXPECT_CALL(change_processor_mock, IsRunning()) |
(...skipping 26 matching lines...) Expand all Loading... |
195 TriggerChanges(®istrar, BOOKMARKS); | 199 TriggerChanges(®istrar, BOOKMARKS); |
196 | 200 |
197 registrar.OnSyncerShutdownComplete(); | 201 registrar.OnSyncerShutdownComplete(); |
198 registrar.StopOnUIThread(); | 202 registrar.StopOnUIThread(); |
199 } | 203 } |
200 | 204 |
201 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { | 205 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { |
202 content::TestBrowserThread db_thread(BrowserThread::DB, &loop_); | 206 content::TestBrowserThread db_thread(BrowserThread::DB, &loop_); |
203 InSequence in_sequence; | 207 InSequence in_sequence; |
204 TestingProfile profile; | 208 TestingProfile profile; |
205 SyncBackendRegistrar registrar(ModelTypeSet(), "test", &profile, &loop_); | 209 SyncBackendRegistrar registrar("test", &profile, &loop_); |
| 210 registrar.SetInitialTypes(ModelTypeSet()); |
206 | 211 |
207 // Should do nothing. | 212 // Should do nothing. |
208 TriggerChanges(®istrar, AUTOFILL); | 213 TriggerChanges(®istrar, AUTOFILL); |
209 | 214 |
210 StrictMock<ChangeProcessorMock> change_processor_mock; | 215 StrictMock<ChangeProcessorMock> change_processor_mock; |
211 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); | 216 EXPECT_CALL(change_processor_mock, StartImpl(&profile)); |
212 EXPECT_CALL(change_processor_mock, IsRunning()) | 217 EXPECT_CALL(change_processor_mock, IsRunning()) |
213 .WillRepeatedly(Return(true)); | 218 .WillRepeatedly(Return(true)); |
214 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); | 219 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _)); |
215 EXPECT_CALL(change_processor_mock, IsRunning()) | 220 EXPECT_CALL(change_processor_mock, IsRunning()) |
(...skipping 25 matching lines...) Expand all Loading... |
241 // Should do nothing. | 246 // Should do nothing. |
242 TriggerChanges(®istrar, AUTOFILL); | 247 TriggerChanges(®istrar, AUTOFILL); |
243 | 248 |
244 registrar.OnSyncerShutdownComplete(); | 249 registrar.OnSyncerShutdownComplete(); |
245 registrar.StopOnUIThread(); | 250 registrar.StopOnUIThread(); |
246 } | 251 } |
247 | 252 |
248 } // namespace | 253 } // namespace |
249 | 254 |
250 } // namespace browser_sync | 255 } // namespace browser_sync |
OLD | NEW |