Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / invalidation / impl / single_object_invalidation_set_unittest.cc
blob102fb73d49d5268c6355d296e2d68cd33af2a545
1 // Copyright 2014 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.
5 #include "components/invalidation/public/single_object_invalidation_set.h"
7 #include "components/invalidation/impl/invalidation_test_util.h"
8 #include "google/cacheinvalidation/types.pb.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace syncer {
13 namespace {
15 class SingleObjectInvalidationSetTest : public testing::Test {
16 public:
17 SingleObjectInvalidationSetTest()
18 : kId(ipc::invalidation::ObjectSource::TEST, "one") {
20 protected:
21 const invalidation::ObjectId kId;
24 TEST_F(SingleObjectInvalidationSetTest, InsertionAndOrdering) {
25 SingleObjectInvalidationSet l1;
26 SingleObjectInvalidationSet l2;
28 Invalidation inv0 = Invalidation::InitUnknownVersion(kId);
29 Invalidation inv1 = Invalidation::Init(kId, 1, "one");
30 Invalidation inv2 = Invalidation::Init(kId, 5, "five");
32 l1.Insert(inv0);
33 l1.Insert(inv1);
34 l1.Insert(inv2);
36 l2.Insert(inv1);
37 l2.Insert(inv2);
38 l2.Insert(inv0);
40 ASSERT_EQ(3U, l1.GetSize());
41 ASSERT_EQ(3U, l2.GetSize());
43 SingleObjectInvalidationSet::const_iterator it1 = l1.begin();
44 SingleObjectInvalidationSet::const_iterator it2 = l2.begin();
45 EXPECT_THAT(inv0, Eq(*it1));
46 EXPECT_THAT(inv0, Eq(*it2));
47 it1++;
48 it2++;
49 EXPECT_THAT(inv1, Eq(*it1));
50 EXPECT_THAT(inv1, Eq(*it2));
51 it1++;
52 it2++;
53 EXPECT_THAT(inv2, Eq(*it1));
54 EXPECT_THAT(inv2, Eq(*it2));
55 it1++;
56 it2++;
57 EXPECT_TRUE(it1 == l1.end());
58 EXPECT_TRUE(it2 == l2.end());
61 TEST_F(SingleObjectInvalidationSetTest, StartWithUnknownVersion) {
62 SingleObjectInvalidationSet list;
63 EXPECT_FALSE(list.StartsWithUnknownVersion());
65 list.Insert(Invalidation::Init(kId, 1, "one"));
66 EXPECT_FALSE(list.StartsWithUnknownVersion());
68 list.Insert(Invalidation::InitUnknownVersion(kId));
69 EXPECT_TRUE(list.StartsWithUnknownVersion());
71 list.Clear();
72 EXPECT_FALSE(list.StartsWithUnknownVersion());
75 TEST_F(SingleObjectInvalidationSetTest, SerializeEmpty) {
76 SingleObjectInvalidationSet list;
78 scoped_ptr<base::ListValue> value = list.ToValue();
79 ASSERT_TRUE(value.get());
80 SingleObjectInvalidationSet deserialized;
81 deserialized.ResetFromValue(*value.get());
82 EXPECT_TRUE(list == deserialized);
85 TEST_F(SingleObjectInvalidationSetTest, SerializeOne) {
86 SingleObjectInvalidationSet list;
87 list.Insert(Invalidation::Init(kId, 1, "one"));
89 scoped_ptr<base::ListValue> value = list.ToValue();
90 ASSERT_TRUE(value.get());
91 SingleObjectInvalidationSet deserialized;
92 deserialized.ResetFromValue(*value.get());
93 EXPECT_TRUE(list == deserialized);
96 TEST_F(SingleObjectInvalidationSetTest, SerializeMany) {
97 SingleObjectInvalidationSet list;
98 list.Insert(Invalidation::Init(kId, 1, "one"));
99 list.Insert(Invalidation::InitUnknownVersion(kId));
101 scoped_ptr<base::ListValue> value = list.ToValue();
102 ASSERT_TRUE(value.get());
103 SingleObjectInvalidationSet deserialized;
104 deserialized.ResetFromValue(*value.get());
105 EXPECT_TRUE(list == deserialized);
108 } // namespace
110 } // namespace syncer