OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "sync/sessions/ordered_commit_set.h" | 5 #include "sync/sessions/ordered_commit_set.h" |
6 #include "sync/test/engine/test_id_factory.h" | 6 #include "sync/test/engine/test_id_factory.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 using std::vector; | 9 using std::vector; |
10 | 10 |
11 namespace syncer { | 11 namespace syncer { |
12 namespace sessions { | 12 namespace sessions { |
13 namespace { | 13 namespace { |
14 | 14 |
15 class OrderedCommitSetTest : public testing::Test { | 15 class OrderedCommitSetTest : public testing::Test { |
16 public: | 16 public: |
17 OrderedCommitSetTest() { | 17 OrderedCommitSetTest() { |
18 routes_[BOOKMARKS] = GROUP_UI; | 18 routes_[BOOKMARKS] = GROUP_UI; |
19 routes_[PREFERENCES] = GROUP_UI; | 19 routes_[PREFERENCES] = GROUP_UI; |
20 routes_[AUTOFILL] = GROUP_DB; | 20 routes_[AUTOFILL] = GROUP_DB; |
21 routes_[TOP_LEVEL_FOLDER] = GROUP_PASSIVE; | 21 routes_[SESSIONS] = GROUP_PASSIVE; |
22 } | 22 } |
23 protected: | 23 protected: |
24 TestIdFactory ids_; | 24 TestIdFactory ids_; |
25 ModelSafeRoutingInfo routes_; | 25 ModelSafeRoutingInfo routes_; |
26 }; | 26 }; |
27 | 27 |
28 TEST_F(OrderedCommitSetTest, Projections) { | 28 TEST_F(OrderedCommitSetTest, Projections) { |
29 vector<syncable::Id> expected; | 29 vector<syncable::Id> expected; |
30 for (int i = 0; i < 8; i++) | 30 for (int i = 0; i < 8; i++) |
31 expected.push_back(ids_.NewLocalId()); | 31 expected.push_back(ids_.NewLocalId()); |
32 | 32 |
33 OrderedCommitSet commit_set1(routes_), commit_set2(routes_); | 33 OrderedCommitSet commit_set1(routes_), commit_set2(routes_); |
34 commit_set1.AddCommitItem(0, expected[0], BOOKMARKS); | 34 commit_set1.AddCommitItem(0, expected[0], BOOKMARKS); |
35 commit_set1.AddCommitItem(1, expected[1], BOOKMARKS); | 35 commit_set1.AddCommitItem(1, expected[1], BOOKMARKS); |
36 commit_set1.AddCommitItem(2, expected[2], PREFERENCES); | 36 commit_set1.AddCommitItem(2, expected[2], PREFERENCES); |
37 // Duplicates should be dropped. | 37 // Duplicates should be dropped. |
38 commit_set1.AddCommitItem(2, expected[2], PREFERENCES); | 38 commit_set1.AddCommitItem(2, expected[2], PREFERENCES); |
39 commit_set1.AddCommitItem(3, expected[3], TOP_LEVEL_FOLDER); | 39 commit_set1.AddCommitItem(3, expected[3], SESSIONS); |
40 commit_set1.AddCommitItem(4, expected[4], TOP_LEVEL_FOLDER); | 40 commit_set1.AddCommitItem(4, expected[4], SESSIONS); |
41 commit_set2.AddCommitItem(7, expected[7], AUTOFILL); | 41 commit_set2.AddCommitItem(7, expected[7], AUTOFILL); |
42 commit_set2.AddCommitItem(6, expected[6], AUTOFILL); | 42 commit_set2.AddCommitItem(6, expected[6], AUTOFILL); |
43 commit_set2.AddCommitItem(5, expected[5], AUTOFILL); | 43 commit_set2.AddCommitItem(5, expected[5], AUTOFILL); |
44 // Add something in set1 to set2, which should get dropped by AppendReverse. | 44 // Add something in set1 to set2, which should get dropped by AppendReverse. |
45 commit_set2.AddCommitItem(0, expected[0], BOOKMARKS); | 45 commit_set2.AddCommitItem(0, expected[0], BOOKMARKS); |
46 commit_set1.AppendReverse(commit_set2); | 46 commit_set1.AppendReverse(commit_set2); |
47 | 47 |
48 // First, we should verify the projections are correct. Second, we want to | 48 // First, we should verify the projections are correct. Second, we want to |
49 // do the same verification after truncating by 1. Next, try truncating | 49 // do the same verification after truncating by 1. Next, try truncating |
50 // the set to a size of 4, so that the DB projection is wiped out and | 50 // the set to a size of 4, so that the DB projection is wiped out and |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 expected.resize(cut_to_size); | 96 expected.resize(cut_to_size); |
97 commit_set1.Truncate(cut_to_size); | 97 commit_set1.Truncate(cut_to_size); |
98 } while (true); | 98 } while (true); |
99 } | 99 } |
100 | 100 |
101 TEST_F(OrderedCommitSetTest, HasBookmarkCommitId) { | 101 TEST_F(OrderedCommitSetTest, HasBookmarkCommitId) { |
102 OrderedCommitSet commit_set(routes_); | 102 OrderedCommitSet commit_set(routes_); |
103 | 103 |
104 commit_set.AddCommitItem(0, ids_.NewLocalId(), AUTOFILL); | 104 commit_set.AddCommitItem(0, ids_.NewLocalId(), AUTOFILL); |
105 commit_set.AddCommitItem(1, ids_.NewLocalId(), TOP_LEVEL_FOLDER); | 105 commit_set.AddCommitItem(1, ids_.NewLocalId(), SESSIONS); |
106 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); | 106 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); |
107 | 107 |
108 commit_set.AddCommitItem(2, ids_.NewLocalId(), PREFERENCES); | 108 commit_set.AddCommitItem(2, ids_.NewLocalId(), PREFERENCES); |
109 commit_set.AddCommitItem(3, ids_.NewLocalId(), PREFERENCES); | 109 commit_set.AddCommitItem(3, ids_.NewLocalId(), PREFERENCES); |
110 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); | 110 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); |
111 | 111 |
112 commit_set.AddCommitItem(4, ids_.NewLocalId(), BOOKMARKS); | 112 commit_set.AddCommitItem(4, ids_.NewLocalId(), BOOKMARKS); |
113 EXPECT_TRUE(commit_set.HasBookmarkCommitId()); | 113 EXPECT_TRUE(commit_set.HasBookmarkCommitId()); |
114 | 114 |
115 commit_set.Truncate(4); | 115 commit_set.Truncate(4); |
116 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); | 116 EXPECT_FALSE(commit_set.HasBookmarkCommitId()); |
117 } | 117 } |
118 | 118 |
119 TEST_F(OrderedCommitSetTest, AddAndRemoveEntries) { | 119 TEST_F(OrderedCommitSetTest, AddAndRemoveEntries) { |
120 OrderedCommitSet commit_set(routes_); | 120 OrderedCommitSet commit_set(routes_); |
121 | 121 |
122 ASSERT_TRUE(commit_set.Empty()); | 122 ASSERT_TRUE(commit_set.Empty()); |
123 | 123 |
124 commit_set.AddCommitItem(0, ids_.NewLocalId(), AUTOFILL); | 124 commit_set.AddCommitItem(0, ids_.NewLocalId(), AUTOFILL); |
125 ASSERT_EQ(static_cast<size_t>(1), commit_set.Size()); | 125 ASSERT_EQ(static_cast<size_t>(1), commit_set.Size()); |
126 | 126 |
127 commit_set.Clear(); | 127 commit_set.Clear(); |
128 ASSERT_TRUE(commit_set.Empty()); | 128 ASSERT_TRUE(commit_set.Empty()); |
129 } | 129 } |
130 | 130 |
131 } // namespace | 131 } // namespace |
132 } // namespace sessions | 132 } // namespace sessions |
133 } // namespace syncer | 133 } // namespace syncer |
OLD | NEW |