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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 vector<syncable::Id> expected_order; | 531 vector<syncable::Id> expected_order; |
532 // The expected order is "x", "b", "c", "e", truncated appropriately. | 532 // The expected order is "x", "b", "c", "e", truncated appropriately. |
533 unsynced_handle_view.push_back(handle_e); | 533 unsynced_handle_view.push_back(handle_e); |
534 expected_order.push_back(ids_.MakeLocal("x")); | 534 expected_order.push_back(ids_.MakeLocal("x")); |
535 expected_order.push_back(ids_.MakeLocal("b")); | 535 expected_order.push_back(ids_.MakeLocal("b")); |
536 expected_order.push_back(ids_.MakeLocal("c")); | 536 expected_order.push_back(ids_.MakeLocal("c")); |
537 expected_order.push_back(ids_.MakeLocal("e")); | 537 expected_order.push_back(ids_.MakeLocal("e")); |
538 DoTruncationTest(dir, unsynced_handle_view, expected_order); | 538 DoTruncationTest(dir, unsynced_handle_view, expected_order); |
539 } | 539 } |
540 | 540 |
541 TEST_F(SyncerTest, GetCommitIdsFilterEntriesNeedingEncryption) { | |
542 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | |
543 ASSERT_TRUE(dir.good()); | |
544 int64 handle_x = CreateUnsyncedDirectory("X", ids_.MakeLocal("x")); | |
545 int64 handle_b = CreateUnsyncedDirectory("B", ids_.MakeLocal("b")); | |
546 int64 handle_c = CreateUnsyncedDirectory("C", ids_.MakeLocal("c")); | |
547 int64 handle_e = CreateUnsyncedDirectory("E", ids_.MakeLocal("e")); | |
548 int64 handle_f = CreateUnsyncedDirectory("F", ids_.MakeLocal("f")); | |
549 sync_pb::EncryptedData encrypted; | |
550 sync_pb::EntitySpecifics encrypted_bookmark; | |
551 encrypted_bookmark.mutable_encrypted(); | |
552 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | |
553 { | |
554 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | |
555 MutableEntry entry_x(&wtrans, GET_BY_HANDLE, handle_x); | |
556 MutableEntry entry_b(&wtrans, GET_BY_HANDLE, handle_b); | |
557 MutableEntry entry_c(&wtrans, GET_BY_HANDLE, handle_c); | |
558 MutableEntry entry_e(&wtrans, GET_BY_HANDLE, handle_e); | |
559 MutableEntry entry_f(&wtrans, GET_BY_HANDLE, handle_f); | |
560 entry_x.Put(SPECIFICS, encrypted_bookmark); | |
561 entry_b.Put(SPECIFICS, DefaultBookmarkSpecifics()); | |
562 entry_c.Put(SPECIFICS, DefaultBookmarkSpecifics()); | |
563 entry_e.Put(SPECIFICS, encrypted_bookmark); | |
564 entry_f.Put(SPECIFICS, DefaultPreferencesSpecifics()); | |
565 } | |
566 | |
567 syncable::ModelTypeSet encrypted_types; | |
568 encrypted_types.insert(syncable::BOOKMARKS); | |
569 syncable::Directory::UnsyncedMetaHandles unsynced_handles; | |
570 unsynced_handles.push_back(handle_x); | |
571 unsynced_handles.push_back(handle_b); | |
572 unsynced_handles.push_back(handle_c); | |
573 unsynced_handles.push_back(handle_e); | |
574 unsynced_handles.push_back(handle_f); | |
575 // The unencrypted bookmarks should be removed from the list. | |
576 syncable::Directory::UnsyncedMetaHandles expected_handles; | |
577 expected_handles.push_back(handle_x); // Was encrypted. | |
578 expected_handles.push_back(handle_e); // Was encrypted. | |
579 expected_handles.push_back(handle_f); // Does not require encryption. | |
580 { | |
581 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | |
582 GetCommitIdsCommand::FilterEntriesNeedingEncryption( | |
583 encrypted_types, | |
584 &wtrans, | |
585 &unsynced_handles); | |
586 EXPECT_EQ(expected_handles, unsynced_handles); | |
587 } | |
588 } | |
589 | |
590 // TODO(chron): More corner case unit tests around validation. | 541 // TODO(chron): More corner case unit tests around validation. |
591 TEST_F(SyncerTest, TestCommitMetahandleIterator) { | 542 TEST_F(SyncerTest, TestCommitMetahandleIterator) { |
592 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 543 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
593 ASSERT_TRUE(dir.good()); | 544 ASSERT_TRUE(dir.good()); |
594 StatusController* status = session_->status_controller(); | 545 StatusController* status = session_->status_controller(); |
595 const vector<int64>& unsynced(status->unsynced_handles()); | 546 const vector<int64>& unsynced(status->unsynced_handles()); |
596 | 547 |
597 { | 548 { |
598 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 549 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
599 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); | 550 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); |
(...skipping 4626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5226 Add(low_id_); | 5177 Add(low_id_); |
5227 Add(high_id_); | 5178 Add(high_id_); |
5228 SyncShareAsDelegate(); | 5179 SyncShareAsDelegate(); |
5229 ExpectLocalOrderIsByServerId(); | 5180 ExpectLocalOrderIsByServerId(); |
5230 } | 5181 } |
5231 | 5182 |
5232 const SyncerTest::CommitOrderingTest | 5183 const SyncerTest::CommitOrderingTest |
5233 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 5184 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
5234 | 5185 |
5235 } // namespace browser_sync | 5186 } // namespace browser_sync |
OLD | NEW |