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

Side by Side Diff: chrome/browser/sync/sessions/sync_session_unittest.cc

Issue 6182004: [SYNC] Refactor SyncSourceInfo and add support in chrome invalidation client ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Missing static for global const Created 9 years, 11 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) 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 "chrome/browser/sync/engine/conflict_resolver.h" 7 #include "chrome/browser/sync/engine/conflict_resolver.h"
8 #include "chrome/browser/sync/engine/syncer_types.h" 8 #include "chrome/browser/sync/engine/syncer_types.h"
9 #include "chrome/browser/sync/engine/syncer_util.h" 9 #include "chrome/browser/sync/engine/syncer_util.h"
10 #include "chrome/browser/sync/syncable/directory_manager.h" 10 #include "chrome/browser/sync/syncable/directory_manager.h"
11 #include "chrome/browser/sync/syncable/model_type.h"
11 #include "chrome/browser/sync/syncable/syncable.h" 12 #include "chrome/browser/sync/syncable/syncable.h"
12 #include "chrome/test/sync/engine/test_directory_setter_upper.h" 13 #include "chrome/test/sync/engine/test_directory_setter_upper.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 using syncable::WriteTransaction; 16 using syncable::WriteTransaction;
16 17
17 namespace browser_sync { 18 namespace browser_sync {
18 namespace sessions { 19 namespace sessions {
19 namespace { 20 namespace {
20 21
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 244 }
244 245
245 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) { 246 TEST_F(SyncSessionTest, MoreToSyncIfConflictsResolved) {
246 // Conflict resolution happens after get updates and commit, 247 // Conflict resolution happens after get updates and commit,
247 // so we need to loop back and get updates / commit again now 248 // so we need to loop back and get updates / commit again now
248 // that we have made forward progress. 249 // that we have made forward progress.
249 status()->update_conflicts_resolved(true); 250 status()->update_conflicts_resolved(true);
250 EXPECT_TRUE(session_->HasMoreToSync()); 251 EXPECT_TRUE(session_->HasMoreToSync());
251 } 252 }
252 253
254 TEST_F(SyncSessionTest, ModelTypeBitSetToTypePayloadMap) {
255 syncable::ModelTypeBitSet types;
256 std::string payload = "test";
257 TypePayloadMap map = ModelTypeBitSetToTypePayloadMap(types, payload);
258 EXPECT_TRUE(map.empty());
259
260 types[syncable::BOOKMARKS] = true;
261 types[syncable::PASSWORDS] = true;
262 types[syncable::AUTOFILL] = true;
263 payload = "test2";
264 map = ModelTypeBitSetToTypePayloadMap(types, payload);
265
266 ASSERT_EQ(3U, map.size());
267 EXPECT_TRUE(map[syncable::BOOKMARKS] == payload);
268 EXPECT_TRUE(map[syncable::PASSWORDS] == payload);
269 EXPECT_TRUE(map[syncable::AUTOFILL] == payload);
270 }
271
272 TEST_F(SyncSessionTest, RoutingInfoToTypePayloadMap) {
273 std::string payload = "test";
274 TypePayloadMap map = RoutingInfoToTypePayloadMap(routes_, payload);
275 ASSERT_EQ(routes_.size(), map.size());
276 for (ModelSafeRoutingInfo::iterator iter = routes_.begin();
277 iter != routes_.end();
278 ++iter) {
279 EXPECT_EQ(payload, map[iter->first]);
280 }
281 }
282
283 TEST_F(SyncSessionTest, CoalescePayloads) {
284 TypePayloadMap original;
285 std::string empty_payload;
286 std::string payload1 = "payload1";
287 std::string payload2 = "payload2";
288 std::string payload3 = "payload3";
289 original[syncable::BOOKMARKS] = empty_payload;
290 original[syncable::PASSWORDS] = payload1;
291 original[syncable::AUTOFILL] = payload2;
292 original[syncable::THEMES] = payload3;
293
294 TypePayloadMap update;
295 update[syncable::BOOKMARKS] = empty_payload; // Same.
296 update[syncable::PASSWORDS] = empty_payload; // Overwrite with empty.
297 update[syncable::AUTOFILL] = payload1; // Overwrite with non-empty.
298 update[syncable::SESSIONS] = payload2; // New.
299 // Themes untouched.
300
301 TypePayloadMap new_map = CoalescePayloads(original, update);
302 ASSERT_EQ(5U, new_map.size());
303 EXPECT_EQ(empty_payload, new_map[syncable::BOOKMARKS]);
304 EXPECT_EQ(payload1, new_map[syncable::PASSWORDS]);
305 EXPECT_EQ(payload1, new_map[syncable::AUTOFILL]);
306 EXPECT_EQ(payload2, new_map[syncable::SESSIONS]);
307 EXPECT_EQ(payload3, new_map[syncable::THEMES]);
308 }
309
253 } // namespace 310 } // namespace
254 } // namespace sessions 311 } // namespace sessions
255 } // namespace browser_sync 312 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698