OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/sessions/sync_session.h" | 5 #include "chrome/browser/sync/sessions/sync_session.h" |
6 | 6 |
7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
8 #include "chrome/browser/sync/engine/conflict_resolver.h" | 8 #include "chrome/browser/sync/engine/conflict_resolver.h" |
9 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" | 9 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" |
10 #include "chrome/browser/sync/engine/syncer_types.h" | 10 #include "chrome/browser/sync/engine/syncer_types.h" |
11 #include "chrome/browser/sync/engine/syncer_util.h" | 11 #include "chrome/browser/sync/engine/syncer_util.h" |
12 #include "chrome/browser/sync/syncable/directory_manager.h" | 12 #include "chrome/browser/sync/syncable/directory_manager.h" |
13 #include "chrome/browser/sync/syncable/model_type.h" | |
14 #include "chrome/browser/sync/syncable/syncable.h" | 13 #include "chrome/browser/sync/syncable/syncable.h" |
15 #include "chrome/test/sync/engine/test_directory_setter_upper.h" | 14 #include "chrome/test/sync/engine/test_directory_setter_upper.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 | 16 |
18 using syncable::WriteTransaction; | 17 using syncable::WriteTransaction; |
19 | 18 |
20 namespace browser_sync { | 19 namespace browser_sync { |
21 namespace sessions { | 20 namespace sessions { |
22 namespace { | 21 namespace { |
23 | 22 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 245 } |
247 | 246 |
248 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { | 247 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { |
249 // Conflict resolution happens after get updates and commit, | 248 // Conflict resolution happens after get updates and commit, |
250 // so we need to loop back and get updates / commit again now | 249 // so we need to loop back and get updates / commit again now |
251 // that we have made forward progress. | 250 // that we have made forward progress. |
252 status()->update_conflicts_resolved(true); | 251 status()->update_conflicts_resolved(true); |
253 EXPECT_TRUE(session_->HasMoreToSync()); | 252 EXPECT_TRUE(session_->HasMoreToSync()); |
254 } | 253 } |
255 | 254 |
256 TEST_F(SyncSessionTest, ModelTypeBitSetToTypePayloadMap) { | |
257 syncable::ModelTypeBitSet types; | |
258 std::string payload = "test"; | |
259 TypePayloadMap types_with_payloads = | |
260 ModelTypeBitSetToTypePayloadMap(types, payload); | |
261 EXPECT_TRUE(types_with_payloads.empty()); | |
262 | |
263 types[syncable::BOOKMARKS] = true; | |
264 types[syncable::PASSWORDS] = true; | |
265 types[syncable::AUTOFILL] = true; | |
266 payload = "test2"; | |
267 types_with_payloads = ModelTypeBitSetToTypePayloadMap(types, payload); | |
268 | |
269 ASSERT_EQ(3U, types_with_payloads.size()); | |
270 EXPECT_EQ(types_with_payloads[syncable::BOOKMARKS], payload); | |
271 EXPECT_EQ(types_with_payloads[syncable::PASSWORDS], payload); | |
272 EXPECT_EQ(types_with_payloads[syncable::AUTOFILL], payload); | |
273 } | |
274 | |
275 TEST_F(SyncSessionTest, RoutingInfoToTypePayloadMap) { | |
276 std::string payload = "test"; | |
277 TypePayloadMap types_with_payloads | |
278 = RoutingInfoToTypePayloadMap(routes_, payload); | |
279 ASSERT_EQ(routes_.size(), types_with_payloads.size()); | |
280 for (ModelSafeRoutingInfo::iterator iter = routes_.begin(); | |
281 iter != routes_.end(); | |
282 ++iter) { | |
283 EXPECT_EQ(payload, types_with_payloads[iter->first]); | |
284 } | |
285 } | |
286 | |
287 TEST_F(SyncSessionTest, CoalescePayloads) { | |
288 TypePayloadMap original; | |
289 std::string empty_payload; | |
290 std::string payload1 = "payload1"; | |
291 std::string payload2 = "payload2"; | |
292 std::string payload3 = "payload3"; | |
293 original[syncable::BOOKMARKS] = empty_payload; | |
294 original[syncable::PASSWORDS] = payload1; | |
295 original[syncable::AUTOFILL] = payload2; | |
296 original[syncable::THEMES] = payload3; | |
297 | |
298 TypePayloadMap update; | |
299 update[syncable::BOOKMARKS] = empty_payload; // Same. | |
300 update[syncable::PASSWORDS] = empty_payload; // Overwrite with empty. | |
301 update[syncable::AUTOFILL] = payload1; // Overwrite with non-empty. | |
302 update[syncable::SESSIONS] = payload2; // New. | |
303 // Themes untouched. | |
304 | |
305 CoalescePayloads(&original, update); | |
306 ASSERT_EQ(5U, original.size()); | |
307 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); | |
308 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); | |
309 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); | |
310 EXPECT_EQ(payload2, original[syncable::SESSIONS]); | |
311 EXPECT_EQ(payload3, original[syncable::THEMES]); | |
312 } | |
313 | |
314 TEST_F(SyncSessionTest, ResetTransientState) { | 255 TEST_F(SyncSessionTest, ResetTransientState) { |
315 status()->update_conflicts_resolved(true); | 256 status()->update_conflicts_resolved(true); |
316 status()->increment_num_successful_commits(); | 257 status()->increment_num_successful_commits(); |
317 EXPECT_TRUE(session_->HasMoreToSync()); | 258 EXPECT_TRUE(session_->HasMoreToSync()); |
318 session_->ResetTransientState(); | 259 session_->ResetTransientState(); |
319 EXPECT_FALSE(status()->conflicts_resolved()); | 260 EXPECT_FALSE(status()->conflicts_resolved()); |
320 EXPECT_FALSE(session_->HasMoreToSync()); | 261 EXPECT_FALSE(session_->HasMoreToSync()); |
321 EXPECT_FALSE(status()->TestAndClearIsDirty()); | 262 EXPECT_FALSE(status()->TestAndClearIsDirty()); |
322 } | 263 } |
323 | 264 |
(...skipping 24 matching lines...) Expand all Loading... |
348 std::vector<ModelSafeWorker*>::const_iterator it_ui = | 289 std::vector<ModelSafeWorker*>::const_iterator it_ui = |
349 std::find(one.workers().begin(), one.workers().end(), ui_worker); | 290 std::find(one.workers().begin(), one.workers().end(), ui_worker); |
350 EXPECT_NE(it_db, one.workers().end()); | 291 EXPECT_NE(it_db, one.workers().end()); |
351 EXPECT_NE(it_ui, one.workers().end()); | 292 EXPECT_NE(it_ui, one.workers().end()); |
352 EXPECT_EQ(routes_two, one.routing_info()); | 293 EXPECT_EQ(routes_two, one.routing_info()); |
353 } | 294 } |
354 | 295 |
355 } // namespace | 296 } // namespace |
356 } // namespace sessions | 297 } // namespace sessions |
357 } // namespace browser_sync | 298 } // namespace browser_sync |
OLD | NEW |