OLD | NEW |
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_host.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/browser/sync/engine/model_safe_worker.h" | 11 #include "chrome/browser/sync/engine/model_safe_worker.h" |
12 #include "chrome/browser/sync/engine/syncapi.h" | 12 #include "chrome/browser/sync/engine/syncapi.h" |
13 #include "chrome/browser/sync/glue/data_type_controller.h" | |
14 #include "chrome/browser/sync/syncable/model_type.h" | 13 #include "chrome/browser/sync/syncable/model_type.h" |
15 #include "chrome/test/base/test_url_request_context_getter.h" | 14 #include "chrome/test/base/test_url_request_context_getter.h" |
16 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
17 #include "chrome/test/testing_browser_process_test.h" | 16 #include "chrome/test/testing_browser_process_test.h" |
18 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
19 #include "content/common/url_fetcher.h" | 18 #include "content/common/url_fetcher.h" |
20 #include "content/test/test_url_fetcher_factory.h" | 19 #include "content/test/test_url_fetcher_factory.h" |
21 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 WeakHandle<JsEventHandler>(), | 104 WeakHandle<JsEventHandler>(), |
106 GURL(k_mock_url), | 105 GURL(k_mock_url), |
107 syncable::ModelTypeSet(), | 106 syncable::ModelTypeSet(), |
108 credentials, | 107 credentials, |
109 true); | 108 true); |
110 backend.Shutdown(false); | 109 backend.Shutdown(false); |
111 } | 110 } |
112 | 111 |
113 TEST_F(SyncBackendHostTest, GetPendingConfigModeState) { | 112 TEST_F(SyncBackendHostTest, GetPendingConfigModeState) { |
114 SyncBackendHost::PendingConfigureDataTypesState state; | 113 SyncBackendHost::PendingConfigureDataTypesState state; |
115 bool deleted_type = false; | |
116 | 114 |
117 // Empty. | 115 // Empty. |
118 { | 116 { |
119 DataTypeController::TypeMap data_type_controllers; | 117 syncable::ModelTypeSet types_to_add; |
120 syncable::ModelTypeSet types; | 118 syncable::ModelTypeSet types_to_remove; |
121 ModelSafeRoutingInfo routing_info; | 119 ModelSafeRoutingInfo routing_info; |
122 | 120 |
123 SyncBackendHost::GetPendingConfigModeState( | 121 SyncBackendHost::GetPendingConfigModeState( |
124 data_type_controllers, types, base::Callback<void(bool)>(), | 122 types_to_add, types_to_remove, base::Callback<void(bool)>(), |
125 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, | 123 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, |
126 false, &state, &deleted_type); | 124 &state); |
127 | 125 |
128 EXPECT_TRUE(routing_info.empty()); | 126 EXPECT_TRUE(routing_info.empty()); |
129 EXPECT_TRUE(state.ready_task.is_null()); | 127 EXPECT_TRUE(state.ready_task.is_null()); |
130 EXPECT_EQ(types, state.initial_types); | 128 EXPECT_TRUE(state.types_to_add.empty()); |
131 EXPECT_FALSE(deleted_type); | 129 EXPECT_TRUE(state.added_types.empty()); |
132 EXPECT_TRUE(state.added_types.none()); | |
133 } | |
134 | |
135 // No enabled types. | |
136 { | |
137 DataTypeController::TypeMap data_type_controllers; | |
138 data_type_controllers[syncable::BOOKMARKS] = NULL; | |
139 syncable::ModelTypeSet types; | |
140 ModelSafeRoutingInfo routing_info; | |
141 | |
142 types.insert(syncable::NIGORI); | |
143 SyncBackendHost::GetPendingConfigModeState( | |
144 data_type_controllers, types, base::Callback<void(bool)>(), | |
145 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, | |
146 true, &state, &deleted_type); | |
147 | |
148 EXPECT_TRUE(routing_info.empty()); | |
149 EXPECT_TRUE(state.ready_task.is_null()); | |
150 EXPECT_EQ(types, state.initial_types); | |
151 EXPECT_TRUE(deleted_type); | |
152 EXPECT_TRUE(state.added_types.none()); | |
153 } | 130 } |
154 | 131 |
155 // Add type. | 132 // Add type. |
156 { | 133 { |
157 DataTypeController::TypeMap data_type_controllers; | 134 syncable::ModelTypeSet types_to_add; |
158 data_type_controllers[syncable::BOOKMARKS] = NULL; | 135 types_to_add.insert(syncable::BOOKMARKS); |
159 syncable::ModelTypeSet types; | 136 syncable::ModelTypeSet types_to_remove; |
160 types.insert(syncable::BOOKMARKS); | |
161 types.insert(syncable::NIGORI); | |
162 ModelSafeRoutingInfo routing_info; | 137 ModelSafeRoutingInfo routing_info; |
163 | 138 |
164 SyncBackendHost::GetPendingConfigModeState( | 139 SyncBackendHost::GetPendingConfigModeState( |
165 data_type_controllers, types, base::Callback<void(bool)>(), | 140 types_to_add, types_to_remove, base::Callback<void(bool)>(), |
166 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, | 141 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, |
167 true, &state, &deleted_type); | 142 &state); |
168 | 143 |
169 ModelSafeRoutingInfo expected_routing_info; | 144 ModelSafeRoutingInfo expected_routing_info; |
170 expected_routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; | 145 expected_routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; |
171 EXPECT_EQ(expected_routing_info, routing_info); | 146 EXPECT_EQ(expected_routing_info, routing_info); |
172 EXPECT_TRUE(state.ready_task.is_null()); | 147 EXPECT_TRUE(state.ready_task.is_null()); |
173 EXPECT_EQ(types, state.initial_types); | 148 EXPECT_EQ(types_to_add, state.types_to_add); |
174 EXPECT_FALSE(deleted_type); | 149 EXPECT_EQ(types_to_add, state.added_types); |
175 | |
176 syncable::ModelTypeBitSet expected_added_types; | |
177 expected_added_types.set(syncable::BOOKMARKS); | |
178 EXPECT_EQ(expected_added_types, state.added_types); | |
179 } | 150 } |
180 | 151 |
181 // Add existing type. | 152 // Add existing type. |
182 { | 153 { |
183 DataTypeController::TypeMap data_type_controllers; | 154 syncable::ModelTypeSet types_to_add; |
184 data_type_controllers[syncable::BOOKMARKS] = NULL; | 155 types_to_add.insert(syncable::BOOKMARKS); |
185 syncable::ModelTypeSet types; | 156 syncable::ModelTypeSet types_to_remove; |
186 types.insert(syncable::BOOKMARKS); | |
187 types.insert(syncable::NIGORI); | |
188 ModelSafeRoutingInfo routing_info; | 157 ModelSafeRoutingInfo routing_info; |
189 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; | 158 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; |
190 ModelSafeRoutingInfo expected_routing_info = routing_info; | 159 ModelSafeRoutingInfo expected_routing_info = routing_info; |
191 | 160 |
192 SyncBackendHost::GetPendingConfigModeState( | 161 SyncBackendHost::GetPendingConfigModeState( |
193 data_type_controllers, types, base::Callback<void(bool)>(), | 162 types_to_add, types_to_remove, base::Callback<void(bool)>(), |
194 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, | 163 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, |
195 true, &state, &deleted_type); | 164 &state); |
196 | 165 |
197 EXPECT_EQ(expected_routing_info, routing_info); | 166 EXPECT_EQ(expected_routing_info, routing_info); |
198 EXPECT_TRUE(state.ready_task.is_null()); | 167 EXPECT_TRUE(state.ready_task.is_null()); |
199 EXPECT_EQ(types, state.initial_types); | 168 EXPECT_EQ(types_to_add, state.types_to_add); |
200 EXPECT_FALSE(deleted_type); | 169 EXPECT_TRUE(state.added_types.empty()); |
201 EXPECT_TRUE(state.added_types.none()); | |
202 } | 170 } |
203 | 171 |
204 // Delete type. | 172 // Delete type. |
205 { | 173 { |
206 DataTypeController::TypeMap data_type_controllers; | 174 syncable::ModelTypeSet types_to_add; |
207 data_type_controllers[syncable::BOOKMARKS] = NULL; | 175 syncable::ModelTypeSet types_to_remove; |
208 syncable::ModelTypeSet types; | 176 types_to_remove.insert(syncable::BOOKMARKS); |
209 types.insert(syncable::NIGORI); | |
210 ModelSafeRoutingInfo routing_info; | 177 ModelSafeRoutingInfo routing_info; |
211 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; | 178 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE; |
212 | 179 |
213 SyncBackendHost::GetPendingConfigModeState( | 180 SyncBackendHost::GetPendingConfigModeState( |
214 data_type_controllers, types, base::Callback<void(bool)>(), | 181 types_to_add, types_to_remove, base::Callback<void(bool)>(), |
215 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, | 182 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, |
216 true, &state, &deleted_type); | 183 &state); |
217 | 184 |
218 ModelSafeRoutingInfo expected_routing_info; | 185 EXPECT_TRUE(routing_info.empty()); |
219 EXPECT_EQ(expected_routing_info, routing_info); | |
220 EXPECT_TRUE(state.ready_task.is_null()); | |
221 EXPECT_EQ(types, state.initial_types); | |
222 EXPECT_TRUE(deleted_type); | |
223 EXPECT_TRUE(state.added_types.none()); | |
224 } | 186 } |
225 | 187 |
226 // Add Nigori. | 188 // Delete nonexistent type. |
227 { | 189 { |
228 DataTypeController::TypeMap data_type_controllers; | 190 syncable::ModelTypeSet types_to_add; |
229 syncable::ModelTypeSet types; | 191 syncable::ModelTypeSet types_to_remove; |
230 types.insert(syncable::NIGORI); | 192 types_to_remove.insert(syncable::BOOKMARKS); |
231 ModelSafeRoutingInfo routing_info; | 193 ModelSafeRoutingInfo routing_info; |
232 | 194 |
233 SyncBackendHost::GetPendingConfigModeState( | 195 SyncBackendHost::GetPendingConfigModeState( |
234 data_type_controllers, types, base::Callback<void(bool)>(), | 196 types_to_add, types_to_remove, base::Callback<void(bool)>(), |
235 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, | 197 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, |
236 false, &state, &deleted_type); | 198 &state); |
237 | 199 |
238 ModelSafeRoutingInfo expected_routing_info; | 200 EXPECT_TRUE(routing_info.empty()); |
239 expected_routing_info[syncable::NIGORI] = GROUP_PASSIVE; | |
240 EXPECT_EQ(expected_routing_info, routing_info); | |
241 EXPECT_TRUE(state.ready_task.is_null()); | |
242 EXPECT_EQ(types, state.initial_types); | |
243 EXPECT_FALSE(deleted_type); | |
244 | |
245 syncable::ModelTypeBitSet expected_added_types; | |
246 expected_added_types.set(syncable::NIGORI); | |
247 EXPECT_EQ(expected_added_types, state.added_types); | |
248 } | |
249 | |
250 // Delete Nigori. | |
251 { | |
252 DataTypeController::TypeMap data_type_controllers; | |
253 syncable::ModelTypeSet types; | |
254 ModelSafeRoutingInfo routing_info; | |
255 routing_info[syncable::NIGORI] = GROUP_PASSIVE; | |
256 | |
257 SyncBackendHost::GetPendingConfigModeState( | |
258 data_type_controllers, types, base::Callback<void(bool)>(), | |
259 &routing_info, sync_api::CONFIGURE_REASON_RECONFIGURATION, | |
260 true, &state, &deleted_type); | |
261 | |
262 ModelSafeRoutingInfo expected_routing_info; | |
263 EXPECT_EQ(expected_routing_info, routing_info); | |
264 EXPECT_TRUE(state.ready_task.is_null()); | |
265 EXPECT_EQ(types, state.initial_types); | |
266 EXPECT_TRUE(deleted_type); | |
267 | |
268 EXPECT_TRUE(state.added_types.none()); | |
269 } | 201 } |
270 } | 202 } |
271 | 203 |
272 // TODO(akalin): Write more SyncBackendHost unit tests. | 204 // TODO(akalin): Write more SyncBackendHost unit tests. |
273 | 205 |
274 } // namespace browser_sync | 206 } // namespace browser_sync |
OLD | NEW |