OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sync/sessions/ordered_commit_set.h" | |
6 #include "sync/test/engine/test_id_factory.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 using std::vector; | |
10 | |
11 namespace syncer { | |
12 namespace sessions { | |
13 namespace { | |
14 | |
15 class OrderedCommitSetTest : public testing::Test { | |
16 public: | |
17 OrderedCommitSetTest() {} | |
18 protected: | |
19 TestIdFactory ids_; | |
20 }; | |
21 | |
22 TEST_F(OrderedCommitSetTest, Insertions) { | |
23 vector<int64> expected; | |
24 for (int64 i = 0; i < 8; i++) | |
25 expected.push_back(i); | |
26 | |
27 OrderedCommitSet commit_set1, commit_set2; | |
28 commit_set1.AddCommitItem(expected[0], BOOKMARKS); | |
29 commit_set1.AddCommitItem(expected[1], BOOKMARKS); | |
30 commit_set1.AddCommitItem(expected[2], PREFERENCES); | |
31 // Duplicates should be dropped. | |
32 commit_set1.AddCommitItem(expected[2], PREFERENCES); | |
33 commit_set1.AddCommitItem(expected[3], SESSIONS); | |
34 commit_set1.AddCommitItem(expected[4], SESSIONS); | |
35 commit_set2.AddCommitItem(expected[7], AUTOFILL); | |
36 commit_set2.AddCommitItem(expected[6], AUTOFILL); | |
37 commit_set2.AddCommitItem(expected[5], AUTOFILL); | |
38 // Add something in set1 to set2, which should get dropped by AppendReverse. | |
39 commit_set2.AddCommitItem(expected[0], BOOKMARKS); | |
40 commit_set1.AppendReverse(commit_set2); | |
41 | |
42 EXPECT_EQ(8U, commit_set1.Size()); | |
43 | |
44 // First, we should verify the projections are correct. Second, we want to | |
45 // do the same verification after truncating by 1. Next, try truncating | |
46 // the set to a size of 4, so that the DB projection is wiped out and | |
47 // PASSIVE has one element removed. Finally, truncate to 1 so only UI is | |
48 // remaining. | |
49 std::vector<size_t> sizes; | |
50 sizes.push_back(8); | |
51 sizes.push_back(7); | |
52 sizes.push_back(4); | |
53 sizes.push_back(1); | |
54 for (std::vector<size_t>::iterator it = sizes.begin(); | |
55 it != sizes.end(); ++it) { | |
56 commit_set1.Truncate(*it); | |
57 size_t expected_size = *it; | |
58 | |
59 SCOPED_TRACE(::testing::Message("Iteration size = ") << *it); | |
60 std::vector<int64> all_ids = commit_set1.GetAllCommitHandles(); | |
61 EXPECT_EQ(expected_size, all_ids.size()); | |
62 for (size_t i = 0; i < expected_size; i++) { | |
63 EXPECT_TRUE(expected[i] == all_ids[i]); | |
64 EXPECT_TRUE(expected[i] == commit_set1.GetCommitHandleAt(i)); | |
65 } | |
66 } | |
67 } | |
68 | |
69 TEST_F(OrderedCommitSetTest, HasBookmarkCommitId) { | |
70 OrderedCommitSet commit_set; | |
71 | |
72 commit_set.AddCommitItem(0, AUTOFILL); | |
73 commit_set.AddCommitItem(1, SESSIONS); | |
74 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); | |
75 | |
76 commit_set.AddCommitItem(2, PREFERENCES); | |
77 commit_set.AddCommitItem(3, PREFERENCES); | |
78 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); | |
79 | |
80 commit_set.AddCommitItem(4, BOOKMARKS); | |
81 EXPECT_TRUE(commit_set.HasBookmarkCommitId()); | |
82 | |
83 commit_set.Truncate(4); | |
84 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); | |
85 } | |
86 | |
87 TEST_F(OrderedCommitSetTest, AddAndRemoveEntries) { | |
88 OrderedCommitSet commit_set; | |
89 | |
90 ASSERT_TRUE(commit_set.Empty()); | |
91 | |
92 commit_set.AddCommitItem(0, AUTOFILL); | |
93 ASSERT_EQ(static_cast<size_t>(1), commit_set.Size()); | |
94 | |
95 commit_set.Clear(); | |
96 ASSERT_TRUE(commit_set.Empty()); | |
97 } | |
98 | |
99 } // namespace | |
100 } // namespace sessions | |
101 } // namespace syncer | |
OLD | NEW |